diff options
Diffstat (limited to 'include/cppunit/plugin')
| -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 |
6 files changed, 189 insertions, 98 deletions
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 |
