1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>BOOST_TEST: universal and general purpose assertions</title> 5<link rel="stylesheet" href="../../boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Boost.Test"> 8<link rel="up" href="../testing_tools.html" title="Writing unit tests"> 9<link rel="prev" href="tools_assertion_severity_level.html" title="Assertion severity level"> 10<link rel="next" href="reports.html" title="Reported information"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="tools_assertion_severity_level.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../testing_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reports.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_test.testing_tools.boost_test_universal_macro"></a><a class="link" href="boost_test_universal_macro.html" title="BOOST_TEST: universal and general purpose assertions">BOOST_TEST: 28 universal and general purpose assertions</a> 29</h3></div></div></div> 30<p> 31 The <span class="emphasis"><em>Unit Test Framework</em></span> provides an almost unique interface 32 to a great range of test-case scenarios, through the <a class="link" href="../utf_reference/testing_tool_ref/assertion_boost_test_universal_macro.html" title="BOOST_TEST"><code class="computeroutput"><span class="identifier">BOOST_TEST</span></code></a> macro. The general form 33 of <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> is the following: 34 </p> 35<pre class="programlisting"><span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">statement</span><span class="special">);</span> 36<span class="identifier">BOOST_TEST_</span><span class="special"><</span><span class="identifier">level</span><span class="special">>(</span><span class="identifier">statement</span><span class="special">,</span> <span class="identifier">optional_modifiers</span><span class="special">)</span> 37</pre> 38<p> 39 An example of use might be the following: 40 </p> 41<h6> 42<a name="boost_test.testing_tools.boost_test_universal_macro.h0"></a> 43 <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.example_descr"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.example_descr">Example: 44 BOOST_TEST overview</a> 45 </h6> 46<div class="informaltable"><table class="table"> 47<colgroup><col></colgroup> 48<thead><tr><th> 49 <p> 50 Code 51 </p> 52 </th></tr></thead> 53<tbody><tr><td> 54<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">boost_test_macro_overview</span> 55<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 56 57<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_macro_overview</span> <span class="special">)</span> 58<span class="special">{</span> 59 <span class="keyword">namespace</span> <span class="identifier">tt</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">test_tools</span><span class="special">;</span> 60 <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> 61 <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span> 62 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">!=</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span> 63 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special"><</span> <span class="identifier">b</span><span class="special">);</span> 64 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">b</span> <span class="special">-</span><span class="number">1</span> <span class="special">></span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">a</span> <span class="special"><<</span> <span class="string">" < "</span> <span class="special"><<</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">1</span> <span class="special"><<</span> <span class="string">" does not hold"</span><span class="special">);</span> 65 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">bitwise</span><span class="special">());</span> 66 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">0.1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">0.8</span><span class="special">,</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">tolerance</span><span class="special">(</span><span class="number">0.01</span><span class="special">));</span> 67<span class="special">}</span> 68</pre> 69 </td></tr></tbody> 70</table></div> 71<div class="informaltable"><table class="table"> 72<colgroup><col></colgroup> 73<thead><tr><th> 74 <p> 75 Output 76 </p> 77 </th></tr></thead> 78<tbody><tr><td> 79<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="special">./</span><span class="identifier">boost_test_macro_overview</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">all</span> 80<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span> 81<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_overview"</span> 82<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">12</span><span class="special">:</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_macro_overview"</span> 83<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">17</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">!=</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">==</span> <span class="number">1</span><span class="special">]</span> 84<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">18</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special"><</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">+</span> <span class="number">1</span> <span class="special">>=</span> <span class="number">2</span><span class="special">]</span> 85<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">19</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="number">1</span> <span class="special"><</span> <span class="number">1</span> <span class="identifier">does</span> <span class="keyword">not</span> <span class="identifier">hold</span> 86<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">20</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">!=</span> <span class="number">2</span><span class="special">].</span> <span class="identifier">Bitwise</span> <span class="identifier">comparison</span> <span class="identifier">failed</span> 87<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">0</span> 88<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">1</span> 89<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">21</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">0.1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">0.8</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">+</span> <span class="number">0.10000000000000001</span> <span class="special">!=</span> <span class="number">1.2</span><span class="special">].</span> <span class="identifier">Relative</span> <span class="identifier">difference</span> <span class="identifier">exceeds</span> <span class="identifier">tolerance</span> <span class="special">[</span><span class="number">0.0909091</span> <span class="special">></span> <span class="number">0.01</span><span class="special">]</span> 90<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">12</span><span class="special">:</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_macro_overview"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">380u</span><span class="identifier">s</span> 91<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_overview"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">459u</span><span class="identifier">s</span> 92 93<span class="special">***</span> <span class="number">5</span> <span class="identifier">failures</span> <span class="identifier">are</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_overview"</span> 94</pre> 95 </td></tr></tbody> 96</table></div> 97<p> 98 The major features of this tool are: 99 </p> 100<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 101<li class="listitem"> 102 a great flexibility for <code class="computeroutput"><span class="identifier">statement</span></code> 103 which may be almost anything: full expression composed by several operations 104 are supported and handled, 105 </li> 106<li class="listitem"> 107 an extended reporting capability in case of failure: not only <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> reports the location of 108 the failure and a copy of <code class="computeroutput"><span class="identifier">statement</span></code> 109 itself, but also the values of the operands that permits a rapid identification 110 of the issues related to the failed assertion, 111 </li> 112<li class="listitem"> 113 the possibility to control better the behavior or the reports of the 114 checks, in particular: 115 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "> 116<li class="listitem"> 117 floating point comparison: the tolerance may be provided, either 118 using the <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> 119 directly with <code class="computeroutput"><span class="identifier">optional_modifiers</span></code>, 120 or with <span class="emphasis"><em>decorators</em></span> (see <a class="link" href="extended_comparison/floating_point.html" title="Floating point comparison">here</a> 121 for more details), 122 </li> 123<li class="listitem"> 124 container/collection comparisons: different operations for comparison 125 are provided out of the box for comparing collection of elements 126 (default, per-element, lexicographic), with extended diagnostic 127 on failures (covered in <a class="link" href="extended_comparison/collections.html" title="Collections comparison">this</a> 128 section), 129 </li> 130<li class="listitem"> 131 string comparison: C-strings operands are automatically detected 132 and the comparisons are performed as if <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code> 133 objects were used, 134 </li> 135<li class="listitem"> 136 optional failure message, 137 </li> 138<li class="listitem"> 139 bitwise comparison, providing extended diagnostic in case of failure 140 </li> 141</ul></div> 142 </li> 143</ul></div> 144<div class="warning"><table border="0" summary="Warning"> 145<tr> 146<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../doc/src/images/warning.png"></td> 147<th align="left">Warning</th> 148</tr> 149<tr><td align="left" valign="top"><p> 150 To get all the functionalities of <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> 151 family of assertions, a C++11 capable compiler is required, especially 152 supporting the <code class="computeroutput"><span class="keyword">auto</span></code> and <code class="computeroutput"><span class="keyword">decltype</span></code> keywords and the variadic macros. 153 The documentation focuses on these set of compilers. For compilers not 154 supporting all the features of <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code>, 155 the macro <code class="computeroutput"><span class="identifier">BOOST_TEST_MACRO_LIMITED_SUPPORT</span></code>. 156 </p></td></tr> 157</table></div> 158<a name="boost_test_statement_overloads"></a><h4> 159<a name="boost_test.testing_tools.boost_test_universal_macro.h1"></a> 160 <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.complex_statements"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.complex_statements">Complex 161 statements</a> 162 </h4> 163<p> 164 <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> provides an enhanced 165 reporting capability: additional details of the failing operands and operations 166 are provided in the log, as shown on the example below: 167 </p> 168<h6> 169<a name="boost_test.testing_tools.boost_test_universal_macro.h2"></a> 170 <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.example_descr0"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.example_descr0">Example: 171 BOOST_TEST enhanced reporting</a> 172 </h6> 173<div class="informaltable"><table class="table"> 174<colgroup><col></colgroup> 175<thead><tr><th> 176 <p> 177 Code 178 </p> 179 </th></tr></thead> 180<tbody><tr><td> 181<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">boost_test_macro3</span> 182<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 183 184<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_op_reportings</span> <span class="special">)</span> 185<span class="special">{</span> 186 <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">13</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">12</span><span class="special">;</span> 187 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span><span class="special">);</span> 188 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special"><</span> <span class="identifier">b</span><span class="special">);</span> 189 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span> <span class="special"><</span> <span class="identifier">b</span><span class="special">);</span> 190 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">b</span> <span class="special">></span> <span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span> 191<span class="special">}</span> 192</pre> 193 </td></tr></tbody> 194</table></div> 195<div class="informaltable"><table class="table"> 196<colgroup><col></colgroup> 197<thead><tr><th> 198 <p> 199 Output 200 </p> 201 </th></tr></thead> 202<tbody><tr><td> 203<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="special">./</span><span class="identifier">boost_test_macro3</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">all</span> 204<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span> 205<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro3"</span> 206<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">12</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_op_reportings"</span> 207<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">15</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">13</span> <span class="special">!=</span> <span class="number">12</span><span class="special">]</span> 208<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">16</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special"><</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">13</span> <span class="special">>=</span> <span class="number">12</span><span class="special">]</span> 209<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">17</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span> <span class="special"><</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">13</span> <span class="special">-</span> <span class="number">1</span> <span class="special">>=</span> <span class="number">12</span><span class="special">]</span> 210<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">18</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">b</span> <span class="special">></span> <span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">12</span> <span class="special"><=</span> <span class="number">12</span><span class="special">]</span> 211<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">12</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_op_reportings"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">484u</span><span class="identifier">s</span> 212<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro3"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">588u</span><span class="identifier">s</span> 213 214<span class="special">***</span> <span class="number">2</span> <span class="identifier">failures</span> <span class="identifier">are</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro3"</span> 215</pre> 216 </td></tr></tbody> 217</table></div> 218<p> 219 <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> parses the <code class="computeroutput"><span class="identifier">statement</span></code> and constructs an expression 220 out of it. <code class="computeroutput"><span class="identifier">statement</span></code> may 221 be a complex expressions containing almost any of the overloadable operators 222 in C++: 223 </p> 224<div class="informaltable"><table class="table"> 225<colgroup> 226<col> 227<col> 228</colgroup> 229<thead><tr> 230<th> 231 <p> 232 Class of operation 233 </p> 234 </th> 235<th> 236 <p> 237 operators 238 </p> 239 </th> 240</tr></thead> 241<tbody> 242<tr> 243<td> 244 <p> 245 binary comparisons 246 </p> 247 </td> 248<td> 249 <p> 250 <code class="computeroutput"><span class="special">==</span></code>, <code class="computeroutput"><span class="special">!=</span></code>, <code class="computeroutput"><span class="special"><</span></code>, 251 <code class="computeroutput"><span class="special">></span></code>, <code class="computeroutput"><span class="special"><=</span></code>, <code class="computeroutput"><span class="special">>=</span></code> 252 </p> 253 </td> 254</tr> 255<tr> 256<td> 257 <p> 258 arithmetic compositions 259 </p> 260 </td> 261<td> 262 <p> 263 <code class="computeroutput"><span class="special">+</span></code>, <code class="computeroutput"><span class="special">-</span></code>, 264 <code class="computeroutput"><span class="special">*</span></code>, <code class="computeroutput"><span class="special">/</span></code>, 265 <code class="computeroutput"><span class="special">%</span></code> 266 </p> 267 </td> 268</tr> 269<tr> 270<td> 271 <p> 272 bitwise compositions 273 </p> 274 </td> 275<td> 276 <p> 277 <code class="computeroutput"><span class="special">|</span></code>, <code class="computeroutput"><span class="special">&</span></code>, 278 <code class="computeroutput"><span class="special">^</span></code>, <code class="computeroutput"><span class="special"><<</span></code>, 279 <code class="computeroutput"><span class="special">>></span></code> 280 </p> 281 </td> 282</tr> 283<tr> 284<td> 285 <p> 286 assignments 287 </p> 288 </td> 289<td> 290 <p> 291 <code class="computeroutput"><span class="special">=</span></code>, <code class="computeroutput"><span class="special">+=</span></code>, 292 <code class="computeroutput"><span class="special">-=</span></code>, <code class="computeroutput"><span class="special">*=</span></code>, <code class="computeroutput"><span class="special">/=</span></code>, 293 <code class="computeroutput"><span class="special">%=</span></code>, <code class="computeroutput"><span class="special"><<=</span></code>, <code class="computeroutput"><span class="special">>>=</span></code>, 294 <code class="computeroutput"><span class="special">&=</span></code>, <code class="computeroutput"><span class="special">^=</span></code>, <code class="computeroutput"><span class="special">|=</span></code> 295 </p> 296 </td> 297</tr> 298</tbody> 299</table></div> 300<p> 301 <code class="computeroutput"><span class="identifier">statement</span></code> is evaluated and 302 cast to <code class="computeroutput"><span class="keyword">bool</span></code>, as if it would 303 appear as argument to an <code class="computeroutput"><span class="keyword">if</span></code> 304 statement: this is the result of the assertion 305 </p> 306<h4> 307<a name="boost_test.testing_tools.boost_test_universal_macro.h3"></a> 308 <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.uniform_reporting"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.uniform_reporting">Uniform 309 reporting</a> 310 </h4> 311<p> 312 This tool is provided in three variants corresponding to the corresponding 313 <a class="link" href="tools_assertion_severity_level.html" title="Assertion severity level">severity 314 levels</a>. These three levels of assertions are reported into the test 315 log and output, as described in details in the section. The granularity of 316 the report depends on the current <a class="link" href="../utf_reference/rt_param_reference/log_level.html" title="log_level">log 317 level</a> and <a class="link" href="../utf_reference/rt_param_reference/report_level.html" title="report_level">report 318 level</a>. 319 </p> 320<a name="boost_test_statement_limitations"></a><h4> 321<a name="boost_test.testing_tools.boost_test_universal_macro.h4"></a> 322 <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.limitations_workaround"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.limitations_workaround">Limitations 323 & workaround</a> 324 </h4> 325<p> 326 There are a few constructions that are however unsupported, but adding an 327 extra bracket usually solves that: 328 </p> 329<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 330<li class="listitem"> 331 statements containing ternary conditions: those statement should be surrounded 332 by parenthesis as they cannot be overloaded 333 </li> 334<li class="listitem"> 335 statements containing commas: those statements will be intercepted by 336 the preprocessor 337 </li> 338<li class="listitem"> 339<p class="simpara"> 340 compound statements containing any logical composition <code class="computeroutput"><span class="special">||</span></code>, <code class="computeroutput"><span class="special">&&</span></code>. 341 Those are disabled intentionally and should be surrounded by parenthesis 342 </p> 343<pre class="programlisting"><span class="identifier">BOOST_TEST</span><span class="special">((</span><span class="keyword">true</span> <span class="special">||</span> <span class="keyword">false</span><span class="special">));</span> 344</pre> 345<p class="simpara"> 346 The full details are given in <a class="link" href="internal_details.html" title="BOOST_TEST: details on expressions">this 347 section</a>. 348 </p> 349</li> 350</ul></div> 351<h6> 352<a name="boost_test.testing_tools.boost_test_universal_macro.h5"></a> 353 <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.example_descr1"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.example_descr1">Example: 354 BOOST_TEST limitation and workaround</a> 355 </h6> 356<div class="informaltable"><table class="table"> 357<colgroup><col></colgroup> 358<thead><tr><th> 359 <p> 360 Code 361 </p> 362 </th></tr></thead> 363<tbody><tr><td> 364<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">boost_test_macro_workaround</span> 365<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 366<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">sstream</span><span class="special">></span> 367 368<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_logical_not_allowed</span> <span class="special">)</span> 369<span class="special">{</span> 370 <span class="comment">// Boost Unit Test Framework prevents compilation of</span> 371 <span class="comment">// BOOST_TEST(true && true);</span> 372 <span class="identifier">BOOST_TEST</span><span class="special">((</span><span class="keyword">true</span> <span class="special">&&</span> <span class="keyword">true</span><span class="special">));</span> <span class="comment">// with extra brackets, it works as expected</span> 373<span class="special">}</span> 374 375<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_ternary</span> <span class="special">)</span> 376<span class="special">{</span> 377 <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> 378 <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span> 379 <span class="comment">// Boost Unit Test Framework prevents compilation of</span> 380 <span class="comment">// BOOST_TEST(a == b ? true : false);</span> 381 <span class="identifier">BOOST_TEST</span><span class="special">((</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">false</span><span class="special">));</span> <span class="comment">// again works as expected with extra brackets</span> 382<span class="special">}</span> 383</pre> 384 </td></tr></tbody> 385</table></div> 386<div class="informaltable"><table class="table"> 387<colgroup><col></colgroup> 388<thead><tr><th> 389 <p> 390 Output 391 </p> 392 </th></tr></thead> 393<tbody><tr><td> 394<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="special">./</span><span class="identifier">boost_test_macro_workaround</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">all</span> 395<span class="identifier">Running</span> <span class="number">2</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span> 396<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_workaround"</span> 397<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">13</span><span class="special">:</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_logical_not_allowed"</span> 398<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">17</span><span class="special">:</span> <span class="identifier">info</span><span class="special">:</span> <span class="identifier">check</span> <span class="special">(</span><span class="keyword">true</span> <span class="special">&&</span> <span class="keyword">true</span><span class="special">)</span> <span class="identifier">has</span> <span class="identifier">passed</span> 399<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">13</span><span class="special">:</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_logical_not_allowed"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">183u</span><span class="identifier">s</span> 400<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">20</span><span class="special">:</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_ternary"</span> 401<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">26</span><span class="special">:</span> <span class="identifier">info</span><span class="special">:</span> <span class="identifier">check</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">false</span><span class="special">)</span> <span class="identifier">has</span> <span class="identifier">passed</span> 402<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">20</span><span class="special">:</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_ternary"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">123u</span><span class="identifier">s</span> 403<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_workaround"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">547u</span><span class="identifier">s</span> 404 405<span class="special">***</span> <span class="identifier">No</span> <span class="identifier">errors</span> <span class="identifier">detected</span> 406</pre> 407 </td></tr></tbody> 408</table></div> 409</div> 410<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 411<td align="left"></td> 412<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p> 413 Distributed under the Boost Software License, Version 1.0. (See accompanying 414 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 415 </p> 416</div></td> 417</tr></table> 418<hr> 419<div class="spirit-nav"> 420<a accesskey="p" href="tools_assertion_severity_level.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../testing_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reports.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 421</div> 422</body> 423</html> 424