CppUnit project page
FAQ
CppUnit home page
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
static CPPUNIT_NS::TestSuite *suite() \
170
{ \
171
const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \
172
std::auto_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
327
#define CPPUNIT_TEST_EXCEPTION( testMethod, ExceptionType ) \
328
CPPUNIT_TEST_SUITE_ADD_TEST( \
329
(new CPPUNIT_NS::ExceptionTestCaseDecorator< ExceptionType >( \
330
new CPPUNIT_NS::TestCaller< TestFixtureType >( \
331
context.getTestNameFor( #testMethod ), \
332
&TestFixtureType::testMethod, \
333
context.makeFixture() ) ) ) )
334
351
#define CPPUNIT_TEST_FAIL( testMethod ) \
352
CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )
353
402
#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS( testAdderMethod ) \
403
testAdderMethod( context )
404
412
#define CPPUNIT_TEST_SUITE_PROPERTY( APropertyKey, APropertyValue ) \
413
context.addProperty( std::string(APropertyKey), \
414
std::string(APropertyValue) )
415
437
#define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \
438
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
439
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )
440
441
479
#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ATestFixtureType, suiteName ) \
480
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
481
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)
482
510
#define CPPUNIT_REGISTRY_ADD( which, to ) \
511
static CPPUNIT_NS::AutoRegisterRegistry \
512
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )
513
523
#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \
524
static CPPUNIT_NS::AutoRegisterRegistry \
525
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )
526
527
// Backwards compatibility
528
// (Not tested!)
529
530
#if CPPUNIT_ENABLE_CU_TEST_MACROS
531
532
#define CU_TEST_SUITE(tc) CPPUNIT_TEST_SUITE(tc)
533
#define CU_TEST_SUB_SUITE(tc,sc) CPPUNIT_TEST_SUB_SUITE(tc,sc)
534
#define CU_TEST(tm) CPPUNIT_TEST(tm)
535
#define CU_TEST_SUITE_END() CPPUNIT_TEST_SUITE_END()
536
#define CU_TEST_SUITE_REGISTRATION(tc) CPPUNIT_TEST_SUITE_REGISTRATION(tc)
537
538
#endif
539
540
541
#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H
TestNamer.h
AutoRegisterSuite.h
TestSuite.h
TestFixtureFactory.h
TestSuiteBuilderContext.h
ExceptionTestCaseDecorator.h
TestCaller.h
hosts this site.
Send comments to:
CppUnit Developers