CppUnit - The Unit Testing Library

CppUnit project page | FAQ

TestCaller.h
Go to the documentation of this file.
1 #ifndef CPPUNIT_TESTCALLER_H // -*- C++ -*-
2 #define CPPUNIT_TESTCALLER_H
3
4 #include <cppunit/Exception.h>
5 #include <cppunit/TestCase.h>
6
7
8 #if CPPUNIT_USE_TYPEINFO_NAME
9 # include <cppunit/extensions/TypeInfoHelper.h>
10 #endif
11
12
13 CPPUNIT_NS_BEGIN
14
15 #if 0
16
19 class CPPUNIT_API NoExceptionExpected
20 {
21 private:
23 NoExceptionExpected();
24 };
25
26
31 template<class ExceptionType>
32 struct ExpectedExceptionTraits
33 {
34 static void expectedException()
35 {
36 #if CPPUNIT_USE_TYPEINFO_NAME
37 throw Exception( Message(
38 "expected exception not thrown",
39 "Expected exception type: " +
40 TypeInfoHelper::getClassName( typeid( ExceptionType ) ) ) );
41 #else
42 throw Exception( "expected exception not thrown" );
43 #endif
44 }
45 };
46
47
53 template<>
54 struct ExpectedExceptionTraits<NoExceptionExpected>
55 {
56 static void expectedException()
57 {
58 }
59 };
60
61
62 #endif
63
64 //*** FIXME: rework this when class Fixture is implemented. ***//
65
66
103 template <class Fixture>
104 class TestCaller : public TestCase
105 {
106 typedef void (Fixture::*TestMethod)();
107
108 public:
115 TestCaller( std::string name, TestMethod test ) :
116 TestCase( name ),
117 m_ownFixture( true ),
118 m_fixture( new Fixture() ),
119 m_test( test )
120 {
121 }
122
132 TestCaller(std::string name, TestMethod test, Fixture& fixture) :
133 TestCase( name ),
134 m_ownFixture( false ),
135 m_fixture( &fixture ),
136 m_test( test )
137 {
138 }
139
149 TestCaller(std::string name, TestMethod test, Fixture* fixture) :
150 TestCase( name ),
151 m_ownFixture( true ),
152 m_fixture( fixture ),
153 m_test( test )
154 {
155 }
156
157 ~TestCaller()
158 {
159 if (m_ownFixture)
160 delete m_fixture;
161 }
162
163 void runTest()
164 {
165 // try {
166 (m_fixture->*m_test)();
167 // }
168 // catch ( ExpectedException & ) {
169 // return;
170 // }
171
172 // ExpectedExceptionTraits<ExpectedException>::expectedException();
173 }
174
175 void setUp()
176 {
177 m_fixture->setUp ();
178 }
179
180 void tearDown()
181 {
182 m_fixture->tearDown ();
183 }
184
185 std::string toString() const
186 {
187 return "TestCaller " + getName();
188 }
189
190 private:
191 TestCaller( const TestCaller &other );
192 TestCaller &operator =( const TestCaller &other );
193
194 private:
195 bool m_ownFixture;
196 Fixture *m_fixture;
197 TestMethod m_test;
198 };
199
200
201
202 CPPUNIT_NS_END
203
204 #endif // CPPUNIT_TESTCALLER_H
Exception
Exceptions thrown by failed assertions.Exception is an exception that serves descriptive strings thro...
Definition: Exception.h:19
TestCaller::m_fixture
Fixture * m_fixture
Definition: TestCaller.h:196
TestCaller::runTest
void runTest()
FIXME: this should probably be pure virtual.
Definition: TestCaller.h:163
TestCaller::toString
std::string toString() const
Definition: TestCaller.h:185
TestCaller::tearDown
void tearDown()
Clean up after the test run.
Definition: TestCaller.h:180
TestCaller::TestCaller
TestCaller(std::string name, TestMethod test, Fixture *fixture)
Definition: TestCaller.h:149
Exception.h
TestCaller
Generate a test case from a fixture method.A test caller provides access to a test case method on a t...
Definition: TestCaller.h:104
TestCaller::setUp
void setUp()
Set up context before running a test.
Definition: TestCaller.h:175
TestCaller::TestCaller
TestCaller(std::string name, TestMethod test, Fixture &fixture)
Definition: TestCaller.h:132
TestCaller::m_ownFixture
bool m_ownFixture
Definition: TestCaller.h:195
CPPUNIT_NS_END
#define CPPUNIT_NS_END
Definition: Portability.h:120
CPPUNIT_NS_BEGIN
#define CPPUNIT_NS_BEGIN
Definition: Portability.h:119
TestCaller::~TestCaller
~TestCaller()
Definition: TestCaller.h:157
TestCaller::m_test
TestMethod m_test
Definition: TestCaller.h:197
Message
Message associated to an Exception.A message is composed of two items:
Definition: Message.h:38
TestCase.h
TestCaller::TestCaller
TestCaller(std::string name, TestMethod test)
Definition: TestCaller.h:115
TestCase
A single test object.
Definition: TestCase.h:27
TypeInfoHelper.h
CPPUNIT_API
#define CPPUNIT_API
Definition: CppUnitApi.h:27

| Send comments to: CppUnit Developers