1155b583aSIngo Weinhold #include <TestSuite.h> 2155b583aSIngo Weinhold #include <cppunit/Test.h> 3155b583aSIngo Weinhold #include <cppunit/TestResult.h> 4155b583aSIngo Weinhold 5*58481f0fSOliver Tappe using std::map; 6*58481f0fSOliver Tappe using std::string; 7*58481f0fSOliver Tappe 8155b583aSIngo Weinhold // Default constructor 9155b583aSIngo Weinhold _EXPORT BTestSuite(string name)10155b583aSIngo WeinholdBTestSuite::BTestSuite( string name ) 11155b583aSIngo Weinhold : fName(name) 12155b583aSIngo Weinhold { 13155b583aSIngo Weinhold } 14155b583aSIngo Weinhold 15155b583aSIngo Weinhold // Destructor 16155b583aSIngo Weinhold _EXPORT ~BTestSuite()17155b583aSIngo WeinholdBTestSuite::~BTestSuite() { 18155b583aSIngo Weinhold deleteContents(); 19155b583aSIngo Weinhold } 20155b583aSIngo Weinhold 21155b583aSIngo Weinhold 22155b583aSIngo Weinhold // Deletes all tests in the suite. 23155b583aSIngo Weinhold _EXPORT 24155b583aSIngo Weinhold void deleteContents()25155b583aSIngo WeinholdBTestSuite::deleteContents() { 26155b583aSIngo Weinhold for ( map<string, CppUnit::Test*>::iterator it = fTests.begin(); 27155b583aSIngo Weinhold it != fTests.end(); 28155b583aSIngo Weinhold ++it) 29155b583aSIngo Weinhold delete it->second; 30155b583aSIngo Weinhold fTests.clear(); 31155b583aSIngo Weinhold } 32155b583aSIngo Weinhold 33155b583aSIngo Weinhold 34155b583aSIngo Weinhold /// Runs the tests and collects their result in a TestResult. 35155b583aSIngo Weinhold _EXPORT 36155b583aSIngo Weinhold void run(CppUnit::TestResult * result)37155b583aSIngo WeinholdBTestSuite::run( CppUnit::TestResult *result ) { 38155b583aSIngo Weinhold for ( map<string, CppUnit::Test*>::iterator it = fTests.begin(); 39155b583aSIngo Weinhold it != fTests.end(); 40155b583aSIngo Weinhold ++it ) 41155b583aSIngo Weinhold { 42155b583aSIngo Weinhold if ( result->shouldStop() ) 43155b583aSIngo Weinhold break; 44155b583aSIngo Weinhold 45155b583aSIngo Weinhold Test *test = it->second; 46155b583aSIngo Weinhold test->run( result ); 47155b583aSIngo Weinhold } 48155b583aSIngo Weinhold } 49155b583aSIngo Weinhold 50155b583aSIngo Weinhold 51155b583aSIngo Weinhold // Counts the number of test cases that will be run by this test. 52155b583aSIngo Weinhold _EXPORT 53155b583aSIngo Weinhold int countTestCases() const54155b583aSIngo WeinholdBTestSuite::countTestCases() const { 55155b583aSIngo Weinhold int count = 0; 56155b583aSIngo Weinhold 57155b583aSIngo Weinhold for ( map<string, CppUnit::Test *>::const_iterator it = fTests.begin(); 58155b583aSIngo Weinhold it != fTests.end(); 59155b583aSIngo Weinhold ++it ) 60155b583aSIngo Weinhold count += it->second->countTestCases(); 61155b583aSIngo Weinhold 62155b583aSIngo Weinhold return count; 63155b583aSIngo Weinhold } 64155b583aSIngo Weinhold 65155b583aSIngo Weinhold 66155b583aSIngo Weinhold // Adds a test to the suite. 67155b583aSIngo Weinhold _EXPORT 68155b583aSIngo Weinhold void addTest(string name,CppUnit::Test * test)69155b583aSIngo WeinholdBTestSuite::addTest(string name, CppUnit::Test *test) { 70155b583aSIngo Weinhold fTests[name] = test; 71155b583aSIngo Weinhold } 72155b583aSIngo Weinhold 73155b583aSIngo Weinhold 74155b583aSIngo Weinhold // Returns a string representation of the test suite. 75155b583aSIngo Weinhold _EXPORT 76155b583aSIngo Weinhold string toString() const77155b583aSIngo WeinholdBTestSuite::toString() const { 78155b583aSIngo Weinhold return "suite " + getName(); 79155b583aSIngo Weinhold } 80155b583aSIngo Weinhold 81155b583aSIngo Weinhold 82155b583aSIngo Weinhold // Returns the name of the test suite. 83155b583aSIngo Weinhold _EXPORT 84155b583aSIngo Weinhold string getName() const85155b583aSIngo WeinholdBTestSuite::getName() const { 86155b583aSIngo Weinhold return fName; 87155b583aSIngo Weinhold } 88155b583aSIngo Weinhold 89155b583aSIngo Weinhold 90155b583aSIngo Weinhold _EXPORT 91155b583aSIngo Weinhold const map<string, CppUnit::Test*> & getTests() const92155b583aSIngo WeinholdBTestSuite::getTests() const { 93155b583aSIngo Weinhold return fTests; 94155b583aSIngo Weinhold } 95155b583aSIngo Weinhold 96155b583aSIngo Weinhold 97