CppUnit - The Unit Testing Library

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>
11#include <cppunit/extensions/AutoRegisterSuite.h>
12#include <cppunit/extensions/ExceptionTestCaseDecorator.h>
13#include <cppunit/extensions/TestFixtureFactory.h>
14#include <cppunit/extensions/TestNamer.h>
15#include <cppunit/extensions/TestSuiteBuilderContext.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 \
169public: \
170 static CPPUNIT_NS::TestSuite *suite() \
171 { \
172 const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
173 std::unique_ptr<CPPUNIT_NS::TestSuite> guard( \
174 new CPPUNIT_NS::TestSuite( namer.getFixtureName() )); \
175 CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory; \
176 CPPUNIT_NS::TestSuiteBuilderContextBase context( *guard.get(), \
177 namer, \
178 factory ); \
179 TestFixtureType::addTestsToSuite( context ); \
180 return guard.release(); \
181 } \
182 private: /* dummy typedef so that the macro can still end with ';'*/ \
183 typedef int CppUnitDummyTypedefForSemiColonEnding__
184
238#define CPPUNIT_TEST_SUITE_END_ABSTRACT() \
239 } \
240 private: /* dummy typedef so that the macro can still end with ';'*/ \
241 typedef int CppUnitDummyTypedefForSemiColonEnding__
242
255#define CPPUNIT_TEST_FIXTURE(TestClass, TestName) \
256 class TestName : public TestClass \
257 { \
258 public: \
259 void TestBody(); \
260 CPPUNIT_TEST_SUITE(TestName); \
261 CPPUNIT_TEST(TestBody); \
262 CPPUNIT_TEST_SUITE_END(); \
263 }; \
264 CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
265 void TestName::TestBody()
266
311#define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
312 context.addTest( test )
313
320#define CPPUNIT_TEST( testMethod ) \
321 CPPUNIT_TEST_SUITE_ADD_TEST( \
322 ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
323 context.getTestNameFor( #testMethod), \
324 &TestFixtureType::testMethod, \
325 context.makeFixture() ) ) )
326
327#define CPPUNIT_TEST_PARAMETERIZED( testMethod, ... ) \
328 for (auto& i : __VA_ARGS__) \
329 { \
330 TestFixtureType* fixture = context.makeFixture(); \
331 CPPUNIT_TEST_SUITE_ADD_TEST( \
332 ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
333 context.getTestNameFor(#testMethod, i), \
334 std::bind(&TestFixtureType::testMethod, fixture, i), \
335 fixture))); \
336 }
337
362#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
363 CPPUNIT_TEST_SUITE_ADD_TEST( \
364 (new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
365 new CPPUNIT_NS::TestCaller< TestFixtureType >( \
366 context.getTestNameFor( #testMethod ), \
367 &TestFixtureType::testMethod, \
368 context.makeFixture() ) ) ) )
369
386#define CPPUNIT_TEST_FAIL( testMethod ) \
387 CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
388
437#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
438 testAdderMethod( context )
439
447#define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
448 context.addProperty( std::string(APropertyKey), \
449 std::string(APropertyValue) )
450
472#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
473 static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
474 CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
475
476
514#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
515 static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
516 CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
517
545#define CPPUNIT_REGISTRY_ADD( which, to ) \
546 static CPPUNIT_NS::AutoRegisterRegistry \
547 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
548
558#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
559 static CPPUNIT_NS::AutoRegisterRegistry \
560 CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
561
562// Backwards compatibility
563// (Not tested!)
564
565#if CPPUNIT_ENABLE_CU_TEST_MACROS
566
567#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
568#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
569#define CU_TEST(tm) CPPUNIT_TEST(tm)
570#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
571#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
572
573#endif
574
575
576#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H
AutoRegisterSuite.h
ExceptionTestCaseDecorator.h
TestCaller.h
TestFixtureFactory.h
TestNamer.h
TestSuite.h
TestSuiteBuilderContext.h

| Send comments to: CppUnit Developers