TestFactoryRegistry |
The class TestFactoryRegistry (see Figure C-21) is a subclass of TestFactory . It acts as both a registry and a factory for Test objects. It registers Test s, and it produces TestSuite s containing registered Test s. Rather than containing the registered Test objects themselves , it contains a TestFactory for each one.
The default registry is a TestFactoryRegistry named "All Tests." Named instances of TestFactoryRegistry may also be created.
The macro CPPUNIT_TEST_SUITE_REGISTRATION( ) takes a Test and adds a TestFactory for it to the default registry. The macro CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ) similarly adds a TestFactory to a named registry. Calling a registry's makeTest( ) method creates a TestSuite containing all the registered Test s, demonstrating the main usefulness of TestFactoryRegistry .
The singleton NamedRegistries manages all instances of TestFactoryRegistry .
The following code snippet registers the Test class BookTest in the default registry and creates a TestSuite containing it:
CPPUNIT_TEST_SUITE_REGISTRATION( BookTest ); TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry( ); TestSuite *suite = registry.makeTest( );
TestFactoryRegistry belongs to the namespace CppUnit . It is declared in extensions/TestFactoryRegistry.h and implemented in TestFactoryRegistry.cpp .
class TestFactoryRegistry : public TestFactory
A constructor. If no name is provided, a default registry named "All Tests" is created.
A destructor. Each TestFactory contained by this TestFactoryRegistry is deleted if NamedRegistries indicates that it has not already been deleted. This prevents double deletion of a TestFactory .
Adds the registered Test objects to a preexisting TestSuite .
Returns the default TestFactoryRegistry named "All Tests."
Returns a TestFactoryRegistry with the given name. If the registry doesn't already exist, it is created.
Creates a TestSuite containing the registered Test objects. The TestSuite has the same name as the TestFactoryRegistry . For example, the TestSuite created by the default registry is named "All Tests."
Adds a TestFactory to the TestFactoryRegistry .
A deprecated method that adds a TestFactory to the TestFactoryRegistry with the given name. The previous version of registerFactory( ) should be used instead.
A copy constructor declared private to prevent its use.
A copy operator declared private to prevent its use.
Defines the type Factories as a map of TestFactory objects by name ( private ).
Factories m_factories
The name of this TestFactoryRegistry ( private ).