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