diff options
| author | Bastiaan Bakker <bastiaan.bakker@lifeline.nl> | 2001-04-29 13:09:16 +0000 |
|---|---|---|
| committer | Bastiaan Bakker <bastiaan.bakker@lifeline.nl> | 2001-04-29 13:09:16 +0000 |
| commit | b08ecaecc1e39b7b01e02b7b73559d8b34ff46a5 (patch) | |
| tree | bf1ed1e3680cb0256e73336e22fb70c692524fcb /src/cppunit/TestFactoryRegistry.cpp | |
| parent | 5ce1a68589aa3ea4f9ee255cfecc94cc1730c6fa (diff) | |
| download | cppunit-b08ecaecc1e39b7b01e02b7b73559d8b34ff46a5.tar.gz | |
Merged Baptiste Lepilleurs CppUnitW 1.2.
Some differences:
TypeInfo stuff (in TestSuite) compiled in only if USE_TYPEINFO is set.
TestSuite.getTests now returns a const ref instead of taking a ref as param.
Removed auto_ptr stuff from TestFactoryRegistry: auto_ptr cannot be used in
containers.
Diffstat (limited to 'src/cppunit/TestFactoryRegistry.cpp')
| -rw-r--r-- | src/cppunit/TestFactoryRegistry.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/cppunit/TestFactoryRegistry.cpp b/src/cppunit/TestFactoryRegistry.cpp new file mode 100644 index 0000000..3f390f6 --- /dev/null +++ b/src/cppunit/TestFactoryRegistry.cpp @@ -0,0 +1,89 @@ +#if _MSC_VER > 1000 // VC++ +#pragma once +#pragma warning( disable : 4786 ) // disable warning debug symbol > 255... +#endif // _MSC_VER > 1000 + +#include <utility> +#include "cppunit/TestSuite.h" +#include "cppunit/extensions/TestFactoryRegistry.h" +#include "cppunit/extensions/TestSuiteBuilder.h" + +#ifdef USE_TYPEINFO +#include "../TypeInfoHelper.h" +#endif // USE_TYPEINFO + +namespace CppUnit { + +TestFactoryRegistry::TestFactoryRegistry( std::string name ) : + m_name( name ) +{ +} + + +TestFactoryRegistry::~TestFactoryRegistry() +{ +} + + +TestFactoryRegistry & +TestFactoryRegistry::getRegistry() +{ + static TestFactoryRegistry registry; + return registry; +} + + +TestFactoryRegistry & +TestFactoryRegistry::getRegistry( const std::string &name ) +{ + static NamedRegistries registries; + + TestFactoryRegistry*& registryPointer = registries[ name ]; + if (NULL == registryPointer) { + registryPointer = new TestFactoryRegistry( name ); + } + + return *registryPointer; +} + + +void +TestFactoryRegistry::registerFactory( const std::string &name, + AbstractTestFactory *factory ) +{ + m_factories[name] = factory; +} + + +#ifdef USE_TYPEINFO +void +TestFactoryRegistry::registerFactory( AbstractTestFactory *factory ) +{ + std::string name = TypeInfoHelper::getClassName( typeid( *factory ) ); + registerFactory( name, factory ); +} +#endif // USE_TYPEINFO + +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 ) + { + AbstractTestFactory *factory = (*it).second; + suite->addTest( factory->makeTest() ); + } +} + + +} // namespace CppUnit |
