CppUnit project page | FAQ

AutoRegisterSuite.h
Go to the documentation of this file.
1 #ifndef CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
2 #define CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
3
4 #include <cppunit/extensions/TestSuiteFactory.h>
5 #include <cppunit/extensions/TestFactoryRegistry.h>
6 #include <string>
7
8 CPPUNIT_NS_BEGIN
9
10
27 template<class TestCaseType>
28 class AutoRegisterSuite
29 {
30 public:
33 AutoRegisterSuite()
34 : m_registry( &TestFactoryRegistry::getRegistry() )
35 {
36 m_registry->registerFactory( &m_factory );
37 }
38
42 AutoRegisterSuite( const std::string &name )
43 : m_registry( &TestFactoryRegistry::getRegistry( name ) )
44 {
45 m_registry->registerFactory( &m_factory );
46 }
47
48 ~AutoRegisterSuite()
49 {
50 if ( TestFactoryRegistry::isValid() )
51 m_registry->unregisterFactory( &m_factory );
52 }
53
54 private:
55 TestFactoryRegistry *m_registry;
56 TestSuiteFactory<TestCaseType> m_factory;
57 };
58
59
65 class AutoRegisterRegistry
66 {
67 public:
68 AutoRegisterRegistry( const std::string &which,
69 const std::string &to )
70 {
71 TestFactoryRegistry::getRegistry( to ).addRegistry( which );
72 }
73
74 AutoRegisterRegistry( const std::string &which )
75 {
76 TestFactoryRegistry::getRegistry().addRegistry( which );
77 }
78 };
79
80
81 CPPUNIT_NS_END
82
83 #endif // CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
TestSuiteFactory
TestFactory for TestFixture that implements a static suite() method.
Definition: TestSuiteFactory.h:16
AutoRegisterSuite::m_factory
TestSuiteFactory< TestCaseType > m_factory
Definition: AutoRegisterSuite.h:56
TestFactoryRegistry::registerFactory
void registerFactory(TestFactory *factory)
Adds the specified TestFactory to the registry.
Definition: TestFactoryRegistry.cpp:114
AutoRegisterSuite::~AutoRegisterSuite
~AutoRegisterSuite()
Definition: AutoRegisterSuite.h:48
TestFactoryRegistry.h
TestSuiteFactory.h
TestFactoryRegistry::unregisterFactory
void unregisterFactory(TestFactory *factory)
Definition: TestFactoryRegistry.cpp:121
TestFactoryRegistry::addRegistry
void addRegistry(const std::string &name)
Definition: TestFactoryRegistry.cpp:128
AutoRegisterRegistry::AutoRegisterRegistry
AutoRegisterRegistry(const std::string &which, const std::string &to)
Definition: AutoRegisterSuite.h:68
AutoRegisterRegistry::AutoRegisterRegistry
AutoRegisterRegistry(const std::string &which)
Definition: AutoRegisterSuite.h:74
AutoRegisterRegistry
(Implementation) Automatically adds a registry into another registry.
Definition: AutoRegisterSuite.h:66
TestFactoryRegistry
Registry for TestFactory.
Definition: TestFactoryRegistry.h:76
CPPUNIT_NS_BEGIN
#define CPPUNIT_NS_BEGIN
Definition: Portability.h:105
CPPUNIT_NS_END
#define CPPUNIT_NS_END
Definition: Portability.h:106
TestFactoryRegistry::getRegistry
static TestFactoryRegistry & getRegistry(const std::string &name="All Tests")
Returns a named registry.
Definition: TestFactoryRegistry.cpp:99
AutoRegisterSuite::AutoRegisterSuite
AutoRegisterSuite()
Auto-register the suite factory in the global registry.
Definition: AutoRegisterSuite.h:33
AutoRegisterSuite
(Implementation) Automatically register the test suite of the specified type.
Definition: AutoRegisterSuite.h:29
AutoRegisterSuite::AutoRegisterSuite
AutoRegisterSuite(const std::string &name)
Auto-register the suite factory in the specified registry.
Definition: AutoRegisterSuite.h:42
AutoRegisterSuite::m_registry
TestFactoryRegistry * m_registry
Definition: AutoRegisterSuite.h:55
TestFactoryRegistry::isValid
static bool isValid()
Definition: TestFactoryRegistry.cpp:157

| Send comments to: CppUnit Developers