CppUnit project page FAQ

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  struct CppUnitExDeleter { /* avoid deprecated auto_ptr warnings */ \
170  CPPUNIT_NS::TestSuite *suite; \
171  CppUnitExDeleter() : suite (0) {} \
172  ~CppUnitExDeleter() { delete suite; } \
173  CPPUNIT_NS::TestSuite *release() { \
174  CPPUNIT_NS::TestSuite *tmp = suite; suite = NULL; return tmp; \
175  } \
176  private: \
177  /*prevent copy c'tor and operator=*/ \
178  CppUnitExDeleter(const CppUnitExDeleter&); \
179  CppUnitExDeleter& operator=(const CppUnitExDeleter&); \
180  }; \
181  \
182 public: \
183  static CPPUNIT_NS::TestSuite *suite() \
184  { \
185  const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
186  CppUnitExDeleter guard; \
187  guard.suite = new CPPUNIT_NS::TestSuite( namer.getFixtureName() ); \
188  CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory; \
189  CPPUNIT_NS::TestSuiteBuilderContextBase context( *guard.suite, \
190  namer, \
191  factory ); \
192  TestFixtureType::addTestsToSuite( context ); \
193  return guard.release(); \
194  } \
195  private: /* dummy typedef so that the macro can still end with ';'*/ \
196  typedef int CppUnitDummyTypedefForSemiColonEnding__
197 
239 #define CPPUNIT_TEST_SUITE_SETUP()
240 
282 #define CPPUNIT_TEST_SUITE_TEARDOWN()
283 
284 
338 #define CPPUNIT_TEST_SUITE_END_ABSTRACT() \
339  } \
340  private: /* dummy typedef so that the macro can still end with ';'*/ \
341  typedef int CppUnitDummyTypedefForSemiColonEnding__
342 
343 
388 #define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
389  context.addTest( test )
390 
397 #define CPPUNIT_TEST( testMethod ) \
398  CPPUNIT_TEST_SUITE_ADD_TEST( \
399  ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
400  context.getTestNameFor( #testMethod), \
401  &TestFixtureType::testMethod, \
402  context.makeFixture() ) ) )
403 
428 #define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
429  CPPUNIT_TEST_SUITE_ADD_TEST( \
430  (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
431  new CPPUNIT_NS::TestCaller< TestFixtureType >( \
432  context.getTestNameFor( #testMethod ), \
433  &TestFixtureType::testMethod, \
434  context.makeFixture() ) ) ) )
435 
452 #define CPPUNIT_TEST_FAIL( testMethod ) \
453  CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
454 
503 #define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
504  testAdderMethod( context )
505 
513 #define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
514  context.addProperty( std::string(APropertyKey), \
515  std::string(APropertyValue) )
516 
538 #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
539  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
540  CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
541 
542 
580 #define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
581  static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
582  CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
583 
611 #define CPPUNIT_REGISTRY_ADD( which, to ) \
612  static CPPUNIT_NS::AutoRegisterRegistry \
613  CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
614 
624 #define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
625  static CPPUNIT_NS::AutoRegisterRegistry \
626  CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
627 
628 // Backwards compatibility
629 // (Not tested!)
630 
631 #if CPPUNIT_ENABLE_CU_TEST_MACROS
632 
633 #define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
634 #define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
635 #define CU_TEST(tm) CPPUNIT_TEST(tm)
636 #define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
637 #define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
638 
639 #endif
640 
641 
642 #endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H

Send comments to:
CppUnit Developers