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 public: \
00170 static CPPUNIT_NS::TestSuite *suite() \
00171 { \
00172 const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
00173 std::unique_ptr<CPPUNIT_NS::TestSuite> guard( \
00174 new CPPUNIT_NS::TestSuite( namer.getFixtureName() )); \
00175 CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory; \
00176 CPPUNIT_NS::TestSuiteBuilderContextBase context( *guard.get(), \
00177 namer, \
00178 factory ); \
00179 TestFixtureType::addTestsToSuite( context ); \
00180 return guard.release(); \
00181 } \
00182 private: \
00183 typedef int CppUnitDummyTypedefForSemiColonEnding__
00184
00238 #define CPPUNIT_TEST_SUITE_END_ABSTRACT() \
00239 } \
00240 private: \
00241 typedef int CppUnitDummyTypedefForSemiColonEnding__
00242
00243
00288 #define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
00289 context.addTest( test )
00290
00297 #define CPPUNIT_TEST( testMethod ) \
00298 CPPUNIT_TEST_SUITE_ADD_TEST( \
00299 ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
00300 context.getTestNameFor( #testMethod), \
00301 &TestFixtureType::testMethod, \
00302 context.makeFixture() ) ) )
00303
00304 #define CPPUNIT_TEST_PARAMETERIZED( testMethod, ... ) \
00305 for (auto& i : __VA_ARGS__) \
00306 { \
00307 TestFixtureType* fixture = context.makeFixture(); \
00308 CPPUNIT_TEST_SUITE_ADD_TEST( \
00309 ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
00310 context.getTestNameFor(#testMethod, i), \
00311 std::bind(&TestFixtureType::testMethod, fixture, i), \
00312 fixture))); \
00313 }
00314
00339 #define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
00340 CPPUNIT_TEST_SUITE_ADD_TEST( \
00341 (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
00342 new CPPUNIT_NS::TestCaller< TestFixtureType >( \
00343 context.getTestNameFor( #testMethod ), \
00344 &TestFixtureType::testMethod, \
00345 context.makeFixture() ) ) ) )
00346
00363 #define CPPUNIT_TEST_FAIL( testMethod ) \
00364 CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
00365
00414 #define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
00415 testAdderMethod( context )
00416
00424 #define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
00425 context.addProperty( std::string(APropertyKey), \
00426 std::string(APropertyValue) )
00427
00449 #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
00450 static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
00451 CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
00452
00453
00491 #define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
00492 static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
00493 CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
00494
00522 #define CPPUNIT_REGISTRY_ADD( which, to ) \
00523 static CPPUNIT_NS::AutoRegisterRegistry \
00524 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
00525
00535 #define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
00536 static CPPUNIT_NS::AutoRegisterRegistry \
00537 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
00538
00539
00540
00541
00542 #if CPPUNIT_ENABLE_CU_TEST_MACROS
00543
00544 #define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
00545 #define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
00546 #define CU_TEST(tm) CPPUNIT_TEST(tm)
00547 #define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
00548 #define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
00549
00550 #endif
00551
00552
00553 #endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H