Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / test / doc / html / boost_test / tests_organization / test_cases / test_organization_templates.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Template test cases</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="../test_cases.html" title="Test cases">
9 <link rel="prev" href="test_case_generation/generators.html" title="Datasets generators">
10 <link rel="next" href="param_test.html" title="Parametrized test cases">
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="test_case_generation/generators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../test_cases.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="param_test.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.test_cases.test_organization_templates"></a><a class="link" href="test_organization_templates.html" title="Template test cases">Template
28         test cases</a>
29 </h4></div></div></div>
30 <p>
31           In order to test a template based component, it is frequently necessary
32           to perform the same set of checks for a component instantiated with different
33           template parameters.
34         </p>
35 <p>
36           One way to perform the same set of checks for a component instantiated
37           with different template parameters would be:
38         </p>
39 <pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
40 <span class="keyword">void</span> <span class="identifier">single_test</span><span class="special">()</span>
41 <span class="special">{</span>
42   <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="comment">/* test assertion */</span> <span class="special">);</span>
43 <span class="special">}</span>
44
45 <span class="keyword">void</span> <span class="identifier">combined_test</span><span class="special">()</span>
46 <span class="special">{</span>
47   <span class="identifier">single_test</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;();</span>
48   <span class="identifier">single_test</span><span class="special">&lt;</span><span class="keyword">float</span><span class="special">&gt;();</span>
49   <span class="identifier">single_test</span><span class="special">&lt;</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;();</span>
50 <span class="special">}</span>
51 </pre>
52 <p>
53           There several problems/inconveniences with above approach, including:
54         </p>
55 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
56 <li class="listitem">
57               Fatal error in one of the invocation will stop whole test case and
58               will skip invocations with different types
59             </li>
60 <li class="listitem">
61               You need to repeat function invocation manually for all the parameters
62               you are interested in
63             </li>
64 <li class="listitem">
65               You need two functions to implement the test
66             </li>
67 </ul></div>
68 <p>
69           The <span class="emphasis"><em>Unit Test Framework</em></span> provides a facility, the
70           <span class="bold"><strong>template test case</strong></span>, to create a series
71           of test cases based on a list of desired types and <span class="emphasis"><em>nullary</em></span>
72           function. This facility comes with an <a class="link" href="test_organization_templates.html#ref_BOOST_AUTO_TEST_CASE_TEMPLATE">automatic</a>
73           and <a class="link" href="test_organization_templates.html#ref_BOOST_TEST_CASE_TEMPLATE">manual</a> registration
74           interface.
75         </p>
76 <div class="tip"><table border="0" summary="Tip">
77 <tr>
78 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/src/images/tip.png"></td>
79 <th align="left">Tip</th>
80 </tr>
81 <tr><td align="left" valign="top"><p>
82             The test case template facility is preferable to the approach in example
83             above, since execution of each sub test case is guarded and counted separately.
84             It produces a better test log/results report (in example above in case
85             of failure you can't say which type is at fault) and allows you to test
86             all types even if one of them causes termination of the sub test case.
87           </p></td></tr>
88 </table></div>
89 <a name="ref_BOOST_AUTO_TEST_CASE_TEMPLATE"></a><h5>
90 <a name="boost_test.tests_organization.test_cases.test_organization_templates.h0"></a>
91           <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.template_test_case_with_automate"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.template_test_case_with_automate">Template
92           test case with automated registration</a>
93         </h5>
94 <p>
95           A template test case, registered automatically and in place of its implementation,
96           is declared through the macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_auto_template.html" title="BOOST_AUTO_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span></code></a>:
97         </p>
98 <pre class="programlisting"><span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">formal_type_parameter_name</span><span class="special">,</span> <span class="identifier">collection_of_types</span><span class="special">);</span>
99 </pre>
100 <p>
101           The arguments are as follow:
102         </p>
103 <div class="orderedlist"><ol class="orderedlist" type="1">
104 <li class="listitem">
105               <code class="computeroutput"><span class="identifier">test_case_name</span></code>: the
106               test case template name: unique test cases template identifier
107             </li>
108 <li class="listitem">
109               <code class="computeroutput"><span class="identifier">formal_type_parameter_name</span></code>:
110               the name of a formal template parameter: name of the type the test
111               case template is instantiated with
112             </li>
113 <li class="listitem">
114               <code class="computeroutput"><span class="identifier">collection_of_types</span></code>:
115               the collection of types to instantiate test case template with. This
116               is an <span class="bold"><strong>arbitrary MPL sequence</strong></span> or a
117               sequence of types wrapped in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span></code>
118               (since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_7"><span class="emphasis"><em>Unit Test Framework</em></span>
119               v3.7</a>, if supported by the compiler)
120             </li>
121 </ol></div>
122 <p>
123           The resulting name of the test is a composition of the <code class="computeroutput"><span class="identifier">test_case_name</span></code>
124           parameter and the current type being tested. Since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_12"><span class="emphasis"><em>Unit
125           Test Framework</em></span> v3.12</a>, the framework tries to unify the
126           name of the resulting type across various platforms such that they are
127           easier to reference from the <a class="link" href="../../runtime_config/test_unit_filtering.html" title="Test unit filtering">command
128           line filter</a>.
129         </p>
130 <h6>
131 <a name="boost_test.tests_organization.test_cases.test_organization_templates.h1"></a>
132           <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.example_descr"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.example_descr">Example:
133           Test case template with automated registration</a>
134         </h6>
135 <div class="informaltable"><table class="table">
136 <colgroup><col></colgroup>
137 <thead><tr><th>
138                   <p>
139                     Code
140                   </p>
141                 </th></tr></thead>
142 <tbody><tr><td>
143 <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">example</span>
144 <span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</span>
145 <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mpl</span><span class="special">/</span><span class="identifier">list</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
146
147 <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">long</span><span class="special">,</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">test_types</span><span class="special">;</span>
148
149 <span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span> <span class="identifier">my_test</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">test_types</span> <span class="special">)</span>
150 <span class="special">{</span>
151   <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</span> <span class="special">);</span>
152 <span class="special">}</span>
153
154 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">long</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">test_types_w_tuples</span><span class="special">;</span>
155
156 <span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span> <span class="identifier">my_tuple_test</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">test_types_w_tuples</span> <span class="special">)</span>
157 <span class="special">{</span>
158   <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</span> <span class="special">);</span>
159 <span class="special">}</span>
160 </pre>
161                 </td></tr></tbody>
162 </table></div>
163 <div class="informaltable"><table class="table">
164 <colgroup><col></colgroup>
165 <thead><tr><th>
166                   <p>
167                     Output
168                   </p>
169                 </th></tr></thead>
170 <tbody><tr><td>
171 <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">example</span>
172 <span class="identifier">Running</span> <span class="number">3</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
173 <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">"my_test&lt;unsigned char&gt;"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</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">4</span><span class="special">]</span>
174
175 <span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</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">"example"</span>
176 </pre>
177                 </td></tr></tbody>
178 </table></div>
179 <div class="warning"><table border="0" summary="Warning">
180 <tr>
181 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
182 <th align="left">Warning</th>
183 </tr>
184 <tr><td align="left" valign="top"><p>
185             Since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_7"><span class="emphasis"><em>Unit Test Framework</em></span>
186             v3.7</a>, the <span class="emphasis"><em>Unit Test Framework</em></span> does not allow
187             for duplicate test case name under the same test suite. As test names
188             are derived from the types in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code>,
189             this indirectly means that <span class="bold"><strong>having a duplicate type</strong></span>
190             in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code>
191             <span class="bold"><strong>yields an error</strong></span>.
192           </p></td></tr>
193 </table></div>
194 <div class="note"><table border="0" summary="Note">
195 <tr>
196 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
197 <th align="left">Note</th>
198 </tr>
199 <tr><td align="left" valign="top">
200 <p>
201             If you prefer having the template parameter list directly in the declaration
202             of <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_auto_template.html" title="BOOST_AUTO_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span></code></a>,
203             you may use the macro <a href="../../../www.boost.org/doc/libs/release/libs/utility/identity_type/doc/html/index.html" target="_top"><code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code></a>. The previous
204             example gives (note the double parenthesis around the MPL list):
205           </p>
206 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
207
208 <span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span>
209   <span class="identifier">my_test</span><span class="special">,</span>
210   <span class="identifier">T</span><span class="special">,</span>
211   <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span>
212     <span class="keyword">int</span><span class="special">,</span>
213     <span class="keyword">long</span><span class="special">,</span>
214     <span class="keyword">unsigned</span> <span class="keyword">char</span>
215   <span class="special">&gt;))</span> <span class="special">)</span>
216 <span class="special">{</span>
217   <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">unsigned</span><span class="special">)</span><span class="number">4</span> <span class="special">);</span>
218 <span class="special">}</span>
219 </pre>
220 </td></tr>
221 </table></div>
222 <a name="ref_BOOST_TEST_CASE_TEMPLATE"></a><h5>
223 <a name="boost_test.tests_organization.test_cases.test_organization_templates.h2"></a>
224           <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.test_case_template_with_manual_r"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.test_case_template_with_manual_r">Test
225           case template with manual registration</a>
226         </h5>
227 <p>
228           To manually register template test cases, two macros should be used:
229         </p>
230 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
231 <li class="listitem">
232               <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
233               to define the template test case body
234             </li>
235 <li class="listitem">
236               <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template.html" title="BOOST_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span></code></a> to
237               register the test case based on the previous declaration
238             </li>
239 </ul></div>
240 <p>
241           The macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
242           requires two arguments:
243         </p>
244 <div class="orderedlist"><ol class="orderedlist" type="1">
245 <li class="listitem">
246               the name of the test case template and
247             </li>
248 <li class="listitem">
249               the name of the format type parameter
250             </li>
251 </ol></div>
252 <pre class="programlisting"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span><span class="special">(</span><span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">type_name</span><span class="special">);</span>
253 </pre>
254 <pre class="programlisting"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span><span class="special">(</span> <span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">type_name</span> <span class="special">)</span>
255 <span class="special">{</span>
256   <span class="comment">// test case template body</span>
257 <span class="special">}</span>
258 </pre>
259 <p>
260           The macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
261           is intended to be used in place of nullary function template signature:
262         </p>
263 <pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">type_name</span><span class="special">&gt;</span>
264 <span class="keyword">void</span> <span class="identifier">test_case_name</span><span class="special">()</span>
265 <span class="special">{</span>
266   <span class="comment">// test case template body</span>
267 <span class="special">}</span>
268 </pre>
269 <p>
270           The only difference is that the <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template_function.html" title="BOOST_TEST_CASE_TEMPLATE_FUNCTION"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span></code></a>
271           makes the test case template name usable in the template argument list.
272         </p>
273 <p>
274           <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template.html" title="BOOST_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span></code></a> requires
275           two arguments:
276         </p>
277 <div class="orderedlist"><ol class="orderedlist" type="1">
278 <li class="listitem">
279               the name of the test case template and
280             </li>
281 <li class="listitem">
282               Boost.MPL compatible collection of types to instantiate it with.
283             </li>
284 </ol></div>
285 <p>
286           The names passed to both macros should be the same.
287         </p>
288 <pre class="programlisting"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case_name</span><span class="special">,</span> <span class="identifier">collection_of_types</span><span class="special">);</span>
289 </pre>
290 <h6>
291 <a name="boost_test.tests_organization.test_cases.test_organization_templates.h3"></a>
292           <span class="phrase"><a name="boost_test.tests_organization.test_cases.test_organization_templates.example_descr0"></a></span><a class="link" href="test_organization_templates.html#boost_test.tests_organization.test_cases.test_organization_templates.example_descr0">Example:
293           Manually registered test case template</a>
294         </h6>
295 <div class="informaltable"><table class="table">
296 <colgroup><col></colgroup>
297 <thead><tr><th>
298                   <p>
299                     Code
300                   </p>
301                 </th></tr></thead>
302 <tbody><tr><td>
303 <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</span>
304 <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mpl</span><span class="special">/</span><span class="identifier">list</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
305 <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>
306
307 <span class="identifier">BOOST_TEST_CASE_TEMPLATE_FUNCTION</span><span class="special">(</span> <span class="identifier">my_test</span><span class="special">,</span> <span class="identifier">T</span> <span class="special">)</span>
308 <span class="special">{</span>
309   <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="number">4U</span> <span class="special">);</span>
310 <span class="special">}</span>
311
312 <span class="identifier">test_suite</span><span class="special">*</span> <span class="identifier">init_unit_test_suite</span><span class="special">(</span> <span class="keyword">int</span> <span class="comment">/*argc*/</span><span class="special">,</span> <span class="keyword">char</span><span class="special">*</span> <span class="comment">/*argv*/</span><span class="special">[]</span> <span class="special">)</span>
313 <span class="special">{</span>
314   <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">,</span><span class="keyword">long</span><span class="special">,</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">test_types</span><span class="special">;</span>
315
316   <span class="identifier">framework</span><span class="special">::</span><span class="identifier">master_test_suite</span><span class="special">().</span>
317     <span class="identifier">add</span><span class="special">(</span> <span class="identifier">BOOST_TEST_CASE_TEMPLATE</span><span class="special">(</span> <span class="identifier">my_test</span><span class="special">,</span> <span class="identifier">test_types</span> <span class="special">)</span> <span class="special">);</span>
318
319   <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
320 <span class="special">}</span>
321 </pre>
322                 </td></tr></tbody>
323 </table></div>
324 <div class="informaltable"><table class="table">
325 <colgroup><col></colgroup>
326 <thead><tr><th>
327                   <p>
328                     Output
329                   </p>
330                 </th></tr></thead>
331 <tbody><tr><td>
332 <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">example</span>
333 <span class="identifier">Running</span> <span class="number">3</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
334 <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">"my_test&lt;unsigned char&gt;"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="number">4U</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">4</span><span class="special">]</span>
335
336 <span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</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">"Master Test Suite"</span>
337 </pre>
338                 </td></tr></tbody>
339 </table></div>
340 <p>
341           <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_case_template.html" title="BOOST_TEST_CASE_TEMPLATE"><code class="computeroutput"><span class="identifier">BOOST_TEST_CASE_TEMPLATE</span></code></a> creates
342           an instance of the test case generator. When passed to the method <code class="computeroutput"><a class="link" href="../../../boost/unit_test/test_suite.html#idm46279112866240-bb">test_suite::add</a></code>,
343           the generator produces a separate sub test case for each type in the supplied
344           collection of types and registers it immediately in the test suite. Each
345           test case is based on the test case template body instantiated with a particular
346           test type.
347         </p>
348 <p>
349           The names for the <span class="emphasis"><em>sub test cases</em></span> are deduced from
350           the macro argument <code class="computeroutput"><span class="identifier">test_case_name</span></code>.
351           If you prefer to assign different test case names, you need to use the
352           underlying <code class="computeroutput"><a class="link" href="../../../header/boost/test/tree/test_unit_hpp.html" title="Header &lt;boost/test/tree/test_unit.hpp&gt;">make_test_case</a></code> interface
353           instead. Both test cases creation and registration is performed in the
354           test module initialization function.
355         </p>
356 <div class="warning"><table border="0" summary="Warning">
357 <tr>
358 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
359 <th align="left">Warning</th>
360 </tr>
361 <tr><td align="left" valign="top"><p>
362             Since <a class="link" href="../../change_log.html#ref_CHANGE_LOG_3_7"><span class="emphasis"><em>Unit Test Framework</em></span>
363             v3.7</a>, the <span class="emphasis"><em>Unit Test Framework</em></span> does not allow
364             for duplicate test case name under the same test suite. As test names
365             are derived from the types in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code>,
366             this indirectly means that having a duplicate of types in the <code class="computeroutput"><span class="identifier">collection_of_types</span></code> will yield an error.
367           </p></td></tr>
368 </table></div>
369 </div>
370 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
371 <td align="left"></td>
372 <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2019 Boost.Test
373       contributors<p>
374         Distributed under the Boost Software License, Version 1.0. (See accompanying
375         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>)
376       </p>
377 </div></td>
378 </tr></table>
379 <hr>
380 <div class="spirit-nav">
381 <a accesskey="p" href="test_case_generation/generators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../test_cases.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="param_test.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
382 </div>
383 </body>
384 </html>