summaryrefslogtreecommitdiff
path: root/src/cppunit/TestFactoryRegistry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cppunit/TestFactoryRegistry.cpp')
-rw-r--r--src/cppunit/TestFactoryRegistry.cpp25
1 files changed, 19 insertions, 6 deletions
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;
}