File: generic.html

package info (click to toggle)
boost1.42 1.42.0-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 277,864 kB
  • ctags: 401,076
  • sloc: cpp: 1,235,659; xml: 74,142; ansic: 41,313; python: 26,756; sh: 11,840; cs: 2,118; makefile: 655; perl: 494; yacc: 456; asm: 353; csh: 6
file content (176 lines) | stat: -rwxr-xr-x 8,230 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Generic usage recommendations</title>
<link rel="stylesheet" href="../../../style/style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="../../index.html" title="Boost Test Library">
<link rel="up" href="../usage-recommendations.html" title="The unit test framework usage recommendations">
<link rel="prev" href="../usage-recommendations.html" title="The unit test framework usage recommendations">
<link rel="next" href="dot-net-specific.html" title="Microsoft Visual Studio .NET usage recommendations">
<script language="JavaScript1.2" src="../../../js/boost-test.js"></script>
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table width="100%"><tr>
<td width="10%"><a href="../../index.html"><img alt="Home" width="229" height="61" border="0" src="../../../../../../libs/test/docbook/img/boost.test.logo.png"></a></td>
<td valign="middle" align="left"> &gt; <a href="../../utf.html">The Unit Test Framework</a> &gt; <a href="../usage-recommendations.html">Usage recommendations</a> &gt; <b>Generic</b>
</td>
<td><div class="spirit-nav">
<a href="../usage-recommendations.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a href="dot-net-specific.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div></td>
</tr></table>
<hr>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="utf.usage-recommendations.generic"></a>Generic usage recommendations</h4></div></div></div>
<div class="qandaset">
<dl>
<dt> <a href="generic.html#id663440">
      Prefer offline compiled libraries to the inline included components
     </a>
</dt>
<dt> <a href="generic.html#id663471">
      If you use only free function based test cases advance to the automatic registration facility
     </a>
</dt>
<dt> <a href="generic.html#id663496">
      To find location of first error reported by test tool within reused template function, use special hook within 
      framework headers
     </a>
</dt>
<dt> <a href="generic.html#id663542">
      To test reusable template base component with different template parameter use test case template facility
     </a>
</dt>
<dt> <a href="generic.html#id663600">
      Prefer BOOST_CHECK_EQUAL to BOOST_CHECK
     </a>
</dt>
</dl>
<table border="0" summary="Q and A Set">
<col align="left" width="1%">
<tbody>
<tr class="question">
<td align="left" valign="top">
<a name="id663440"></a><a name="id663443"></a>
</td>
<td align="left" valign="top"><b><p>
      Prefer offline compiled libraries to the inline included components
     </p></b></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top"><p class="first-line-indented">
      If you are just want to write quick simple test in environment where you never used Boost.Test before - yes, 
      use included components. But if you plan to use Boost.Test on permanent basis, small investment of time needed 
      to build (if not build yet), install and change you makefiles/project settings will soon return to you in a 
      form of shorter compilation time. Why do you need to make your compiler do the same work over and over again?
     </p></td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id663471"></a><a name="id663473"></a>
</td>
<td align="left" valign="top"><b><p>
      If you use only free function based test cases advance to the automatic registration facility
     </p></b></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top"><p class="first-line-indented">
      It's really easy to switch to automatic registration. And you don't need to worry about forgotten test case 
      anymore
     </p></td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id663496"></a><a name="id663498"></a>
</td>
<td align="left" valign="top"><b><p>
      To find location of first error reported by test tool within reused template function, use special hook within 
      framework headers
     </p></b></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top"><p class="first-line-indented">
      In some cases you are reusing the same template based code from within one test case (actually I recommend 
      better solution in such case- see below). Now if an error gets reported by the test tool within that reused 
      code you may have difficulty locating were exactly error occurred. To address this issue you could either a add 
      <a class="link" href="../user-guide/test-output/BOOST_TEST_MESSAGE.html" title="BOOST_TEST_MESSAGE">BOOST_TEST_MESSAGE</a> statements in 
      templated code that log current type id of template parameters or you can use special hook located in 
      unit_test_result.hpp called first_failed_assertion(). If you set a breakpoint right on the line where this 
      function is defined you will be able to unroll the stack and see where error actually occurred.
     </p></td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id663542"></a><a name="id663545"></a>
</td>
<td align="left" valign="top"><b><p>
      To test reusable template base component with different template parameter use test case template facility
     </p></b></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top">
<p class="first-line-indented">
      If you writing unit test for generic reusable component you may have a need to test it against set of different 
      template parameter types . Most probably you will end up with a code like this:
     </p>
<pre class="programlisting">template&lt;typename TestType&gt;
void
specific_type_test( TestType* = 0 )
{
    MyComponent&lt;TestType&gt; c;
    ... // here we perform actual testing
}

void my_component_test()
{
    specific_type_test( (int*)0 );
    specific_type_test( (float*)0 );
    specific_type_test( (UDT*)0 );
    ... 
}
</pre>
<p class="first-line-indented">
      This is namely the situation where you would use test case template facility. It not only simplifies this kind 
      of unit testing by automating some of the work, in addition every argument type gets tested separately under 
      unit test monitor. As a result if one of types produce exception or non-fatal error you may still continue and 
      get results from testing with other types.
     </p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id663600"></a><a name="id663603"></a>
</td>
<td align="left" valign="top"><b><p>
      Prefer BOOST_CHECK_EQUAL to BOOST_CHECK
     </p></b></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top"><p class="first-line-indented">
      Even though BOOSK_CHECK tool is most generic and allows validating any bool convertible expression, I would 
      recommend using, if possible, more specific tools dedicated to the task. For example if you need you validate 
      some variable vs. some expected value use BOOST_CHECK_EQUAL instead. The main advantage is that in case of 
      failure you will see the mismatched value - the information most useful for error identification. The same 
      applies to other tools supplied by the framework.
     </p></td>
</tr>
</tbody>
</table>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright  2001-2007 Gennadiy Rozental</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../usage-recommendations.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../usage-recommendations.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="dot-net-specific.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>