CppUnit project page FAQ CppUnit home page

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CppUnit::TestFactoryRegistry Class Reference
[Creating TestSuite]

Registry for TestFactory. More...

#include <TestFactoryRegistry.h>

Inheritance diagram for CppUnit::TestFactoryRegistry:

CppUnit::TestFactory List of all members.

Public Methods

 TestFactoryRegistry (std::string name="All Tests")
 Constructs the registry with the specified name. More...

virtual ~TestFactoryRegistry ()
 Destructor. More...

virtual TestmakeTest ()
 Returns a new TestSuite that contains the registered test. More...

void addTestToSuite (TestSuite *suite)
 Adds the registered tests to the specified suite. More...

void registerFactory (const std::string &name, TestFactory *factory)
 Adds the specified TestFactory with a specific name (DEPRECATED). More...

void registerFactory (TestFactory *factory)
 Adds the specified TestFactory to the registry. More...


Static Public Methods

TestFactoryRegistry & getRegistry ()
 Returns unnamed the registry. More...

TestFactoryRegistry & getRegistry (const std::string &name)
 Returns a named registry. More...


Private Types

typedef std::map< std::string,
TestFactory * > 
Factories

Private Methods

 TestFactoryRegistry (const TestFactoryRegistry &copy)
void operator= (const TestFactoryRegistry &copy)

Private Attributes

Factories m_factories
std::string m_name

Detailed Description

Registry for TestFactory.

Notes that the registry assumes lifetime control for any registered test.

To register tests, use the macros:

Example 1: retreiving a suite that contains all the test registered with CPPUNIT_TEST_SUITE_REGISTRATION().
 CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
 CppUnit::TestSuite *suite = registry.makeTest();

Example 2: retreiving a suite that contains all the test registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" ).

 CppUnit::TestFactoryRegistry &mathRegistry = CppUnit::TestFactoryRegistry::getRegistry( "Math" );
 CppUnit::TestSuite *mathSuite = mathRegistry.makeTest();

Example 3: creating a test suite hierarchy composed of unnamed registration and named registration:

 CppUnit::TestSuite *rootSuite = new CppUnit::TestSuite( "All tests" );
 rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ).makeTest() );
 rootSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry( "Math" ).makeTest() );
 CppUnit::TestFactoryRegistry::getRegistry().addTestToSuite( rootSuite );

The same result can be obtained with:

 CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
 registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ) );
 registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Math" ) );
 CppUnit::TestSuite *suite = registry.makeTest();

Since a TestFactoryRegistry is a TestFactory, the named registries can be registered in the unnamed registry, creating the hierarchy links.

See also:
TestSuiteFactory, AutoRegisterSuite , CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION


Member Typedef Documentation

typedef std::map<std::string, TestFactory *> CppUnit::TestFactoryRegistry::Factories [private]
 


Constructor & Destructor Documentation

CppUnit::TestFactoryRegistry::TestFactoryRegistry std::string    name = "All Tests"
 

Constructs the registry with the specified name.

Parameters:
name  Name of the registry. It is the name of TestSuite returned by makeTest().

CppUnit::TestFactoryRegistry::~TestFactoryRegistry   [virtual]
 

Destructor.

CppUnit::TestFactoryRegistry::TestFactoryRegistry const TestFactoryRegistry &    copy [private]
 


Member Function Documentation

void CppUnit::TestFactoryRegistry::addTestToSuite TestSuite   suite
 

Adds the registered tests to the specified suite.

Parameters:
suite  Suite the tests are added to.

TestFactoryRegistry & CppUnit::TestFactoryRegistry::getRegistry const std::string &    name [static]
 

Returns a named registry.

TestSuite registered using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() are registered in the registry of the same name.

Parameters:
name  Name of the registry to return.
Returns:
Registry. If the registry does not exist, it is created with the specified name.

TestFactoryRegistry & CppUnit::TestFactoryRegistry::getRegistry   [static]
 

Returns unnamed the registry.

TestSuite registered using CPPUNIT_TEST_SUITE_REGISTRATION() are registered in this registry.

Returns:
Registry which name is "All Tests".

Test * CppUnit::TestFactoryRegistry::makeTest   [virtual]
 

Returns a new TestSuite that contains the registered test.

Returns:
A new TestSuite which contains all the test added using registerFactory(TestFactory *).

Implements CppUnit::TestFactory.

void CppUnit::TestFactoryRegistry::operator= const TestFactoryRegistry &    copy [private]
 

void CppUnit::TestFactoryRegistry::registerFactory TestFactory   factory
 

Adds the specified TestFactory to the registry.

Parameters:
factory  Factory to register.

void CppUnit::TestFactoryRegistry::registerFactory const std::string &    name,
TestFactory   factory
 

Adds the specified TestFactory with a specific name (DEPRECATED).

Parameters:
name  Name associated to the factory.
factory  Factory to register.
Deprecated:
Use registerFactory( TestFactory *) instead.


Member Data Documentation

Factories CppUnit::TestFactoryRegistry::m_factories [private]
 

std::string CppUnit::TestFactoryRegistry::m_name [private]
 


The documentation for this class was generated from the following files:
SourceForge Logo hosts this site. Send comments to:
CppUnit Developers