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 WrappingSuite(const std::string & name)10TestRunner::WrappingSuite::WrappingSuite( const std::string &name ) 11 : TestSuite( name ) 12 { 13 } 14 15 16 int getChildTestCount() const17TestRunner::WrappingSuite::getChildTestCount() const 18 { 19 if ( hasOnlyOneTest() ) 20 return getUniqueChildTest()->getChildTestCount(); 21 return TestSuite::getChildTestCount(); 22 } 23 24 25 std::string getName() const26TestRunner::WrappingSuite::getName() const 27 { 28 if ( hasOnlyOneTest() ) 29 return getUniqueChildTest()->getName(); 30 return TestSuite::getName(); 31 } 32 33 34 Test * doGetChildTestAt(int index) const35TestRunner::WrappingSuite::doGetChildTestAt( int index ) const 36 { 37 if ( hasOnlyOneTest() ) 38 return getUniqueChildTest()->getChildTestAt( index ); 39 return TestSuite::doGetChildTestAt( index ); 40 } 41 42 43 void run(TestResult * result)44TestRunner::WrappingSuite::run( TestResult *result ) 45 { 46 if ( hasOnlyOneTest() ) 47 getUniqueChildTest()->run( result ); 48 else 49 TestSuite::run( result ); 50 } 51 52 53 bool hasOnlyOneTest() const54TestRunner::WrappingSuite::hasOnlyOneTest() const 55 { 56 return TestSuite::getChildTestCount() == 1; 57 } 58 59 60 Test * getUniqueChildTest() const61TestRunner::WrappingSuite::getUniqueChildTest() const 62 { 63 return TestSuite::doGetChildTestAt( 0 ); 64 } 65 66 67 68 69 TestRunner()70TestRunner::TestRunner() 71 : m_suite( new WrappingSuite() ) 72 { 73 } 74 75 ~TestRunner()76TestRunner::~TestRunner() 77 { 78 delete m_suite; 79 } 80 81 82 void addTest(Test * test)83TestRunner::addTest( Test *test ) 84 { 85 m_suite->addTest( test ); 86 } 87 88 89 void run(TestResult & controller,const std::string & testPath)90TestRunner::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 102