mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
more easy, 1 single macro
This commit is contained in:
parent
1a2908119b
commit
5bd95da3bf
1 changed files with 11 additions and 17 deletions
|
|
@ -3,29 +3,23 @@
|
|||
|
||||
#include "ParameterizedTest.h"
|
||||
|
||||
// For a local usage, use SET_SUITE_PARAMETERS directly in your "myTestSuite.cpp".
|
||||
// If you want to reuse a parameterized from an other *.cpp file, use IMPORT_SUITE_PARAMETERS in the new file.
|
||||
// If you want to generalize a parameterized (example: "myParameterizedGlobals.h"), use SET_SUITE_PARAMETERS in the *.cpp and IMPORT_SUITE_PARAMETERS in the *.h
|
||||
//
|
||||
// Warning: please do not use SET_SUITE_PARAMETERS in a *.h file, you might have unexpected duplicate instances !
|
||||
|
||||
|
||||
#define SET_SUITE_PARAMETERS(Type, IterationName, SetUpBody) \
|
||||
class ParameterizedCreator ## IterationName\
|
||||
class ParameterizedCreator ## IterationName \
|
||||
{ \
|
||||
public: \
|
||||
ParameterizedCreator ## IterationName() { create(); } \
|
||||
vector<## Type> parameters; \
|
||||
ParameterizedCreator ## IterationName() : globalInstance(getGlobalInstance()) {} \
|
||||
UnitTest::ParameterizedTest<## Type> & globalInstance; \
|
||||
private: \
|
||||
void create() \
|
||||
## SetUpBody \
|
||||
} parameterizedCreator ## IterationName ## Instance; \
|
||||
static UnitTest::ParameterizedTest<## Type> & getGlobalInstance() \
|
||||
{ \
|
||||
static UnitTest::ParameterizedTest<## Type> instance(create(), #IterationName); \
|
||||
return instance; \
|
||||
} \
|
||||
static vector<## Type> create() { vector<## Type> parameters; SetUpBody return parameters; } \
|
||||
} static parameterizedCreator ## IterationName ## Instance; \
|
||||
\
|
||||
UnitTest::ParameterizedTest<## Type> ## IterationName(parameterizedCreator ## IterationName ## Instance.parameters, #IterationName);
|
||||
|
||||
|
||||
#define IMPORT_SUITE_PARAMETERS(Type, IterationName) \
|
||||
extern UnitTest::ParameterizedTest<## Type> ## IterationName;
|
||||
static UnitTest::ParameterizedTest<## Type> & ## IterationName(parameterizedCreator ## IterationName ## Instance.globalInstance)
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue