I'm working with CPPUNIT 1.12.1.
It has those macro defined:
#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 (as CPPUNIT works, every test must be a void
function, so using template makes it possible to call the same void
function with different "parameters"...).
This works perfectly:
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() { /* test here */ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(MyTestSuite1);
while this does 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() { /* test here */ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(MyTestSuite2);
Compiler (Visual Studio 2015) reports:
1>b:\dev\vobs_diabeloop\private\tst\regulation\cppunit\hyper_ftac3\test.cpp(20): warning C4002: too many actual parameters for macro 'CPPUNIT_TEST' 1>b:\dev\vobs_diabeloop\private\tst\regulation\cppunit\hyper_ftac3\test.cpp(21): warning C4002: too many actual parameters for macro 'CPPUNIT_TEST' 1>b:\dev\vobs_diabeloop\private\tst\regulation\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 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\regulation\cppunit\hyper_ftac3\test.cpp(22): error C2065: 'factory': undeclared identifier 1>b:\dev\vobs_diabeloop\private\tst\regulation\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 is that? How could the macro handle correctly 1 template parameter, but fails for two? Any idea how I could easily have it compile and work?
Edit:
Already tried CPPUNIT_TEST((doTest<false,false>));
without success (getting error C2143: syntax error: missing ';' before ')'
)
#define COMMA ,
thenCPPUNIT_TEST(doTest<false COMMA false>);
– StormCPPUNIT_TEST((doTest<false,false>));
->&TestFixtureType::(doTest<false,false>)
is invalid. Preprocessor thinkCPPUNIT_TEST(doTest<false COMMA false>);
has 1 parameter – Regimen