|
Packit |
8c9aa0 |
#ifndef CPPUNIT_PLUGIN_TESTPLUGIN
|
|
Packit |
8c9aa0 |
#define CPPUNIT_PLUGIN_TESTPLUGIN
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
#include <cppunit/Portability.h>
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
#if !defined(CPPUNIT_NO_TESTPLUGIN)
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
#include <cppunit/plugin/PlugInParameters.h>
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_NS_BEGIN
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
class Test;
|
|
Packit |
8c9aa0 |
class TestFactoryRegistry;
|
|
Packit |
8c9aa0 |
class TestResult;
|
|
Packit |
8c9aa0 |
class XmlOutputter;
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
CPPUNIT_NS_END
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \file
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Test plug-in interface.
|
|
Packit |
8c9aa0 |
* \ingroup WritingTestPlugIn
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* This class define the interface implemented by test plug-in. A pointer to that
|
|
Packit |
8c9aa0 |
* interface is returned by the function exported by the test plug-in.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Plug-in are loaded/unloaded by PlugInManager. When a plug-in is loaded,
|
|
Packit |
8c9aa0 |
* initialize() is called. Before unloading the plug-in, the PlugInManager
|
|
Packit |
8c9aa0 |
* call uninitialize().
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* addListener() and removeListener() are called respectively before and after
|
|
Packit |
8c9aa0 |
* the test run.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* addXmlOutputterHooks() and removeXmlOutputterHooks() are called respectively
|
|
Packit |
8c9aa0 |
* before and after writing the XML output using a XmlOutputter.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* \see CPPUNIT_PLUGIN_IMPLEMENT, CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL
|
|
Packit |
8c9aa0 |
* \see CppUnit::TestPlugInDefaultImpl, CppUnit::XmlOutputter.
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
struct CPPUNIT_API CppUnitTestPlugIn
|
|
Packit |
8c9aa0 |
{
|
|
Packit |
8c9aa0 |
/*! \brief Called just after loading the dynamic library.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Override this method to add additional suite to the registry, though this
|
|
Packit |
8c9aa0 |
* is preferably done using the macros (CPPUNIT_TEST_SUITE_REGISTRATION...).
|
|
Packit |
8c9aa0 |
* If you are creating a custom listener to extends the plug-in runner,
|
|
Packit |
8c9aa0 |
* you can use this to configure the listener using the \a parameters.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* You could also use the parameters to specify some global parameter, such
|
|
Packit |
8c9aa0 |
* as test datas location, database name...
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* N.B.: Parameters interface is not define yet, and the plug-in runner does
|
|
Packit |
8c9aa0 |
* not yet support plug-in parameter.
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
virtual void initialize( CPPUNIT_NS::TestFactoryRegistry *registry,
|
|
Packit |
8c9aa0 |
const CPPUNIT_NS::PlugInParameters ¶meters ) =0;
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Gives a chance to the plug-in to register TestListener.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Override this method to add a TestListener for the test run. This is useful
|
|
Packit |
8c9aa0 |
* if you are writing a custom TestListener, but also if you need to
|
|
Packit |
8c9aa0 |
* setUp some global resource: listen to TestListener::startTestRun(),
|
|
Packit |
8c9aa0 |
* and TestListener::endTestRun().
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
virtual void addListener( CPPUNIT_NS::TestResult *eventManager ) =0;
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Gives a chance to the plug-in to remove its registered TestListener.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Override this method to remove a TestListener that has been added.
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
virtual void removeListener( CPPUNIT_NS::TestResult *eventManager ) =0;
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Provides a way for the plug-in to register some XmlOutputterHook.
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
virtual void addXmlOutputterHooks( CPPUNIT_NS::XmlOutputter *outputter ) =0;
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Called when the XmlOutputter is destroyed.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Can be used to free some resources allocated by addXmlOutputterHooks().
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
virtual void removeXmlOutputterHooks() = 0;
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Called just before unloading the dynamic library.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* Override this method to unregister test factory added in initialize().
|
|
Packit |
8c9aa0 |
* This is necessary to keep the TestFactoryRegistry 'clean'. When
|
|
Packit |
8c9aa0 |
* the plug-in is unloaded from memory, the TestFactoryRegistry will hold
|
|
Packit |
8c9aa0 |
* reference on test that are no longer available if they are not
|
|
Packit |
8c9aa0 |
* unregistered.
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
virtual void uninitialize( CPPUNIT_NS::TestFactoryRegistry *registry ) =0;
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
virtual ~CppUnitTestPlugIn() {}
|
|
Packit |
8c9aa0 |
};
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Name of the function exported by a test plug-in.
|
|
Packit |
8c9aa0 |
* \ingroup WritingTestPlugIn
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* The signature of the exported function is:
|
|
Packit |
8c9aa0 |
* \code
|
|
Packit |
8c9aa0 |
* CppUnitTestPlugIn *CPPUNIT_PLUGIN_EXPORTED_NAME(void);
|
|
Packit |
8c9aa0 |
* \endcode
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTestPlugIn
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Type of the function exported by a plug-in.
|
|
Packit |
8c9aa0 |
* \ingroup WritingTestPlugIn
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
typedef CppUnitTestPlugIn *(*TestPlugInSignature)();
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Implements the function exported by the test plug-in
|
|
Packit |
8c9aa0 |
* \ingroup WritingTestPlugIn
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
#define CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( TestPlugInInterfaceType ) \
|
|
Packit |
8c9aa0 |
CPPUNIT_PLUGIN_EXPORT CppUnitTestPlugIn *CPPUNIT_PLUGIN_EXPORTED_NAME(void) \
|
|
Packit |
8c9aa0 |
{ \
|
|
Packit |
8c9aa0 |
static TestPlugInInterfaceType plugIn; \
|
|
Packit |
8c9aa0 |
return &plugIn; \
|
|
Packit |
8c9aa0 |
} \
|
|
Packit |
8c9aa0 |
typedef char __CppUnitPlugInExportFunctionDummyTypeDef // dummy typedef so it can end with ';'
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
// Note: This include should remain after definition of CppUnitTestPlugIn
|
|
Packit |
8c9aa0 |
#include <cppunit/plugin/TestPlugInDefaultImpl.h>
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \def CPPUNIT_PLUGIN_IMPLEMENT_MAIN()
|
|
Packit |
8c9aa0 |
* \brief Implements the 'main' function for the plug-in.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* This macros implements the main() function for dynamic library.
|
|
Packit |
8c9aa0 |
* For example, WIN32 requires a DllMain function, while some Unix
|
|
Packit |
8c9aa0 |
* requires a main() function. This macros takes care of the implementation.
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
// Win32
|
|
Packit |
8c9aa0 |
#if defined(CPPUNIT_HAVE_WIN32_DLL_LOADER)
|
|
Packit |
8c9aa0 |
#if !defined(APIENTRY)
|
|
Packit |
8c9aa0 |
#define WIN32_LEAN_AND_MEAN
|
|
Packit |
8c9aa0 |
#define NOGDI
|
|
Packit |
8c9aa0 |
#define NOUSER
|
|
Packit |
8c9aa0 |
#define NOKERNEL
|
|
Packit |
8c9aa0 |
#define NOSOUND
|
|
Packit |
8c9aa0 |
#define NOMINMAX
|
|
Packit |
8c9aa0 |
#define BLENDFUNCTION void // for mingw & gcc
|
|
Packit |
8c9aa0 |
#include <windows.h>
|
|
Packit |
8c9aa0 |
#endif
|
|
Packit |
8c9aa0 |
#define CPPUNIT_PLUGIN_IMPLEMENT_MAIN() \
|
|
Packit |
8c9aa0 |
BOOL APIENTRY DllMain( HANDLE, DWORD, LPVOID ) \
|
|
Packit |
8c9aa0 |
{ \
|
|
Packit |
8c9aa0 |
return TRUE; \
|
|
Packit |
8c9aa0 |
} \
|
|
Packit |
8c9aa0 |
typedef char __CppUnitPlugInImplementMainDummyTypeDef
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
// Unix
|
|
Packit |
8c9aa0 |
#elif defined(CPPUNIT_HAVE_UNIX_DLL_LOADER) || defined(CPPUNIT_HAVE_UNIX_SHL_LOADER)
|
|
Packit |
8c9aa0 |
#define CPPUNIT_PLUGIN_IMPLEMENT_MAIN() \
|
|
Packit |
8c9aa0 |
int main() \
|
|
Packit |
8c9aa0 |
{ \
|
|
Packit |
8c9aa0 |
return 0; \
|
|
Packit |
8c9aa0 |
} \
|
|
Packit |
8c9aa0 |
typedef char __CppUnitPlugInImplementMainDummyTypeDef
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
// Other
|
|
Packit |
8c9aa0 |
#else // other platforms don't require anything specifics
|
|
Packit |
8c9aa0 |
#endif
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
/*! \brief Implements and exports the test plug-in interface.
|
|
Packit |
8c9aa0 |
* \ingroup WritingTestPlugIn
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* This macro exports the test plug-in function using the subclass,
|
|
Packit |
8c9aa0 |
* and implements the 'main' function for the plug-in using
|
|
Packit |
8c9aa0 |
* CPPUNIT_PLUGIN_IMPLEMENT_MAIN().
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* When using this macro, CppUnit must be linked as a DLL (shared library).
|
|
Packit |
8c9aa0 |
* Otherwise, tests registered to the TestFactoryRegistry in the DLL will
|
|
Packit |
8c9aa0 |
* not be visible to the DllPlugInTester.
|
|
Packit |
8c9aa0 |
*
|
|
Packit |
8c9aa0 |
* \see CppUnitTestPlugIn
|
|
Packit |
8c9aa0 |
* \see CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL(), CPPUNIT_PLUGIN_IMPLEMENT_MAIN().
|
|
Packit |
8c9aa0 |
*/
|
|
Packit |
8c9aa0 |
#define CPPUNIT_PLUGIN_IMPLEMENT() \
|
|
Packit |
8c9aa0 |
CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( CPPUNIT_NS::TestPlugInDefaultImpl ); \
|
|
Packit |
8c9aa0 |
CPPUNIT_PLUGIN_IMPLEMENT_MAIN()
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
#endif // !defined(CPPUNIT_NO_TESTPLUGIN)
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
|
|
Packit |
8c9aa0 |
#endif // CPPUNIT_PLUGIN_TESTPLUGIN
|