diff --git a/UnitTest++/ParameterizedMacros.h b/UnitTest++/ParameterizedMacros.h index e2d15b9..d9d2d09 100644 --- a/UnitTest++/ParameterizedMacros.h +++ b/UnitTest++/ParameterizedMacros.h @@ -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 \ No newline at end of file