1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Explicit decorator declaration</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="../decorators.html" title="Decorators"> 9<link rel="prev" href="suite_level_decorators.html" title="Suite-level decorators"> 10<link rel="next" href="../fixtures.html" title="Fixtures"> 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="suite_level_decorators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../decorators.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="../fixtures.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="boost_test.tests_organization.decorators.explicit_decorator_declaration"></a><a class="link" href="explicit_decorator_declaration.html" title="Explicit decorator declaration">Explicit 28 decorator declaration</a> 29</h4></div></div></div> 30<p> 31 There is another way of associating a decorator set with test units. Macro 32 <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_decorator.html" title="BOOST_TEST_DECORATOR"><code class="computeroutput"><span class="identifier">BOOST_TEST_DECORATOR</span></code></a> indicates 33 that its set of decorators is to be applied to the test unit or <span class="emphasis"><em>test 34 case sequence</em></span> that immediately follows the declaration. 35 </p> 36<h6> 37<a name="boost_test.tests_organization.decorators.explicit_decorator_declaration.h0"></a> 38 <span class="phrase"><a name="boost_test.tests_organization.decorators.explicit_decorator_declaration.example_descr"></a></span><a class="link" href="explicit_decorator_declaration.html#boost_test.tests_organization.decorators.explicit_decorator_declaration.example_descr">Example: 39 explicit decorator declaration</a> 40 </h6> 41<div class="informaltable"><table class="table"> 42<colgroup><col></colgroup> 43<thead><tr><th> 44 <p> 45 Code 46 </p> 47 </th></tr></thead> 48<tbody><tr><td> 49<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">decorator_00</span> 50<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> 51<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">data</span><span class="special">/</span><span class="identifier">test_case</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 52 53<span class="keyword">namespace</span> <span class="identifier">utf</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span> 54<span class="keyword">namespace</span> <span class="identifier">data</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">::</span><span class="identifier">data</span><span class="special">;</span> 55 56<span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">description</span><span class="special">(</span><span class="string">"with description"</span><span class="special">))</span> 57<span class="identifier">BOOST_DATA_TEST_CASE</span><span class="special">(</span><span class="identifier">test_1</span><span class="special">,</span> <span class="identifier">data</span><span class="special">::</span><span class="identifier">xrange</span><span class="special">(</span><span class="number">4</span><span class="special">))</span> 58<span class="special">{</span> 59 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">sample</span> <span class="special">>=</span> <span class="number">0</span><span class="special">);</span> 60<span class="special">}</span> 61</pre> 62 </td></tr></tbody> 63</table></div> 64<div class="informaltable"><table class="table"> 65<colgroup><col></colgroup> 66<thead><tr><th> 67 <p> 68 Output 69 </p> 70 </th></tr></thead> 71<tbody><tr><td> 72<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="identifier">decorator_00</span> <span class="special">--</span><span class="identifier">list_content</span> 73<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span> 74<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span> 75<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span> 76<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span> 77</pre> 78 </td></tr></tbody> 79</table></div> 80<p> 81 In the above example a decorator is applied to a <a class="link" href="../test_cases/test_case_generation.html" title="Data-driven test cases">data-driven 82 test case</a>. Macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_dataset.html" title="BOOST_DATA_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_DATA_TEST_CASE</span></code></a> cannot take 83 the decorator set as one of its arguments, therefore the explicit decorator 84 declaration is used. Macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_dataset.html" title="BOOST_DATA_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_DATA_TEST_CASE</span></code></a> generates 85 a sequence of 4 test cases. The decorator set is applied to each of them. 86 </p> 87<p> 88 Another use case for the explicit decorator declaration is when you intend 89 for your test program to compile also on compilers without variadic macros. 90 In this case it is recommended that you use the more verbose syntax. It 91 is summarized in the following table: 92 </p> 93<div class="informaltable"><table class="table"> 94<colgroup> 95<col> 96<col> 97<col> 98</colgroup> 99<thead><tr> 100<th> 101 <p> 102 Test unit to register 103 </p> 104 </th> 105<th> 106 <p> 107 Concise syntax 108 </p> 109 </th> 110<th> 111 <p> 112 Universal syntax 113 </p> 114 </th> 115</tr></thead> 116<tbody> 117<tr> 118<td> 119 <p> 120 test case 121 </p> 122 </td> 123<td> 124<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 125<span class="special">{</span> 126 <span class="comment">// assertions</span> 127<span class="special">}</span> 128</pre> 129 </td> 130<td> 131<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 132<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">)</span> 133<span class="special">{</span> 134 <span class="comment">// assertions</span> 135<span class="special">}</span> 136</pre> 137 </td> 138</tr> 139<tr> 140<td> 141 <p> 142 test case with fixture 143 </p> 144 </td> 145<td> 146<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_FIXTURE_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 147<span class="special">{</span> 148 <span class="comment">// assertions</span> 149<span class="special">}</span> 150</pre> 151 </td> 152<td> 153<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 154<span class="identifier">BOOST_FIXTURE_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">)</span> 155<span class="special">{</span> 156 <span class="comment">// assertions</span> 157<span class="special">}</span> 158</pre> 159 </td> 160</tr> 161<tr> 162<td> 163 <p> 164 test suite 165 </p> 166 </td> 167<td> 168<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_AUTO_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 169 170 <span class="comment">// test units</span> 171 172<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span> 173</pre> 174 </td> 175<td> 176<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 177<span class="identifier">BOOST_AUTO_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">)</span> 178 179 <span class="comment">// test units</span> 180 181<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span> 182</pre> 183 </td> 184</tr> 185<tr> 186<td> 187 <p> 188 test suite with fixture 189 </p> 190 </td> 191<td> 192<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_FIXTURE_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 193 194 <span class="comment">// test units</span> 195 196<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span> 197</pre> 198 </td> 199<td> 200<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 201<span class="identifier">BOOST_FIXTURE_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">)</span> 202 203 <span class="comment">// test units</span> 204 205<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span> 206</pre> 207 </td> 208</tr> 209<tr> 210<td> 211 <p> 212 data-driven test case 213 </p> 214 </td> 215<td> 216<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// not doable</span> 217</pre> 218 </td> 219<td> 220<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 221<span class="identifier">BOOST_DATA_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">data</span><span class="special">,</span> <span class="identifier">var</span><span class="special">)</span> 222<span class="special">{</span> 223 <span class="comment">// assertions</span> 224<span class="special">}</span> 225</pre> 226 </td> 227</tr> 228<tr> 229<td> 230 <p> 231 test case template 232 </p> 233 </td> 234<td> 235<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// not doable</span> 236</pre> 237 </td> 238<td> 239<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 240<span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">type_list</span><span class="special">)</span> 241<span class="special">{</span> 242 <span class="comment">// assertions</span> 243<span class="special">}</span> 244</pre> 245 </td> 246</tr> 247<tr> 248<td> 249 <p> 250 test case template with fixture 251 </p> 252 </td> 253<td> 254<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// not doable</span> 255</pre> 256 </td> 257<td> 258<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span> 259<span class="identifier">BOOST_FIXTURE_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">type_list</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">)</span> 260<span class="special">{</span> 261 <span class="comment">// assertions</span> 262<span class="special">}</span> 263</pre> 264 </td> 265</tr> 266</tbody> 267</table></div> 268<p> 269 Throughout the reminder of this documentation we use only the concise syntax. 270 </p> 271</div> 272<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 273<td align="left"></td> 274<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p> 275 Distributed under the Boost Software License, Version 1.0. (See accompanying 276 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>) 277 </p> 278</div></td> 279</tr></table> 280<hr> 281<div class="spirit-nav"> 282<a accesskey="p" href="suite_level_decorators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../decorators.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="../fixtures.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 283</div> 284</body> 285</html> 286