?? _helper_macros_8h.html
字號:
<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>HelperMacros.h File Reference</h1>Macros intended to ease the definition of test suites. <a href="#_details">More...</a><p><code>#include <<a class="el" href="_test_caller_8h-source.html">cppunit/TestCaller.h</a>></code><br><code>#include <<a class="el" href="_test_suite_8h-source.html">cppunit/TestSuite.h</a>></code><br><code>#include <<a class="el" href="_auto_register_suite_8h-source.html">cppunit/extensions/AutoRegisterSuite.h</a>></code><br><code>#include <<a class="el" href="_exception_test_case_decorator_8h-source.html">cppunit/extensions/ExceptionTestCaseDecorator.h</a>></code><br><code>#include <<a class="el" href="_test_fixture_factory_8h-source.html">cppunit/extensions/TestFixtureFactory.h</a>></code><br><code>#include <<a class="el" href="_test_namer_8h-source.html">cppunit/extensions/TestNamer.h</a>></code><br><code>#include <<a class="el" href="_test_suite_builder_context_8h-source.html">cppunit/extensions/TestSuiteBuilderContext.h</a>></code><br><code>#include <memory></code><br><p><a href="_helper_macros_8h-source.html">Go to the source code of this file.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></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_fixture.html#ga0">CPPUNIT_TEST_SUITE</a>(ATestFixtureType)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Begin test suite. <a href="group___writing_test_fixture.html#ga0"></a><br><br></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_fixture.html#ga1">CPPUNIT_TEST_SUB_SUITE</a>(ATestFixtureType, ASuperClass)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Begin test suite (includes parent suite). <a href="group___writing_test_fixture.html#ga1"></a><br><br></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_fixture.html#ga2">CPPUNIT_TEST_SUITE_END</a>()</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">End declaration of the test suite. <a href="group___writing_test_fixture.html#ga2"></a><br><br></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_fixture.html#ga3">CPPUNIT_TEST_SUITE_END_ABSTRACT</a>()</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">End declaration of an abstract test suite. <a href="group___writing_test_fixture.html#ga3"></a><br><br></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_fixture.html#ga4">CPPUNIT_TEST_SUITE_ADD_TEST</a>(test) context.addTest( test )</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Add a test to the suite (for custom test macro). <a href="group___writing_test_fixture.html#ga4"></a><br><br></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_fixture.html#ga5">CPPUNIT_TEST</a>(testMethod)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Add a method to the suite. <a href="group___writing_test_fixture.html#ga5"></a><br><br></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_fixture.html#ga6">CPPUNIT_TEST_EXCEPTION</a>(testMethod, ExceptionType)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Add a test which fail if the specified exception is not caught. <a href="group___writing_test_fixture.html#ga6"></a><br><br></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_fixture.html#ga7">CPPUNIT_TEST_FAIL</a>(testMethod) CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception )</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Adds a test case which is excepted to fail. <a href="group___writing_test_fixture.html#ga7"></a><br><br></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_fixture.html#ga8">CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS</a>(testAdderMethod) testAdderMethod( context )</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Adds some custom test cases. <a href="group___writing_test_fixture.html#ga8"></a><br><br></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_fixture.html#ga9">CPPUNIT_TEST_SUITE_PROPERTY</a>(APropertyKey, APropertyValue)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Adds a property to the test suite builder context. <a href="group___writing_test_fixture.html#ga9"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___creating_test_suite.html#ga0">CPPUNIT_TEST_SUITE_REGISTRATION</a>(ATestFixtureType)</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___creating_test_suite.html#ga1">CPPUNIT_TEST_SUITE_NAMED_REGISTRATION</a>(ATestFixtureType, suiteName)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Adds the specified fixture suite to the specified registry suite. <a href="group___creating_test_suite.html#ga1"></a><br><br></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___creating_test_suite.html#ga2">CPPUNIT_REGISTRY_ADD</a>(which, to)</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>#define </td><td class="memItemRight" valign=bottom><a class="el" href="group___creating_test_suite.html#ga3">CPPUNIT_REGISTRY_ADD_TO_DEFAULT</a>(which)</td></tr></table><hr><a name="_details"></a><h2>Detailed Description</h2>Macros intended to ease the definition of test suites. <p>The macros <a class="el" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE()</a>, <a class="el" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST()</a>, and <a class="el" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END()</a> are designed to facilitate easy creation of a test suite. For example,<p><pre><div class="fragment"><span class="preprocessor"> #include <<a class="code" href="_helper_macros_8h.html">cppunit/extensions/HelperMacros.h</a>></span> <span class="keyword">class </span>MyTest : <span class="keyword">public</span> CppUnit::<a class="code" href="class_test_fixture.html">TestFixture</a> { <a class="code" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE</a>( MyTest ); <a class="code" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST</a>( testEquality ); <a class="code" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST</a>( testSetName ); <a class="code" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END</a>(); <span class="keyword">public</span>: <span class="keywordtype">void</span> testEquality(); <span class="keywordtype">void</span> testSetName(); };</div></pre><p>The effect of these macros is to define two methods in the class MyTest. The first method is an auxiliary function named registerTests that you will not need to call directly. The second function <pre><div class="fragment"> <span class="keyword">static</span> CppUnit::TestSuite *suite()</div></pre>returns a pointer to the suite of tests defined by the <a class="el" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST()</a> macros.<p>Rather than invoking suite() directly, the macro <a class="el" href="group___creating_test_suite.html#ga0">CPPUNIT_TEST_SUITE_REGISTRATION()</a> is used to create a static variable that automatically registers its test suite in a global registry. The registry yields a <a class="el" href="class_test.html">Test</a> instance containing all the registered suites. <pre><div class="fragment"> <a class="code" href="group___creating_test_suite.html#ga0">CPPUNIT_TEST_SUITE_REGISTRATION</a>( MyTest ); CppUnit::Test* tp = CppUnit::TestFactoryRegistry::getRegistry().makeTest();</div></pre><p>The test suite macros can even be used with templated test classes. For example:<p><pre><div class="fragment"> <span class="keyword">template</span><<span class="keyword">typename</span> CharType> <span class="keyword">class </span>StringTest : <span class="keyword">public</span> CppUnit::<a class="code" href="class_test_fixture.html">TestFixture</a> { <a class="code" href="group___writing_test_fixture.html#ga0">CPPUNIT_TEST_SUITE</a>( StringTest ); <a class="code" href="group___writing_test_fixture.html#ga5">CPPUNIT_TEST</a>( testAppend ); <a class="code" href="group___writing_test_fixture.html#ga2">CPPUNIT_TEST_SUITE_END</a>(); <span class="keyword">public</span>: ... };</div></pre><p>You need to add in an implementation file:<p><pre><div class="fragment"> <a class="code" href="group___creating_test_suite.html#ga0">CPPUNIT_TEST_SUITE_REGISTRATION</a>( StringTest<char> ); <a class="code" href="group___creating_test_suite.html#ga0">CPPUNIT_TEST_SUITE_REGISTRATION</a>( StringTest<wchar_t> );</div></pre><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
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -