CppUnit project page FAQ CppUnit home page

Classes | Macros | Typedefs
Writing Test Plug-in

Classes

struct  CppUnitTestPlugIn
 Test plug-in interface.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. More...
 
class  TestPlugInDefaultImpl
 Default implementation of test plug-in interface.Override getSuiteName() to specify the suite name. Default is "All Tests". More...
 

Macros

#define CPPUNIT_PLUGIN_EXPORT   extern "C"
 A macro to export a function from a dynamic library. More...
 
#define CPPUNIT_PLUGIN_EXPORTED_NAME   cppunitTestPlugIn
 Name of the function exported by a test plug-in.The signature of the exported function is: More...
 
#define CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL(TestPlugInInterfaceType)
 Implements the function exported by the test plug-in. More...
 
#define CPPUNIT_PLUGIN_IMPLEMENT()
 Implements and exports the test plug-in interface.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(). More...
 

Typedefs

typedef CppUnitTestPlugIn *(* TestPlugInSignature )()
 Type of the function exported by a plug-in. More...
 

Detailed Description

Creating a test plug-in is really simple:

Example:

* #include <cppunit/include/plugin/TestPlugIn.h>
*
*

The interface CppUnitTestPlugIn is automatically implemented by the previous macro. You can define your own implementation.

To provide your custom implementation of the plug-in interface, you must:

Some of the reason you may want to do this:

See CppUnitTestPlugIn for further detail on how to do this.

Creating your own test plug-in with VC++:

See examples/simple/simple_plugin.dsp for an example.

Notes to VC++ users:

How does it works ?

When CppUnit is linked as a DLL, the singleton used for the TestFactoryRegistry is the same for the plug-in runner (also linked against CppUnit DLL). This means that the tests registered with the macros (at static initialization) are registered in the same registry. As soon as a DLL is loaded by the PlugInManager, the DLL static variable are constructed and the test registered to the TestFactoryRegistry.

After loading the DLL, the PlugInManager look-up a specific function exported by the DLL. That function returns a pointer on the plug-in interface, which is later used by the PlugInManager.

See Also
Creating TestSuite.

Macro Definition Documentation

#define CPPUNIT_PLUGIN_EXPORT   extern "C"

A macro to export a function from a dynamic library.

This macro export the C function following it from a dynamic library. Exporting the function makes it accessible to the DynamicLibraryManager.

Example of usage:

* #include <cppunit/include/plugin/TestPlugIn.h>
*
* {
* ...
* return &myPlugInInterface;
* }
*
#define CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL (   TestPlugInInterfaceType)
Value:
{ \
static TestPlugInInterfaceType plugIn; \
return &plugIn; \
} \
typedef char __CppUnitPlugInExportFunctionDummyTypeDef
Test plug-in interface.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.
Definition: TestPlugIn.h:43
#define CPPUNIT_PLUGIN_EXPORTED_NAME
Name of the function exported by a test plug-in.The signature of the exported function is: ...
Definition: TestPlugIn.h:109
#define CPPUNIT_PLUGIN_EXPORT
A macro to export a function from a dynamic library.
Definition: SelectDllLoader.h:71

Implements the function exported by the test plug-in.

#define CPPUNIT_PLUGIN_EXPORTED_NAME   cppunitTestPlugIn

Name of the function exported by a test plug-in.The signature of the exported function is:

#define CPPUNIT_PLUGIN_IMPLEMENT ( )
Value:
CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( CPPUNIT_NS::TestPlugInDefaultImpl ); \
CPPUNIT_PLUGIN_IMPLEMENT_MAIN()
#define CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL(TestPlugInInterfaceType)
Implements the function exported by the test plug-in.
Definition: TestPlugIn.h:120

Implements and exports the test plug-in interface.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 Also
CppUnitTestPlugIn
CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL(), CPPUNIT_PLUGIN_IMPLEMENT_MAIN().

Typedef Documentation

typedef CppUnitTestPlugIn*(* TestPlugInSignature)()

Type of the function exported by a plug-in.


SourceForge Logo hosts this site. Send comments to:
CppUnit Developers