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