I work with CPPUNIT 1.12.1.
It has the following macros:
#define CPPUNIT_TEST_SUITE_ADD_TEST( test ) \ context.addTest( test ) #define CPPUNIT_TEST( testMethod ) \ CPPUNIT_TEST_SUITE_ADD_TEST( \ ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \ context.getTestNameFor( #testMethod), \ &TestFixtureType::testMethod, \ context.makeFixture() ) ) )
I want to add many tests to the same test suite using templates (how CPPUNIT works, each test should be a void function, so using a template allows you to call the same void function with different "parameters", ...).
This works great:
class MyTestSuite1 : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(MyTestSuite1); CPPUNIT_TEST(doTest<false>); CPPUNIT_TEST(doTest<true>); CPPUNIT_TEST_SUITE_END(); template<bool param> void doTest() { } }; CPPUNIT_TEST_SUITE_REGISTRATION(MyTestSuite1);
while it is not:
class MyTestSuite2 : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(MyTestSuite2); CPPUNIT_TEST(doTest<false,false>); CPPUNIT_TEST(doTest<true,false>); CPPUNIT_TEST_SUITE_END(); template<bool param1,bool param2> void doTest() { } }; CPPUNIT_TEST_SUITE_REGISTRATION(MyTestSuite2);
Compiler Reports (Visual Studio 2015):
1> b: \ DEV \ vobs_diabeloop \ private \ TST \ regulation \ CppUnit \ hyper_ftac3 \ test.cpp (20): warning C4002: too many actual parameters for the macro "CPPUNIT_TEST" 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ throttling \ CppUnit \ hyper_ftac3 \ test.cpp (21): warning C4002: too many actual parameters for the macro "CPPUNIT_TEST" 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ throttling \ CppUnit \ hyper_ftac3 \ test.cpp (20 ): error C2059: syntax error: ')' 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ regulation \ CppUnit \ hyper_ftac3 \ test.cpp (21): error C2059: syntax error: ')' 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ regulation \ CppUnit \ hyper_ftac3 \ test.cpp (22): error C2143: syntax I error: missing ';' before '}' 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ regulation \ CppUnit \ hyper_ftac3 \ test.cpp (22): error C2065: 'namer': undeclared identifier 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ throttling \ CppUnit \ hyper_ftac3 \ test.cpp (22): error C2065: 'factory': undeclared identifier 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ throttling \ CppUnit \ hyper_ftac3 \ test.cpp (22): error C2059: syntax error: ')' 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ regulation \ CppUnit \ hyper_ftac3 \ test.cpp (29): error C2143: syntax error: missing ';' before '{' 1> b: \ DEV \ vobs_diabeloop \ private \ TST \ regulation \ CppUnit \ hyper_ftac3 \ test.cpp (30): error C2143: syntax error: missing ';' before '{'
Why? How can a macro correctly handle 1 template parameter, but cannot execute two? Any idea how I could easily compile and work it?
Edit: Already tried CPPUNIT_TEST((doTest<false,false>)); without success (getting error C2143: syntax error: missing ';' before ')' )
c ++ macros templates cppunit
jpo38
source share