⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class_xml_outputter_hook.html

📁 c++开发的一个不错的工具
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<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&nbsp;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&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>XmlOutputterHook Class Reference</h1>Hook to customize Xml output.  <a href="#_details">More...</a><p><code>#include &lt;<a class="el" href="_xml_outputter_hook_8h-source.html">XmlOutputterHook.h</a>&gt;</code><p><a href="class_xml_outputter_hook-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Public Member Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>virtual void&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_xml_outputter_hook.html#a0">beginDocument</a> (<a class="el" href="class_xml_document.html">XmlDocument</a> *document)</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>virtual void&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_xml_outputter_hook.html#a1">endDocument</a> (<a class="el" href="class_xml_document.html">XmlDocument</a> *document)</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>virtual void&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_xml_outputter_hook.html#a2">failTestAdded</a> (<a class="el" href="class_xml_document.html">XmlDocument</a> *document, <a class="el" href="class_xml_element.html">XmlElement</a> *testElement, <a class="el" href="class_test.html">Test</a> *test, <a class="el" href="class_test_failure.html">TestFailure</a> *failure)</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>virtual void&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_xml_outputter_hook.html#a3">successfulTestAdded</a> (<a class="el" href="class_xml_document.html">XmlDocument</a> *document, <a class="el" href="class_xml_element.html">XmlElement</a> *testElement, <a class="el" href="class_test.html">Test</a> *test)</td></tr><tr><td class="memItemLeft" nowrap align=right valign=top>virtual void&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_xml_outputter_hook.html#a4">statisticsAdded</a> (<a class="el" href="class_xml_document.html">XmlDocument</a> *document, <a class="el" href="class_xml_element.html">XmlElement</a> *statisticsElement)</td></tr></table><hr><a name="_details"></a><h2>Detailed Description</h2>Hook to customize Xml output. <p>XmlOutputterHook can be passed to <a class="el" href="class_xml_outputter.html">XmlOutputter</a> to customize the <a class="el" href="class_xml_document.html">XmlDocument</a>.<p>Common customizations are:<ul><li>adding some datas to successfull or failed test with failTestAdded() and successfulTestAdded(),</li><li>adding some statistics with statisticsAdded(),</li><li>adding other datas with beginDocument() or endDocument().</li></ul><p>See examples/ClockerPlugIn which makes use of most the hook.<p>Another simple example of an outputter hook is shown below. It may be used to add some meta information to your result files. In the example, the author name as well as the project name and test creation date is added to the head of the xml file.<p>In order to make this information stored within the xml file, the virtual member function beginDocument() is overriden where a new <a class="el" href="class_xml_element.html">XmlElement</a> object is created.<p>This element is simply added to the root node of the document which makes the information automatically being stored when the xml file is written.<p><pre><div class="fragment"><span class="preprocessor"> #include &lt;<a class="code" href="_xml_outputter_hook_8h.html">cppunit/XmlOutputterHook.h</a>&gt;</span><span class="preprocessor"> #include &lt;cppunit/XmlElement.h&gt;</span><span class="preprocessor"> #include &lt;<a class="code" href="_string_tools_8h.html">cppunit/tools/StringTools.h</a>&gt;</span>  ...  <span class="keyword">class </span>MyXmlOutputterHook : <span class="keyword">public</span> CppUnit::<a class="code" href="class_xml_outputter_hook.html">XmlOutputterHook</a> { <span class="keyword">public</span>:   MyXmlOutputterHook(<span class="keyword">const</span> std::string projectName,                      <span class="keyword">const</span> std::string author)   {      m_projectName = projectName;      m_author      = author;   };    <span class="keyword">virtual</span> ~MyXmlOutputterHook()   {   };    <span class="keywordtype">void</span> beginDocument(CppUnit::XmlDocument* document)   {     <span class="keywordflow">if</span> (!document)       <span class="keywordflow">return</span>;     <span class="comment">// dump current time</span>     std::string szDate          = CppUnit::StringTools::toString( (<span class="keywordtype">int</span>)time(0) );     CppUnit::XmlElement* metaEl = <span class="keyword">new</span> CppUnit::XmlElement(<span class="stringliteral">"SuiteInfo"</span>,                                                            <span class="stringliteral">""</span>);     metaEl-&gt;addElement( <span class="keyword">new</span> CppUnit::XmlElement(<span class="stringliteral">"Author"</span>, m_author) );     metaEl-&gt;addElement( <span class="keyword">new</span> CppUnit::XmlElement(<span class="stringliteral">"Project"</span>, m_projectName) );     metaEl-&gt;addElement( <span class="keyword">new</span> CppUnit::XmlElement(<span class="stringliteral">"Date"</span>, szDate ) );         document-&gt;rootElement().addElement(metaEl);   }; <span class="keyword">private</span>:   std::string m_projectName;   std::string m_author; }; </div></pre><p>Within your application's main code, you need to snap the hook object into your xml outputter object like shown below:<p><pre><div class="fragment"> CppUnit::TextUi::TestRunner runner; std::ofstream outputFile(<span class="stringliteral">"testResults.xml"</span>);  CppUnit::XmlOutputter* outputter = <span class="keyword">new</span> CppUnit::XmlOutputter( &amp;runner.result(),                                                               outputFile );     MyXmlOutputterHook hook(<span class="stringliteral">"myProject"</span>, <span class="stringliteral">"meAuthor"</span>); outputter-&gt;addHook(&amp;hook); runner.setOutputter(outputter);     runner.addTest( VectorFixture::suite() );    runner.run(); outputFile.close();</div></pre><p>This results into the following output:<p><pre><div class="fragment"> &lt;TestRun&gt;   &lt;suiteInfo&gt;     &lt;author&gt;meAuthor&lt;/author&gt;     &lt;project&gt;myProject&lt;/project&gt;     &lt;date&gt;1028143912&lt;/date&gt;   &lt;/suiteInfo&gt;   &lt;FailedTests&gt;    ...</div></pre><p><dl compact><dt><b>See also:</b></dt><dd><a class="el" href="class_xml_outputter.html">XmlOutputter</a>, <a class="el" href="struct_cpp_unit_test_plug_in.html">CppUnitTestPlugIn</a>. </dd></dl><p><hr><h2>Member Function Documentation</h2><a class="anchor" name="a0" doxytag="XmlOutputterHook::beginDocument" ></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"> CPPUNIT_NS_BEGIN void XmlOutputterHook::beginDocument           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="class_xml_document.html">XmlDocument</a> *&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>document</em>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Called before any elements is added to the root element. <dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td></td><td valign=top><em>document</em>&nbsp;</td><td>XML Document being created. </td></tr>  </table></dl>    </td>  </tr></table><a class="anchor" name="a1" doxytag="XmlOutputterHook::endDocument" ></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"> void XmlOutputterHook::endDocument           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="class_xml_document.html">XmlDocument</a> *&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>document</em>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -