[Cppunit-devel] Macro for crossplatform development
Brought to you by:
blep
From: Baptiste L. <gai...@fr...> - 2001-06-08 16:56:12
|
Steve talking about the macros got me thinking. The main reason why they are an extension is that they use template member methods which is not very portable. Thinking a bit more, I realised that the macro where the way to use the best of your platform: if you have RTTI, then it will be used, if you don't then it won't. You can get the best of your platform without giving up portability. Here I propose a way to get ride of that template member method. The template member method is actually used to instantiate a TestCaller with the right fixture type when sublcassing. The TestCaller class has evolved since then and you can now specify the fixture instance in the constructor. What I propose is to use a factory method that returns the instance of the fixture to use. It would look like this: the CPPUNIT_TEST_SUITE would define: virtual TestCase *makeTestCase() { return new ThisTestCase(); } void registerTests( TestSuiteBuilder<ThisTestCaseType> &suite ) { and the CPPUNIT_TEST macro would do: suite.addTest( new TestCaller<ThisTestCaseType>( #method, method, makeTestCase() ) ); } I don't have the source under my hand so some stuff might be a bit of, but the idea is there. You could even have a version of the macro not defining the method makeTestCase(), allowing you to construct the test case in a specific way when your subclassing a test case. So what do you think ? Baptiste. --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Language: English, French |