From b08ecaecc1e39b7b01e02b7b73559d8b34ff46a5 Mon Sep 17 00:00:00 2001 From: Bastiaan Bakker Date: Sun, 29 Apr 2001 13:09:16 +0000 Subject: 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. --- src/cppunit/TestFactoryRegistry.cpp | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/cppunit/TestFactoryRegistry.cpp (limited to 'src/cppunit/TestFactoryRegistry.cpp') 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 +#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 -- cgit v1.2.1