xref: /haiku/src/tools/cppunit/BTestSuite.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 #include <TestSuite.h>
2 #include <cppunit/Test.h>
3 #include <cppunit/TestResult.h>
4 
5 using std::map;
6 using std::string;
7 
8 // Default constructor
9 _EXPORT
10 BTestSuite::BTestSuite( string name )
11 	: fName(name)
12 {
13 }
14 
15 // Destructor
16 _EXPORT
17 BTestSuite::~BTestSuite() {
18 	deleteContents();
19 }
20 
21 
22 // Deletes all tests in the suite.
23 _EXPORT
24 void
25 BTestSuite::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
36 void
37 BTestSuite::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
53 int
54 BTestSuite::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
68 void
69 BTestSuite::addTest(string name, CppUnit::Test *test) {
70 	fTests[name] = test;
71 }
72 
73 
74 // Returns a string representation of the test suite.
75 _EXPORT
76 string
77 BTestSuite::toString() const {
78 	return "suite " + getName();
79 }
80 
81 
82 // Returns the name of the test suite.
83 _EXPORT
84 string
85 BTestSuite::getName() const {
86 	return fName;
87 }
88 
89 
90 _EXPORT
91 const map<string, CppUnit::Test*> &
92 BTestSuite::getTests() const {
93 	return fTests;
94 }
95 
96 
97