?? group___writing_test_plug_in.html
字號(hào):
<html><head><title>CppUnit - The Unit Testing Library</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"> <table width="100%"> <tr> <td width="40%" align="left" valign="center"> <a href="http://sourceforge.net/projects/cppunit"> CppUnit project page </a> </td> <td> <a href="FAQ">FAQ</a> </td> <td width="40%" align="right" valign="center"> <a href="http://cppunit.sourceforge.net">CppUnit home page</a> </td> </tr></table><hr><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div><h1>Writing Test Plug-in</h1><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Classes</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>struct </td><td class="memItemRight" valign=bottom><a class="el" href="struct_cpp_unit_test_plug_in.html">CppUnitTestPlugIn</a></td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight"><a class="el" href="class_test.html">Test</a> plug-in interface. <a href="struct_cpp_unit_test_plug_in.html#_details">More...</a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>class </td><td class="memItemRight" valign=bottom><a class="el" href="class_test_plug_in_default_impl.html">TestPlugInDefaultImpl</a></td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Default implementation of test plug-in interface. <a href="class_test_plug_in_default_impl.html#_details">More...</a><br><br></td></tr><tr><td colspan=2><br><h2>Defines</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___writing_test_plug_in.html#ga0">CPPUNIT_PLUGIN_EXPORT</a> extern "C"</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">A macro to export a function from a dynamic library. <a href="#ga0"></a><br><br></td></tr></table><hr><a name="_details"></a><h2>Detailed Description</h2>Creating a test plug-in is really simple:<ul><li>make your project a dynamic library (with VC++, choose Win32 Dynamic Library in the project wizard), and link against the dynamic library version of CppUnit (cppunit*_dll.lib for VC++).</li><li>in a cpp file, include <a class="el" href="_test_plug_in_8h.html">TestPlugIn.h</a>, and use the macro <a class="el" href="_test_plug_in_8h.html#a2">CPPUNIT_PLUGIN_IMPLEMENT()</a> to declare the test plug-in.</li><li>That's it, you're done! All the tests registered using the <a class="el" href="class_test_factory_registry.html">TestFactoryRegistry</a>, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION, or CPPUNIT_TEST_SUITE_REGISTRATION will be visible to other plug-in and to the DllPlugInRunner.</li></ul><p>Example: <pre><div class="fragment"><span class="preprocessor"> #include <cppunit/include/plugin/TestPlugIn.h></span> <a class="code" href="_test_plug_in_8h.html#a2">CPPUNIT_PLUGIN_IMPLEMENT</a>();</div></pre><p>The interface <a class="el" href="struct_cpp_unit_test_plug_in.html">CppUnitTestPlugIn</a> is automatically implemented by the previous macro. You can define your one implementation.<p>To provide your custom implementation of the plug-in interface, you must:<ul><li>create a class that implements the <a class="el" href="struct_cpp_unit_test_plug_in.html">CppUnitTestPlugIn</a> interface</li><li>use <a class="el" href="_test_plug_in_8h.html#a1">CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL()</a> with your class to export the plug-in interface</li><li>implements the 'main' function with CPPUNIT_PLUGIN_IMPLEMENT_MAIN().</li></ul><p>Some of the reason you may want to do this:<ul><li>You do not use the <a class="el" href="class_test_factory_registry.html">TestFactoryRegistry</a> to register your test.</li><li>You want to create a custom listener to use with DllPlugInRunner.</li><li>You want to do initialize some globale resources before running the test (setting up COM for example).</li></ul><p>See <a class="el" href="struct_cpp_unit_test_plug_in.html">CppUnitTestPlugIn</a> for further detail on how to do this.<p>Creating your own test plug-in with VC++:<ul><li>Create a new "Win32 Dynamic Library" project, choose the empty template</li><li>For the Debug Configuration, add cppunitd_dll.lib to 'Project Settings/Link/Object/Libariries modules', and for the Release Configuration, add cppunit_dll.lib.</li><li>For All Configuration, in 'C++/Preprocessor/Preprocessors definitions', add the symbol 'CPPUNIT_DLL' at the end of the line (it means that you are linking against cppunit dll).</li><li>Create a 'main' file that contains: <pre><div class="fragment">#include <cppunit/plugin/TestPlugIn.h>CPPUNIT_PLUGIN_IMPLEMENT();</div></pre></li><li>Add your tests</li><li>You're done !</li></ul><p>See examples/simple/simple_plugin.dsp for an example.<p>Notes to VC++ users:<ul><li>you can run a post-build check on the plug-in. Add the following line to your post-build tab: "DllPlugInTesterd_dll.exe $(TargetPath)". DllPlugInTesterd_dll.exe need to be some place were it can be found (path, ...), or you need to indicate the correct path. is the filename of your plug-in.</li><li>you can debug your DLL, set the executable for debug session to the plug-in runner, and the name of the DLL in the program arguments ( won't work this time).</li></ul><p>How does it works ?<p>When CppUnit is linked as a DLL, the singleton used for the <a class="el" href="class_test_factory_registry.html">TestFactoryRegistry</a> 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 <a class="el" href="class_plug_in_manager.html">PlugInManager</a>, the DLL static variable are constructed and the test registered to the <a class="el" href="class_test_factory_registry.html">TestFactoryRegistry</a>.<p>After loading the DLL, the <a class="el" href="class_plug_in_manager.html">PlugInManager</a> 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 <a class="el" href="class_plug_in_manager.html">PlugInManager</a>.<p><dl compact><dt><b>See also:</b></dt><dd><a class="el" href="group___creating_test_suite.html">CreatingTestSuite</a>. </dd></dl><hr><h2>Define Documentation</h2><a class="anchor" name="ga0" doxytag="SelectDllLoader.h::CPPUNIT_PLUGIN_EXPORT" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> #define CPPUNIT_PLUGIN_EXPORT extern "C" </td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>A macro to export a function from a dynamic library. <p>This macro export the C function following it from a dynamic library. Exporting the function makes it accessible to the <a class="el" href="class_dynamic_library_manager.html">DynamicLibraryManager</a>.<p>Example of usage: <pre><div class="fragment"><span class="preprocessor"> #include <cppunit/include/plugin/TestPlugIn.h></span> <a class="code" href="group___writing_test_plug_in.html#ga0">CPPUNIT_PLUGIN_EXPORT</a> <a class="code" href="struct_cpp_unit_test_plug_in.html">CppUnitTestPlugIn</a> *<a class="code" href="_test_plug_in_8h.html#a0">CPPUNIT_PLUGIN_EXPORTED_NAME</a>(<span class="keywordtype">void</span>) { ... <span class="keywordflow">return</span> &myPlugInInterface; }</div></pre> </td> </tr></table><hr><table width="100%"> <tr> <td width="10%" align="left" valign="center"> <a href="http://sourceforge.net"> <img src="http://sourceforge.net/sflogo.php?group_id=11795" width="88" height="31" border="0" alt="SourceForge Logo"></a> </td> <td width="20%" align="left" valign="center"> hosts this site. </td> <td> </td> <td align="right" valign="center"> Send comments to:<br> <a href="mailto:cppunit-devel@lists.sourceforge.net">CppUnit Developers</a> </td> </tr></table></body> </html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -