📄 _orthodox_8h-source.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>Orthodox.h</h1><a href="_orthodox_8h.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 <span class="preprocessor">#ifndef CPPUNIT_EXTENSIONS_ORTHODOX_H</span>00002 <span class="preprocessor"></span><span class="preprocessor">#define CPPUNIT_EXTENSIONS_ORTHODOX_H</span>00003 <span class="preprocessor"></span>00004 <span class="preprocessor">#include <<a class="code" href="_test_case_8h.html">cppunit/TestCase.h</a>></span>00005 00006 <a class="code" href="_portability_8h.html#a6">CPPUNIT_NS_BEGIN</a>00007 00008 00009 <span class="comment">/*</span>00010 <span class="comment"> * Orthodox performs a simple set of tests on an arbitary</span>00011 <span class="comment"> * class to make sure that it supports at least the</span>00012 <span class="comment"> * following operations:</span>00013 <span class="comment"> *</span>00014 <span class="comment"> * default construction - constructor</span>00015 <span class="comment"> * equality/inequality - operator== && operator!=</span>00016 <span class="comment"> * assignment - operator=</span>00017 <span class="comment"> * negation - operator!</span>00018 <span class="comment"> * safe passage - copy construction</span>00019 <span class="comment"> *</span>00020 <span class="comment"> * If operations for each of these are not declared</span>00021 <span class="comment"> * the template will not instantiate. If it does </span>00022 <span class="comment"> * instantiate, tests are performed to make sure</span>00023 <span class="comment"> * that the operations have correct semantics.</span>00024 <span class="comment"> * </span>00025 <span class="comment"> * Adding an orthodox test to a suite is very </span>00026 <span class="comment"> * easy: </span>00027 <span class="comment"> * </span>00028 <span class="comment"> * public: Test *suite () {</span>00029 <span class="comment"> * TestSuite *suiteOfTests = new TestSuite;</span>00030 <span class="comment"> * suiteOfTests->addTest (new ComplexNumberTest ("testAdd");</span>00031 <span class="comment"> * suiteOfTests->addTest (new TestCaller<Orthodox<Complex> > ());</span>00032 <span class="comment"> * return suiteOfTests;</span>00033 <span class="comment"> * }</span>00034 <span class="comment"> *</span>00035 <span class="comment"> * Templated test cases be very useful when you are want to</span>00036 <span class="comment"> * make sure that a group of classes have the same form.</span>00037 <span class="comment"> *</span>00038 <span class="comment"> * see TestSuite</span>00039 <span class="comment"> */</span>00040 00041 <a name="l00042"></a><a class="code" href="class_orthodox.html">00042</a> <span class="keyword">template</span> <<span class="keyword">class</span> ClassUnderTest> <span class="keyword">class </span><a class="code" href="class_orthodox.html">Orthodox</a> : <span class="keyword">public</span> <a class="code" href="class_test_case.html">TestCase</a>00043 {00044 <span class="keyword">public</span>:<a name="l00045"></a><a class="code" href="class_orthodox.html#a0">00045</a> <a class="code" href="class_orthodox.html#a0">Orthodox</a> () : <a class="code" href="class_test_case.html">TestCase</a> ("<a class="code" href="class_orthodox.html">Orthodox</a>") {}00046 00047 <span class="keyword">protected</span>:00048 ClassUnderTest call (ClassUnderTest object);00049 <span class="keywordtype">void</span> <a class="code" href="class_orthodox.html#b1">runTest</a> ();00050 00051 00052 };00053 00054 00055 <span class="comment">// Run an orthodoxy test</span><a name="l00056"></a><a class="code" href="class_orthodox.html#b1">00056</a> <span class="keyword">template</span> <<span class="keyword">class</span> ClassUnderTest> <span class="keywordtype">void</span> <a class="code" href="class_orthodox.html#b1">Orthodox<ClassUnderTest>::runTest</a> ()00057 {00058 <span class="comment">// make sure we have a default constructor</span>00059 ClassUnderTest a, b, c;00060 00061 <span class="comment">// make sure we have an equality operator</span>00062 <a class="code" href="group___assertions.html#ga0">CPPUNIT_ASSERT</a> (a == b);00063 00064 <span class="comment">// check the inverse</span>00065 b.operator= (a.operator! ());00066 <a class="code" href="group___assertions.html#ga0">CPPUNIT_ASSERT</a> (a != b);00067 00068 <span class="comment">// double inversion</span>00069 b = !!a;00070 <a class="code" href="group___assertions.html#ga0">CPPUNIT_ASSERT</a> (a == b);00071 00072 <span class="comment">// invert again</span>00073 b = !a;00074 00075 <span class="comment">// check calls</span>00076 c = a;00077 <a class="code" href="group___assertions.html#ga0">CPPUNIT_ASSERT</a> (c == <a class="code" href="class_orthodox.html#b0">call</a> (a));00078 00079 c = b;00080 <a class="code" href="group___assertions.html#ga0">CPPUNIT_ASSERT</a> (c == <a class="code" href="class_orthodox.html#b0">call</a> (b));00081 00082 }00083 00084 00085 <span class="comment">// Exercise a call</span>00086 <span class="keyword">template</span> <<span class="keyword">class</span> ClassUnderTest> <a name="l00087"></a><a class="code" href="class_orthodox.html#b0">00087</a> ClassUnderTest <a class="code" href="class_orthodox.html">Orthodox<ClassUnderTest>::call</a> (ClassUnderTest object)00088 {00089 <span class="keywordflow">return</span> object;00090 }00091 00092 00093 <a class="code" href="_portability_8h.html#a7">CPPUNIT_NS_END</a>00094 00095 <span class="preprocessor">#endif</span></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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -