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