1
#ifndef CPPUNIT_PLUGIN_TESTPLUGIN
2
#define CPPUNIT_PLUGIN_TESTPLUGIN
4
#include <cppunit/Portability.h>
6
#if !defined(CPPUNIT_NO_TESTPLUGIN)
8
#include <cppunit/plugin/PlugInParameters.h>
14
class TestFactoryRegistry;
24
/*! \brief Test plug-in interface.
25
* \ingroup WritingTestPlugIn
27
* This class define the interface implemented by test plug-in. A pointer to that
28
* interface is returned by the function exported by the test plug-in.
30
* Plug-in are loaded/unloaded by PlugInManager. When a plug-in is loaded,
31
* initialize() is called. Before unloading the plug-in, the PlugInManager
32
* call uninitialize().
34
* addListener() and removeListener() are called respectively before and after
37
* addXmlOutputterHooks() and removeXmlOutputterHooks() are called respectively
38
* before and after writing the XML output using a XmlOutputter.
40
* \see CPPUNIT_PLUGIN_IMPLEMENT, CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL
41
* \see CppUnit::TestPlugInDefaultImpl, CppUnit::XmlOutputter.
43
struct CppUnitTestPlugIn
45
/*! \brief Called just after loading the dynamic library.
47
* Override this method to add additional suite to the registry, though this
48
* is preferably done using the macros (CPPUNIT_TEST_SUITE_REGISTRATION...).
49
* If you are creating a custom listener to extends the plug-in runner,
50
* you can use this to configure the listener using the \a parameters.
52
* You could also use the parameters to specify some global parameter, such
53
* as test datas location, database name...
55
* N.B.: Parameters interface is not define yet, and the plug-in runner does
56
* not yet support plug-in parameter.
58
virtual void initialize( CPPUNIT_NS::TestFactoryRegistry *registry,
59
const CPPUNIT_NS::PlugInParameters ¶meters ) =0;
61
/*! \brief Gives a chance to the plug-in to register TestListener.
63
* Override this method to add a TestListener for the test run. This is useful
64
* if you are writing a custom TestListener, but also if you need to
65
* setUp some global resource: listen to TestListener::startTestRun(),
66
* and TestListener::endTestRun().
68
virtual void addListener( CPPUNIT_NS::TestResult *eventManager ) =0;
70
/*! \brief Gives a chance to the plug-in to remove its registered TestListener.
72
* Override this method to remove a TestListener that has been added.
74
virtual void removeListener( CPPUNIT_NS::TestResult *eventManager ) =0;
76
/*! \brief Provides a way for the plug-in to register some XmlOutputterHook.
78
virtual void addXmlOutputterHooks( CPPUNIT_NS::XmlOutputter *outputter ) =0;
80
/*! \brief Called when the XmlOutputter is destroyed.
82
* Can be used to free some resources allocated by addXmlOutputterHooks().
84
virtual void removeXmlOutputterHooks() = 0;
86
/*! \brief Called just before unloading the dynamic library.
88
* Override this method to unregister test factory added in initialize().
89
* This is necessary to keep the TestFactoryRegistry 'clean'. When
90
* the plug-in is unloaded from memory, the TestFactoryRegistry will hold
91
* reference on test that are no longer available if they are not
94
virtual void uninitialize( CPPUNIT_NS::TestFactoryRegistry *registry ) =0;
96
virtual ~CppUnitTestPlugIn() {}
101
/*! \brief Name of the function exported by a test plug-in.
102
* \ingroup WritingTestPlugIn
104
* The signature of the exported function is:
106
* CppUnitTestPlugIn *CPPUNIT_PLUGIN_EXPORTED_NAME(void);
109
#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTestPlugIn
111
/*! \brief Type of the function exported by a plug-in.
112
* \ingroup WritingTestPlugIn
114
typedef CppUnitTestPlugIn *(*TestPlugInSignature)();
117
/*! \brief Implements the function exported by the test plug-in
118
* \ingroup WritingTestPlugIn
120
#define CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( TestPlugInInterfaceType ) \
121
CPPUNIT_PLUGIN_EXPORT CppUnitTestPlugIn *CPPUNIT_PLUGIN_EXPORTED_NAME(void) \
123
static TestPlugInInterfaceType plugIn; \
126
typedef char __CppUnitPlugInExportFunctionDummyTypeDef // dummy typedef so it can end with ';'
129
// Note: This include should remain after definition of CppUnitTestPlugIn
130
#include <cppunit/plugin/TestPlugInDefaultImpl.h>
133
/*! \def CPPUNIT_PLUGIN_IMPLEMENT_MAIN()
134
* \brief Implements the 'main' function for the plug-in.
136
* This macros implements the main() function for dynamic library.
137
* For example, WIN32 requires a DllMain function, while some Unix
138
* requires a main() function. This macros takes care of the implementation.
142
#if defined(CPPUNIT_HAVE_WIN32_DLL_LOADER)
143
#if !defined(APIENTRY)
144
#define WIN32_LEAN_AND_MEAN
150
#define BLENDFUNCTION void // for mingw & gcc
153
#define CPPUNIT_PLUGIN_IMPLEMENT_MAIN() \
154
BOOL APIENTRY DllMain( HANDLE hModule, \
155
DWORD ul_reason_for_call, \
156
LPVOID lpReserved ) \
160
typedef char __CppUnitPlugInImplementMainDummyTypeDef
163
#elif defined(CPPUNIT_HAVE_UNIX_DLL_LOADER) || defined(CPPUNIT_HAVE_UNIX_SHL_LOADER)
164
#define CPPUNIT_PLUGIN_IMPLEMENT_MAIN() \
165
int main( int argc, char *argv[] ) \
169
typedef char __CppUnitPlugInImplementMainDummyTypeDef
173
#else // other platforms don't require anything specifics
178
/*! \brief Implements and exports the test plug-in interface.
179
* \ingroup WritingTestPlugIn
181
* This macro exports the test plug-in function using the subclass,
182
* and implements the 'main' function for the plug-in using
183
* CPPUNIT_PLUGIN_IMPLEMENT_MAIN().
185
* When using this macro, CppUnit must be linked as a DLL (shared library).
186
* Otherwise, tests registered to the TestFactoryRegistry in the DLL will
187
* not be visible to the DllPlugInTester.
189
* \see CppUnitTestPlugIn
190
* \see CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL(), CPPUNIT_PLUGIN_IMPLEMENT_MAIN().
192
#define CPPUNIT_PLUGIN_IMPLEMENT() \
193
CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( CPPUNIT_NS::TestPlugInDefaultImpl ); \
194
CPPUNIT_PLUGIN_IMPLEMENT_MAIN()
197
#endif // !defined(CPPUNIT_NO_TESTPLUGIN)
200
#endif // CPPUNIT_PLUGIN_TESTPLUGIN