00001
00002
00003
00004
00005
00006 #ifndef CPPUNIT_EXTENSIONS_HELPERMACROS_H
00007 #define CPPUNIT_EXTENSIONS_HELPERMACROS_H
00008
00009 #include <cppunit/TestCaller.h>
00010 #include <cppunit/TestSuite.h>
00011 #include <cppunit/extensions/AutoRegisterSuite.h>
00012 #include <cppunit/extensions/ExceptionTestCaseDecorator.h>
00013 #include <cppunit/extensions/TestFixtureFactory.h>
00014 #include <cppunit/extensions/TestNamer.h>
00015 #include <cppunit/extensions/TestSuiteBuilderContext.h>
00016 #include <memory>
00017
00018
00100 #define CPPUNIT_TEST_SUITE( ATestFixtureType ) \
00101 public: \
00102 typedef ATestFixtureType TestFixtureType; \
00103 \
00104 private: \
00105 static const CPPUNIT_NS::TestNamer &getTestNamer__() \
00106 { \
00107 static CPPUNIT_TESTNAMER_DECL( testNamer, ATestFixtureType ); \
00108 return testNamer; \
00109 } \
00110 \
00111 public: \
00112 typedef CPPUNIT_NS::TestSuiteBuilderContext<TestFixtureType> \
00113 TestSuiteBuilderContextType; \
00114 \
00115 static void \
00116 addTestsToSuite( CPPUNIT_NS::TestSuiteBuilderContextBase &baseContext ) \
00117 { \
00118 TestSuiteBuilderContextType context( baseContext )
00119
00120
00151 #define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass ) \
00152 public: \
00153 typedef ASuperClass ParentTestFixtureType; \
00154 private: \
00155 CPPUNIT_TEST_SUITE( ATestFixtureType ); \
00156 ParentTestFixtureType::addTestsToSuite( baseContext )
00157
00158
00166 #define CPPUNIT_TEST_SUITE_END() \
00167 } \
00168 \
00169 struct CppUnitExDeleter { \
00170 CPPUNIT_NS::TestSuite *suite; \
00171 CppUnitExDeleter() : suite (0) {} \
00172 ~CppUnitExDeleter() { delete suite; } \
00173 CPPUNIT_NS::TestSuite *release() { \
00174 CPPUNIT_NS::TestSuite *tmp = suite; suite = NULL; return tmp; \
00175 } \
00176 }; \
00177 \
00178 public: \
00179 static CPPUNIT_NS::TestSuite *suite() \
00180 { \
00181 const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
00182 CppUnitExDeleter guard; \
00183 guard.suite = new CPPUNIT_NS::TestSuite( namer.getFixtureName() ); \
00184 CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory; \
00185 CPPUNIT_NS::TestSuiteBuilderContextBase context( *guard.suite, \
00186 namer, \
00187 factory ); \
00188 TestFixtureType::addTestsToSuite( context ); \
00189 return guard.release(); \
00190 } \
00191 private: \
00192 typedef int CppUnitDummyTypedefForSemiColonEnding__
00193
00247 #define CPPUNIT_TEST_SUITE_END_ABSTRACT() \
00248 } \
00249 private: \
00250 typedef int CppUnitDummyTypedefForSemiColonEnding__
00251
00252
00297 #define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
00298 context.addTest( test )
00299
00306 #define CPPUNIT_TEST( testMethod ) \
00307 CPPUNIT_TEST_SUITE_ADD_TEST( \
00308 ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
00309 context.getTestNameFor( #testMethod), \
00310 &TestFixtureType::testMethod, \
00311 context.makeFixture() ) ) )
00312
00337 #define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
00338 CPPUNIT_TEST_SUITE_ADD_TEST( \
00339 (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
00340 new CPPUNIT_NS::TestCaller< TestFixtureType >( \
00341 context.getTestNameFor( #testMethod ), \
00342 &TestFixtureType::testMethod, \
00343 context.makeFixture() ) ) ) )
00344
00361 #define CPPUNIT_TEST_FAIL( testMethod ) \
00362 CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
00363
00412 #define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
00413 testAdderMethod( context )
00414
00422 #define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
00423 context.addProperty( std::string(APropertyKey), \
00424 std::string(APropertyValue) )
00425
00447 #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
00448 static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
00449 CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
00450
00451
00489 #define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
00490 static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
00491 CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
00492
00520 #define CPPUNIT_REGISTRY_ADD( which, to ) \
00521 static CPPUNIT_NS::AutoRegisterRegistry \
00522 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
00523
00533 #define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
00534 static CPPUNIT_NS::AutoRegisterRegistry \
00535 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
00536
00537
00538
00539
00540 #if CPPUNIT_ENABLE_CU_TEST_MACROS
00541
00542 #define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
00543 #define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
00544 #define CU_TEST(tm) CPPUNIT_TEST(tm)
00545 #define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
00546 #define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
00547
00548 #endif
00549
00550
00551 #endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H