CppUnit project page
FAQ
include
cppunit
extensions
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
\
169
public: \
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
243
288
#define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
289
context.addTest( test )
290
297
#define CPPUNIT_TEST( testMethod ) \
298
CPPUNIT_TEST_SUITE_ADD_TEST( \
299
( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
300
context.getTestNameFor( #testMethod), \
301
&TestFixtureType::testMethod, \
302
context.makeFixture() ) ) )
303
304
#define CPPUNIT_TEST_PARAMETERIZED( testMethod, ... ) \
305
for (auto& i : __VA_ARGS__) \
306
{ \
307
TestFixtureType* fixture = context.makeFixture(); \
308
CPPUNIT_TEST_SUITE_ADD_TEST( \
309
( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
310
context.getTestNameFor(#testMethod, i), \
311
std::bind(&TestFixtureType::testMethod, fixture, i), \
312
fixture))); \
313
}
314
339
#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
340
CPPUNIT_TEST_SUITE_ADD_TEST( \
341
(new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
342
new CPPUNIT_NS::TestCaller< TestFixtureType >( \
343
context.getTestNameFor( #testMethod ), \
344
&TestFixtureType::testMethod, \
345
context.makeFixture() ) ) ) )
346
363
#define CPPUNIT_TEST_FAIL( testMethod ) \
364
CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
365
414
#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
415
testAdderMethod( context )
416
424
#define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
425
context.addProperty( std::string(APropertyKey), \
426
std::string(APropertyValue) )
427
449
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
450
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
451
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
452
453
491
#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
492
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
493
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
494
522
#define CPPUNIT_REGISTRY_ADD( which, to ) \
523
static CPPUNIT_NS::AutoRegisterRegistry \
524
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
525
535
#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
536
static CPPUNIT_NS::AutoRegisterRegistry \
537
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
538
539
// Backwards compatibility
540
// (Not tested!)
541
542
#if CPPUNIT_ENABLE_CU_TEST_MACROS
543
544
#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
545
#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
546
#define CU_TEST(tm) CPPUNIT_TEST(tm)
547
#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
548
#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
549
550
#endif
551
552
553
#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H
TestNamer.h
AutoRegisterSuite.h
TestSuite.h
TestFixtureFactory.h
TestSuiteBuilderContext.h
ExceptionTestCaseDecorator.h
TestCaller.h
Send comments to:
CppUnit Developers