00001 #ifndef CPPUNIT_TESTCALLER_H // -*- C++ -*-
00002 #define CPPUNIT_TESTCALLER_H
00003
00004 #include <cppunit/Exception.h>
00005 #include <cppunit/TestCase.h>
00006
00007
00008 #if CPPUNIT_USE_TYPEINFO_NAME
00009 # include <cppunit/extensions/TypeInfoHelper.h>
00010 #endif
00011
00012
00013 CPPUNIT_NS_BEGIN
00014
00015 #if 0
00016
00019 class CPPUNIT_API NoExceptionExpected
00020 {
00021 private:
00023 NoExceptionExpected();
00024 };
00025
00026
00031 template<class ExceptionType>
00032 struct ExpectedExceptionTraits
00033 {
00034 static void expectedException()
00035 {
00036 #if CPPUNIT_USE_TYPEINFO_NAME
00037 throw Exception( Message(
00038 "expected exception not thrown",
00039 "Expected exception type: " +
00040 TypeInfoHelper::getClassName( typeid( ExceptionType ) ) ) );
00041 #else
00042 throw Exception( "expected exception not thrown" );
00043 #endif
00044 }
00045 };
00046
00047
00053 template<>
00054 struct ExpectedExceptionTraits<NoExceptionExpected>
00055 {
00056 static void expectedException()
00057 {
00058 }
00059 };
00060
00061
00062 #endif
00063
00064
00065
00066
00103 template <class Fixture>
00104 class TestCaller : public TestCase
00105 {
00106 typedef void (Fixture::*TestMethod)();
00107
00108 public:
00115 TestCaller( std::string name, TestMethod test ) :
00116 TestCase( name ),
00117 m_ownFixture( true ),
00118 m_fixture( new Fixture() ),
00119 m_test( test )
00120 {
00121 }
00122
00132 TestCaller(std::string name, TestMethod test, Fixture& fixture) :
00133 TestCase( name ),
00134 m_ownFixture( false ),
00135 m_fixture( &fixture ),
00136 m_test( test )
00137 {
00138 }
00139
00149 TestCaller(std::string name, TestMethod test, Fixture* fixture) :
00150 TestCase( name ),
00151 m_ownFixture( true ),
00152 m_fixture( fixture ),
00153 m_test( test )
00154 {
00155 }
00156
00157 ~TestCaller()
00158 {
00159 if (m_ownFixture)
00160 delete m_fixture;
00161 }
00162
00163 void runTest()
00164 {
00165
00166 (m_fixture->*m_test)();
00167
00168
00169
00170
00171
00172
00173 }
00174
00175 void setUp()
00176 {
00177 m_fixture->setUp ();
00178 }
00179
00180 void tearDown()
00181 {
00182 m_fixture->tearDown ();
00183 }
00184
00185 std::string toString() const
00186 {
00187 return "TestCaller " + getName();
00188 }
00189
00190 private:
00191 TestCaller( const TestCaller &other );
00192 TestCaller &operator =( const TestCaller &other );
00193
00194 private:
00195 bool m_ownFixture;
00196 Fixture *m_fixture;
00197 TestMethod m_test;
00198 };
00199
00200
00201
00202 CPPUNIT_NS_END
00203
00204 #endif // CPPUNIT_TESTCALLER_H