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 
00327 #define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType )          \
00328   CPPUNIT_TEST_SUITE_ADD_TEST(                                        \
00329       (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >(  \
00330           new CPPUNIT_NS::TestCaller< TestFixtureType >(             \
00331                                context.getTestNameFor( #testMethod ),  \
00332                                &TestFixtureType::testMethod,         \
00333                                context.makeFixture() ) ) ) )
00334 
00351 #define CPPUNIT_TEST_FAIL( testMethod ) \
00352               CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
00353 
00402 #define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
00403       testAdderMethod( context )
00404 
00412 #define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
00413     context.addProperty( std::string(APropertyKey),                 \
00414                          std::string(APropertyValue) )
00415 
00437 #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType )      \
00438   static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >       \
00439              CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
00440 
00441 
00479 #define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
00480   static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType >                   \
00481              CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
00482 
00510 #define CPPUNIT_REGISTRY_ADD( which, to )                                     \
00511   static CPPUNIT_NS::AutoRegisterRegistry                                     \
00512              CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
00513 
00523 #define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which )                         \
00524   static CPPUNIT_NS::AutoRegisterRegistry                                \
00525              CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
00526 
00527 // Backwards compatibility
00528 // (Not tested!)
00529 
00530 #if CPPUNIT_ENABLE_CU_TEST_MACROS
00531 
00532 #define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
00533 #define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
00534 #define CU_TEST(tm) CPPUNIT_TEST(tm)
00535 #define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
00536 #define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
00537 
00538 #endif
00539 
00540 
00541 #endif  // CPPUNIT_EXTENSIONS_HELPERMACROS_H

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