CppUnit project page FAQ

Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
TestFactoryRegistry Class Reference

Registry for TestFactory.Notes that the registry DON'T assumes lifetime control for any registered tests anymore. More...

#include <TestFactoryRegistry.h>

Inheritance diagram for TestFactoryRegistry:
Inheritance graph
[legend]
Collaboration diagram for TestFactoryRegistry:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TestFactoryRegistry (std::string name)
 Constructs the registry with the specified name.
virtual ~TestFactoryRegistry ()
 Destructor.
virtual TestmakeTest ()
 Returns a new TestSuite that contains the registered test.
void addTestToSuite (TestSuite *suite)
 Adds the registered tests to the specified suite.
void registerFactory (TestFactory *factory)
 Adds the specified TestFactory to the registry.
void unregisterFactory (TestFactory *factory)
void addRegistry (const std::string &name)
void registerFactory (const std::string &name, TestFactory *factory)
 Adds the specified TestFactory with a specific name (DEPRECATED).
- Public Member Functions inherited from TestFactory
virtual ~TestFactory ()

Static Public Member Functions

static TestFactoryRegistrygetRegistry (const std::string &name="All Tests")
 Returns a named registry.
static bool isValid ()

Private Types

typedef CppUnitSet
< TestFactory *, std::less
< TestFactory * > > 
Factories

Private Member Functions

 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 DON'T assumes lifetime control for any registered tests anymore.

The default registry is the registry returned by getRegistry() with the default name parameter value.

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() );

The same result can be obtained with:

CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
registry.addRegistry( "Graph" );
registry.addRegistry( "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


Constructor & Destructor Documentation

TestFactoryRegistry::TestFactoryRegistry ( std::string  name)

Constructs the registry with the specified name.

Parameters:
nameName of the registry. It is the name of TestSuite returned by makeTest().
TestFactoryRegistry::~TestFactoryRegistry ( )
virtual

Destructor.

TestFactoryRegistry::TestFactoryRegistry ( const TestFactoryRegistry copy)
private

Member Function Documentation

void TestFactoryRegistry::addRegistry ( const std::string &  name)

Adds a registry to the registry.

Convenience method to help create test hierarchy. See TestFactoryRegistry detail for examples of use. Calling this method is equivalent to:

Parameters:
nameName of the registry to add.
void TestFactoryRegistry::addTestToSuite ( TestSuite suite)

Adds the registered tests to the specified suite.

Parameters:
suiteSuite the tests are added to.
TestFactoryRegistry & TestFactoryRegistry::getRegistry ( const std::string &  name = "All Tests")
static

Returns a named registry.

If the name is left to its default value, then the registry that is returned is the one used by CPPUNIT_TEST_SUITE_REGISTRATION(): the 'top' level registry.

Parameters:
nameName of the registry to return.
Returns:
Registry. If the registry does not exist, it is created with the specified name.
bool TestFactoryRegistry::isValid ( )
static

Tests if the registry is valid.

This method should be used when unregistering test factory on static variable destruction to ensure that the registry has not been already destroyed (in that case there is no need to unregister the test factory).

You should not concern yourself with this method unless you are writing a class like AutoRegisterSuite.

Returns:
true if the specified registry has not been destroyed, otherwise returns false.
See also:
AutoRegisterSuite.
Test * 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 TestFactory.

void TestFactoryRegistry::operator= ( const TestFactoryRegistry copy)
private
void TestFactoryRegistry::registerFactory ( TestFactory factory)

Adds the specified TestFactory to the registry.

Parameters:
factoryFactory to register.
void TestFactoryRegistry::registerFactory ( const std::string &  name,
TestFactory factory 
)

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

Parameters:
nameName associated to the factory.
factoryFactory to register.
Deprecated:
Use registerFactory( TestFactory *) instead.
void TestFactoryRegistry::unregisterFactory ( TestFactory factory)

Removes the specified TestFactory from the registry.

The specified factory is not destroyed.

Parameters:
factoryFactory to remove from the registry.
Todo:
Address case when trying to remove a TestRegistryFactory.

Member Data Documentation

Factories TestFactoryRegistry::m_factories
private
std::string TestFactoryRegistry::m_name
private

The documentation for this class was generated from the following files:

Send comments to:
CppUnit Developers