| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Master Test Suite</title> |
| <link rel="stylesheet" href="../../../../style/style.css" type="text/css"> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> |
| <link rel="home" href="../../../index.html" title="Boost Test Library"> |
| <link rel="up" href="test-suite.html" title="Test suite"> |
| <link rel="prev" href="auto-test-suite.html" title="Test suites with automated registration"> |
| <link rel="next" href="expected-failures.html" title="Expected failures specification"> |
| <script language="JavaScript1.2" src="../../../../js/boost-test.js"></script> |
| </head> |
| <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| <table width="100%"><tr> |
| <td width="10%"><a href="../../../index.html"><img alt="Home" width="229" height="61" border="0" src="../../../../../../../libs/test/docbook/img/boost.test.logo.png"></a></td> |
| <td valign="middle" align="left"> > <a href="../../../utf.html">The Unit Test Framework</a> > <a href="../../user-guide.html">User's guide</a><a href="../../testing-tools.html"> |
| > |
| </a><a href="../test-organization.html">Test organization</a><a href="../fixture.html"> |
| > |
| </a><a href="test-suite.html">Test suite</a><a href="expected-failures.html"> |
| > |
| </a><b>Master Test Suite</b> |
| </td> |
| <td><div class="spirit-nav"> |
| <a href="auto-test-suite.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a href="expected-failures.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a> |
| </div></td> |
| </tr></table> |
| <hr> |
| <div class="section" lang="en"> |
| <div class="titlepage"><div><div><h6 class="title"> |
| <a name="utf.user-guide.test-organization.master-test-suite"></a>Master Test Suite</h6></div></div></div> |
| <p class="first-line-indented"> |
| As defined in introduction section the master test suite is a root node of a test tree. Each test module built |
| with the <acronym class="acronym">UTF</acronym> always has the master test suite defined. The <acronym class="acronym">UTF</acronym> maintain the master test suite instance |
| internally. All other test units are registered as direct or indirect children of the master test suite. |
| </p> |
| <pre class="programlisting">namespace boost { |
| namespace unit_test { |
| class master_test_suite_t : public test_suite { |
| public: |
| int argc; |
| char** argv; |
| }; |
| |
| } // namespace unit_test |
| |
| } // namespace boost</pre> |
| <p class="first-line-indented"> |
| To access single instance of the master test suite use the following interface: |
| </p> |
| <pre class="programlisting">namespace boost { |
| namespace unit_test { |
| namespace framework { |
| |
| master_test_suite_t& master_test_suite(); |
| |
| } // namespace framework |
| } // namespace unit_test |
| } // namespace boost</pre> |
| <div class="section" lang="en"> |
| <div class="titlepage"><div><div><h6 class="title"> |
| <a name="utf.user-guide.test-organization.cla-access"></a>Command line arguments access interface</h6></div></div></div> |
| <p class="first-line-indented"> |
| Master test suite implemented as an extension to the regular test suite, since it maintains references to the |
| command line arguments passed to the test module. To access the command line arguments use |
| </p> |
| <pre class="programlisting">boost::unit_test::framework::master_test_suite().argc |
| boost::unit_test::framework::master_test_suite().argv</pre> |
| <p class="first-line-indented"> |
| In below example references to the command line arguments are accessible either as an initialization function |
| parameters or as members of the master test suite. Both references point to the same values. A test module that |
| uses the alternative initialization function specification can only access command line arguments through the |
| master test suite. |
| </p> |
| <div class="note"><table border="0" summary="Note"> |
| <tr> |
| <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td> |
| <th align="left">Note</th> |
| </tr> |
| <tr><td align="left" valign="top"><p> |
| This interface for runtime parameter access is temporary. It's planned to be updated once runtime |
| parameters support is redesigned. |
| </p></td></tr> |
| </table></div> |
| <p class="first-line-indented"> |
| Returning to the free function example, let's modify initialization function to check for absence of any |
| test module arguments. |
| </p> |
| <div class="example"> |
| <a name="utf.user-guide.test-organization.cla-access.example13"></a><p class="title"><b>Example 18. Command line access in initialization function</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#include <boost/test/included/unit_test.hpp> |
| using namespace boost::unit_test; |
| |
| //____________________________________________________________________________// |
| |
| void free_test_function() |
| { |
| BOOST_CHECK( true /* test assertion */ ); |
| } |
| |
| //____________________________________________________________________________// |
| |
| test_suite* |
| init_unit_test_suite( int argc, char* argv[] ) |
| { |
| if( framework::master_test_suite().argc > 1 ) |
| return 0; |
| |
| framework::master_test_suite(). |
| add( BOOST_TEST_CASE( &free_test_function ) ); |
| |
| return 0; |
| } |
| |
| //____________________________________________________________________________// |
| |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../../src/examples/example13.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id651615" onclick="toggle_element( 'example13-output', 'id651615', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example13-output">> example 1 |
| Test setup error: test tree is empty</pre> |
| </div> |
| </div> |
| <br class="example-break"> |
| </div> |
| <div class="section" lang="en"> |
| <div class="titlepage"><div><div><h6 class="title"> |
| <a name="utf.user-guide.test-organization.master-test-suite-name"></a>Naming</h6></div></div></div> |
| <p class="first-line-indented"> |
| The master test suite is created with default name "Master Test Suite". There are two methods two |
| reset the name to a different value: using the macro <a class="xref" href="../../compilation.html#utf.flag.module">BOOST_TEST_MODULE</a> |
| and from within the test module initialization function. Former is used for test modules that don't have the |
| manually implemented initialization function. Following examples illustrate these methods. |
| </p> |
| <div class="example"> |
| <a name="utf.user-guide.test-organization.master-test-suite-name.example14"></a><p class="title"><b>Example 19. Naming master test suite using the macro <a class="xref" href="../../compilation.html#utf.flag.module">BOOST_TEST_MODULE</a></b></p> |
| <div class="example-contents"> |
| <p class="first-line-indented"> |
| If the macro <a class="xref" href="../../compilation.html#utf.flag.module">BOOST_TEST_MODULE</a> is defined, the test module initialization |
| function is <a class="link" href="../initialization.html#utf.user-guide.initialization.auto-generation" title="Automated generation of the test module initialization function">automatically generated</a> and the |
| macro value becomes the name of the master test suite. The name may include spaces. |
| </p> |
| <pre class="programlisting">#define BOOST_TEST_DYN_LINK |
| #define BOOST_TEST_MODULE my master test suite name |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( free_test_function ) |
| { |
| BOOST_CHECK( true /* test assertion */ ); |
| } |
| |
| //____________________________________________________________________________// |
| |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../../src/examples/example14.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id651774" onclick="toggle_element( 'example14-output', 'id651774', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example14-output">> example --log_level=test_suite |
| Running 1 test case... |
| Entering test suite "my master test suite name" |
| Entering test case "free_test_function" |
| Leaving test case "free_test_function"; testing time: 1ms |
| Leaving test suite "my master test suite name" |
| |
| *** No errors detected |
| |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><div class="example"> |
| <a name="utf.user-guide.test-organization.master-test-suite-name.example15"></a><p class="title"><b>Example 20. Naming master test suite explicitly in the test module initialization function</b></p> |
| <div class="example-contents"> |
| <p class="first-line-indented"> |
| Without the <a class="xref" href="../../compilation.html#utf.flag.main">BOOST_TEST_MAIN</a> and the <a class="xref" href="../../compilation.html#utf.flag.module">BOOST_TEST_MODULE</a> flags defined, the test module initialization function has to be manually implemented. |
| The master test suite name can be reset at any point within this function. |
| </p> |
| <pre class="programlisting">#include <boost/test/included/unit_test.hpp> |
| using namespace boost::unit_test; |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( free_test_function ) |
| { |
| BOOST_CHECK( true /* test assertion */ ); |
| } |
| |
| //____________________________________________________________________________// |
| |
| test_suite* |
| init_unit_test_suite( int argc, char* argv[] ) |
| { |
| framework::master_test_suite().p_name.value = "my master test suite name"; |
| |
| return 0; |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../../src/examples/example15.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id651887" onclick="toggle_element( 'example15-output', 'id651887', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example15-output">> example --log_level=test_suite |
| Running 1 test case... |
| Entering test suite "my master test suite name" |
| Entering test case "free_test_function" |
| Leaving test case "free_test_function"; testing time: 1ms |
| Leaving test suite "my master test suite name" |
| |
| *** No errors detected |
| |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"> |
| </div> |
| </div> |
| <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> |
| <td align="left"></td> |
| <td align="right"><div class="copyright-footer">Copyright © 2001-2007 Gennadiy Rozental</div></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="auto-test-suite.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="test-suite.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="expected-failures.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a> |
| </div> |
| </body> |
| </html> |