00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef MOCKPP_VerifyingTestCaller_H
00031 #define MOCKPP_VerifyingTestCaller_H
00032
00033 #include <mockpp/mockpp.h>
00034
00035 #include <mockpp/MockObject.h>
00036
00037 #include <mockpp/framework/VerifyingTestCase.h>
00038
00039 #ifdef MOCKPP_USE_CPPUNIT
00040
00041 #include <cppunit/TestCaller.h>
00042
00043
00044 MOCKPP_NS_START
00045
00046
00054 template <typename VerifyingFixtureType, bool DoTheVerify>
00055 class VerifyingTestCaller : public ::CppUnit::TestCaller<VerifyingFixtureType>
00056 {
00057 typedef void (VerifyingFixtureType::*TestCaseMethod)();
00058
00059 public:
00060
00069 VerifyingTestCaller(const MOCKPP_STD_NS::string &name,
00070 TestCaseMethod test,
00071 VerifyingFixtureType& fixture)
00072 : ::CppUnit::TestCaller<VerifyingFixtureType>(name, test, fixture)
00073 , testcase(&fixture)
00074 {
00075 }
00076
00085 VerifyingTestCaller(const MOCKPP_STD_NS::string &name,
00086 TestCaseMethod test,
00087 VerifyingFixtureType* fixture)
00088 : ::CppUnit::TestCaller<VerifyingFixtureType>(name, test, fixture)
00089 , testcase(fixture)
00090 {
00091 }
00092
00095 virtual void runTest()
00096 {
00097 testcase->unregisterVerifiables();
00098 MOCKPP_TRY
00099 {
00100 ::CppUnit::TestCaller<VerifyingFixtureType>::runTest();
00101 bool doVerify = DoTheVerify;
00102 if (doVerify)
00103 testcase->verify();
00104 }
00105 #ifndef MOCKPP_NO_EXCEPTIONS
00106 catch(...)
00107 {
00108 testcase->unregisterVerifiables();
00109 MOCKPP_RETHROW;
00110 }
00111 #endif
00112 testcase->unregisterVerifiables();
00113 }
00114
00117 MOCKPP_STL::string toString() const
00118 {
00119 return "VerifyingTestCaller " + this->getName();
00120 }
00121
00122 private:
00123
00124 VerifyingTestCase *testcase;
00125
00126 VerifyingTestCaller( const VerifyingTestCaller &other );
00127 VerifyingTestCaller &operator =( const VerifyingTestCaller &other );
00128 };
00129
00130
00131 MOCKPP_NS_END
00132
00133
00142 #define MOCKPP_VERIFYING_TEST( testMethod ) \
00143 CPPUNIT_TEST_SUITE_ADD_TEST( \
00144 ( new MOCKPP_NS::VerifyingTestCaller<TestFixtureType, true>( \
00145 context.getTestNameFor( #testMethod), \
00146 &TestFixtureType::testMethod, \
00147 context.makeFixture() ) ) )
00148
00149
00157 #define MOCKPP_TEST( testMethod ) \
00158 CPPUNIT_TEST_SUITE_ADD_TEST( \
00159 ( new MOCKPP_NS::VerifyingTestCaller<TestFixtureType, false>( \
00160 context.getTestNameFor( #testMethod), \
00161 &TestFixtureType::testMethod, \
00162 context.makeFixture() ) ) )
00163
00164
00175 #define MOCKPP_VERIFYING_TEST_EXCEPTION( testMethod, ExceptionType ) \
00176 CPPUNIT_TEST_SUITE_ADD_TEST( \
00177 (new ::CppUnit::ExceptionTestCaseDecorator< ExceptionType >( \
00178 new MOCKPP_NS::VerifyingTestCaller< TestFixtureType, true >( \
00179 context.getTestNameFor( #testMethod ), \
00180 &TestFixtureType::testMethod, \
00181 context.makeFixture() ) ) ) )
00182
00192 #define MOCKPP_TEST_EXCEPTION( testMethod, ExceptionType ) \
00193 CPPUNIT_TEST_SUITE_ADD_TEST( \
00194 (new ::CppUnit::ExceptionTestCaseDecorator< ExceptionType >( \
00195 new MOCKPP_NS::VerifyingTestCaller< TestFixtureType, false >( \
00196 context.getTestNameFor( #testMethod ), \
00197 &TestFixtureType::testMethod, \
00198 context.makeFixture() ) ) ) )
00199
00200 #endif // MOCKPP_USE_CPPUNIT
00201
00202 #endif // MOCKPP_VerifyingTestCaller_H
00203