<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Test Logging </TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Check Tutorial" HREF="index.html"><LINK REL="UP" TITLE="Advanced Features " HREF="c163.html"><LINK REL="PREVIOUS" TITLE="Test timeouts " HREF="x226.html"><LINK REL="NEXT" TITLE="Conclusion " HREF="x246.html"></HEAD ><BODY CLASS="SECTION" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Check Tutorial</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x226.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 4. Advanced Features</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x246.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECTION" ><H1 CLASS="SECTION" ><A NAME="AEN232" >4.7. Test Logging<A NAME="TESTLOGGING" ></A ></A ></H1 ><P >Check supports operation to log the results of a test run. To use test logging, use the srunner_set_log function with the name of the log file you wish to create: </P ><PRE CLASS="PROGRAMLISTING" >SRunner *sr; sr = srunner_create(make_s1_suite()); srunner_add_suite(sr, make_s2_suite()); srunner_set_log(sr, "test.log"); srunner_run_all(sr, CRNORMAL);</PRE ><P >Check will write the results of the run to test.log. The printmode argument to srunner_run_all does not apply to test logging; the log will contain a result entry, organized by suite, for every test run. Here is an example of test log output: </P ><PRE CLASS="PROGRAMLISTING" >Running suite S1 ex_log_output.c:8:P:Core:test_pass: Test passed ex_log_output.c:14:F:Core:test_fail: Failure ex_log_output.c:18:E:Core:test_exit: (after this point) Early exit with return value 1 Running suite S2 ex_log_output.c:26:P:Core:test_pass2: Test passed Results for all suites run: 50%: Checks: 4, Failures: 1, Errors: 1</PRE ><DIV CLASS="SECTION" ><H2 CLASS="SECTION" ><A NAME="AEN239" >4.7.1. XML logging</A ></H2 ><P >The log can also be written in XML. The following functions define the interface for XML logs: </P ><PRE CLASS="PROGRAMLISTING" >void srunner_set_xml(SRunner *sr, const char *fname); int srunner_has_xml(SRunner *sr); const char *srunner_xml_fname(SRunner *sr);</PRE ><P >The only thing you need to do to get XML output is call <CODE CLASS="FUNCTION" >srunner_set_xml()</CODE > before the tests are run. Here is an example of the same log output as above but in XML: </P ><PRE CLASS="PROGRAMLISTING" ><?xml version="1.0"?> <testsuites xmlns="http://check.sourceforge.net/ns"> <datetime>2004-08-20 12:53:32</datetime> <suite> <title>S1</title> <test result="success"> <path>.</path> <fn>ex_xml_output.c:8</fn> <id>test_pass</id> <description>Core</description> <message>Passed</message> </test> <test result="failure"> <path>.</path> <fn>ex_xml_output.c:14</fn> <id>test_fail</id> <description>Core</description> <message>Failure</message> </test> <test result="error"> <path>.</path> <fn>ex_xml_output.c:18</fn> <id>test_exit</id> <description>Core</description> <message>Early exit with return value 1</message> </test> </suite> <suite> <title>S2</title> <test result="success"> <path>.</path> <fn>ex_xml_output.c:26</fn> <id>test_pass2</id> <description>Core</description> <message>Passed</message> </test> </suite> <duration>0.304875</duration> </testsuites></PRE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x226.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x246.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Test timeouts</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c163.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Conclusion</TD ></TR ></TABLE ></DIV ></BODY ></HTML >