1 #ifndef CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
2 #define CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
4 #include <cppunit/extensions/TestSuiteFactory.h>
5 #include <cppunit/extensions/TestFactoryRegistry.h>
11 /*! \brief (Implementation) Automatically register the test suite of the specified type.
13 * You should not use this class directly. Instead, use the following macros:
14 * - CPPUNIT_TEST_SUITE_REGISTRATION()
15 * - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION()
17 * This object will register the test returned by TestCaseType::suite()
18 * when constructed to the test registry.
20 * This object is intented to be used as a static variable.
23 * \param TestCaseType Type of the test case which suite is registered.
24 * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
25 * \see CppUnit::TestFactoryRegistry.
27 template<class TestCaseType>
28 class AutoRegisterSuite
31 /** Auto-register the suite factory in the global registry.
34 : m_registry( &TestFactoryRegistry::getRegistry() )
36 m_registry->registerFactory( &m_factory );
39 /** Auto-register the suite factory in the specified registry.
40 * \param name Name of the registry.
42 AutoRegisterSuite( const std::string &name )
43 : m_registry( &TestFactoryRegistry::getRegistry( name ) )
45 m_registry->registerFactory( &m_factory );
50 if ( TestFactoryRegistry::isValid() )
51 m_registry->unregisterFactory( &m_factory );
55 TestFactoryRegistry *m_registry;
56 TestSuiteFactory<TestCaseType> m_factory;
60 /*! \brief (Implementation) Automatically adds a registry into another registry.
62 * Don't use this class. Use the macros CPPUNIT_REGISTRY_ADD() and
63 * CPPUNIT_REGISTRY_ADD_TO_DEFAULT() instead.
65 class AutoRegisterRegistry
68 AutoRegisterRegistry( const std::string &which,
69 const std::string &to )
71 TestFactoryRegistry::getRegistry( to ).addRegistry( which );
74 AutoRegisterRegistry( const std::string &which )
76 TestFactoryRegistry::getRegistry().addRegistry( which );
83 #endif // CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H