CppUnit - The Unit Testing Library

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
27template<class TestCaseType>
28 class AutoRegisterSuite
29{
30public:
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
54private:
55 TestFactoryRegistry *m_registry;
56 TestSuiteFactory<TestCaseType> m_factory;
57};
58
59
65 class AutoRegisterRegistry
66{
67public:
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
CPPUNIT_NS_END
#define CPPUNIT_NS_END
Definition Portability.h:106
CPPUNIT_NS_BEGIN
#define CPPUNIT_NS_BEGIN
Definition Portability.h:105
TestFactoryRegistry.h
TestSuiteFactory.h
AutoRegisterRegistry
(Implementation) Automatically adds a registry into another registry.
Definition AutoRegisterSuite.h:66
AutoRegisterRegistry::AutoRegisterRegistry
AutoRegisterRegistry(const std::string &which)
Definition AutoRegisterSuite.h:74
AutoRegisterRegistry::AutoRegisterRegistry
AutoRegisterRegistry(const std::string &which, const std::string &to)
Definition AutoRegisterSuite.h:68
AutoRegisterSuite
(Implementation) Automatically register the test suite of the specified type.
Definition AutoRegisterSuite.h:29
AutoRegisterSuite::m_registry
TestFactoryRegistry * m_registry
Definition AutoRegisterSuite.h:55
AutoRegisterSuite::AutoRegisterSuite
AutoRegisterSuite()
Auto-register the suite factory in the global registry.
Definition AutoRegisterSuite.h:33
AutoRegisterSuite::AutoRegisterSuite
AutoRegisterSuite(const std::string &name)
Auto-register the suite factory in the specified registry.
Definition AutoRegisterSuite.h:42
AutoRegisterSuite::m_factory
TestSuiteFactory< TestCaseType > m_factory
Definition AutoRegisterSuite.h:56
AutoRegisterSuite::~AutoRegisterSuite
~AutoRegisterSuite()
Definition AutoRegisterSuite.h:48
TestFactoryRegistry
Registry for TestFactory.
Definition TestFactoryRegistry.h:76
TestFactoryRegistry::isValid
static bool isValid()
Definition TestFactoryRegistry.cpp:157
TestFactoryRegistry::registerFactory
void registerFactory(TestFactory *factory)
Adds the specified TestFactory to the registry.
Definition TestFactoryRegistry.cpp:114
TestFactoryRegistry::addRegistry
void addRegistry(const std::string &name)
Definition TestFactoryRegistry.cpp:128
TestFactoryRegistry::getRegistry
static TestFactoryRegistry & getRegistry(const std::string &name="All Tests")
Returns a named registry.
Definition TestFactoryRegistry.cpp:99
TestFactoryRegistry::unregisterFactory
void unregisterFactory(TestFactory *factory)
Definition TestFactoryRegistry.cpp:121
TestSuiteFactory
TestFactory for TestFixture that implements a static suite() method.
Definition TestSuiteFactory.h:16

| Send comments to: CppUnit Developers