Imported Upstream version 2.81
[platform/upstream/libbullet.git] / UnitTests / cppunit / src / cppunit / TestRunner.cpp
1 #include <cppunit/config/SourcePrefix.h>
2 #include <cppunit/TestRunner.h>
3 #include <cppunit/TestPath.h>
4 #include <cppunit/TestResult.h>
5
6
7 CPPUNIT_NS_BEGIN
8
9
10 TestRunner::WrappingSuite::WrappingSuite( const std::string &name ) 
11     : TestSuite( name )
12 {
13 }
14
15
16 int 
17 TestRunner::WrappingSuite::getChildTestCount() const
18 {
19   if ( hasOnlyOneTest() )
20     return getUniqueChildTest()->getChildTestCount();
21   return TestSuite::getChildTestCount();
22 }
23
24
25 std::string 
26 TestRunner::WrappingSuite::getName() const
27 {
28   if ( hasOnlyOneTest() )
29     return getUniqueChildTest()->getName();
30   return TestSuite::getName();
31 }
32
33
34 Test *
35 TestRunner::WrappingSuite::doGetChildTestAt( int index ) const
36 {
37   if ( hasOnlyOneTest() )
38     return getUniqueChildTest()->getChildTestAt( index );
39   return TestSuite::doGetChildTestAt( index );
40 }
41
42
43 void 
44 TestRunner::WrappingSuite::run( TestResult *result )
45 {
46   if ( hasOnlyOneTest() )
47     getUniqueChildTest()->run( result );
48   else
49     TestSuite::run( result );
50 }
51
52
53 bool 
54 TestRunner::WrappingSuite::hasOnlyOneTest() const
55 {
56   return TestSuite::getChildTestCount() == 1;
57 }
58
59
60 Test *
61 TestRunner::WrappingSuite::getUniqueChildTest() const
62 {
63   return TestSuite::doGetChildTestAt( 0 );
64 }
65
66
67
68
69
70 TestRunner::TestRunner()
71     : m_suite( new WrappingSuite() )
72 {
73 }
74
75
76 TestRunner::~TestRunner()
77 {
78   delete m_suite;
79 }
80
81
82 void 
83 TestRunner::addTest( Test *test )
84 {
85   m_suite->addTest( test ); 
86 }
87
88
89 void 
90 TestRunner::run( TestResult &controller,
91                  const std::string &testPath )
92 {
93   TestPath path = m_suite->resolveTestPath( testPath );
94   Test *testToRun = path.getChildTest();
95
96   controller.runTest( testToRun );
97 }
98
99
100 CPPUNIT_NS_END
101