Skip to content

Commit ee5e12d

Browse files
committed
Simplified PropertyManager unit tests.
1 parent 621f50c commit ee5e12d

File tree

1 file changed

+21
-53
lines changed

1 file changed

+21
-53
lines changed

test/TestPropertyManager.cpp

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace shellanything { namespace test
115115
ASSERT_EQ("The quick ${color fox jumps over the lazy dog.", expanded);
116116
}
117117
//--------------------------------------------------------------------------------------------------
118-
TEST_F(TestPropertyManager, testExpandRecursive)
118+
TEST_F(TestPropertyManager, testExpandRecursivePermutations)
119119
{
120120
PropertyManager & pmgr = PropertyManager::GetInstance();
121121

@@ -135,67 +135,35 @@ namespace shellanything { namespace test
135135

136136
//Assert that property registration order have no impact.
137137
//Test all permutations of ABC.
138+
static const char * permutations[] = {"abc", "acb", "bac", "bca", "cba", "cab"};
139+
static const size_t num_permutations = sizeof(permutations)/sizeof(permutations[0]);
140+
for(size_t i=0; i<num_permutations; i++)
138141
{
139142
pmgr.Clear();
140-
pmgr.SetProperty("first", "Silence"); // A
141-
pmgr.SetProperty("third", "Lambs"); // C
142-
pmgr.SetProperty("second", "${third}"); // B
143-
144-
//The second property should be expanded by a property reference ${third}
145-
std::string expanded = pmgr.Expand("${first} of the ${second}");
146-
147-
//Assert the property was expanded recursively
148-
ASSERT_EQ("Silence of the Lambs", expanded);
149-
}
150-
{
151-
pmgr.Clear();
152-
pmgr.SetProperty("second", "${third}"); // B
153-
pmgr.SetProperty("first", "Silence"); // A
154-
pmgr.SetProperty("third", "Lambs"); // C
155-
156-
//The second property should be expanded by a property reference ${third}
157-
std::string expanded = pmgr.Expand("${first} of the ${second}");
158-
159-
//Assert the property was expanded recursively
160-
ASSERT_EQ("Silence of the Lambs", expanded);
161-
}
162-
{
163-
pmgr.Clear();
164-
pmgr.SetProperty("second", "${third}"); // B
165-
pmgr.SetProperty("third", "Lambs"); // C
166-
pmgr.SetProperty("first", "Silence"); // A
167-
168-
//The second property should be expanded by a property reference ${third}
169-
std::string expanded = pmgr.Expand("${first} of the ${second}");
170-
171-
//Assert the property was expanded recursively
172-
ASSERT_EQ("Silence of the Lambs", expanded);
173-
}
174-
{
175-
pmgr.Clear();
176-
pmgr.SetProperty("third", "Lambs"); // C
177-
pmgr.SetProperty("second", "${third}"); // B
178-
pmgr.SetProperty("first", "Silence"); // A
179143

180-
//The second property should be expanded by a property reference ${third}
181-
std::string expanded = pmgr.Expand("${first} of the ${second}");
182-
183-
//Assert the property was expanded recursively
184-
ASSERT_EQ("Silence of the Lambs", expanded);
185-
}
186-
{
187-
pmgr.Clear();
188-
pmgr.SetProperty("third", "Lambs"); // C
189-
pmgr.SetProperty("first", "Silence"); // A
190-
pmgr.SetProperty("second", "${third}"); // B
144+
const char * permutation = permutations[i];
145+
size_t length = strlen(permutation);
146+
147+
//register permutations
148+
for(size_t j=0; j<length; j++)
149+
{
150+
char c = permutation[j];
151+
if (c == 'a')
152+
pmgr.SetProperty("first", "Silence"); // A
153+
else if (c == 'b')
154+
pmgr.SetProperty("second", "${third}"); // B
155+
else if (c == 'c')
156+
pmgr.SetProperty("third", "Lambs"); // C
157+
else
158+
FAIL() << "Unkown permutation character: " << c << ".";
159+
}
191160

192161
//The second property should be expanded by a property reference ${third}
193162
std::string expanded = pmgr.Expand("${first} of the ${second}");
194163

195164
//Assert the property was expanded recursively
196-
ASSERT_EQ("Silence of the Lambs", expanded);
165+
ASSERT_EQ("Silence of the Lambs", expanded) << "Failed testing permutation: " << permutation << ".";
197166
}
198-
199167
}
200168
//--------------------------------------------------------------------------------------------------
201169
TEST_F(TestPropertyManager, testExpandRecursiveReverseAlphabeticalOrder)

0 commit comments

Comments
 (0)