1
#include <cppunit/extensions/TestFactoryRegistry.h>
2
#include <cppunit/portability/CppUnitMap.h>
3
#include <cppunit/TestSuite.h>
9
/*! \brief (INTERNAL) List of all TestFactoryRegistry.
11
class TestFactoryRegistryList
14
typedef CppUnitMap<std::string, TestFactoryRegistry *, std::less<std::string> > Registries;
15
Registries m_registries;
24
static State stateFlag( State newState = doNotChange )
26
static State state = notCreated;
27
if ( newState != doNotChange )
32
static TestFactoryRegistryList *getInstance()
34
static TestFactoryRegistryList list;
38
TestFactoryRegistry *getInternalRegistry( const std::string &name )
40
Registries::const_iterator foundIt = m_registries.find( name );
41
if ( foundIt == m_registries.end() )
43
TestFactoryRegistry *factory = new TestFactoryRegistry( name );
44
m_registries.insert( std::pair<const std::string, TestFactoryRegistry*>( name, factory ) );
47
return (*foundIt).second;
51
TestFactoryRegistryList()
56
~TestFactoryRegistryList()
58
for ( Registries::iterator it = m_registries.begin(); it != m_registries.end(); ++it )
61
stateFlag( destroyed );
64
static TestFactoryRegistry *getRegistry( const std::string &name )
66
// If the following assertion failed, then TestFactoryRegistry::getRegistry()
67
// was called during static variable destruction without checking the registry
68
// validity beforehand using TestFactoryRegistry::isValid() beforehand.
70
if ( !isValid() ) // release mode
71
return NULL; // => force CRASH
73
return getInstance()->getInternalRegistry( name );
78
return stateFlag() != destroyed;
84
TestFactoryRegistry::TestFactoryRegistry( std::string name ) :
90
TestFactoryRegistry::~TestFactoryRegistry()
96
TestFactoryRegistry::getRegistry( const std::string &name )
98
return *TestFactoryRegistryList::getRegistry( name );
103
TestFactoryRegistry::registerFactory( const std::string &name,
104
TestFactory *factory )
106
registerFactory( factory );
111
TestFactoryRegistry::registerFactory( TestFactory *factory )
113
m_factories.insert( factory );
118
TestFactoryRegistry::unregisterFactory( TestFactory *factory )
120
m_factories.erase( factory );
125
TestFactoryRegistry::addRegistry( const std::string &name )
127
registerFactory( &getRegistry( name ) );
132
TestFactoryRegistry::makeTest()
134
TestSuite *suite = new TestSuite( m_name );
135
addTestToSuite( suite );
141
TestFactoryRegistry::addTestToSuite( TestSuite *suite )
143
for ( Factories::iterator it = m_factories.begin();
144
it != m_factories.end();
147
TestFactory *factory = *it;
148
suite->addTest( factory->makeTest() );
154
TestFactoryRegistry::isValid()
156
return TestFactoryRegistryList::isValid();