[Cppunit-devel] CU_TEST_SUITE and friends
Brought to you by:
blep
|
From: Steve M. R. <ste...@vi...> - 2001-05-25 21:38:30
|
Hi,
I discovered these macros yesterday --- they are fantastic! They make
writing the test case classes a whole lot less tedious.
I had to change two things to get them to work with GCC, however. The
first patch is a trivial matter. I don't know why the two
constructors of AutoRegisterSuite were different, but GCC didn't like
one of them.
The second patch just moves the definition of the suite() method from
CU_TEST_SUITE to CU_TEST_SUITE_END. GCC gets itself in a knot if the
code has a forward reference to a templated function. In this case
suite() calls registerTests(), but the latter is only defined after
the CU_TEST_SUITE/CU_TEST/.../CU_TEST_SUITE_END sequence. Moving the
definition of suite() cures this.
What conclusion should I draw from the fact that these macros are
hiding in the "extensions" directory? Are they less desirable in some
way that eludes me? To a novice like me, they appear MORE desirable.
I wish that the "cookbook" had been using them. I think that would
have lowered my learning curve.
In fact, I have example code, modelled on the cookbook, that uses
these macros. I'm inclined to re-write the cookbook in the CU_TEST
style and include this code in examples/ as a test program for "make
check". Shall I send this patch along, or slow down? I feel a little
like I'm shouting into a void ... are the patches unwelcome? arriving
too fast?
Regards,
-Steve
Index: AutoRegisterSuite.h
===================================================================
RCS file: /cvsroot/cppunit/cppunit/include/cppunit/extensions/AutoRegisterSuite.h,v
retrieving revision 1.4
diff -u -b -B -r1.4 AutoRegisterSuite.h
--- AutoRegisterSuite.h 2001/05/06 18:19:04 1.4
+++ AutoRegisterSuite.h 2001/05/25 21:20:18
@@ -34,7 +34,7 @@
*/
AutoRegisterSuite( const std::string &name )
{
- TestSuiteFactory *factory = new TestSuiteFactory<TestCaseType>();
+ TestFactory *factory = new TestSuiteFactory<TestCaseType>();
TestFactoryRegistry::getRegistry( name ).registerFactory( factory );
}
};
Index: HelperMacros.h
===================================================================
RCS file: /cvsroot/cppunit/cppunit/include/cppunit/extensions/HelperMacros.h,v
retrieving revision 1.6
diff -u -b -B -r1.6 HelperMacros.h
--- HelperMacros.h 2001/05/23 18:34:54 1.6
+++ HelperMacros.h 2001/05/25 21:20:18
@@ -91,14 +98,6 @@
private: \
typedef ATestCaseType __ThisTestCaseType; \
public: \
- static CppUnit::Test *suite() \
- { \
- __ThisTestCaseType *test =NULL; \
- CppUnit::TestSuiteBuilder<__ThisTestCaseType> \
- suite __CU_SUITE_CTOR_ARGS( ATestCaseType ); \
- __ThisTestCaseType::registerTests( suite, test ); \
- return suite.takeSuite(); \
- } \
template<typename TestCaseType> \
static void \
registerTests( CppUnit::TestSuiteBuilder<TestCaseType> &suite, \
@@ -156,6 +162,14 @@
*/
#define CU_TEST_SUITE_END() \
} \
+ static CppUnit::Test *suite() \
+ { \
+ __ThisTestCaseType *test =NULL; \
+ CppUnit::TestSuiteBuilder<__ThisTestCaseType> \
+ suite __CU_SUITE_CTOR_ARGS( ATestCaseType ); \
+ __ThisTestCaseType::registerTests( suite, test ); \
+ return suite.takeSuite(); \
+ } \
private:
#define __CU_CONCATENATE_DIRECT( s1, s2 ) s1##s2
--
by Rocket to the Moon,
by Airplane to the Rocket,
by Taxi to the Airport,
by Frontdoor to the Taxi,
by throwing back the blanket and laying down the legs ...
- They Might Be Giants
|