1 #include "cppunit/TestSuite.h" 2 #include "cppunit/TestResult.h" 3 4 namespace CppUnit { 5 6 /// Default constructor 7 TestSuite::TestSuite( string name ) 8 : m_name( name ) 9 { 10 } 11 12 13 /// Destructor 14 TestSuite::~TestSuite() 15 { 16 deleteContents(); 17 } 18 19 20 /// Deletes all tests in the suite. 21 void 22 TestSuite::deleteContents() 23 { 24 for ( vector<Test *>::iterator it = m_tests.begin(); 25 it != m_tests.end(); 26 ++it) 27 delete *it; 28 m_tests.clear(); 29 } 30 31 32 /// Runs the tests and collects their result in a TestResult. 33 void 34 TestSuite::run( TestResult *result ) 35 { 36 for ( vector<Test *>::iterator it = m_tests.begin(); 37 it != m_tests.end(); 38 ++it ) 39 { 40 if ( result->shouldStop() ) 41 break; 42 43 Test *test = *it; 44 test->run( result ); 45 } 46 } 47 48 49 /// Counts the number of test cases that will be run by this test. 50 int 51 TestSuite::countTestCases() const 52 { 53 int count = 0; 54 55 for ( vector<Test *>::const_iterator it = m_tests.begin(); 56 it != m_tests.end(); 57 ++it ) 58 count += (*it)->countTestCases(); 59 60 return count; 61 } 62 63 64 /// Adds a test to the suite. 65 void 66 TestSuite::addTest( Test *test ) 67 { 68 m_tests.push_back( test ); 69 } 70 71 72 /// Returns a string representation of the test suite. 73 string 74 TestSuite::toString() const 75 { 76 return "suite " + getName(); 77 } 78 79 80 /// Returns the name of the test suite. 81 string 82 TestSuite::getName() const 83 { 84 return m_name; 85 } 86 87 88 const vector<Test *> & 89 TestSuite::getTests() const 90 { 91 return m_tests; 92 } 93 94 95 } // namespace CppUnit 96 97