CppUnit project page FAQ CppUnit home page

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
10#endif
11
12
14
15#if 0
19class CPPUNIT_API NoExceptionExpected
20{
21private:
23 NoExceptionExpected();
24};
25
26
31template<class ExceptionType>
32struct 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
53template<>
54struct 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
102
103template <class Fixture>
104class TestCaller : public TestCase
105{
106 typedef void (Fixture::*TestMethod)();
107
108public:
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
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
190private:
191 TestCaller( const TestCaller &other );
193
194private:
196 Fixture *m_fixture;
198};
199
200
201
203
204#endif // CPPUNIT_TESTCALLER_H
#define CPPUNIT_API
Definition CppUnitApi.h:27
#define CPPUNIT_NS_END
Definition Portability.h:120
#define CPPUNIT_NS_BEGIN
Definition Portability.h:119
void tearDown()
Clean up after the test run.
Definition TestCaller.h:180
TestCaller(std::string name, TestMethod test, Fixture &fixture)
Definition TestCaller.h:132
std::string toString() const
Definition TestCaller.h:185
void(Fixture::* TestMethod)()
Definition TestCaller.h:106
Fixture * m_fixture
Definition TestCaller.h:196
TestCaller(std::string name, TestMethod test, Fixture *fixture)
Definition TestCaller.h:149
TestCaller & operator=(const TestCaller &other)
~TestCaller()
Definition TestCaller.h:157
TestCaller(std::string name, TestMethod test)
Definition TestCaller.h:115
bool m_ownFixture
Definition TestCaller.h:195
TestMethod m_test
Definition TestCaller.h:197
void runTest()
FIXME: this should probably be pure virtual.
Definition TestCaller.h:163
void setUp()
Set up context before running a test.
Definition TestCaller.h:175
TestCaller(const TestCaller &other)
std::string getName() const
Returns the name of the test case.
Definition TestCase.cpp:131
TestCase(const std::string &name)
Constructs a test case.
Definition TestCase.cpp:45

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers