1 #include "CoreSuite.h"
2 #include "TestPathTest.h"
3
4
5 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestPathTest,
6 coreSuiteName() );
7
8
TestPathTest()9 TestPathTest::TestPathTest()
10 {
11 }
12
13
~TestPathTest()14 TestPathTest::~TestPathTest()
15 {
16 }
17
18
19 void
setUp()20 TestPathTest::setUp()
21 {
22 m_path = new CPPUNIT_NS::TestPath();
23 m_test1 = new CPPUNIT_NS::TestCase( "test1" );
24 m_test2 = new CPPUNIT_NS::TestCase( "test2" );
25 m_test3 = new CPPUNIT_NS::TestCase( "test3" );
26 m_test4 = new CPPUNIT_NS::TestCase( "test4" );
27
28 m_suite1 = new CPPUNIT_NS::TestSuite( "All Tests" );
29 m_suite2 = new CPPUNIT_NS::TestSuite( "Custom" );
30 m_testSuite2a = new CPPUNIT_NS::TestCase( "MyTest::testDefaultConstructor" );
31 m_testSuite2b = new CPPUNIT_NS::TestCase( "MyTest::testConstructor" );
32 m_suite2->addTest( m_testSuite2a );
33 m_suite2->addTest( m_testSuite2b );
34 m_suite1->addTest( m_suite2 );
35 }
36
37
38 void
tearDown()39 TestPathTest::tearDown()
40 {
41 delete m_suite1;
42 delete m_path;
43 delete m_test4;
44 delete m_test3;
45 delete m_test2;
46 delete m_test1;
47 }
48
49
50 void
testDefaultConstructor()51 TestPathTest::testDefaultConstructor()
52 {
53 CPPUNIT_ASSERT_EQUAL( 0, m_path->getTestCount() );
54 CPPUNIT_ASSERT( !m_path->isValid() );
55 }
56
57
58 void
testAddTest()59 TestPathTest::testAddTest()
60 {
61 m_path->add( m_test1 );
62 CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
63 CPPUNIT_ASSERT( m_path->isValid() );
64 CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
65 }
66
67
68 void
testGetTestAtThrow1()69 TestPathTest::testGetTestAtThrow1()
70 {
71 m_path->getTestAt( 0 );
72 }
73
74
75 void
testGetTestAtThrow2()76 TestPathTest::testGetTestAtThrow2()
77 {
78 m_path->add( m_test1 );
79 m_path->getTestAt( 1 );
80 }
81
82
83 void
testGetChildTest()84 TestPathTest::testGetChildTest()
85 {
86 m_path->add( m_test1 );
87 CPPUNIT_ASSERT( m_test1 == m_path->getChildTest() );
88 }
89
90
91 void
testGetChildTestManyTests()92 TestPathTest::testGetChildTestManyTests()
93 {
94 m_path->add( m_test1 );
95 m_path->add( m_test2 );
96 m_path->add( m_test3 );
97 CPPUNIT_ASSERT( m_test3 == m_path->getChildTest() );
98 }
99
100
101 void
testGetChildTestThrowIfNotValid()102 TestPathTest::testGetChildTestThrowIfNotValid()
103 {
104 m_path->getChildTest();
105 }
106
107
108 void
testAddPath()109 TestPathTest::testAddPath()
110 {
111 CPPUNIT_NS::TestPath path;
112 path.add( m_test2 );
113 path.add( m_test3 );
114
115 m_path->add( m_test1 );
116 m_path->add( path );
117
118 CPPUNIT_ASSERT_EQUAL( 3, m_path->getTestCount() );
119 CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
120 CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) );
121 CPPUNIT_ASSERT( m_test3 == m_path->getTestAt(2) );
122 }
123
124
125 void
testAddInvalidPath()126 TestPathTest::testAddInvalidPath()
127 {
128 CPPUNIT_NS::TestPath path;
129 m_path->add( path );
130
131 CPPUNIT_ASSERT( !m_path->isValid() );
132 }
133
134
135 void
testRemoveTests()136 TestPathTest::testRemoveTests()
137 {
138 m_path->add( m_test1 );
139 m_path->add( m_test2 );
140
141 m_path->removeTests();
142
143 CPPUNIT_ASSERT( !m_path->isValid() );
144 }
145
146
147 void
testRemoveTest()148 TestPathTest::testRemoveTest()
149 {
150 m_path->add( m_test1 );
151 m_path->add( m_test2 );
152
153 m_path->removeTest( 0 );
154
155 CPPUNIT_ASSERT_EQUAL( 1, m_path->getTestCount() );
156 CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(0) );
157 }
158
159
160 void
testRemoveTestThrow1()161 TestPathTest::testRemoveTestThrow1()
162 {
163 m_path->removeTest( -1 );
164 }
165
166
167 void
testRemoveTestThrow2()168 TestPathTest::testRemoveTestThrow2()
169 {
170 m_path->add( m_test1 );
171
172 m_path->removeTest( 1 );
173 }
174
175
176 void
testUp()177 TestPathTest::testUp()
178 {
179 m_path->add( m_test1 );
180
181 m_path->up();
182
183 CPPUNIT_ASSERT( !m_path->isValid() );
184 }
185
186
187 void
testUpThrow()188 TestPathTest::testUpThrow()
189 {
190 m_path->up();
191 }
192
193
194 void
testInsert()195 TestPathTest::testInsert()
196 {
197 m_path->add( m_test1 );
198
199 m_path->insert( m_test2, 0 );
200
201 CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() );
202 CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(0) );
203 CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(1) );
204 }
205
206
207 void
testInsertAtEnd()208 TestPathTest::testInsertAtEnd()
209 {
210 m_path->add( m_test1 );
211
212 m_path->insert( m_test2, 1 );
213
214 CPPUNIT_ASSERT_EQUAL( 2, m_path->getTestCount() );
215 CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
216 CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) );
217 }
218
219
220 void
testInsertThrow1()221 TestPathTest::testInsertThrow1()
222 {
223 m_path->insert( m_test1, -1 );
224 }
225
226
227 void
testInsertThrow2()228 TestPathTest::testInsertThrow2()
229 {
230 m_path->add( m_test1 );
231
232 m_path->insert( m_test1, 2 );
233 }
234
235
236 void
testInsertPath()237 TestPathTest::testInsertPath()
238 {
239 CPPUNIT_NS::TestPath path;
240 path.add( m_test2 );
241 path.add( m_test3 );
242
243 m_path->add( m_test1 );
244 m_path->add( m_test4 );
245 m_path->insert( path, 1 );
246
247 CPPUNIT_ASSERT_EQUAL( 4, m_path->getTestCount() );
248 CPPUNIT_ASSERT( m_test1 == m_path->getTestAt(0) );
249 CPPUNIT_ASSERT( m_test2 == m_path->getTestAt(1) );
250 CPPUNIT_ASSERT( m_test3 == m_path->getTestAt(2) );
251 CPPUNIT_ASSERT( m_test4 == m_path->getTestAt(3) );
252 }
253
254
255 void
testInsertPathThrow()256 TestPathTest::testInsertPathThrow()
257 {
258 CPPUNIT_NS::TestPath path;
259 path.add( m_test2 );
260
261 m_path->insert( path, 1 );
262 }
263
264
265 void
testInsertPathDontThrowIfInvalid()266 TestPathTest::testInsertPathDontThrowIfInvalid()
267 {
268 CPPUNIT_NS::TestPath path;
269 m_path->insert( path, 1 );
270 }
271
272
273 void
testRootConstructor()274 TestPathTest::testRootConstructor()
275 {
276 CPPUNIT_NS::TestPath path( m_test1 );
277 CPPUNIT_ASSERT( path.isValid() );
278 CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
279 CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
280 }
281
282
283 void
testPathSliceConstructorCopyUntilEnd()284 TestPathTest::testPathSliceConstructorCopyUntilEnd()
285 {
286 m_path->add( m_test1 );
287 m_path->add( m_test2 );
288 m_path->add( m_test3 );
289
290 CPPUNIT_NS::TestPath path( *m_path, 1 );
291
292 CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() );
293 CPPUNIT_ASSERT( m_test2 == path.getTestAt(0) );
294 CPPUNIT_ASSERT( m_test3 == path.getTestAt(1) );
295 }
296
297
298 void
testPathSliceConstructorCopySpecifiedCount()299 TestPathTest::testPathSliceConstructorCopySpecifiedCount()
300 {
301 m_path->add( m_test1 );
302 m_path->add( m_test2 );
303 m_path->add( m_test3 );
304
305 CPPUNIT_NS::TestPath path( *m_path, 0, 1 );
306
307 CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
308 CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
309 }
310
311
312 void
testPathSliceConstructorCopyNone()313 TestPathTest::testPathSliceConstructorCopyNone()
314 {
315 m_path->add( m_test1 );
316
317 CPPUNIT_NS::TestPath path( *m_path, 0, 0 );
318 CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() );
319 }
320
321
322 void
testPathSliceConstructorNegativeIndex()323 TestPathTest::testPathSliceConstructorNegativeIndex()
324 {
325 m_path->add( m_test1 );
326 m_path->add( m_test2 );
327
328 CPPUNIT_NS::TestPath path( *m_path, -1, 2 );
329
330 CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
331 CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
332 }
333
334
335 void
testPathSliceConstructorAfterEndIndex()336 TestPathTest::testPathSliceConstructorAfterEndIndex()
337 {
338 m_path->add( m_test1 );
339 m_path->add( m_test2 );
340
341 CPPUNIT_NS::TestPath path( *m_path, 2, 5 );
342
343 CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() );
344 }
345
346
347 void
testPathSliceConstructorNegativeIndexUntilEnd()348 TestPathTest::testPathSliceConstructorNegativeIndexUntilEnd()
349 {
350 m_path->add( m_test1 );
351 m_path->add( m_test2 );
352
353 CPPUNIT_NS::TestPath path( *m_path, -1 );
354
355 CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() );
356 CPPUNIT_ASSERT( m_test1 == path.getTestAt(0) );
357 CPPUNIT_ASSERT( m_test2 == path.getTestAt(1) );
358 }
359
360
361 void
testPathSliceConstructorNegativeIndexNone()362 TestPathTest::testPathSliceConstructorNegativeIndexNone()
363 {
364 m_path->add( m_test1 );
365 m_path->add( m_test2 );
366
367 CPPUNIT_NS::TestPath path( *m_path, -2, 1 );
368
369 CPPUNIT_ASSERT_EQUAL( 0, path.getTestCount() );
370 }
371
372
373 void
testToStringNoTest()374 TestPathTest::testToStringNoTest()
375 {
376 std::string expected = "/";
377 std::string actual = m_path->toString();
378
379 CPPUNIT_ASSERT_EQUAL( expected, actual );
380 }
381
382
383 void
testToStringOneTest()384 TestPathTest::testToStringOneTest()
385 {
386 m_path->add( m_test1 );
387
388 std::string expected = "/test1";
389 std::string actual = m_path->toString();
390
391 CPPUNIT_ASSERT_EQUAL( expected, actual );
392 }
393
394
395 void
testToStringHierarchy()396 TestPathTest::testToStringHierarchy()
397 {
398 m_path->add( m_suite1 );
399 m_path->add( m_suite2 );
400 m_path->add( m_suite2->getChildTestAt(0) );
401
402 std::string expected = "/All Tests/Custom/MyTest::testDefaultConstructor";
403 std::string actual = m_path->toString();
404
405 CPPUNIT_ASSERT_EQUAL( expected, actual );
406 }
407
408
409 void
testPathStringConstructorRoot()410 TestPathTest::testPathStringConstructorRoot()
411 {
412 CPPUNIT_NS::TestPath path( m_suite1, "/All Tests" );
413
414 CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
415 CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
416 }
417
418
419 void
testPathStringConstructorEmptyIsRoot()420 TestPathTest::testPathStringConstructorEmptyIsRoot()
421 {
422 CPPUNIT_NS::TestPath path( m_suite1, "" );
423
424 CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
425 CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
426 }
427
428
429 void
testPathStringConstructorHierarchy()430 TestPathTest::testPathStringConstructorHierarchy()
431 {
432 CPPUNIT_NS::TestPath path( m_suite1, "/All Tests/Custom/MyTest::testDefaultConstructor" );
433
434 CPPUNIT_ASSERT_EQUAL( 3, path.getTestCount() );
435 CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
436 CPPUNIT_ASSERT( m_suite2 == path.getTestAt(1) );
437 CPPUNIT_ASSERT( m_testSuite2a == path.getTestAt(2) );
438 }
439
440
441 void
testPathStringConstructorBadRootThrow()442 TestPathTest::testPathStringConstructorBadRootThrow()
443 {
444 CPPUNIT_NS::TestPath path( m_suite1, "/Custom" );
445 }
446
447
448 void
testPathStringConstructorRelativeRoot()449 TestPathTest::testPathStringConstructorRelativeRoot()
450 {
451 CPPUNIT_NS::TestPath path( m_suite1, "All Tests" );
452
453 CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
454 CPPUNIT_ASSERT( m_suite1 == path.getTestAt(0) );
455 }
456
457
458 void
testPathStringConstructorRelativeRoot2()459 TestPathTest::testPathStringConstructorRelativeRoot2()
460 {
461 CPPUNIT_NS::TestPath path( m_suite1, "Custom" );
462
463 CPPUNIT_ASSERT_EQUAL( 1, path.getTestCount() );
464 CPPUNIT_ASSERT( m_suite2 == path.getTestAt(0) );
465 }
466
467
468 void
testPathStringConstructorThrow1()469 TestPathTest::testPathStringConstructorThrow1()
470 {
471 CPPUNIT_NS::TestPath path( m_suite1, "/" );
472 }
473
474
475 void
testPathStringConstructorRelativeHierarchy()476 TestPathTest::testPathStringConstructorRelativeHierarchy()
477 {
478 CPPUNIT_NS::TestPath path( m_suite1, "Custom/MyTest::testConstructor" );
479
480 CPPUNIT_ASSERT_EQUAL( 2, path.getTestCount() );
481 CPPUNIT_ASSERT( m_suite2 == path.getTestAt(0) );
482 CPPUNIT_ASSERT( m_testSuite2b == path.getTestAt(1) );
483 }
484
485
486 void
testPathStringConstructorBadRelativeHierarchyThrow()487 TestPathTest::testPathStringConstructorBadRelativeHierarchyThrow()
488 {
489 CPPUNIT_NS::TestPath path( m_suite1, "Custom/MyBadTest::testConstructor" );
490 }
491