[Cppunit-devel] hierarchy sample bug...
Brought to you by:
blep
From: Baptiste L. <bl...@cl...> - 2001-05-05 21:43:11
|
Well, another stuff to clean up would be that one. There is a well hidden bug in this sample dealing with hiearchy: In the template BoardGameTest: virtual void registerTests(CppUnit::TestSuite *suite) { suite->addTest (new CppUnit::TestCaller<BoardGameTest> ("testReset", &BoardGameTest<GAMECLASS>::testReset)); suite->addTest (new CppUnit::TestCaller<BoardGameTest> ("testReset", &BoardGameTest<GAMECLASS>::testResetShouldFail)); } => BoardGameTest class will be instantiated by each test caller. and: class ChessTest : public BoardGameTest<GAMECLASS> { ... void registerTests(CppUnit::TestSuite *suite) { BoardGameTest<GAMECLASS>::registerTests(suite); suite->addTest ( new CppUnit::TestCaller<ChessTest> ("testNumberOfPieces", &ChessTest<GAMECLASS>::testNumberOfPieces)); } => for ChessTest we have the parent class test caller instantiating BoardGameTest instead of ChessTest !!!! The way I found to correct this is to make registerTests() a template member :-(. This is done in the HelperMacros as follow: static CppUnit::Test *suite() __ThisTestCaseType *test =NULL; CppUnit::TestSuiteBuilder<__ThisTestCaseType> suite; __ThisTestCaseType::registerTests( suite, test ); return suite.takeSuite(); } template<class TestCaseType> static void registerTests( CppUnit::TestSuiteBuilder<TestCaseType> &suite, TestCaseType *test ) { __ThisSuperClassType::registerTests( suite, test ) ... } At the current time, I haven't found any easier way to to this :-(. Any ideas ? Baptiste. --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Author of The Text Reformatter, a tool for fanfiction readers and writers. Language: English, French (Well, I'm French). |