blob: c9b1096a524ed9ac010f6e1a24d892deeba6c4e8 (
plain)
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
101
102
103
|
#if _MSC_VER > 1000 // VC++
#pragma once
#pragma warning( disable : 4786 ) // disable warning debug symbol > 255...
#endif // _MSC_VER > 1000
#include <sstream>
#include <utility>
#include "cppunit/TestSuite.h"
#include "cppunit/extensions/TestFactoryRegistry.h"
#ifdef CU_USE_TYPEINFO
#include "cppunit/extensions/TypeInfoHelper.h"
#endif // CU_USE_TYPEINFO
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 )
{
std::ostringstream stream;
static int serialNumber = 1;
stream << "@Dummy@" << serialNumber++;
std::string name( stream.str() );
registerFactory( name, factory );
}
Test *
TestFactoryRegistry::makeTest()
{
TestSuite *suite = new TestSuite( "All Tests" );
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
|