Menu

[r150]: / trunk / cppunit / src / cppunit / TestFactoryRegistry.cpp  Maximize  Restore  History

Download this file

101 lines (78 with data), 2.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#include <utility>
#include <cppunit/Portability.h>
#include <cppunit/TestSuite.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#if CPPUNIT_USE_TYPEINFO_NAME
# include "cppunit/extensions/TypeInfoHelper.h"
#endif
namespace CppUnit {
TestFactoryRegistry::TestFactoryRegistry( std::string name ) :
m_name( name )
{
}
TestFactoryRegistry::~TestFactoryRegistry()
{
for ( Factories::iterator it = m_factories.begin(); it != m_factories.end(); ++it )
{
TestFactory *factory = it->second;
delete factory;
}
}
TestFactoryRegistry &
TestFactoryRegistry::getRegistry()
{
static TestFactoryRegistry registry;
return registry;
}
TestFactoryRegistry &
TestFactoryRegistry::getRegistry( const std::string &name )
{
// No clean-up at the current time => memory leaks.
// Need to find a way to solve the folowing issue:
// getRegistry().registryFactory( "Functionnal",
// getRegistry( "Functionnal" ) );
// => the test factory registry "Functionnal" would be
// destroyed twice: once by the map below, once by the getRegistry() factory.
static NamedRegistries registries;
NamedRegistries::const_iterator foundIt = registries.find( name );
if ( foundIt == registries.end() )
{
TestFactoryRegistry *factory = new TestFactoryRegistry( name );
registries.insert( std::make_pair( name, factory ) );
return *factory;
}
return *foundIt->second;
}
void
TestFactoryRegistry::registerFactory( const std::string &name,
TestFactory *factory )
{
m_factories[name] = factory;
}
void
TestFactoryRegistry::registerFactory( TestFactory *factory )
{
static int serialNumber = 1;
OStringStream ost;
ost << "@Dummy@" << serialNumber++;
registerFactory( ost.str(), factory );
}
Test *
TestFactoryRegistry::makeTest()
{
TestSuite *suite = new TestSuite( m_name );
addTestToSuite( suite );
return suite;
}
void
TestFactoryRegistry::addTestToSuite( TestSuite *suite )
{
for ( Factories::iterator it = m_factories.begin();
it != m_factories.end();
++it )
{
TestFactory *factory = (*it).second;
suite->addTest( factory->makeTest() );
}
}
} // namespace CppUnit
MongoDB Logo MongoDB