summaryrefslogtreecommitdiff
path: root/src/cppunit/TestSuite.cpp
blob: 8fe5e658e9cb2c30f483a5a35c1944bd250a0f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "cppunit/TestSuite.h"
#include "cppunit/TestResult.h"

namespace CppUnit {

/// Deletes all tests in the suite.
void TestSuite::deleteContents ()
{
  for (std::vector<Test *>::iterator it = m_tests.begin ();
       it != m_tests.end ();
       ++it)
    delete *it;
  m_tests.clear();
}


/// Runs the tests and collects their result in a TestResult.
void TestSuite::run (TestResult *result)
{
    for (std::vector<Test *>::iterator it = m_tests.begin ();
            it != m_tests.end ();
            ++it) {
        if (result->shouldStop ())
            break;

        Test *test = *it;
        test->run (result);
    }

}


/// Counts the number of test cases that will be run by this test.
int TestSuite::countTestCases () const
{
    int count = 0;

    for (std::vector<Test *>::const_iterator it = m_tests.begin ();
            it != m_tests.end ();
            ++it)
        count += (*it)->countTestCases ();

    return count;

}



/// Default constructor
TestSuite::TestSuite (std::string name)
  : m_name (name)
{
}


/// Destructor
TestSuite::~TestSuite ()
{ 
  deleteContents (); 
}


/// Adds a test to the suite. 
void 
  TestSuite::addTest (Test *test)
{ 
  m_tests.push_back (test); 
}


/// Returns a string representation of the test suite.
std::string 
  TestSuite::toString () const
{ 
  return "suite " + getName(); 
}

/// Returns the name of the test suite.
std::string 
  TestSuite::getName () const
{ 
  return m_name; 
}

} // namespace CppUnit