CppUnit project page FAQ CppUnit home page

HelperMacros.h
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////////
2 // Header file HelperMacros.h
3 // (c)Copyright 2000, Baptiste Lepilleur.
4 // Created: 2001/04/15
5 // //////////////////////////////////////////////////////////////////////////
6 #ifndef CPPUNIT_EXTENSIONS_HELPERMACROS_H
7 #define CPPUNIT_EXTENSIONS_HELPERMACROS_H
8 
9 #include <cppunit/TestCaller.h>
10 #include <cppunit/TestSuite.h>
16 #include <memory>
17 
18 
100 #define CPPUNIT_TEST_SUITE( ATestFixtureType ) \
101  public: \
102  typedef ATestFixtureType TestFixtureType; \
103  \
104  private: \
105  static const CPPUNIT_NS::TestNamer &getTestNamer__() \
106  { \
107  static CPPUNIT_TESTNAMER_DECL( testNamer, ATestFixtureType ); \
108  return testNamer; \
109  } \
110  \
111  public: \
112  typedef CPPUNIT_NS::TestSuiteBuilderContext<TestFixtureType> \
113  TestSuiteBuilderContextType; \
114  \
115  static void \
116  addTestsToSuite( CPPUNIT_NS::TestSuiteBuilderContextBase &baseContext ) \
117  { \
118  TestSuiteBuilderContextType context( baseContext )
119 
120 
151 #define CPPUNIT_TEST_SUB_SUITE( ATestFixtureType, ASuperClass ) \
152  public: \
153  typedef ASuperClass ParentTestFixtureType; \
154  private: \
155  CPPUNIT_TEST_SUITE( ATestFixtureType ); \
156  ParentTestFixtureType::addTestsToSuite( baseContext )
157 
158 
166 #define CPPUNIT_TEST_SUITE_END() \
167  } \
168  \
169  static CPPUNIT_NS::TestSuite *suite() \
170  { \
171  const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
172  std::unique_ptr<CPPUNIT_NS::TestSuite> suite( \
173  new CPPUNIT_NS::TestSuite( namer.getFixtureName() )); \
174  CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory; \
175  CPPUNIT_NS::TestSuiteBuilderContextBase context( *suite.get(), \
176  namer, \
177  factory ); \
178  TestFixtureType::addTestsToSuite( context ); \
179  return suite.release(); \
180  } \
181  private: /* dummy typedef so that the macro can still end with ';'*/ \
182  typedef int CppUnitDummyTypedefForSemiColonEnding__
183 
237 #define CPPUNIT_TEST_SUITE_END_ABSTRACT() \
238  } \
239  private: /* dummy typedef so that the macro can still end with ';'*/ \
240  typedef int CppUnitDummyTypedefForSemiColonEnding__
241 
242 
287 #define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
288  context.addTest( test )
289 
296 #define CPPUNIT_TEST( testMethod ) \
297  CPPUNIT_TEST_SUITE_ADD_TEST( \
298  ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
299  context.getTestNameFor( #testMethod), \
300  &TestFixtureType::testMethod, \
301  context.makeFixture() ) ) )
302 
303 #define CPPUNIT_TEST_IGNORED( testMethod ) \
304  CPPUNIT_TEST_SUITE_ADD_TEST( \
305  ( &(new CPPUNIT_NS::TestCaller<TestFixtureType>( \
306  context.getTestNameFor( #testMethod), \
307  &TestFixtureType::testMethod, \
308  context.makeFixture() ))->setType(CPPUNIT_NS::Test::IGNORED) ) )
309 
310 #define CPPUNIT_TEST_DISABLED( testMethod ) \
311  CPPUNIT_TEST_SUITE_ADD_TEST( \
312  ( &(new CPPUNIT_NS::TestCaller<TestFixtureType>( \
313  context.getTestNameFor( #testMethod), \
314  &TestFixtureType::testMethod, \
315  context.makeFixture() ))->setType(CPPUNIT_NS::Test::DISABLED) ) )
316 
341 #define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
342  CPPUNIT_TEST_SUITE_ADD_TEST( \
343  (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
344  new CPPUNIT_NS::TestCaller< TestFixtureType >( \
345  context.getTestNameFor( #testMethod ), \
346  &TestFixtureType::testMethod, \
347  context.makeFixture() ) ) ) )
348 
365 #define CPPUNIT_TEST_FAIL( testMethod ) \
366  CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
367 
416 #define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
417  testAdderMethod( context )
418 
426 #define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
427  context.addProperty( std::string(APropertyKey), \
428  std::string(APropertyValue) )
429 
451 #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
452  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
453  CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
454 
455 
493 #define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
494  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
495  CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
496 
524 #define CPPUNIT_REGISTRY_ADD( which, to ) \
525  static CPPUNIT_NS::AutoRegisterRegistry \
526  CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
527 
537 #define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
538  static CPPUNIT_NS::AutoRegisterRegistry \
539  CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
540 
541 // Backwards compatibility
542 // (Not tested!)
543 
544 #if CPPUNIT_ENABLE_CU_TEST_MACROS
545 
546 #define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
547 #define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
548 #define CU_TEST(tm) CPPUNIT_TEST(tm)
549 #define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
550 #define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
551 
552 #endif
553 
554 
555 #endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H

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