CppUnit project page
FAQ
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
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
}; \
177
\
178
public: \
179
static CPPUNIT_NS::TestSuite *suite() \
180
{ \
181
const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
182
CppUnitExDeleter guard; \
183
guard.suite = new CPPUNIT_NS::TestSuite( namer.getFixtureName() ); \
184
CPPUNIT_NS::ConcretTestFixtureFactory<TestFixtureType> factory; \
185
CPPUNIT_NS::TestSuiteBuilderContextBase context( *guard.suite, \
186
namer, \
187
factory ); \
188
TestFixtureType::addTestsToSuite( context ); \
189
return guard.release(); \
190
} \
191
private:
/* dummy typedef so that the macro can still end with ';'*/
\
192
typedef int CppUnitDummyTypedefForSemiColonEnding__
193
247
#define CPPUNIT_TEST_SUITE_END_ABSTRACT() \
248
} \
249
private:
/* dummy typedef so that the macro can still end with ';'*/
\
250
typedef int CppUnitDummyTypedefForSemiColonEnding__
251
252
297
#define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \
298
context.addTest( test )
299
306
#define CPPUNIT_TEST( testMethod ) \
307
CPPUNIT_TEST_SUITE_ADD_TEST( \
308
( new CPPUNIT_NS::TestCaller<TestFixtureType>( \
309
context.getTestNameFor( #testMethod), \
310
&TestFixtureType::testMethod, \
311
context.makeFixture() ) ) )
312
337
#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
338
CPPUNIT_TEST_SUITE_ADD_TEST( \
339
(new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
340
new CPPUNIT_NS::TestCaller< TestFixtureType >( \
341
context.getTestNameFor( #testMethod ), \
342
&TestFixtureType::testMethod, \
343
context.makeFixture() ) ) ) )
344
361
#define CPPUNIT_TEST_FAIL( testMethod ) \
362
CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
363
412
#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
413
testAdderMethod( context )
414
422
#define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
423
context.addProperty( std::string(APropertyKey), \
424
std::string(APropertyValue) )
425
447
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
448
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
449
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
450
451
489
#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
490
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
491
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
492
520
#define CPPUNIT_REGISTRY_ADD( which, to ) \
521
static CPPUNIT_NS::AutoRegisterRegistry \
522
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
523
533
#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
534
static CPPUNIT_NS::AutoRegisterRegistry \
535
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
536
537
// Backwards compatibility
538
// (Not tested!)
539
540
#if CPPUNIT_ENABLE_CU_TEST_MACROS
541
542
#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
543
#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
544
#define CU_TEST(tm) CPPUNIT_TEST(tm)
545
#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
546
#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
547
548
#endif
549
550
551
#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H
TestNamer.h
AutoRegisterSuite.h
TestSuite.h
TestFixtureFactory.h
TestSuiteBuilderContext.h
ExceptionTestCaseDecorator.h
TestCaller.h
Send comments to:
CppUnit Developers