CppUnit project page FAQ CppUnit home page

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

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/Portability.h>
00010 #include <cppunit/extensions/AutoRegisterSuite.h>
00011 #include <cppunit/extensions/TestSuiteBuilder.h>
00012 #include <string>
00013 
00014 // The macro __CPPUNIT_SUITE_CTOR_ARGS expand to an expression used to construct
00015 // the TestSuiteBuilder with macro CPPUNIT_TEST_SUITE.
00016 //
00017 // The name of the suite is obtained using RTTI if CPPUNIT_USE_TYPEINFO_NAME 
00018 // is defined, otherwise it is extracted from the macro parameter
00019 //
00020 // This macro is for cppunit internal and should not be use otherwise.
00021 #if CPPUNIT_USE_TYPEINFO_NAME
00022 #  define __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType )
00023 #else
00024 #  define __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType ) (std::string(#ATestCaseType))
00025 #endif
00026 
00027 
00101 #define CPPUNIT_TEST_SUITE( ATestCaseType )                               \
00102   private:                                                                \
00103     typedef ATestCaseType __ThisTestCaseType;                             \
00104     class ThisTestCaseFactory : public CppUnit::TestFactory               \
00105     {                                                                     \
00106       virtual CppUnit::Test *makeTest()                                   \
00107       {                                                                   \
00108         return new ATestCaseType();                                       \
00109       }                                                                   \
00110     };                                                                    \
00111   public:                                                                 \
00112     static void                                                           \
00113     registerTests( CppUnit::TestSuite *suite,                             \
00114                    CppUnit::TestFactory *factory )                        \
00115     {                                                                     \
00116       CppUnit::TestSuiteBuilder<__ThisTestCaseType> builder( suite );
00117 
00118 
00148 #define CPPUNIT_TEST_SUB_SUITE( ATestCaseType, ASuperClass )  \
00149   private:                                                    \
00150     typedef ASuperClass __ThisSuperClassType;                 \
00151     CPPUNIT_TEST_SUITE( ATestCaseType );                      \
00152       __ThisSuperClassType::registerTests( suite, factory )
00153 
00154 
00161 #define CPPUNIT_TEST( testMethod )                                      \
00162       builder.addTestCaller( #testMethod,                               \
00163                              &__ThisTestCaseType::testMethod ,          \
00164                              (__ThisTestCaseType*)factory->makeTest() ) 
00165 
00166 
00174 #define CPPUNIT_TEST_SUITE_END()                                        \
00175       builder.takeSuite();                                              \
00176     }                                                                   \
00177     static CppUnit::TestSuite *suite()                                  \
00178     {                                                                   \
00179       CppUnit::TestSuiteBuilder<__ThisTestCaseType>                     \
00180           builder __CPPUNIT_SUITE_CTOR_ARGS( ATestCaseType );           \
00181       ThisTestCaseFactory factory;                                      \
00182       __ThisTestCaseType::registerTests( builder.suite(), &factory );   \
00183       return builder.takeSuite();                                       \
00184     }                                                                   \
00185   private: /* dummy typedef so that the macro can still end with ';'*/  \
00186     typedef ThisTestCaseFactory __ThisTestCaseFactory                   
00187 
00188 #define __CPPUNIT_CONCATENATE_DIRECT( s1, s2 ) s1##s2
00189 #define __CPPUNIT_CONCATENATE( s1, s2 ) __CPPUNIT_CONCATENATE_DIRECT( s1, s2 )
00190 
00194 #define __CPPUNIT_MAKE_UNIQUE_NAME( str ) __CPPUNIT_CONCATENATE( str, __LINE__ )
00195 
00196 
00209 #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestCaseType )                     \
00210   static CppUnit::AutoRegisterSuite< ATestCaseType >                    \
00211              __CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )
00212 
00213 
00214 // Backwards compatibility
00215 // (Not tested!)
00216 
00217 #if CPPUNIT_ENABLE_CU_TEST_MACROS
00218 
00219 #define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
00220 #define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
00221 #define CU_TEST(tm) CPPUNIT_TEST(tm)
00222 #define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
00223 #define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
00224 
00225 #endif
00226 
00227 
00228 #endif  // CPPUNIT_EXTENSIONS_HELPERMACROS_H

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