| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>The UTF testing tools reference</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="../testing-tools.html" title="The UTF testing tools or tester's toolbox for all occasions"> |
| <link rel="prev" href="floating_point_comparison.html" title="Floating-point comparison algorithms"> |
| <link rel="next" href="../usage-recommendations.html" title="The unit test framework usage recommendations"> |
| <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="../testing-tools.html">Testing tools</a><a href="../usage-recommendations.html"> |
| > |
| </a><b>Reference</b> |
| </td> |
| <td><div class="spirit-nav"> |
| <a href="floating_point_comparison.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a href="../usage-recommendations.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><h4 class="title"> |
| <a name="utf.testing-tools.reference"></a>The <acronym class="acronym">UTF</acronym> testing tools reference</h4></div></div></div> |
| <script language="JavaScript1.2"> |
| var id298906; |
| </script><table class="inline-reference"><tr> |
| <td class="index" valign="top"><ul> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_BITWISE_EQUAL', id298906 ); return false;">BOOST_<level>_BITWISE_EQUAL</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE', id298906 ); return false;">BOOST_<level>_CLOSE</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE_FRACTION', id298906 ); return false;">BOOST_<level>_CLOSE_FRACTION</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EQUAL', id298906 ); return false;">BOOST_<level>_EQUAL</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EQUAL_COLLECTION', id298906 ); return false;">BOOST_<level>_EQUAL_COLLECTION</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EXCEPTION', id298906 ); return false;">BOOST_<level>_EXCEPTION</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GE', id298906 ); return false;">BOOST_<level>_GE</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GT', id298906 ); return false;">BOOST_<level>_GT</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LE', id298906 ); return false;">BOOST_<level>_LE</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LT', id298906 ); return false;">BOOST_<level>_LT</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_MESSAGE', id298906 ); return false;">BOOST_<level>_MESSAGE</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_NE', id298906 ); return false;">BOOST_<level>_NE</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_NO_THROW', id298906 ); return false;">BOOST_<level>_NO_THROW</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_PREDICATE', id298906 ); return false;">BOOST_<level>_PREDICATE</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_SMALL', id298906 ); return false;">BOOST_<level>_SMALL</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_THROW', id298906 ); return false;">BOOST_<level>_THROW</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_ERROR', id298906 ); return false;">BOOST_ERROR</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_FAIL', id298906 ); return false;">BOOST_FAIL</a></li> |
| <li><a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_IS_DEFINED', id298906 ); return false;">BOOST_IS_DEFINED</a></li> |
| </ul></td> |
| <td class="content" valign="top"> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN"></a>BOOST_WARN(<span class="emphasis"><em>predicate</em></span>) |
| <a name="BOOST_CHECK"></a>BOOST_CHECK(<span class="emphasis"><em>predicate</em></span>) |
| <a name="BOOST_REQUIRE"></a>BOOST_REQUIRE(<span class="emphasis"><em>predicate</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to validate the predicate value. The only parameter for these tools is a boolean predicate |
| value that gets validated. It could be any expression that could be evaluated and converted to boolean value. The |
| expression gets evaluated only once, so it's safe to pass complex expression for validation. |
| </p> |
| <div class="example"> |
| <a name=".example34"></a><p class="title"><b>Example 38. BOOST_<level> usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i=2; |
| BOOST_WARN( sizeof(int) == sizeof(short) ); |
| BOOST_CHECK( i == 1 ); |
| BOOST_REQUIRE( i > 5 ); |
| BOOST_CHECK( i == 6 ); // will never reach this check |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example34.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id659766" onclick="toggle_element( 'example34-output', 'id659766', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example34-output">> example --log_level=warning |
| Running 1 test case... |
| test.cpp(9): warning in "test": condition sizeof(int) == sizeof(short) is not satisfied |
| test.cpp(10): error in "test": check i == 1 failed |
| test.cpp(11): fatal error in "test": critical check i > 5 failed |
| |
| *** 2 failures detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_MESSAGE', id298906 ); return false;">BOOST_<level>_MESSAGE</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_BITWISE_EQUAL"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_BITWISE_EQUAL"></a>BOOST_WARN_BITWISE_EQUAL(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_CHECK_BITWISE_EQUAL"></a>BOOST_CHECK_BITWISE_EQUAL(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_REQUIRE_BITWISE_EQUAL"></a>BOOST_REQUIRE_BITWISE_EQUAL(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to perform bitwise comparison of two values. The check shows all positions where left and |
| right value's bits mismatch. |
| </p> |
| <p class="first-line-indented"> |
| The first parameter is the left compared value. The second parameter is the right compared value. Parameters are |
| not required to be of the same type, but warning is issued if their type's size does not coincide. |
| </p> |
| <div class="example"> |
| <a name=".example33"></a><p class="title"><b>Example 39. BOOST_<level>_BITWISE_EQUAL usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| BOOST_CHECK_BITWISE_EQUAL( (char)0x26, 0x04 ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example33.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id659940" onclick="toggle_element( 'example33-output', 'id659940', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example33-output">> example |
| Running 1 test case... |
| test.cpp(8): error in "test": check (char)0x26 =.= 0x04 failed. |
| Mismatch in a position 1 |
| Mismatch in a position 5 |
| Operands bit sizes mismatch: 8 != 32 |
| |
| *** 1 failure detected in test suite "example" </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EQUAL', id298906 ); return false;">BOOST_<level>_EQUAL</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_CLOSE"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_CLOSE"></a>BOOST_WARN_CLOSE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>, <span class="emphasis"><em>tolerance</em></span>) |
| <a name="BOOST_CHECK_CLOSE"></a>BOOST_CHECK_CLOSE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>, <span class="emphasis"><em>tolerance</em></span>) |
| <a name="BOOST_REQUIRE_CLOSE"></a>BOOST_REQUIRE_CLOSE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>, <span class="emphasis"><em>tolerance</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to check on closeness using strong relationship defined by the predicate |
| <code class="computeroutput">check_is_close</code>( left, right, tolerance ). To check for the weak relationship use |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_PREDICATE', id298906 ); return false;">BOOST_<level>_PREDICATE</a> family of tools with explicit <code class="computeroutput">check_is_close</code> |
| invocation. |
| </p> |
| <p> |
| The first parameter is the <span class="emphasis"><em>left</em></span> compared value. The second parameter is the |
| <span class="emphasis"><em>right</em></span> compared value. Last third parameter defines the tolerance for the comparison in |
| <a class="link" href="floating_point_comparison.html#utf.testing-tools.fpv-comparison.tolerance-selection" title="Tolerance selection considerations"><span class="bold"><strong>percentage units</strong></span></a>. |
| </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> |
| It is required for left and right parameters to be of the same floating point type. You will need to explicitly |
| resolve any type mismatch to select which type to use for comparison. |
| </p></td></tr> |
| </table></div> |
| <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> |
| Note that to use these tools you need to include additional header floating_point_comparison.hpp. |
| </p></td></tr> |
| </table></div> |
| <div class="example"> |
| <a name=".example42"></a><p class="title"><b>Example 40. BOOST_<level>_CLOSE usage with very small values</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| #include <boost/test/floating_point_comparison.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| double v1 = 1.23456e-10; |
| double v2 = 1.23457e-10; |
| |
| BOOST_CHECK_CLOSE( v1, v2, 0.0001 ); |
| // Absolute value of difference between these two values is 1e-15. They seems |
| // to be very close. But we want to checks that these values differ no more then 0.0001% |
| // of their value. And this test will fail at tolerance supplied. |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example42.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id660188" onclick="toggle_element( 'example42-output', 'id660188', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example42-output">> example |
| Running 1 test case... |
| test.cpp(12): error in "test": difference between v1{1.23456e-010} and v2{1.23457e-010} exceeds 0.0001% |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><div class="example"> |
| <a name=".example43"></a><p class="title"><b>Example 41. BOOST_<level>_CLOSE usage with very big values</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| #include <boost/test/floating_point_comparison.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| double v1 = 1.23456e28; |
| double v2 = 1.23457e28; |
| |
| BOOST_REQUIRE_CLOSE( v1, v2, 0.001 ); |
| // Absolute value of difference between these two values is 1e+23. |
| // But we are interested only that it does not exeed 0.001% of a values compared |
| // And this test will pass. |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example43.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id660271" onclick="toggle_element( 'example43-output', 'id660271', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example43-output">> example |
| Running 1 test case... |
| |
| *** No errors detected |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE_FRACTION', id298906 ); return false;">BOOST_<level>_CLOSE_FRACTION</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_SMALL', id298906 ); return false;">BOOST_<level>_SMALL</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EQUAL', id298906 ); return false;">BOOST_<level>_EQUAL</a>, |
| <a class="link" href="floating_point_comparison.html" title="Floating-point comparison algorithms">Floating point comparison algorithms</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_CLOSE_FRACTION"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_CLOSE_FRACTION"></a>BOOST_WARN_CLOSE_FRACTION(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>, <span class="emphasis"><em>tolerance</em></span>) |
| <a name="BOOST_CHECK_CLOSE_FRACTION"></a>BOOST_CHECK_CLOSE_FRACTION(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>, <span class="emphasis"><em>tolerance</em></span>) |
| <a name="BOOST_REQUIRE_CLOSE_FRACTION"></a>BOOST_REQUIRE_CLOSE_FRACTION(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>, <span class="emphasis"><em>tolerance</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to check on closeness using strong relationship defined by the predicate |
| <code class="computeroutput">check_is_close</code>( left, right, tolerance ). To check for the weak relationship use |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_PREDICATE', id298906 ); return false;">BOOST_<level>_PREDICATE</a> family of tools with explicit <code class="computeroutput">check_is_close</code> |
| invocation. |
| </p> |
| <p> |
| The first parameter is the <span class="emphasis"><em>left</em></span> compared value. The second parameter is the |
| <span class="emphasis"><em>right</em></span> compared value. Last third parameter defines the tolerance for the comparison in |
| <a class="link" href="floating_point_comparison.html#utf.testing-tools.fpv-comparison.tolerance-selection" title="Tolerance selection considerations"><span class="bold"><strong>percentage units</strong></span></a>. |
| </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> |
| It is required for left and right parameters to be of the same floating point type. You will need to explicitly |
| resolve any type mismatch to select which type to use for comparison. |
| </p></td></tr> |
| </table></div> |
| <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> |
| Note that to use these tools you need to include additional header floating_point_comparison.hpp. |
| </p></td></tr> |
| </table></div> |
| <div class="example"> |
| <a name=".example44"></a><p class="title"><b>Example 42. BOOST_<level>_CLOSE_FRACTION usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| #include <boost/test/floating_point_comparison.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| double v1 = 1.111e-10; |
| double v2 = 1.112e-10; |
| |
| BOOST_CHECK_CLOSE_FRACTION( v1, v2, 0.0008999 ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example44.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id660537" onclick="toggle_element( 'example44-output', 'id660537', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example44-output">> example |
| Running 1 test case... |
| test.cpp(12): error in "test": difference between v1{1.111e-010} and v2{1.112e-010} exceeds 0.0008999 |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE', id298906 ); return false;">BOOST_<level>_CLOSE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_SMALL', id298906 ); return false;">BOOST_<level>_SMALL</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EQUAL', id298906 ); return false;">BOOST_<level>_EQUAL</a>, |
| <a class="link" href="floating_point_comparison.html" title="Floating-point comparison algorithms">Floating point comparison algorithms</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_EQUAL"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_EQUAL"></a>BOOST_WARN_EQUAL(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_CHECK_EQUAL"></a>BOOST_CHECK_EQUAL(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_REQUIRE_EQUAL"></a>BOOST_REQUIRE_EQUAL(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>)</pre> |
| <p class="first-line-indented"> |
| Check performed by these tools is the same as the one performed by <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a>( left == right ). |
| The difference is that the mismatched values are reported as well. |
| </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> |
| It is bad idea to use these tools to compare floating point values. Use <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE', id298906 ); return false;">BOOST_<level>_CLOSE</a> or |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE_FRACTION', id298906 ); return false;">BOOST_<level>_CLOSE_FRACTION</a> tools instead. |
| </p></td></tr> |
| </table></div> |
| <div class="example"> |
| <a name=".example35"></a><p class="title"><b>Example 43. BOOST_<level>_EQUAL usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 2; |
| int j = 1; |
| BOOST_REQUIRE_EQUAL( i, j ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example35.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id660741" onclick="toggle_element( 'example35-output', 'id660741', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example35-output">> example |
| Running 1 test case... |
| test.cpp(10): fatal error in "test": critical check i == j failed [2 != 1] |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE', id298906 ); return false;">BOOST_<level>_CLOSE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_NE', id298906 ); return false;">BOOST_<level>_NE</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_EQUAL_COLLECTION"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_EQUAL_COLLECTION"></a>BOOST_WARN_EQUAL_COLLECTION(<span class="emphasis"><em>left_begin</em></span>, <span class="emphasis"><em>left_end</em></span>, <span class="emphasis"><em>right_begin</em></span>, <span class="emphasis"><em>right_end</em></span>) |
| <a name="BOOST_CHECK_EQUAL_COLLECTION"></a>BOOST_CHECK_EQUAL_COLLECTION(<span class="emphasis"><em>left_begin</em></span>, <span class="emphasis"><em>left_end</em></span>, <span class="emphasis"><em>right_begin</em></span>, <span class="emphasis"><em>right_end</em></span>) |
| <a name="BOOST_REQUIRE_EQUAL_COLLECTION"></a>BOOST_REQUIRE_EQUAL_COLLECTION(<span class="emphasis"><em>left_begin</em></span>, <span class="emphasis"><em>left_end</em></span>, <span class="emphasis"><em>right_begin</em></span>, <span class="emphasis"><em>right_end</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to perform an element by element comparison of two collections. They print all mismatched |
| positions, collection elements at these positions and check that the collections have the same size. The first two |
| parameters designate begin and end of the first collection. The two parameters designate begin and end of the |
| second collection. |
| </p> |
| <div class="example"> |
| <a name=".example36"></a><p class="title"><b>Example 44. BOOST_<level>_EQUAL_COLLECTION usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int col1 [] = { 1, 2, 3, 4, 5, 6, 7 }; |
| int col2 [] = { 1, 2, 4, 4, 5, 7, 7 }; |
| |
| BOOST_CHECK_EQUAL_COLLECTIONS( col1, col1+7, col2, col2+7 ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example36.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id660942" onclick="toggle_element( 'example36-output', 'id660942', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example36-output">> example |
| Running 1 test case... |
| test.cpp(11): error in "test": check { col1, col1+7 } == { col2, col2+7 } failed. |
| Mismatch in a position 2: 3 != 4 |
| Mismatch in a position 5: 6 != 7 |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EQUAL', id298906 ); return false;">BOOST_<level>_EQUAL</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_EXCEPTION"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_EXCEPTION"></a>BOOST_WARN_EXCEPTION(<span class="emphasis"><em>expression</em></span>, <span class="emphasis"><em>exception</em></span>, <span class="emphasis"><em>predicate</em></span>) |
| <a name="BOOST_CHECK_EXCEPTION"></a>BOOST_CHECK_EXCEPTION(<span class="emphasis"><em>expression</em></span>, <span class="emphasis"><em>exception</em></span>, <span class="emphasis"><em>predicate</em></span>) |
| <a name="BOOST_REQUIRE_EXCEPTION"></a>BOOST_REQUIRE_EXCEPTION(<span class="emphasis"><em>expression</em></span>, <span class="emphasis"><em>exception</em></span>, <span class="emphasis"><em>predicate</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to perform an exception detection and validation check. Tools execute the supplied expression |
| and validate that it throws an exception of supplied class (or the one derived from it) that complies with the |
| supplied predicate. If the expression throws any other unrelated exception, doesn't throw at all or |
| predicate evaluates to false, check fails. In comparison with <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_THROW', id298906 ); return false;">BOOST_<level>_THROW</a> tools these |
| allow performing more fine-grained checks. For example: make sure that an expected exception has specific |
| error message. |
| </p> |
| <div class="example"> |
| <a name=".example37"></a><p class="title"><b>Example 45. BOOST_<level>_EXCEPTION usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| struct my_exception { |
| explicit my_exception( int ec = 0 ) : m_error_code( ec ) {} |
| |
| int m_error_code; |
| }; |
| |
| bool is_critical( my_exception const& ex ) { return ex.m_error_code < 0; } |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| BOOST_CHECK_EXCEPTION( throw my_exception( 1 ), my_exception, is_critical ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example37.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id661130" onclick="toggle_element( 'example37-output', 'id661130', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example37-output">> example |
| Running 1 test case... |
| test.cpp(16): error in "test": incorrect exception my_exception is caught |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_THROW', id298906 ); return false;">BOOST_<level>_THROW</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_GE"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_GE"></a>BOOST_WARN_GE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_CHECK_GE"></a>BOOST_CHECK_GE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_REQUIRE_GE"></a>BOOST_REQUIRE_GE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>)</pre> |
| <p class="first-line-indented"> |
| Check performed by these tools is the same as the one performed by <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a>( left >= right ). |
| The difference is that the argument values are reported as well. |
| </p> |
| <div class="example"> |
| <a name=".example57"></a><p class="title"><b>Example 46. BOOST_<level>_GE usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 1; |
| int j = 4; |
| BOOST_CHECK_GE( i, j ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example57.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id661298" onclick="toggle_element( 'example57-output', 'id661298', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example57-output">>example |
| Running 1 test case... |
| test.cpp(10): error in "test": check i >= j failed [1 < 4] |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LE', id298906 ); return false;">BOOST_<level>_LE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LT', id298906 ); return false;">BOOST_<level>_LT</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GT', id298906 ); return false;">BOOST_<level>_GT</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_GT"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_GT"></a>BOOST_WARN_GT(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_CHECK_GT"></a>BOOST_CHECK_GT(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_REQUIRE_GT"></a>BOOST_REQUIRE_GT(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>)</pre> |
| <p class="first-line-indented"> |
| Check performed by these tools is the same as the one performed by <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a>( left >= right ). |
| The difference is that the argument values are reported as well. |
| </p> |
| <div class="example"> |
| <a name=".example58"></a><p class="title"><b>Example 47. BOOST_<level>_GT usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 2; |
| int j = 14; |
| BOOST_CHECK_GT( i, j ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example58.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id661474" onclick="toggle_element( 'example58-output', 'id661474', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example58-output">>example |
| Running 1 test case... |
| test.cpp(10): error in "test": check i > j failed [2 < 14] |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LE', id298906 ); return false;">BOOST_<level>_LE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LT', id298906 ); return false;">BOOST_<level>_LT</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GE', id298906 ); return false;">BOOST_<level>_GE</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_LE"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_LE"></a>BOOST_WARN_LE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_CHECK_LE"></a>BOOST_CHECK_LE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_REQUIRE_LE"></a>BOOST_REQUIRE_LE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>)</pre> |
| <p class="first-line-indented"> |
| Check performed by these tools is the same as the one performed by <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a>( left <= right ). |
| The difference is that the argument values are reported as well. |
| </p> |
| <div class="example"> |
| <a name=".example55"></a><p class="title"><b>Example 48. BOOST_<level>_LE usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 9; |
| int j = 6; |
| BOOST_CHECK_LE( i, j ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example55.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id661651" onclick="toggle_element( 'example55-output', 'id661651', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example55-output">>example |
| Running 1 test case... |
| test.cpp(10): error in "test": check i <= j failed [9 > 6] |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LT', id298906 ); return false;">BOOST_<level>_LT</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GE', id298906 ); return false;">BOOST_<level>_GE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GT', id298906 ); return false;">BOOST_<level>_GT</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_LT"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_LT"></a>BOOST_WARN_LT(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_CHECK_LT"></a>BOOST_CHECK_LT(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_REQUIRE_LT"></a>BOOST_REQUIRE_LT(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>)</pre> |
| <p class="first-line-indented"> |
| Check performed by these tools is the same as the one performed by <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a>( left < right ). |
| The difference is that the argument values are reported as well. |
| </p> |
| <div class="example"> |
| <a name=".example56"></a><p class="title"><b>Example 49. BOOST_<level>_LT usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 7; |
| int j = 7; |
| BOOST_CHECK_LT( i, j ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example56.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id661827" onclick="toggle_element( 'example56-output', 'id661827', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example56-output">>example |
| Running 1 test case... |
| test.cpp(10): error in "test": check i < j failed [7 >= 7] |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_LE', id298906 ); return false;">BOOST_<level>_LE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GE', id298906 ); return false;">BOOST_<level>_GE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_GT', id298906 ); return false;">BOOST_<level>_GT</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_MESSAGE"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_MESSAGE"></a>BOOST_WARN_MESSAGE(<span class="emphasis"><em>predicate</em></span>, <span class="emphasis"><em>message</em></span>) |
| <a name="BOOST_CHECK_MESSAGE"></a>BOOST_CHECK_MESSAGE(<span class="emphasis"><em>predicate</em></span>, <span class="emphasis"><em>message</em></span>) |
| <a name="BOOST_REQUIRE_MESSAGE"></a>BOOST_REQUIRE_MESSAGE(<span class="emphasis"><em>predicate</em></span>, <span class="emphasis"><em>message</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools perform exactly the same check as <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> tools. The only difference is that |
| instead of generating an error/confirm message these use the supplied one. |
| </p> |
| <p> |
| The first parameter is the boolean expression. The second parameter is the message reported in case of check |
| failure. The message argument can be constructed of components of any type supporting the |
| <code class="computeroutput">std::ostream& operator<<(std::ostream&)</code>. |
| </p> |
| <div class="example"> |
| <a name=".example38"></a><p class="title"><b>Example 50. BOOST_<level>_MESSAGE usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| #include <cmath> |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| double res = std::sin( 45. ); |
| |
| BOOST_WARN_MESSAGE( res > 1, "sin(45){" << res << "} is <= 1. Hmm.. Strange. " ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example38.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id662020" onclick="toggle_element( 'example38-output', 'id662020', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example38-output">> example --log_level=warning |
| Running 1 test case... |
| test.cpp(12): warning in "test": sin(45){0.850904} is <= 1. Hmm.. Strange. |
| |
| *** No errors detected</pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_NE"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_NE"></a>BOOST_WARN_NE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_CHECK_NE"></a>BOOST_CHECK_NE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>) |
| <a name="BOOST_REQUIRE_NE"></a>BOOST_REQUIRE_NE(<span class="emphasis"><em>left</em></span>, <span class="emphasis"><em>right</em></span>)</pre> |
| <p class="first-line-indented"> |
| Check performed by these tools is the same as the one performed by <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a>( left != right ). |
| The difference is that the matched values are reported as well. |
| </p> |
| <div class="example"> |
| <a name=".example54"></a><p class="title"><b>Example 51. BOOST_<level>_NE usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 3; |
| int j = 3; |
| BOOST_CHECK_NE( i, j ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example54.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id662185" onclick="toggle_element( 'example54-output', 'id662185', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example54-output">>example |
| Running 1 test case... |
| test.cpp(10): error in "test": check i != j failed [3 == 3] |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_EQUAL', id298906 ); return false;">BOOST_<level>_EQUAL</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_NO_THROW"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_NO_THROW"></a>BOOST_WARN_NO_THROW(<span class="emphasis"><em>expression</em></span>) |
| <a name="BOOST_CHECK_NO_THROW"></a>BOOST_CHECK_NO_THROW(<span class="emphasis"><em>expression</em></span>) |
| <a name="BOOST_REQUIRE_NO_THROW"></a>BOOST_REQUIRE_NO_THROW(<span class="emphasis"><em>expression</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to perform a "no throw" check. Tools execute the supplied expression and validate that it does |
| not throw any exceptions. Error would be reported by the framework even if the statement appear directly in test |
| case body and throw any exception. But these tools allow proceeding further with test case in case of failure. |
| </p> |
| <p> |
| If check is successful, tools may produce a confirmation message, in other case they produce an error message in |
| a form "error in <test case name>exception was thrown by <expression>. |
| </p> |
| <p> |
| The only parameter is an expression to execute. You can use do-while(0) block if you want to execute more than one |
| statement. |
| </p> |
| <div class="example"> |
| <a name=".example39"></a><p class="title"><b>Example 52. BOOST_<level>_NO_THROW usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| class my_exception{}; |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| BOOST_CHECK_NO_THROW( throw my_exception() ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example39.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id662354" onclick="toggle_element( 'example39-output', 'id662354', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example39-output">> example |
| Running 1 test case... |
| test.cpp(10): error in "test": exception thrown by throw my_exception() |
| |
| *** 1 failure detected in test suite "example"</pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_THROW', id298906 ); return false;">BOOST_<level>_THROW</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_PREDICATE"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_PREDICATE"></a>BOOST_WARN_PREDICATE(<span class="emphasis"><em>predicate</em></span>, <span class="emphasis"><em>arguments_list</em></span>) |
| <a name="BOOST_CHECK_PREDICATE"></a>BOOST_CHECK_PREDICATE(<span class="emphasis"><em>predicate</em></span>, <span class="emphasis"><em>arguments_list</em></span>) |
| <a name="BOOST_REQUIRE_PREDICATE"></a>BOOST_REQUIRE_PREDICATE(<span class="emphasis"><em>predicate</em></span>, <span class="emphasis"><em>arguments_list</em></span>)</pre> |
| <p class="first-line-indented"> |
| These are generic tools used to validate an arbitrary supplied predicate functor (there is a compile time limit on |
| predicate arity defined by the configurable macro <code class="computeroutput">BOOST_TEST_MAX_PREDICATE_ARITY</code>). To |
| validate zero arity predicate use <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> tools. In other cases prefer theses tools. The |
| advantage of these tools is that they show arguments values in case of predicate failure. |
| </p> |
| <p> |
| The first parameter is the predicate itself. The second parameter is the list of predicate arguments each wrapped |
| in round brackets (BOOST_PP sequence format). |
| </p> |
| <div class="example"> |
| <a name=".example40"></a><p class="title"><b>Example 53. BOOST_<level>_PREDICATE usage</b></p> |
| <div class="example-contents"> |
| <p> |
| Note difference in error log from |
| </p> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| using namespace boost::unit_test; |
| |
| //____________________________________________________________________________// |
| |
| bool moo( int arg1, int arg2, int mod ) { return ((arg1+arg2) % mod) == 0; } |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 17; |
| int j = 15; |
| unit_test_log.set_threshold_level( log_warnings ); |
| BOOST_WARN( moo( 12,i,j ) ); |
| BOOST_WARN_PREDICATE( moo, (12)(i)(j) ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example40.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id662544" onclick="toggle_element( 'example40-output', 'id662544', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example40-output">> example |
| Running 1 test case... |
| test.cpp(14): warning in "test": condition moo( 12,i,j ) is not satisfied |
| test.cpp(15): warning in "test": condition moo( 12, i, j ) is not satisfied for ( 12, 17, 15 ) |
| |
| *** No errors detected</pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_SMALL"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_SMALL"></a>BOOST_WARN_SMALL(<span class="emphasis"><em>value</em></span>, <span class="emphasis"><em>tolerance</em></span>) |
| <a name="BOOST_CHECK_SMALL"></a>BOOST_CHECK_SMALL(<span class="emphasis"><em>value</em></span>, <span class="emphasis"><em>tolerance</em></span>) |
| <a name="BOOST_REQUIRE_SMALL"></a>BOOST_REQUIRE_SMALL(<span class="emphasis"><em>value</em></span>, <span class="emphasis"><em>tolerance</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to check that supplied value is small enough. The "smallness" is defined by absolute value |
| of the tolerance supplied as a second argument. Use these tools with caution. To compare to values on closeness |
| it's preferable to use <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE', id298906 ); return false;">BOOST_<level>_CLOSE</a> tools instead. |
| </p> |
| <p class="first-line-indented"> |
| The first parameter is the value to check. The second parameter is the tolerance. |
| </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> |
| Note that to use these tools you need to include additional header floating_point_comparison.hpp. |
| </p></td></tr> |
| </table></div> |
| <div class="example"> |
| <a name=".example41"></a><p class="title"><b>Example 54. BOOST_<level>_SMALL usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| #include <boost/test/floating_point_comparison.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| double v = -1.23456e-3; |
| |
| BOOST_CHECK_SMALL( v, 0.000001 ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example41.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id662730" onclick="toggle_element( 'example41-output', 'id662730', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example41-output">> example |
| Running 1 test case... |
| test.cpp(11): error in "test": absolute value of v{-0.00123456} exceeds 1e-006 |
| |
| *** 1 failure detected in test suite "example" |
| </pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE', id298906 ); return false;">BOOST_<level>_CLOSE</a>, <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>_CLOSE_FRACTION', id298906 ); return false;">BOOST_<level>_CLOSE_FRACTION</a>, |
| <a class="link" href="floating_point_comparison.html" title="Floating-point comparison algorithms">Floating point comparison algorithms</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_<level>_THROW"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_WARN_THROW"></a>BOOST_WARN_THROW(<span class="emphasis"><em>expression</em></span>, <span class="emphasis"><em>exception</em></span>) |
| <a name="BOOST_CHECK_THROW"></a>BOOST_CHECK_THROW(<span class="emphasis"><em>expression</em></span>, <span class="emphasis"><em>exception</em></span>) |
| <a name="BOOST_REQUIRE_THROW"></a>BOOST_REQUIRE_THROW(<span class="emphasis"><em>expression</em></span>, <span class="emphasis"><em>exception</em></span>)</pre> |
| <p class="first-line-indented"> |
| These tools are used to perform an exception detection check. Tools execute the supplied expression and validate |
| that it throws an exception of supplied class (or the one derived from it) or it's child. If the statement |
| throws any other unrelated exception or doesn't throw at all, check fails. |
| </p> |
| <p> |
| If check is successful, the tool produces a confirmation message, in other case it produces an error message in a |
| form "error in <em class="replaceable"><code>test case name</code></em>: exception <em class="replaceable"><code>exception</code></em> expected. |
| </p> |
| <p class="first-line-indented"> |
| The first parameter is the expression to execute. Use do-while(0) block if you want to execute more than one |
| statement. The second parameter is an expected exception. |
| </p> |
| <div class="example"> |
| <a name=".example45"></a><p class="title"><b>Example 55. BOOST_<level>_THROW usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| class my_exception{}; |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| int i = 0; |
| BOOST_CHECK_THROW( i++, my_exception ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example45.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id662935" onclick="toggle_element( 'example45-output', 'id662935', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example45-output">> example |
| Running 1 test case... |
| test.cpp(11): error in "test": exception my_exception is expected |
| |
| *** 1 failure detected in test suite "example"</pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>NO_THROW', id298906 ); return false;">BOOST_<level>NO_THROW</a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_ERROR"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_ERROR"></a>BOOST_ERROR(<span class="emphasis"><em>message</em></span>)</pre> |
| <p class="first-line-indented"> |
| BOOST_ERROR tool behave the same way as <code class="computeroutput">BOOST_CHECK_MESSAGE( false, message )</code>. This tool is used for |
| an unconditional error counter increasing and message logging. |
| </p> |
| <p> |
| The only tool's parameter is an error message to log. |
| </p> |
| <div class="example"> |
| <a name=".example46"></a><p class="title"><b>Example 56. BOOST_ERROR usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| BOOST_ERROR( "Nothing to test" ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example46.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id663071" onclick="toggle_element( 'example46-output', 'id663071', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example46-output">> example |
| Running 1 test case... |
| test.cpp(8): error in "test": Nothing to test |
| |
| *** 1 failure detected in test suite "example"</pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_FAIL"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_FAIL"></a>BOOST_FAIL(<span class="emphasis"><em>message</em></span>)</pre> |
| <p class="first-line-indented"> |
| BOOST_FAIL behave the same way as <code class="computeroutput">BOOST_REQUIRE_MESSAGE( false, message )</code>. This tool is used for an |
| unconditional error counter increasing, message logging and the current test case aborting. |
| </p> |
| <p> |
| The only tool's parameter is an error message to log. |
| </p> |
| <div class="example"> |
| <a name=".example47"></a><p class="title"><b>Example 57. BOOST_FAIL usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| BOOST_FAIL( "Test is not ready yet" ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example47.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id663209" onclick="toggle_element( 'example47-output', 'id663209', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example47-output">> example |
| Running 1 test case... |
| test.cpp(8): fatal error in "test": Test is not ready yet |
| |
| *** 1 failure detected in test suite "example"</pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> |
| </div> |
| <div class="entry" id="utf.testing-tools.reference.body.BOOST_IS_DEFINED"> |
| <pre class="inline-synopsis"> |
| <a name="BOOST_IS_DEFINED"></a>BOOST_IS_DEFINED(<span class="emphasis"><em>symbol</em></span>)</pre> |
| <p class="first-line-indented"> |
| Unlike the rest of the tools in the toolbox this tool does not perform the logging itself. Its only purpose |
| is to check at runtime whether or not the supplied preprocessor symbol is defined. Use it in combination with |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> to perform and log validation. Macros of any arity could be checked. To check the |
| macro definition with non-zero arity specify dummy arguments for it. See below for example. |
| </p> |
| <p> |
| The only tool's parameter is a preprocessor symbol that gets validated. |
| </p> |
| <div class="example"> |
| <a name=".example48"></a><p class="title"><b>Example 58. BOOST_IS_DEFINED usage</b></p> |
| <div class="example-contents"> |
| <pre class="programlisting">#define BOOST_TEST_MODULE example |
| #include <boost/test/included/unit_test.hpp> |
| |
| //____________________________________________________________________________// |
| |
| BOOST_AUTO_TEST_CASE( test ) |
| { |
| BOOST_CHECK( BOOST_IS_DEFINED(SYMBOL1) ); |
| BOOST_CHECK( BOOST_IS_DEFINED(SYMBOL2(arg)) ); |
| } |
| |
| //____________________________________________________________________________// |
| </pre> |
| <table class="simplelist" border="0" summary="Simple list"><tr> |
| <td><code class="literal"><a href="../../../src/examples/example48.cpp" target="_top">Source code</a></code></td> |
| <td> | </td> |
| <td><code class="literal"><a href="#" target="_top" id="id663347" onclick="toggle_element( 'example48-output', 'id663347', 'Show output', 'Hide output' ); return false;">Show output</a></code></td> |
| </tr></table> |
| <pre class="example-output" id="example48-output">> example |
| Running 1 test case... |
| test.cpp(8): error in "test": check ::boost::test_tools::tt_detail::is_defined_impl( "SYMBOL1", "= SYMBOL1" ) failed |
| test.cpp(9): error in "test": check ::boost::test_tools::tt_detail::is_defined_impl( "SYMBOL2(arg)", "= SYMBOL2(arg)" ) failed |
| |
| *** 2 failures detected in test suite "example"</pre> |
| </div> |
| </div> |
| <br class="example-break"><span class="inline-ref-see-also">See also: </span> |
| <a href="#" onclick="id298906 = select_form_page( 'utf.testing-tools.reference.body.BOOST_<level>', id298906 ); return false;">BOOST_<level></a> |
| </div> |
| </td> |
| </tr></table> |
| </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="floating_point_comparison.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../testing-tools.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="../usage-recommendations.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a> |
| </div> |
| </body> |
| </html> |