Sophie

Sophie

distrib > Mandriva > 10.0 > i586 > by-pkgid > ef9bad9e14fc2a68cb7c992c11d75f5e > files > 4116

libboost1-devel-1.31.0-1mdk.i586.rpm

<HTML>
<HEAD>
<TITLE>The automatic registration facility</TITLE>
<LINK rel="stylesheet" type="text/css" href="../../../../style/btl.css" media="screen">
<LINK rel="stylesheet" type="text/css" href="../../../../style/btl-print.css" media="print">
<META http-equiv="Content-Language" content="en-us">
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<DIV class="header"> <A href="../../../../index.html">Boost.Test</A> > <A href="../../../index.html">Components</A> 
  > <A href="../../index.html">The Unit Test Framework</A> > <A href="../index.html">Components</A> 
  > <A href="index.html">The Test Case</A> > <SPAN class="current_article">The 
  automatic registration facility</SPAN> </DIV>
<DIV class="body"> <IMG src='../../../../btl1.gif' width='252' height='43' alt="Boost Test logo"> 
  <H1 class="subtitle">The automatic registration facility</H1>
  <H5>Definition</H5>
  <P class="first-line-indented"> defined in <A href="../../../../../../../boost/test/auto_unit_test.hpp"> 
    auto_unit_test.hpp</A> 
  <H5>Description</H5>
  <P class="first-line-indented">This form of test cases is based on free function, 
    but unlike class <a href="function_test_case.html">function_test_case</a> 
    you don't need to manually create and register them. Instances of the class 
    <a href="function_test_case.html">function_test_case</a> are created automatically 
    by the framework at the point of test case definition and registered in single 
    global test suite. This way you never forget to include any test cases - it's 
    done on a fly. You doesn't need to supply init_unit_test_suite anymore. It's 
    implemented by the framework and instantiated in one of the compilation unit. 
    To notify which compilation unit should contain initialization function you 
    need to define macro <SPAN class="new-term">BOOST_AUTO_TEST_MAIN</span>. In 
    test with multiple compilation units <u>one and only one</u> should define 
    above macro. 
  <H5>Construction</H5>
  <P class="first-line-indented">To use automatic registration facility you need
    to define a test case as a zero arity free function, but instead of usual 
    void test_case_name(), use following statement</P>
  <P><SPAN class="new-term">BOOST_AUTO_UNIT_TEST</SPAN>( test_case_name )</P>
  <P class="first-line-indented">BOOST_TEST_CASE hides all the machinery used 
    to implement <a href="function_test_case.html"></a>automatic registration. 
    The only requirements are that test case names are unique within compilation 
    unit and no two test case definition are located on the same line.</P>
  <H5>Examples</H5>
  <PRE class="code" id="ff_ex_1">#<SPAN class=reserv-word>define</span> <SPAN class="new-term">BOOST_AUTO_TEST_MAIN</span>
#<SPAN class="reserv-word">include</span> &lt;<SPAN class="literal">boost/test/auto_unit_test.hpp</span>&gt;

// _____________________________________

<SPAN class="new-term">BOOST_AUTO_UNIT_TEST</span>( test1 )
{
    ...
}

// _____________________________________

<span class="new-term">BOOST_AUTO_UNIT_TEST</span>( test2 )
{
    ...
}

// _____________________________________</PRE>
</DIV>
<DIV class="footer"> 
  <DIV class="footer-body"> 
    <P> &copy <A name="Copyright">Copyright</A> <A href='mailto:rogeeff@fusemail.com'>Gennadiy Rozental</A> 2001-2004. <BR>
      Use, modification, and distribution are subject to the Boost Software License, Version 1.0. 
      (See accompanying file <A href="../../../../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or copy at 
      <A href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</A>)</P>
        <P>Revised:        <!-- #BeginDate format:Sw1 -->6 January, 2004<!-- #EndDate -->     </P>
  </DIV>
</DIV>
</BODY>
</HTML>