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
10 #endif
11 
12 
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 
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:
196  Fixture *m_fixture;
198 };
199 
200 
201 
203 
204 #endif // CPPUNIT_TESTCALLER_H

Send comments to:
CppUnit Developers