forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCaller.h
More file actions
95 lines (75 loc) · 1.68 KB
/
TestCaller.h
File metadata and controls
95 lines (75 loc) · 1.68 KB
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
87
88
89
90
91
92
93
94
95
//
// TestCaller.h
//
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestCaller.h#1 $
//
#ifndef CppUnit_TestCaller_INCLUDED
#define CppUnit_TestCaller_INCLUDED
#include "CppUnit/CppUnit.h"
#include "Guards.h"
#include "TestCase.h"
#include <memory>
namespace CppUnit {
/*
* A test caller provides access to a test case method
* on a test case class. Test callers are useful when
* you want to run an individual test or add it to a
* suite.
*
* Here is an example:
*
* class MathTest : public TestCase {
* ...
* public:
* void setUp ();
* void tearDown ();
*
* void testAdd ();
* void testSubtract ();
* };
*
* Test *MathTest::suite () {
* TestSuite *suite = new TestSuite;
*
* suite->addTest (new TestCaller<MathTest> ("testAdd", testAdd));
* return suite;
* }
*
* You can use a TestCaller to bind any test method on a TestCase
* class, as long as it returns accepts void and returns void.
*
* See TestCase
*/
template <class Fixture>
class TestCaller: public TestCase
{
REFERENCEOBJECT (TestCaller)
typedef void (Fixture::*TestMethod)();
public:
TestCaller(const std::string& name, TestMethod test):
TestCase(name),
_test(test),
_fixture(new Fixture(name))
{
}
protected:
void runTest()
{
(_fixture.get()->*_test)();
}
void setUp()
{
_fixture.get()->setUp();
}
void tearDown()
{
_fixture.get()->tearDown();
}
private:
TestMethod _test;
std::auto_ptr<Fixture> _fixture;
};
} // namespace CppUnit
#define CppUnit_addTest(suite, cls, mth) \
suite->addTest(new CppUnit::TestCaller<cls>(#mth, &cls::mth))
#endif // CppUnit_TestCaller_INCLUDED