diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-17 21:27:28 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-17 21:27:28 +0000 |
| commit | 87e5cf8f526380c40f63208c6c9e785f73d327b7 (patch) | |
| tree | ba1871a917dfae7667b31587ced4072d5d18657d /include/cppunit | |
| parent | 6c1e9ed0f8fd7339084186df71b4dfc4c98a524e (diff) | |
| download | cppunit-87e5cf8f526380c40f63208c6c9e785f73d327b7.tar.gz | |
Bumped version to 1.
bumped version to 1.9.3
* FAQ: added question about 4786 warning on VC++.
* NEWS: updated.
* contrib/msvc/readme.txt: moved to contrib/readme.txt.
* contrib/xml-xsl/report.xsl: added XML style sheet contributed by
'cuppa' project team (http://sourceforge.jp/projects/cuppa/)
* examples/cppunittest/TestResultTest.h:
* examples/cppunittest/TestResultTest.cpp: added tests for
startTestRun()/endTestRun().
* examples/simple/*: added. A simple example.
* include/cppunit/BriefTestProgressListener.h:
* src/cppunit/BriefTestProgressListener.cpp: added. Verbose progess listener
that print the test name before running the test.
* include/cppunit/TestListener.h: added startTestRun()/endTestRun().
* include/cppunit/TestResult.h:
* src/cppunit/TestResult.cpp: added runTest(), to be called to run
a test by test runner.
* src/cppunit/TextTestRunner.cpp:
* src/cppunit/TestRunner.cpp: updated to use TestResult::runTest().
* include/cppunit/plugin/PlugInManager.h:
* src/cppunit/PlugInManager.cpp: added. Managers for all loaded plug-ins.
* include/cppunit/plugin/TestPlugInDefaultImpl.h:
* src/cppunit/TestPlugInDefaultImpl.cpp: renamed TestPlugInAdapter. All
implementations are empty.
* include/cppunit/plugin/TestPlugInSuite.h: removed.
* src/cppunit/TestPlugInSuite.cpp: removed. Replaced by PlugInManager.
* include/cppunit/plugin/TestPlugIn.h: rewrote the plug-in interface to
provide more versatility. updated macros to match new interface.
* include/cppunit/extensions/TestFactoryRegistry.h:
* include/cppunit/extensions/TestFactoryRegistry.cpp: Added unregisterFactory().
Added convenience method addRegistry(). Rewrote registry life cycle
management. AutoRegisterSuite can now detect that the registry has been
destroy and not call to it to unregister its test factory.
* include/cppunit/extensions/AutoRegisterTest.h: on destruction, the registered
factory is unregistered from the registry.
* include/cppunit/extensions/HelperMacros.h: added macros
CPPUNIT_REGISTRY_ADD_TO_DEFAULT and CPPUNIT_REGISTRY_ADD to help
build test suite hierarchy.
* src/cppunit/msvc/DllPlugInTester/*: moved to src/cppunit/DllPlugInTester/.
* src/cppunit/DllPlugInTester/DllPlugInTester.cpp: removed UNICODE stuffs. Use
the PlugInManager instead of PlugInTestSuite. Simplified: only one test on
command line, but many DLL can be specified. Added configurations to link
against cppunit dll, those are now the default configuration (static linking
don't make much sense for plug-in).
Diffstat (limited to 'include/cppunit')
| -rw-r--r-- | include/cppunit/BriefTestProgressListener.h | 49 | ||||
| -rw-r--r-- | include/cppunit/Makefile.am | 1 | ||||
| -rw-r--r-- | include/cppunit/TestListener.h | 23 | ||||
| -rw-r--r-- | include/cppunit/TestResult.h | 5 | ||||
| -rw-r--r-- | include/cppunit/TestResultCollector.h | 2 | ||||
| -rw-r--r-- | include/cppunit/TextTestProgressListener.h | 2 | ||||
| -rw-r--r-- | include/cppunit/config/SelectDllLoader.h | 2 | ||||
| -rw-r--r-- | include/cppunit/config/config-msvc6.h | 8 | ||||
| -rw-r--r-- | include/cppunit/extensions/AutoRegisterSuite.h | 103 | ||||
| -rw-r--r-- | include/cppunit/extensions/HelperMacros.h | 47 | ||||
| -rw-r--r-- | include/cppunit/extensions/TestFactoryRegistry.h | 84 | ||||
| -rw-r--r-- | include/cppunit/plugin/DynamicLibraryManager.h | 2 | ||||
| -rw-r--r-- | include/cppunit/plugin/Parameters.h | 22 | ||||
| -rw-r--r-- | include/cppunit/plugin/PlugInManager.h | 101 | ||||
| -rw-r--r-- | include/cppunit/plugin/TestPlugIn.h | 84 | ||||
| -rw-r--r-- | include/cppunit/plugin/TestPlugInAdapter.h (renamed from include/cppunit/plugin/TestPlugInDefaultImpl.h) | 24 | ||||
| -rw-r--r-- | include/cppunit/plugin/TestPlugInSuite.h | 54 |
17 files changed, 448 insertions, 165 deletions
diff --git a/include/cppunit/BriefTestProgressListener.h b/include/cppunit/BriefTestProgressListener.h new file mode 100644 index 0000000..f2ee606 --- /dev/null +++ b/include/cppunit/BriefTestProgressListener.h @@ -0,0 +1,49 @@ +#ifndef CPPUNIT_BRIEFTESTPROGRESSLISTENER_H +#define CPPUNIT_BRIEFTESTPROGRESSLISTENER_H + +#include <cppunit/TestListener.h> + + +namespace CppUnit +{ + +/*! \brief TestListener that prints the name of each test before running it. + * \ingroup TrackingTestExecution + */ +class BriefTestProgressListener : public TestListener +{ +public: + /*! Constructs a BriefTestProgressListener object. + */ + BriefTestProgressListener(); + + /// Destructor. + virtual ~BriefTestProgressListener(); + + void startTest( Test *test ); + + void addFailure( const TestFailure &failure ); + + void endTest( Test *test ); + + /*! Call this method after running the tests. + */ + void done(); + +private: + /// Prevents the use of the copy constructor. + BriefTestProgressListener( const BriefTestProgressListener © ); + + /// Prevents the use of the copy operator. + void operator =( const BriefTestProgressListener © ); + +private: + bool m_lastTestFailed; +}; + + + +} // namespace CppUnit + + +#endif // CPPUNIT_BRIEFTESTPROGRESSLISTENER_H diff --git a/include/cppunit/Makefile.am b/include/cppunit/Makefile.am index 60cf36b..4b7766b 100644 --- a/include/cppunit/Makefile.am +++ b/include/cppunit/Makefile.am @@ -32,6 +32,7 @@ libcppunitinclude_HEADERS = \ TextTestResult.h \ TextTestRunner.h \ TestListener.h \ + VerboseTestProgressListener.h \ XmlOutputter.h dist-hook: diff --git a/include/cppunit/TestListener.h b/include/cppunit/TestListener.h index 2f54bc7..b75265f 100644 --- a/include/cppunit/TestListener.h +++ b/include/cppunit/TestListener.h @@ -9,6 +9,7 @@ namespace CppUnit { class Exception; class Test; class TestFailure; +class TestResult; /*! \brief Listener for test progress and result. @@ -114,6 +115,28 @@ public: /*! Called by a TestComposite after running its child tests. */ virtual void endSuite( Test *suite ) {} + + /*! Called by a TestRunner before running the test. + * + * You can use this to do some global initialisation. A listener + * could also use to output a 'prolog' to the test run. + * + * \param suite Test that is going to be run. + * \param eventManager Event manager used for the test run. + */ + virtual void startTestRun( Test *test, + TestResult *eventManager ) {} + + /*! Called by a TestRunner after running the test. + * + * TextTestProgressListener use this to emit a line break. You can also use this + * to do some global uninitialisation. + * + * \param suite Test that was run. + * \param eventManager Event manager used for the test run. + */ + virtual void endTestRun( Test *test, + TestResult *eventManager ) {} }; diff --git a/include/cppunit/TestResult.h b/include/cppunit/TestResult.h index 200c7fb..5a39d4d 100644 --- a/include/cppunit/TestResult.h +++ b/include/cppunit/TestResult.h @@ -64,8 +64,13 @@ public: virtual void startSuite( Test *test ); virtual void endSuite( Test *test ); + virtual void runTest( Test *test ); + protected: void addFailure( const TestFailure &failure ); + + virtual void startTestRun( Test *test ); + virtual void endTestRun( Test *test ); protected: typedef std::deque<TestListener *> TestListeners; diff --git a/include/cppunit/TestResultCollector.h b/include/cppunit/TestResultCollector.h index 9505dd7..961b1b0 100644 --- a/include/cppunit/TestResultCollector.h +++ b/include/cppunit/TestResultCollector.h @@ -5,7 +5,7 @@ #if CPPUNIT_NEED_DLL_DECL #pragma warning( push ) -#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#pragma warning( disable: 4251 4660 ) // X needs to have dll-interface to be used by clients of class Z #endif #include <cppunit/TestSuccessListener.h> diff --git a/include/cppunit/TextTestProgressListener.h b/include/cppunit/TextTestProgressListener.h index dbd22cb..180633e 100644 --- a/include/cppunit/TextTestProgressListener.h +++ b/include/cppunit/TextTestProgressListener.h @@ -24,6 +24,8 @@ public: void startTest( Test *test ); void addFailure( const TestFailure &failure ); + /*! Call this method after running the tests. + */ void done(); private: diff --git a/include/cppunit/config/SelectDllLoader.h b/include/cppunit/config/SelectDllLoader.h index 74d5fbb..55959e6 100644 --- a/include/cppunit/config/SelectDllLoader.h +++ b/include/cppunit/config/SelectDllLoader.h @@ -60,7 +60,7 @@ // Otherwise, disable support for DllLoader #else -#define CPPUNIT_NO_TESTPLUGIN +#define CPPUNIT_NO_TESTPLUGIN 1 #endif #if !defined(CPPUNIT_PLUGIN_EXPORT) diff --git a/include/cppunit/config/config-msvc6.h b/include/cppunit/config/config-msvc6.h index 7047851..c55e2c9 100644 --- a/include/cppunit/config/config-msvc6.h +++ b/include/cppunit/config/config-msvc6.h @@ -1,6 +1,10 @@ #ifndef _INCLUDE_CPPUNIT_CONFIG_MSVC6_H #define _INCLUDE_CPPUNIT_CONFIG_MSVC6_H 1 +#if _MSC_VER > 1000 // VC++ +#pragma warning( disable : 4786 ) // disable warning debug symbol > 255... +#endif // _MSC_VER > 1000 + #define HAVE_CMATH 1 /* include/cppunit/config-msvc6.h. Manually adapted from @@ -60,10 +64,6 @@ #undef CPPUNIT_COMPILER_LOCATION_FORMAT #define CPPUNIT_COMPILER_LOCATION_FORMAT "%p(%l):" -#if _MSC_VER > 1000 // VC++ -#pragma warning( disable : 4786 ) // disable warning debug symbol > 255... -#endif // _MSC_VER > 1000 - /* _INCLUDE_CPPUNIT_CONFIG_MSVC6_H */ #endif diff --git a/include/cppunit/extensions/AutoRegisterSuite.h b/include/cppunit/extensions/AutoRegisterSuite.h index 8af3489..ccf6997 100644 --- a/include/cppunit/extensions/AutoRegisterSuite.h +++ b/include/cppunit/extensions/AutoRegisterSuite.h @@ -1,49 +1,80 @@ #ifndef CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H #define CPPUNIT_EXTENSIONS_AUTOREGISTERSUITE_H -#include <string> #include <cppunit/extensions/TestSuiteFactory.h> #include <cppunit/extensions/TestFactoryRegistry.h> +#include <string> namespace CppUnit { - /** Automatically register the test suite of the specified type. - * - * You should not use this class directly. Instead, use the following macros: - * - CPPUNIT_TEST_SUITE_REGISTRATION() - * - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() - * - * This object will register the test returned by TestCaseType::suite() - * when constructed to the test registry. - * - * This object is intented to be used as a static variable. - * - * - * \param TestCaseType Type of the test case which suite is registered. - * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION - * \see CppUnit::TestFactoryRegistry. +/** Automatically register the test suite of the specified type. (Implementation) + * + * You should not use this class directly. Instead, use the following macros: + * - CPPUNIT_TEST_SUITE_REGISTRATION() + * - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() + * + * This object will register the test returned by TestCaseType::suite() + * when constructed to the test registry. + * + * This object is intented to be used as a static variable. + * + * + * \param TestCaseType Type of the test case which suite is registered. + * \see CPPUNIT_TEST_SUITE_REGISTRATION, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION + * \see CppUnit::TestFactoryRegistry. + */ +template<typename TestCaseType> +class AutoRegisterSuite +{ +public: + /** Auto-register the suite factory in the global registry. */ - template<typename TestCaseType> - class AutoRegisterSuite + AutoRegisterSuite() + : m_registry( &TestFactoryRegistry::getRegistry() ) + { + m_registry->registerFactory( &m_factory ); + } + + /** Auto-register the suite factory in the specified registry. + * \param name Name of the registry. + */ + AutoRegisterSuite( const std::string &name ) + : m_registry( &TestFactoryRegistry::getRegistry( name ) ) + { + m_registry->registerFactory( &m_factory ); + } + + ~AutoRegisterSuite() + { + if ( TestFactoryRegistry::isValid() ) + m_registry->unregisterFactory( &m_factory ); + } + +private: + TestFactoryRegistry *m_registry; + TestSuiteFactory<TestCaseType> m_factory; +}; + + +/*! Automatically adds a registry into another registry. (Implementation) + * + * Don't use this class. Use the macros CPPUNIT_REGISTRY_ADD() and + * CPPUNIT_REGISTRY_ADD_TO_DEFAULT() instead. + */ +class AutoRegisterRegistry +{ +public: + AutoRegisterRegistry( const std::string &which, + const std::string &to ) + { + TestFactoryRegistry::getRegistry( to ).addRegistry( which ); + } + + AutoRegisterRegistry( const std::string &which ) { - public: - /** Auto-register the suite factory in the global registry. - */ - AutoRegisterSuite() - { - TestFactory *factory = new TestSuiteFactory<TestCaseType>(); - TestFactoryRegistry::getRegistry().registerFactory( factory ); - } - - /** Auto-register the suite factory in the specified registry. - * \param name Name of the registry. - */ - AutoRegisterSuite( const std::string &name ) - { - TestFactory *factory = new TestSuiteFactory<TestCaseType>(); - TestFactoryRegistry::getRegistry( name ).registerFactory( factory ); - } - }; + TestFactoryRegistry::getRegistry().addRegistry( which ); + } +}; } // namespace CppUnit diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h index c7be1aa..e8dfbef 100644 --- a/include/cppunit/extensions/HelperMacros.h +++ b/include/cppunit/extensions/HelperMacros.h @@ -272,6 +272,8 @@ namespace CppUnit * \warning This macro should be used only once per line of code (the line * number is used to name a hidden static variable). * \see CPPUNIT_TEST_SUITE_NAMED_REGISTRATION + * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT + * \see CPPUNIT_REGISTRY_ADD * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, * CppUnit::TestFactoryRegistry. */ @@ -312,6 +314,8 @@ namespace CppUnit * \warning This macro should be used only once per line of code (the line * number is used to name a hidden static variable). * \see CPPUNIT_TEST_SUITE_REGISTRATION + * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT + * \see CPPUNIT_REGISTRY_ADD * \see CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, * CppUnit::TestFactoryRegistry.. */ @@ -319,6 +323,49 @@ namespace CppUnit static CppUnit::AutoRegisterSuite< ATestFixtureType > \ CPPUNIT_MAKE_UNIQUE_NAME(__autoRegisterSuite )(suiteName) +/*! Adds that the specified registry suite to another registry suite. + * \ingroup CreatingTestSuite + * + * Use this macros to automatically create test registry suite hierarchy. For example, + * if you want to create the following hierarchy: + * - Math + * - IntegerMath + * - FloatMath + * - FastFloat + * - StandardFloat + * + * You can do this automatically with: + * \code + * CPPUNIT_REGISTRY_ADD( "FastFloat", "FloatMath" ); + * CPPUNIT_REGISTRY_ADD( "IntegerMath", "Math" ); + * CPPUNIT_REGISTRY_ADD( "FloatMath", "Math" ); + * CPPUNIT_REGISTRY_ADD( "StandardFloat", "FloatMath" ); + * \endcode + * + * There is no specific order of declaration. Think of it as declaring links. + * + * You register the test in each suite using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION. + * + * \param which Name of the registry suite to add to the registry suite named \a to. + * \param to Name of the registry suite \a which is added to. + * \see CPPUNIT_REGISTRY_ADD_TO_DEFAULT, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION. + */ +#define CPPUNIT_REGISTRY_ADD( which, to ) \ + static CppUnit::AutoRegisterRegistry \ + CPPUNIT_MAKE_UNIQUE_NAME( __autoRegisterRegistry)( which, to ) + +/*! Adds that the specified registry suite to the default registry suite. + * \ingroup CreatingTestSuite + * + * This macro is just like CPPUNIT_REGISTRY_ADD except the specified registry + * suite is added to the default suite (root suite). + * + * \param which Name of the registry suite to add to the default registry suite. + * \see CPPUNIT_REGISTRY_ADD. + */ +#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT( which ) \ + static CppUnit::AutoRegisterRegistry \ + CPPUNIT_MAKE_UNIQUE_NAME( __autoRegisterRegistry)( which ) // Backwards compatibility // (Not tested!) diff --git a/include/cppunit/extensions/TestFactoryRegistry.h b/include/cppunit/extensions/TestFactoryRegistry.h index 6553fe5..5020219 100644 --- a/include/cppunit/extensions/TestFactoryRegistry.h +++ b/include/cppunit/extensions/TestFactoryRegistry.h @@ -5,11 +5,11 @@ #if CPPUNIT_NEED_DLL_DECL #pragma warning( push ) -#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#pragma warning( disable: 4251) // X needs to have dll-interface to be used by clients of class Z #endif #include <cppunit/extensions/TestFactory.h> -#include <map> +#include <set> #include <string> namespace CppUnit { @@ -17,17 +17,21 @@ namespace CppUnit { class TestSuite; #if CPPUNIT_NEED_DLL_DECL - template class CPPUNIT_API std::map<std::string, TestFactory *>; + template class CPPUNIT_API std::set<TestFactory *>; #endif /*! \brief Registry for TestFactory. * \ingroup CreatingTestSuite * - * Notes that the registry assumes lifetime control for any registered test. + * Notes that the registry \b DON'T assumes lifetime control for any registered tests + * anymore. + * + * The <em>default</em> 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 unnamed registry. + * - 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 @@ -61,8 +65,8 @@ class TestSuite; * The same result can be obtained with: * \code * CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); - * registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Graph" ) ); - * registry.registerFactory( CppUnit::TestFactoryRegistry::getRegistry( "Math" ) ); + * registry.addRegistry( "Graph" ); + * registry.addRegistry( "Math" ); * CppUnit::TestSuite *suite = registry.makeTest(); * \endcode * @@ -79,7 +83,7 @@ public: * \param name Name of the registry. It is the name of TestSuite returned by * makeTest(). */ - TestFactoryRegistry( std::string name = "All Tests" ); + TestFactoryRegistry( std::string name ); /// Destructor. virtual ~TestFactoryRegistry(); @@ -90,27 +94,63 @@ public: */ virtual Test *makeTest(); - /** Returns unnamed the registry. - * TestSuite registered using CPPUNIT_TEST_SUITE_REGISTRATION() are registered - * in this registry. - * \return Registry which name is "All Tests". - */ - static TestFactoryRegistry &getRegistry(); - /** Returns a named registry. - * TestSuite registered using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() are registered - * in the registry of the same name. + * + * If the \a 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. + * * \param name Name of the registry to return. * \return Registry. If the registry does not exist, it is created with the * specified name. */ - static TestFactoryRegistry &getRegistry( const std::string &name ); + static TestFactoryRegistry &getRegistry( const std::string &name = "All Tests" ); /** Adds the registered tests to the specified suite. * \param suite Suite the tests are added to. */ void addTestToSuite( TestSuite *suite ); + /** Adds the specified TestFactory to the registry. + * + * \param factory Factory to register. + */ + void registerFactory( TestFactory *factory ); + + /*! Removes the specified TestFactory from the registry. + * + * The specified factory is not destroyed. + * \param factory Factory to remove from the registry. + * \todo Address case when trying to remove a TestRegistryFactory. + */ + void unregisterFactory( TestFactory *factory ); + + /*! 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: + * \code + * this->registerFactory( TestFactoryRegistry::getRegistry( name ) ); + * \endcode + * + * \param name Name of the registry to add. + */ + void addRegistry( const std::string &name ); + + /*! 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. + * + * \return \c true if the specified registry has not been destroyed, + * otherwise returns \c false. + * \see AutoRegisterSuite. + */ + static bool isValid(); + /** Adds the specified TestFactory with a specific name (DEPRECATED). * \param name Name associated to the factory. * \param factory Factory to register. @@ -119,18 +159,12 @@ public: void registerFactory( const std::string &name, TestFactory *factory ); - /** Adds the specified TestFactory to the registry. - * - * \param factory Factory to register. - */ - void registerFactory( TestFactory *factory ); - private: TestFactoryRegistry( const TestFactoryRegistry © ); void operator =( const TestFactoryRegistry © ); private: - typedef std::map<std::string, TestFactory *> Factories; + typedef std::set<TestFactory *> Factories; Factories m_factories; std::string m_name; diff --git a/include/cppunit/plugin/DynamicLibraryManager.h b/include/cppunit/plugin/DynamicLibraryManager.h index 93ce583..2a95f30 100644 --- a/include/cppunit/plugin/DynamicLibraryManager.h +++ b/include/cppunit/plugin/DynamicLibraryManager.h @@ -4,8 +4,6 @@ #include <cppunit/Portability.h> #if !defined(CPPUNIT_NO_TESTPLUGIN) -#include <string> - namespace CppUnit { diff --git a/include/cppunit/plugin/Parameters.h b/include/cppunit/plugin/Parameters.h new file mode 100644 index 0000000..8175235 --- /dev/null +++ b/include/cppunit/plugin/Parameters.h @@ -0,0 +1,22 @@ +#ifndef CPPUNIT_PLUGIN_PARAMETERS +#define CPPUNIT_PLUGIN_PARAMETERS + +#include <cppunit/Portability.h> + +#if !defined(CPPUNIT_NO_TESTPLUGIN) + +#include <deque> +#include <string> + +namespace CppUnit +{ + +typedef std::deque<std::string> Parameters; + + +} // namespace CppUnit + +#endif // !defined(CPPUNIT_NO_TESTPLUGIN) + + +#endif // CPPUNIT_PLUGIN_PARAMETERS diff --git a/include/cppunit/plugin/PlugInManager.h b/include/cppunit/plugin/PlugInManager.h new file mode 100644 index 0000000..d3bbc5f --- /dev/null +++ b/include/cppunit/plugin/PlugInManager.h @@ -0,0 +1,101 @@ +#ifndef CPPUNIT_PLUGIN_PLUGINMANAGER_H +#define CPPUNIT_PLUGIN_PLUGINMANAGER_H + +#include <cppunit/Portability.h> + +#if !defined(CPPUNIT_NO_TESTPLUGIN) + +#if CPPUNIT_NEED_DLL_DECL +#pragma warning( push ) +#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z +#endif + +#include <cppunit/plugin/Parameters.h> +struct CppUnitTestPlugIn; + +namespace CppUnit +{ + +class DynamicLibraryManager; +class TestResult; + + +/*! \brief Manges TestPlugIn. + */ +class CPPUNIT_API PlugInManager +{ +public: + /*! Constructs a PlugInManager object. + */ + PlugInManager(); + + /// Destructor. + virtual ~PlugInManager(); + + /*! Loads the specified plug-in. + * + * After being loaded, the CppUnitTestPlugIn::initialize() is called. + * + * \param libraryFileName Name of the file that contains the TestPlugIn. + * \param parameters List of string passed to the plug-in. + * \return Pointer on the DynamicLibraryManager associated to the library. + * Valid until the library is unloaded. Never \c NULL. + * \exception DynamicLibraryManager is thrown if an error occurs during loading. + */ + void load( const std::string &libraryFileName, + const Parameters ¶meters = Parameters() ); + + /*! Unloads the specified plug-in. + * \param libraryFileName Name of the file that contains the TestPlugIn passed + * to a previous call to load(). + */ + void unload( const std::string &libraryFileName ); + + /*! Gives a chance to each loaded plug-in to register TestListener. + * + * For each plug-in, call CppUnitTestPlugIn::addListener(). + */ + void addListener( TestResult *eventManager ); + + /*! Gives a chance to each loaded plug-in to unregister TestListener. + * For each plug-in, call CppUnitTestPlugIn::removeListener(). + */ + void removeListener( TestResult *eventManager ); + +protected: + struct PlugInInfo + { + std::string m_fileName; + DynamicLibraryManager *m_manager; + CppUnitTestPlugIn *m_interface; + }; + + /*! Unloads the specified plug-in. + * \param plugIn Information about the plug-in. + */ + void unload( PlugInInfo &plugIn ); + +private: + /// Prevents the use of the copy constructor. + PlugInManager( const PlugInManager © ); + + /// Prevents the use of the copy operator. + void operator =( const PlugInManager © ); + +private: + typedef std::deque<PlugInInfo> PlugIns; + PlugIns m_plugIns; +}; + + +} // namespace CppUnit + + +#if CPPUNIT_NEED_DLL_DECL +#pragma warning( pop ) +#endif + +#endif // !defined(CPPUNIT_NO_TESTPLUGIN) + + +#endif // CPPUNIT_PLUGIN_PLUGINMANAGER_H diff --git a/include/cppunit/plugin/TestPlugIn.h b/include/cppunit/plugin/TestPlugIn.h index 02facd0..0847928 100644 --- a/include/cppunit/plugin/TestPlugIn.h +++ b/include/cppunit/plugin/TestPlugIn.h @@ -5,9 +5,13 @@ #if !defined(CPPUNIT_NO_TESTPLUGIN) +#include <cppunit/plugin/Parameters.h> + namespace CppUnit { class Test; +class TestFactoryRegistry; +class TestResult; } /*! \file @@ -19,6 +23,14 @@ class Test; * * This class define the interface implemented by test plug-in. A pointer to that * interface is returned by the function exported by the test plug-in. + * + * Plug-in are loaded/unloaded by PlugInManager. When a plug-in is loaded, + * initialize() is called. Before unloading the plug-in, the PlugInManager + * call uninitialize(). + * + * addListener() and removeListener() are called respectively before and after + * the test run. + * * \see CPPUNIT_PLUGIN_IMPLEMENT, CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL * \see TestPlugInDefaultImpl. */ @@ -26,23 +38,44 @@ struct CppUnitTestPlugIn { /*! Called just after loading the dynamic library. * - * Initializes the plug-in. + * Override this method to add additional suite to the registry, though this + * is preferably done using the macros (CPPUNIT_TEST_SUITE_REGISTRATION...). + * If you are creating a custom listener to extends the plug-in runner, + * you can use this to configure the listener using the \a parameters. + * + * You could also use the parameters to specify some global parameter, such + * as test datas location, database name... + * + * N.B.: Parameters interface is not define yet, and the plug-in runner does + * not yet support plug-in parameter. + */ + virtual void initialize( CppUnit::TestFactoryRegistry *registry, + const CppUnit::Parameters ¶meters ) =0; + + /*! Gives a chance to the plug-in to register TestListener. + * + * Override this method to add a TestListener for the test run. This is useful + * if you are writing a custom TestListener, but also if you need to + * setUp some global resource: listen to TestListener::startTestRun(), + * and TestListener::endTestRun(). */ - virtual void initialize() = 0; + virtual void addListener( CppUnit::TestResult *eventManager ) =0; - /*! Returns the root test of the plug-in. + /*! Gives a chance to the plug-in to remove its registered TestListener. * - * Caller does not assume ownership of the test. - * \return Pointer on a Test. Must never be \c NULL. The caller does not assume - * ownership of the returned Test. The Test must remain valid until - * uninitialize() is called. + * Override this method to remove a TestListener that has been added. */ - virtual CppUnit::Test *getTestSuite() =0; + virtual void removeListener( CppUnit::TestResult *eventManager ) =0; /*! Called just before unloading the dynamic library. - * Unitializes the plug-in. + * + * Override this method to unregister test factory added in initialize(). + * This is necessary to keep the TestFactoryRegistry 'clean'. When + * the plug-in is unloaded from memory, the TestFactoryRegistry will hold + * reference on test that are no longer available if they are not + * unregistered. */ - virtual void uninitialize() = 0; + virtual void uninitialize( CppUnit::TestFactoryRegistry *registry ) =0; }; @@ -60,7 +93,7 @@ struct CppUnitTestPlugIn /*! Type of the function exported by a plug-in. * \ingroup WritingTestPlugIn */ -typedef CppUnitTestPlugIn *(*CppUnitTestPlugInSignature)(); +typedef CppUnitTestPlugIn *(*TestPlugInSignature)(); /*! Implements the function exported by the test plug-in @@ -76,7 +109,7 @@ typedef CppUnitTestPlugIn *(*CppUnitTestPlugInSignature)(); // Note: This include should remain after definition of CppUnitTestPlugIn -#include <cppunit/plugin/TestPlugInDefaultImpl.h> +#include <cppunit/plugin/TestPlugInAdapter.h> /*! \def CPPUNIT_PLUGIN_IMPLEMENT_MAIN() @@ -116,8 +149,6 @@ typedef CppUnitTestPlugIn *(*CppUnitTestPlugInSignature)(); } \ typedef char __CppUnitPlugInImplementMainDummyTypeDef -// (void)argc; (void)argv; \ - // Other #else // other platforms don't require anything specifics @@ -128,24 +159,19 @@ typedef CppUnitTestPlugIn *(*CppUnitTestPlugInSignature)(); /*! Implements and exports the test plug-in interface. * \ingroup WritingTestPlugIn * - * This macro creates a subclass of CppUnitTestPlugInDefaultImpl to specify set - * the name of the suite returned by CppUnitTestPlugIn::getTestSuite(), exports - * the test plug-in function using the subclass, and implements the 'main' - * function for the plug-in using CPPUNIT_PLUGIN_IMPLEMENT_MAIN(). + * This macro exports the test plug-in function using the subclass, + * and implements the 'main' function for the plug-in using + * CPPUNIT_PLUGIN_IMPLEMENT_MAIN(). + * + * When using this macro, CppUnit must be linked as a DLL (shared library). + * Otherwise, tests registered to the TestFactoryRegistry in the DLL will + * not be visible to the DllPlugInTester. * - * \see CppUnitTestPlugIn, CppUnitTestPlugInDefaultImpl + * \see CppUnitTestPlugIn * \see CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL(), CPPUNIT_PLUGIN_IMPLEMENT_MAIN(). */ -#define CPPUNIT_PLUGIN_IMPLEMENT( suiteName ) \ - class __CppUnitTestPlugInNamedDefaultImpl : public CppUnit::TestPlugInDefaultImpl \ - { \ - virtual std::string getSuiteName() \ - { \ - return suiteName; \ - } \ - }; \ - \ - CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( __CppUnitTestPlugInNamedDefaultImpl ); \ +#define CPPUNIT_PLUGIN_IMPLEMENT() \ + CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( CppUnit::TestPlugInAdapter ); \ CPPUNIT_PLUGIN_IMPLEMENT_MAIN() diff --git a/include/cppunit/plugin/TestPlugInDefaultImpl.h b/include/cppunit/plugin/TestPlugInAdapter.h index 06f1bb3..0e54e0e 100644 --- a/include/cppunit/plugin/TestPlugInDefaultImpl.h +++ b/include/cppunit/plugin/TestPlugInAdapter.h @@ -1,5 +1,5 @@ -#ifndef CPPUNIT_PLUGIN_TESTPLUGINDEFAULTIMPL -#define CPPUNIT_PLUGIN_TESTPLUGINDEFAULTIMPL +#ifndef CPPUNIT_PLUGIN_TESTPLUGINADAPTER +#define CPPUNIT_PLUGIN_TESTPLUGINADAPTER #include <cppunit/Portability.h> @@ -23,23 +23,21 @@ class TestSuite; * ( TestFactoryRegistry::getRegistry() ). * */ -class CPPUNIT_API TestPlugInDefaultImpl : public CppUnitTestPlugIn +class CPPUNIT_API TestPlugInAdapter : public CppUnitTestPlugIn { public: - TestPlugInDefaultImpl(); + TestPlugInAdapter(); - virtual ~TestPlugInDefaultImpl(); + virtual ~TestPlugInAdapter(); - void initialize(); + void initialize( TestFactoryRegistry *registry, + const Parameters ¶meters ); - CppUnit::Test *getTestSuite(); + void addListener( TestResult *eventManager ); - void uninitialize(); + void removeListener( TestResult *eventManager ); -protected: - virtual std::string getSuiteName(); - - TestSuite *m_suite; + void uninitialize( TestFactoryRegistry *registry ); }; @@ -47,4 +45,4 @@ protected: #endif // !defined(CPPUNIT_NO_TESTPLUGIN) -#endif // CPPUNIT_PLUGIN_TESTPLUGINDEFAULTIMPL +#endif // CPPUNIT_PLUGIN_TESTPLUGINADAPTER diff --git a/include/cppunit/plugin/TestPlugInSuite.h b/include/cppunit/plugin/TestPlugInSuite.h deleted file mode 100644 index 19dc65d..0000000 --- a/include/cppunit/plugin/TestPlugInSuite.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef CPPUNIT_EXTENSIONS_TESTPLUGINSUITE_H -#define CPPUNIT_EXTENSIONS_TESTPLUGINSUITE_H - -#include <cppunit/TestComposite.h> -#if !defined(CPPUNIT_NO_TESTPLUGIN) - -#include <cppunit/plugin/TestPlugIn.h> - -namespace CppUnit -{ - -class DynamicLibraryManager; - - -/*! \brief A suite that wrap a test plug-in. - * \ingroup WritingTestPlugIn - */ -class TestPlugInSuite : public TestComposite -{ -public: - /*! Constructs a TestPlugInSuite object. - */ - TestPlugInSuite( const std::string &libraryFileName ); - - /// Destructor. - virtual ~TestPlugInSuite(); - - int getChildTestCount() const; - -protected: - Test *doGetChildTestAt( int index ) const; - - /// Prevents the use of the copy constructor. - TestPlugInSuite( const TestPlugInSuite © ); - - /// Prevents the use of the copy operator. - void operator =( const TestPlugInSuite © ); - -private: - /// Manager for the dynamic library. - DynamicLibraryManager *m_library; - /// Interface returned by the plug-in. - CppUnitTestPlugIn *m_interface; - /// Suite returned by the plug-in. - Test *m_librarySuite; -}; - - -} // namespace CppUnit - - -#endif // !defined(CPPUNIT_NO_TESTPLUGIN) - -#endif // CPPUNIT_EXTENSIONS_TESTPLUGINSUITE_H |
