summaryrefslogtreecommitdiff
path: root/include/cppunit/extensions
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-05-18 18:32:42 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-05-18 18:32:42 +0000
commit82017693c2dcaab03556154d990fe44591fb6f0a (patch)
tree296fe4d4d48a6dbd3545f31ce9b7418c08c997d7 /include/cppunit/extensions
parent15bf5fbb250670464df54ef9155cc3b391118523 (diff)
downloadcppunit-82017693c2dcaab03556154d990fe44591fb6f0a.tar.gz
:registerFactory(factory) now generate a dummy name based on a serial number instead of using RTTI.
* Symbol CU_USE_TYPEINFO must be defined instead of USE_TYPEINFO to compile RTTI. * Added back default constructor to TestSuiteBuilder which use RTTI. It is available only if CU_USE_TYPEINFO is defined. * Moved TypeInfoHelper.h from src/cppunit to include/cppunit/extensions. * Macro CU_TEST_SUITE in HelperMacros.h now use TestSuiteBuilder default constructor if CU_USE_TYPEINFO is defined, otherwise it use the type name given to the CU_TEST_SUITE macro. * TestFactoryRegistry::registerFactory(factory) now generate a dummy name based on a serial number instead of using RTTI. The macro CU_TEST_SUITE_REGISTRATION and class AutoRegisterSuite can now when CU_USE_TYPEINFO is not defined. * Added a new Configuration named "Debug Without CU_USE_TYPEINFO" to msvc6 projects. The flag CU_USE_TYPEINFO is not defined in that configuration.
Diffstat (limited to 'include/cppunit/extensions')
-rw-r--r--include/cppunit/extensions/HelperMacros.h29
-rw-r--r--include/cppunit/extensions/TestFactoryRegistry.h2
-rw-r--r--include/cppunit/extensions/TestSuiteBuilder.h12
-rw-r--r--include/cppunit/extensions/TypeInfoHelper.h29
4 files changed, 64 insertions, 8 deletions
diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h
index 126483e..cb6869d 100644
--- a/include/cppunit/extensions/HelperMacros.h
+++ b/include/cppunit/extensions/HelperMacros.h
@@ -1,5 +1,5 @@
// //////////////////////////////////////////////////////////////////////////
-// Header file AutoRegisterTests.h for class AutoRegisterTests
+// Header file HelperMacros.h
// (c)Copyright 2000, Baptiste Lepilleur.
// Created: 2001/04/15
// //////////////////////////////////////////////////////////////////////////
@@ -10,6 +10,23 @@
#include <cppunit/extensions/AutoRegisterSuite.h>
#include <cppunit/extensions/TestSuiteBuilder.h>
+// The macro __CU_SUITE_CTOR_ARGS expand to an expression used to construct
+// the TestSuiteBuilder with macro CU_TEST_SUITE.
+//
+// The name of the suite is extracted from the macro parameter
+// if CU_USE_TYPEINFO is not defined, otherwise it is extracted using
+// RTTI.
+//
+// This macro is for cppunit internal and should not be use otherwise.
+#ifdef CU_USE_TYPEINFO
+#define __CU_SUITE_CTOR_ARGS( ATestCaseType )
+
+#else // CU_USE_TYPEINFO
+#define __CU_SUITE_CTOR_ARGS( ATestCaseType ) (std::string(#ATestCaseType))
+
+#endif // CU_USE_TYPEINFO
+
+
/** Begins the declaration of the test suite
*
* The CU_TEST_XXX macros are helper to define test suite that are
@@ -78,7 +95,7 @@
{ \
__ThisTestCaseType *test =NULL; \
CppUnit::TestSuiteBuilder<__ThisTestCaseType> \
- suite(std::string(#ATestCaseType)); \
+ suite __CU_SUITE_CTOR_ARGS( ATestCaseType ); \
__ThisTestCaseType::registerTests( suite, test ); \
return suite.takeSuite(); \
} \
@@ -141,13 +158,13 @@
} \
private:
-#define CU_CONCATENATE_DIRECT( s1, s2 ) s1##s2
-#define CU_CONCATENATE( s1, s2 ) CU_CONCATENATE_DIRECT( s1, s2 )
+#define __CU_CONCATENATE_DIRECT( s1, s2 ) s1##s2
+#define __CU_CONCATENATE( s1, s2 ) __CU_CONCATENATE_DIRECT( s1, s2 )
/** Decorates the specified string with the line number to obtain a unique name;
* @param str String to decorate.
*/
-#define CU_MAKE_UNIQUE_NAME( str ) CU_CONCATENATE( str, __LINE__ )
+#define __CU_MAKE_UNIQUE_NAME( str ) __CU_CONCATENATE( str, __LINE__ )
/** Implementation of the auto-registration of test into the TestRegistry.
* Should be placed in the cpp file.
@@ -158,7 +175,7 @@
*/
#define CU_TEST_SUITE_REGISTRATION( ATestCaseType ) \
static CppUnit::AutoRegisterSuite< ATestCaseType > \
- CU_MAKE_UNIQUE_NAME(__autoRegisterSuite )
+ __CU_MAKE_UNIQUE_NAME(__autoRegisterSuite )
#endif // CPPUNIT_EXTENSIONS_HELPERMACROS_H
diff --git a/include/cppunit/extensions/TestFactoryRegistry.h b/include/cppunit/extensions/TestFactoryRegistry.h
index cc6c035..2475e57 100644
--- a/include/cppunit/extensions/TestFactoryRegistry.h
+++ b/include/cppunit/extensions/TestFactoryRegistry.h
@@ -56,12 +56,10 @@ namespace CppUnit {
void registerFactory( const std::string &name,
TestFactory *factory );
-#ifdef USE_TYPEINFO
/** Registers a test factory using its class name.
* \param factory Factory to register.
*/
void registerFactory( TestFactory *factory );
-#endif // USE_TYPEINFO
private:
TestFactoryRegistry( const TestFactoryRegistry &copy );
diff --git a/include/cppunit/extensions/TestSuiteBuilder.h b/include/cppunit/extensions/TestSuiteBuilder.h
index ab553e9..11b86fb 100644
--- a/include/cppunit/extensions/TestSuiteBuilder.h
+++ b/include/cppunit/extensions/TestSuiteBuilder.h
@@ -5,6 +5,10 @@
#include <cppunit/TestSuite.h>
#include <cppunit/TestCaller.h>
+#ifdef CU_USE_TYPEINFO
+#include <cppunit/extensions/TypeInfoHelper.h>
+#endif // CU_USE_TYPEINFO
+
namespace CppUnit {
template<typename Fixture>
@@ -13,6 +17,14 @@ namespace CppUnit {
public:
typedef void (Fixture::*TestMethod)();
+#ifdef CU_USE_TYPEINFO
+ TestSuiteBuilder() :
+ m_suite( new TestSuite(
+ TypeInfoHelper::getClassName( typeid(Fixture) ) ) )
+ {
+ }
+#endif // CU_USE_TYPEINFO
+
TestSuiteBuilder( TestSuite *suite ) : m_suite( suite )
{
}
diff --git a/include/cppunit/extensions/TypeInfoHelper.h b/include/cppunit/extensions/TypeInfoHelper.h
new file mode 100644
index 0000000..8ce5b16
--- /dev/null
+++ b/include/cppunit/extensions/TypeInfoHelper.h
@@ -0,0 +1,29 @@
+#ifndef CPPUNIT_TYPEINFOHELPER_H
+#define CPPUNIT_TYPEINFOHELPER_H
+
+#ifdef CU_USE_TYPEINFO
+
+#include <typeinfo>
+
+
+namespace CppUnit {
+
+ /** Helper to use type_info.
+ */
+ class TypeInfoHelper
+ {
+ public:
+ /** Get the class name of the specified type_info.
+ * \param info Info which the class name is extracted from.
+ * \return The string returned by type_info::name() without
+ * the "class" prefix. If the name is not prefixed
+ * by "class", it is returned as this.
+ */
+ static std::string getClassName( const std::type_info &info );
+ };
+
+} // namespace CppUnit
+
+#endif // CU_USE_TYPEINFO
+
+#endif // CPPUNIT_TYPEINFOHELPER_H