diff --git a/src/tools/cppunit/TestSuite.cpp b/src/tools/cppunit/TestSuite.cpp new file mode 100644 index 0000000000..dd9f4278ff --- /dev/null +++ b/src/tools/cppunit/TestSuite.cpp @@ -0,0 +1,84 @@ +#include +#include +#include + +// Default constructor +BTestSuite::BTestSuite( std::string name ) + : fName(name) +{ +} + +// Destructor +BTestSuite::~BTestSuite() { + deleteContents(); +} + + +// Deletes all tests in the suite. +void +BTestSuite::deleteContents() { + for ( std::map::iterator it = fTests.begin(); + it != fTests.end(); + ++it) + delete it->second; + fTests.clear(); +} + + +/// Runs the tests and collects their result in a TestResult. +void +BTestSuite::run( CppUnit::TestResult *result ) { + for ( std::map::iterator it = fTests.begin(); + it != fTests.end(); + ++it ) + { + if ( result->shouldStop() ) + break; + + Test *test = it->second; + test->run( result ); + } +} + + +// Counts the number of test cases that will be run by this test. +int +BTestSuite::countTestCases() const { + int count = 0; + + for ( std::map::const_iterator it = fTests.begin(); + it != fTests.end(); + ++it ) + count += it->second->countTestCases(); + + return count; +} + + +// Adds a test to the suite. +void +BTestSuite::addTest(std::string name, CppUnit::Test *test) { + fTests[name] = test; +} + + +// Returns a string representation of the test suite. +std::string +BTestSuite::toString() const { + return "suite " + getName(); +} + + +// Returns the name of the test suite. +std::string +BTestSuite::getName() const { + return fName; +} + + +const std::map & +BTestSuite::getTests() const { + return fTests; +} + +