more easy, 1 single macro

This commit is contained in:
Gabriel Schlozer 2016-06-09 12:02:52 +02:00
parent 1a2908119b
commit 5bd95da3bf

View file

@ -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