1 |
|
2 |
#ifndef CPPUNIT_TESTSUITE_H |
3 |
#define CPPUNIT_TESTSUITE_H |
4 |
|
5 |
#include <vector> |
6 |
#include <string> |
7 |
|
8 |
#include "CppUnitTest/Guards.h" |
9 |
#include "CppUnitTest/Test.h" |
10 |
|
11 |
#include "CppUnitTest/CppUnitTestNamespace.h" |
12 |
BEGIN_NAMESPACE_CPPUNITTEST |
13 |
|
14 |
class TestResult; |
15 |
|
16 |
/* |
17 |
* A TestSuite is a Composite of Tests. |
18 |
* It runs a collection of test cases. Here is an example. |
19 |
* |
20 |
* TestSuite *suite= new TestSuite(); |
21 |
* suite->addTest(new TestCaller<MathTest> ("testAdd", testAdd)); |
22 |
* suite->addTest(new TestCaller<MathTest> ("testDivideByZero", testDivideByZero)); |
23 |
* |
24 |
* Note that TestSuites assume lifetime |
25 |
* control for any tests added to them. |
26 |
* |
27 |
* see Test and TestCaller |
28 |
*/ |
29 |
|
30 |
|
31 |
class TestSuite : public Test |
32 |
{ |
33 |
REFERENCEOBJECT (TestSuite) |
34 |
|
35 |
public: |
36 |
TestSuite (std::string name = ""); |
37 |
~TestSuite (); |
38 |
|
39 |
void run (TestResult *result); |
40 |
int countTestCases (); |
41 |
void addTest (Test *test); |
42 |
std::string toString (); |
43 |
|
44 |
virtual void deleteContents (); |
45 |
|
46 |
private: |
47 |
std::vector<Test *> m_tests; |
48 |
const std::string m_name; |
49 |
|
50 |
|
51 |
}; |
52 |
|
53 |
|
54 |
// Default constructor |
55 |
inline TestSuite::TestSuite (std::string name) |
56 |
: m_name (name) |
57 |
{} |
58 |
|
59 |
|
60 |
// Destructor |
61 |
inline TestSuite::~TestSuite () |
62 |
{ deleteContents (); } |
63 |
|
64 |
|
65 |
// Adds a test to the suite. |
66 |
inline void TestSuite::addTest (Test *test) |
67 |
{ m_tests.push_back (test); } |
68 |
|
69 |
|
70 |
// Returns a string representation of the test suite. |
71 |
inline std::string TestSuite::toString () |
72 |
{ return "suite " + m_name; } |
73 |
|
74 |
|
75 |
END_NAMESPACE_CPPUNITTEST |
76 |
|
77 |
#endif |