From b657aa515178205772ab2e95f365bd5a77364610 Mon Sep 17 00:00:00 2001 From: Bastiaan Bakker Date: Sat, 5 May 2001 22:34:50 +0000 Subject: Merge of CppUnitW 1.2 phase 2. --- src/cppunit/TestFactoryRegistry.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/cppunit/TestFactoryRegistry.cpp') diff --git a/src/cppunit/TestFactoryRegistry.cpp b/src/cppunit/TestFactoryRegistry.cpp index 3f390f6..b38cbb4 100644 --- a/src/cppunit/TestFactoryRegistry.cpp +++ b/src/cppunit/TestFactoryRegistry.cpp @@ -9,7 +9,7 @@ #include "cppunit/extensions/TestSuiteBuilder.h" #ifdef USE_TYPEINFO -#include "../TypeInfoHelper.h" +#include "TypeInfoHelper.h" #endif // USE_TYPEINFO namespace CppUnit { @@ -22,6 +22,11 @@ TestFactoryRegistry::TestFactoryRegistry( std::string name ) : TestFactoryRegistry::~TestFactoryRegistry() { + for ( Factories::iterator it = m_factories.begin(); it != m_factories.end(); ++it ) + { + AbstractTestFactory *factory = it->second; + delete factory; + } } @@ -36,14 +41,22 @@ TestFactoryRegistry::getRegistry() 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; - TestFactoryRegistry*& registryPointer = registries[ name ]; - if (NULL == registryPointer) { - registryPointer = new TestFactoryRegistry( name ); + 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 *registryPointer; + return *foundIt->second; } -- cgit v1.2.1