CppUnit project page | FAQ

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
TestFactoryRegistry Class Reference
Creating TestSuite

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:

## Public Member Functions

| TestFactoryRegistry (std::string name)
| Constructs the registry with the specified name. More...
virtual | ~TestFactoryRegistry ()
| Destructor. More...
virtual Test * | makeTest ()
| 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 (TestFactory *factory)
| Adds the specified TestFactory to the registry. More...
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). More...
Public Member Functions inherited from TestFactory
virtual | ~TestFactory ()

## Static Public Member Functions

static TestFactoryRegistry & | getRegistry (const std::string &name="All Tests")
| Returns a named registry. More...
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:

- CPPUNIT_TEST_SUITE_REGISTRATION(): to add tests in the default registry.
- CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(): to add tests in a named registry.

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:

- All Tests
  - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Graph" )
  - tests registered with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ..., "Math" )
  - tests registered with CPPUNIT_TEST_SUITE_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.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

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

private

## Constructor & Destructor Documentation

TestFactoryRegistry::TestFactoryRegistry | ( | std::string | name | ) |

Constructs the registry with the specified name.

Parameters

  name | Name 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:

this->registerFactory( TestFactoryRegistry::getRegistry( name ) );

Parameters

  name | Name of the registry to add.

void TestFactoryRegistry::addTestToSuite | ( | TestSuite * | suite | ) |

Adds the registered tests to the specified suite.

Parameters

  suite | Suite 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

  name | Name 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

  factory | Factory to register.

void 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.

void TestFactoryRegistry::unregisterFactory | ( | TestFactory * | factory | ) |

Removes the specified TestFactory from the registry.

The specified factory is not destroyed.

Parameters

  factory | Factory 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:

- TestFactoryRegistry.h
- TestFactoryRegistry.cpp

| Send comments to: CppUnit Developers