Sophie

Sophie

distrib > Mandriva > 2006.0 > i586 > by-pkgid > 9c646fa862f3ddbc469622b1cf108654 > files > 24

check-0.9.2-1mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>SRunner output
   </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="Tutorial: Basic unit testing
  "
HREF="c57.html"><LINK
REL="PREVIOUS"
TITLE="Creating a suite
   "
HREF="x108.html"><LINK
REL="NEXT"
TITLE="Advanced Features
  "
HREF="c163.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="x108.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 3. Tutorial: Basic unit testing</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="c163.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECTION"
><H1
CLASS="SECTION"
><A
NAME="AEN115"
>3.5. SRunner output</A
></H1
><P
>The function to run tests in an SRunner is defined as follows:
   </P
><PRE
CLASS="PROGRAMLISTING"
>void srunner_run_all(SRunner *sr, enum print_output print_mode);</PRE
><P
>This function does two things:
   </P
><P
></P
><OL
TYPE="1"
><LI
><P
>Runs all of the unit tests for all of the test cases defined for all of the suites in the SRunner, and collects the results in the SRunner
    </P
></LI
><LI
><P
>Prints the results according to the print mode specified
    </P
></LI
></OL
><P
>For SRunners that have already been run, there is also a separate printing function defined as follows:
   </P
><PRE
CLASS="PROGRAMLISTING"
>void srunner_print(SRunner *sr, enum print_output print_mode);</PRE
><P
>The enumeration values defined in Check to control print output are as follows:
   </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>CK_SILENT</DT
><DD
><P
>Specifies that no output is to be generated. If you use this flag, you either need to programmatically examine the SRunner object, print separately, or use test logging (described below: <A
HREF="x232.html#TESTLOGGING"
>Test Logging</A
>).
       </P
></DD
><DT
>CK_MINIMAL</DT
><DD
><P
>Only a summary of the test run will be printed (number run, passed, failed, errors).
       </P
></DD
><DT
>CK_NORMAL</DT
><DD
><P
>Prints the summary of the run, and prints one message per failed tests.
     </P
></DD
><DT
>CK_VERBOSE</DT
><DD
><P
>Prints the summary, and one message per test (passed or failed)
       </P
></DD
><DT
>CK_ENV</DT
><DD
><P
>Gets the print mode from the environment variable CK_VERBOSITY, which can have the values "silent", "minimal", "normal, "verbose". If the variable is not found or the value is not recognized, the print mode is set to CK_NORMAL.
       </P
></DD
></DL
></DIV
><P
>With the CK_NORMAL flag specified, let's rerun make check now. We get the following satisfying output:
   </P
><PRE
CLASS="PROGRAMLISTING"
>Running suite(s): Money 
0%: Checks: 1, Failures: 1, Errors: 0 
check_money.c:9:F:Core:test_create: Amount not set correctly on creation</PRE
><P
>The first number in the summary line tells us that 0&percnt; of our tests passed, and the rest of the line tells us that there was one check, and one failure. The next line tells us exactly where that failure occurred, what kind of failure it was (P for pass, F for failure, E for error).
   </P
><P
>Let's implement the money_amount function, so that it will pass its tests. We first have to create a Money structure to hold the amount:
   </P
><PRE
CLASS="PROGRAMLISTING"
>struct Money { 
  int amount; 
};</PRE
><P
>Then we will implement the money_amount function to return the correct amount:
   </P
><PRE
CLASS="PROGRAMLISTING"
>int money_amount(Money *m) 
{ 
  return m-&#62;amount;
}</PRE
><P
>We will now rerun make check and... What's this? The output is now as follows:
   </P
><PRE
CLASS="PROGRAMLISTING"
>Running suite(s): Money 
0%: Checks: 1, Failures: 0, Errors: 1 
check_money.c:5:E:Core:test_create: (after this point) Received signal 11</PRE
><P
>What does this mean? Note that we now have an error, rather than a failure. This means that our unit test either exited early, or was signaled. Next note that the failure message says &ldquo;after this point&rdquo; This means that somewhere after the point noted (check_money.c, line 5) there was a problem: signal 11 (AKA segmentation fault). The last point reached is set on entry to the unit test, and after every call to fail_unless, fail, or the special function mark_point. E.g., if we wrote some test code as follows:
   </P
><PRE
CLASS="PROGRAMLISTING"
>stuff_that_works();
mark_point();
stuff_that_dies();</PRE
><P
>then the point returned will be that marked by mark_point.
   </P
><P
>The reason our test failed so horribly is that we haven't implemented money_create to create any money. Go ahead and implement that, and money_currency, to make the unit tests pass.
   </P
></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="x108.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="c163.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Creating a suite</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c57.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Advanced Features</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>