summaryrefslogtreecommitdiff
path: root/include/cppunit/extensions/AutoRegisterSuite.h
diff options
context:
space:
mode:
authorBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-04-29 13:09:16 +0000
committerBastiaan Bakker <bastiaan.bakker@lifeline.nl>2001-04-29 13:09:16 +0000
commitb08ecaecc1e39b7b01e02b7b73559d8b34ff46a5 (patch)
treebf1ed1e3680cb0256e73336e22fb70c692524fcb /include/cppunit/extensions/AutoRegisterSuite.h
parent5ce1a68589aa3ea4f9ee255cfecc94cc1730c6fa (diff)
downloadcppunit-b08ecaecc1e39b7b01e02b7b73559d8b34ff46a5.tar.gz
Merged Baptiste Lepilleurs CppUnitW 1.2.
Some differences: TypeInfo stuff (in TestSuite) compiled in only if USE_TYPEINFO is set. TestSuite.getTests now returns a const ref instead of taking a ref as param. Removed auto_ptr stuff from TestFactoryRegistry: auto_ptr cannot be used in containers.
Diffstat (limited to 'include/cppunit/extensions/AutoRegisterSuite.h')
-rw-r--r--include/cppunit/extensions/AutoRegisterSuite.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/include/cppunit/extensions/AutoRegisterSuite.h b/include/cppunit/extensions/AutoRegisterSuite.h
new file mode 100644
index 0000000..a9fb117
--- /dev/null
+++ b/include/cppunit/extensions/AutoRegisterSuite.h
@@ -0,0 +1,47 @@
+#ifndef CPPUNIT_AUTOREGISTERSUITE_H
+#define CPPUNIT_AUTOREGISTERSUITE_H
+
+#include <string>
+
+#include "TestSuiteFactory.h"
+#include "TestFactoryRegistry.h"
+
+
+namespace CppUnit {
+
+ /** Automatically register the test suite of the specified type.
+ *
+ * This object will register the test returned by TestCaseType::suite()
+ * when constructed to the test registry.
+ *
+ * This object is intented to be used as a static variable.
+ *
+ * \param TestCaseType Type of the test case which suite is registered.
+ * \see CU_TEST_SUITE_REGISTRATION.
+ */
+ template<class TestCaseType>
+ class AutoRegisterSuite
+ {
+ public:
+ /** Auto-register the suite factory in the global registry.
+ */
+ AutoRegisterSuite()
+ {
+ AbstractTestFactory *factory = new TestSuiteFactory<TestCaseType>();
+ TestFactoryRegistry::getRegistry().registerFactory( factory );
+ }
+
+ /** Auto-register the suite factory in the specified registry.
+ * \param name Name of the registry.
+ */
+ AutoRegisterSuite( const std::string &name )
+ {
+ TestSuiteFactory *factory = new TestSuiteFactory<TestCaseType>();
+ TestFactoryRegistry::getRegistry( name ).registerFactory( factory );
+ }
+ };
+
+} // namespace CppUnit
+
+
+#endif // CPPUNIT_AUTOREGISTERSUITE_H