CppUnit project page FAQ CppUnit home page

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

HelperMacros.h

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////////
00002 // Header file HelperMacros.h
00003 // (c)Copyright 2000, Baptiste Lepilleur.
00004 // Created: 2001/04/15
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     static CPPUNIT_NS::TestSuite *suite()                                      \
00170     {                                                                          \
00171       const CPPUNIT_NS::TestNamer &namer = getTestNamer__();                   \
00172       std::auto_ptr<CPPUNIT_NS::TestSuite> suite(                              \
00173              new CPPUNIT_NS::TestSuite( namer.getFixtureName() ));             \
00174       CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory;          \
00175       CPPUNIT_NS::TestSuiteBuilderContextBase context( *suite.get(),           \
00176                                                        namer,                  \
00177                                                        factory );              \
00178       TestFixtureType::addTestsToSuite( context );                             \
00179       return suite.release();                                                  \
00180     }                                                                          \
00181   private: /* dummy typedef so that the macro can still end with ';'*/         \
00182     typedef int CppUnitDummyTypedefForSemiColonEnding__
00183 
00237 #define CPPUNIT_TEST_SUITE_END_ABSTRACT()                                      \
00238     }                                                                          \
00239   private: /* dummy typedef so that the macro can still end with ';'*/         \
00240     typedef int CppUnitDummyTypedefForSemiColonEnding__
00241 
00242 
00287 #define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
00288       context.addTest( test )
00289 
00296 #define CPPUNIT_TEST( testMethod )                        \
00297     CPPUNIT_TEST_SUITE_ADD_TEST(                           \
00298         ( new CPPUNIT_NS::TestCaller<TestFixtureType>(    \
00299                   context.getTestNameFor( #testMethod),   \
00300                   &TestFixtureType::testMethod,           \
00301                   context.makeFixture() ) ) )
00302 
00326 #define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType )          \
00327   CPPUNIT_TEST_SUITE_ADD_TEST(                                        \
00328       (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >(  \
00329           new CPPUNIT_NS::TestCaller< TestFixtureType >(             \
00330                                context.getTestNameFor( #testMethod ),  \
00331                                &TestFixtureType::testMethod,         \
00332                                context.makeFixture() ) ) ) )
00333 
00349 #define CPPUNIT_TEST_FAIL( testMethod ) \
00350               CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
00351 
00400 #define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
00401       testAdderMethod( context )
00402 
00410 #define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
00411     context.addProperty( std::string(APropertyKey),                 \
00412                          std::string(APropertyValue) )
00413 
00435 #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType )      \
00436   static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >       \
00437              CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
00438 
00439 
00477 #define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
00478   static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >                   \
00479              CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
00480 
00508 #define CPPUNIT_REGISTRY_ADD( which, to )                                     \
00509   static CPPUNIT_NS::AutoRegisterRegistry                                     \
00510              CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
00511 
00521 #define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which )                         \
00522   static CPPUNIT_NS::AutoRegisterRegistry                                \
00523              CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
00524 
00525 // Backwards compatibility
00526 // (Not tested!)
00527 
00528 #if CPPUNIT_ENABLE_CU_TEST_MACROS
00529 
00530 #define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
00531 #define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
00532 #define CU_TEST(tm) CPPUNIT_TEST(tm)
00533 #define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
00534 #define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
00535 
00536 #endif
00537 
00538 
00539 #endif  // CPPUNIT_EXTENSIONS_HELPERMACROS_H

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers