Fw: [Cppunit-devel] A better version of CPPUNIT_TEST_SUITE_REGISTRATION macro(?)
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-08-05 08:25:29
|
Baptiste Lepilleur wrote: > Gola Bartlomiej-ABG014 wrote: >> Hi Baptiste, >> >> Yes, you are right, the original version of the >> CPPUNIT_TEST_SUITE_REGISTRATION macro work well in source files. >> However my version of this macro can also be used in header files. >> That's why I dare to say it's a bit better than the original. > > The problem with the proposed implementation is that is does not work > with all 'ATestFixtureType ' types. It assumes that the Type is a > simple identifier while CppUnit allows just any types. For example: > > CPPUNIT_TEST_SUITE_REGISTRATION( MyNamespace::SomeTest ) > CPPUNIT_TEST_SUITE_REGISTRATION( BoardGameTest<BoardGame> ) > > are perfectly valid usage. > >> >> Of course it is a matter of style or personal preference whether one >> creates unit test code using header file only (or a classic pair: >> header + source file). I myself prefer to have a test code for a >> given class in a single header file. And that's why I've created the >> new version of the CPPUNIT_TEST_SUITE_REGISTRATION macro. > > I see two solutions: > - stick to using only source files instead of headers (registration > works fine and meet is initial goal of preventing compile time > dependencies) - use only headers and drop registration macros: use > explicit registration such as > runner.addTest( BoardGameTest<BoardGame>::suite() ); > runner.addTest( ChessTest<Chess>::suite() ); > as atempting to use registration macro in that context completly > defeat their initial goal. > > Baptiste. >> [...] >> >> Hi, >> >> I've encountered a problem when using CPPUNIT_TEST_SUITE_REGISTRATION >> macro. >> >> I have several files with various tests and in each one of them I'm >> using the above macro to register the test class. The problem arises >> when you put the registration macro in the same line (but in the >> separate files!) which generates compilation error (identifier >> redefinition). >> >> To resolve the problem, I've modified the >> CPPUNIT_TEST_SUITE_REGISTRATION macro: instead of using the >> "autoRegisterRegistry__" prefix for a class name, a little bit more >> complex syntax could be used. >> >> The modified macro: >> #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \ >> static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \ >> CPPUNIT_MAKE_UNIQUE_NAME( CPPUNIT_JOIN(ATestFixtureType, >> _AutoRegisterSuite_) ) >> >> >> The original version: >> #define CPPUNIT_TEST_SUITE_REGISTRATION( ATestFixtureType ) \ >> static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \ >> CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ ) >> >> If you think it is a good idea I would more than happy if you used my >> solution in the next CppUnit version. >> >> Best regards and thanks for a great test framework, >> Bartek Gola >> > --- > Baptiste Lepilleur <bl...@us...> > CppUnit maintainer > OpenTest and CppUnit 2 developer. |