1#ifndef CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
2#define CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
3
4#include <string>
5#include <cppunit/extensions/TestSuiteFactory.h>
6#include <cppunit/extensions/TestFactoryRegistry.h>
7
8namespace CppUnit {
9
10  /** Automatically register the test suite of the specified type.
11   *
12   * You should not use this class directly. Instead, use the following macros:
13   * - CPPUNIT_TEST_SUITE_REGISTRATION()
14   * - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION()
15   *
16   * This object will register the test returned by TestCaseType::suite()
17   * when constructed to the test registry.
18   *
19   * This object is intented to be used as a static variable.
20   *
21   *
22   * \param TestCaseType Type of the test case which suite is registered.
23   * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
24   * \see CppUnit::TestFactoryRegistry.
25   */
26  template<typename TestCaseType>
27  class AutoRegisterSuite
28  {
29    public:
30      /** Auto-register the suite factory in the global registry.
31       */
32      AutoRegisterSuite()
33      {
34        TestFactory *factory = new TestSuiteFactory<TestCaseType>();
35        TestFactoryRegistry::getRegistry().registerFactory( factory );
36      }
37
38      /** Auto-register the suite factory in the specified registry.
39       * \param name Name of the registry.
40       */
41      AutoRegisterSuite( const string &name )
42      {
43        TestFactory *factory = new TestSuiteFactory<TestCaseType>();
44        TestFactoryRegistry::getRegistry( name ).registerFactory( factory );
45      }
46  };
47
48} // namespace CppUnit
49
50
51#endif  // CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H
52