~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/include/cppunit/plugin/TestPlugIn.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef CPPUNIT_PLUGIN_TESTPLUGIN
2
 
#define CPPUNIT_PLUGIN_TESTPLUGIN
3
 
 
4
 
#include <cppunit/Portability.h>
5
 
 
6
 
#if !defined(CPPUNIT_NO_TESTPLUGIN)
7
 
 
8
 
#include <cppunit/plugin/PlugInParameters.h>
9
 
 
10
 
CPPUNIT_NS_BEGIN
11
 
 
12
 
 
13
 
class Test;
14
 
class TestFactoryRegistry;
15
 
class TestResult;
16
 
class XmlOutputter;
17
 
 
18
 
CPPUNIT_NS_END
19
 
 
20
 
/*! \file
21
 
 */
22
 
 
23
 
 
24
 
/*! \brief Test plug-in interface.
25
 
 * \ingroup WritingTestPlugIn
26
 
 *
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.
29
 
 *
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().
33
 
 *
34
 
 * addListener() and removeListener() are called respectively before and after
35
 
 * the test run.
36
 
 *
37
 
 * addXmlOutputterHooks() and removeXmlOutputterHooks() are called respectively
38
 
 * before and after writing the XML output using a XmlOutputter.
39
 
 *
40
 
 * \see CPPUNIT_PLUGIN_IMPLEMENT, CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL
41
 
 * \see CppUnit::TestPlugInDefaultImpl, CppUnit::XmlOutputter.
42
 
 */
43
 
struct CppUnitTestPlugIn
44
 
{
45
 
  /*! \brief Called just after loading the dynamic library. 
46
 
   *
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.
51
 
   *
52
 
   * You could also use the parameters to specify some global parameter, such
53
 
   * as test datas location, database name...
54
 
   *
55
 
   * N.B.: Parameters interface is not define yet, and the plug-in runner does
56
 
   * not yet support plug-in parameter.
57
 
   */
58
 
  virtual void initialize( CPPUNIT_NS::TestFactoryRegistry *registry,
59
 
                           const CPPUNIT_NS::PlugInParameters &parameters ) =0;
60
 
 
61
 
  /*! \brief Gives a chance to the plug-in to register TestListener.
62
 
   * 
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().
67
 
   */
68
 
  virtual void addListener( CPPUNIT_NS::TestResult *eventManager ) =0;
69
 
 
70
 
  /*! \brief Gives a chance to the plug-in to remove its registered TestListener.
71
 
   *
72
 
   * Override this method to remove a TestListener that has been added.
73
 
   */
74
 
  virtual void removeListener( CPPUNIT_NS::TestResult *eventManager ) =0;
75
 
 
76
 
  /*! \brief Provides a way for the plug-in to register some XmlOutputterHook.
77
 
   */
78
 
  virtual void addXmlOutputterHooks( CPPUNIT_NS::XmlOutputter *outputter ) =0;
79
 
 
80
 
  /*! \brief Called when the XmlOutputter is destroyed.
81
 
   * 
82
 
   * Can be used to free some resources allocated by addXmlOutputterHooks().
83
 
   */
84
 
  virtual void removeXmlOutputterHooks() = 0;
85
 
 
86
 
  /*! \brief Called just before unloading the dynamic library.
87
 
   * 
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 
92
 
   * unregistered.
93
 
   */
94
 
  virtual void uninitialize( CPPUNIT_NS::TestFactoryRegistry *registry ) =0;
95
 
 
96
 
  virtual ~CppUnitTestPlugIn() {}
97
 
};
98
 
 
99
 
 
100
 
 
101
 
/*! \brief Name of the function exported by a test plug-in.
102
 
 * \ingroup WritingTestPlugIn
103
 
 *
104
 
 * The signature of the exported function is:
105
 
 * \code
106
 
 * CppUnitTestPlugIn *CPPUNIT_PLUGIN_EXPORTED_NAME(void);
107
 
 * \endcode
108
 
 */
109
 
#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTestPlugIn
110
 
 
111
 
/*! \brief Type of the function exported by a plug-in.
112
 
 * \ingroup WritingTestPlugIn
113
 
 */
114
 
typedef CppUnitTestPlugIn *(*TestPlugInSignature)();
115
 
 
116
 
 
117
 
/*! \brief Implements the function exported by the test plug-in
118
 
 * \ingroup WritingTestPlugIn
119
 
 */
120
 
#define CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( TestPlugInInterfaceType )       \
121
 
  CPPUNIT_PLUGIN_EXPORT CppUnitTestPlugIn *CPPUNIT_PLUGIN_EXPORTED_NAME(void)  \
122
 
  {                                                                            \
123
 
    static TestPlugInInterfaceType plugIn;                                     \
124
 
    return &plugIn;                                                            \
125
 
  }                                                                            \
126
 
  typedef char __CppUnitPlugInExportFunctionDummyTypeDef  // dummy typedef so it can end with ';'
127
 
 
128
 
 
129
 
// Note: This include should remain after definition of CppUnitTestPlugIn
130
 
#include <cppunit/plugin/TestPlugInDefaultImpl.h>
131
 
 
132
 
 
133
 
/*! \def CPPUNIT_PLUGIN_IMPLEMENT_MAIN()
134
 
 * \brief Implements the 'main' function for the plug-in.
135
 
 *
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.
139
 
 */
140
 
 
141
 
// Win32
142
 
#if defined(CPPUNIT_HAVE_WIN32_DLL_LOADER)
143
 
#if !defined(APIENTRY)
144
 
#define WIN32_LEAN_AND_MEAN 
145
 
#define NOGDI
146
 
#define NOUSER
147
 
#define NOKERNEL
148
 
#define NOSOUND
149
 
#define NOMINMAX
150
 
#define BLENDFUNCTION void    // for mingw & gcc
151
 
#include <windows.h>
152
 
#endif
153
 
#define CPPUNIT_PLUGIN_IMPLEMENT_MAIN()               \
154
 
  BOOL APIENTRY DllMain( HANDLE hModule,              \
155
 
                         DWORD  ul_reason_for_call,   \
156
 
                         LPVOID lpReserved )          \
157
 
  {                                                   \
158
 
      return TRUE;                                    \
159
 
  }                                                   \
160
 
  typedef char __CppUnitPlugInImplementMainDummyTypeDef
161
 
 
162
 
// Unix
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[] )                  \
166
 
  {                                                   \
167
 
    return 0;                                         \
168
 
  }                                                   \
169
 
  typedef char __CppUnitPlugInImplementMainDummyTypeDef
170
 
 
171
 
 
172
 
// Other
173
 
#else     // other platforms don't require anything specifics
174
 
#endif
175
 
 
176
 
 
177
 
 
178
 
/*! \brief Implements and exports the test plug-in interface.
179
 
 * \ingroup WritingTestPlugIn
180
 
 *
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().
184
 
 *
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.
188
 
 *
189
 
 * \see CppUnitTestPlugIn
190
 
 * \see CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL(), CPPUNIT_PLUGIN_IMPLEMENT_MAIN().
191
 
 */
192
 
#define CPPUNIT_PLUGIN_IMPLEMENT()                                          \
193
 
  CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( CPPUNIT_NS::TestPlugInDefaultImpl );  \
194
 
  CPPUNIT_PLUGIN_IMPLEMENT_MAIN()
195
 
 
196
 
 
197
 
#endif // !defined(CPPUNIT_NO_TESTPLUGIN)
198
 
 
199
 
 
200
 
#endif // CPPUNIT_PLUGIN_TESTPLUGIN