]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/doc/lightweight_test.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / core / doc / lightweight_test.qbk
1 [/
2 Copyright 2010, 2011 Beman Dawes
3 Copyright 2013 Ion Gaztanaga
4 Copyright 2014 Peter Dimov
5
6 Distributed under the Boost Software License, Version 1.0.
7
8 See accompanying file LICENSE_1_0.txt
9 or copy at http://boost.org/LICENSE_1_0.txt
10 ]
11
12 [section:lightweight_test lightweight_test]
13
14 [simplesect Authors]
15
16 * Peter Dimov
17 * Beman Dawes
18
19 [endsimplesect]
20
21 [section Header <boost/core/lightweight_test.hpp>]
22
23 The header `<boost/core/lightweight_test.hpp>` is a
24 lightweight test framework. It's useful for writing
25 Boost regression tests for components that are dependencies
26 of Boost.Test.
27
28 When using `lightweight_test.hpp`, *do not forget* to
29 `return boost::report_errors()` from `main`.
30
31 [section Synopsis]
32
33 ``
34 #define BOOST_TEST(expression) /*unspecified*/
35 #define BOOST_TEST_NOT(expression) /*unspecified*/
36 #define BOOST_ERROR(message) /*unspecified*/
37 #define BOOST_TEST_EQ(expr1, expr2) /*unspecified*/
38 #define BOOST_TEST_NE(expr1, expr2) /*unspecified*/
39 #define BOOST_TEST_THROWS(expr, excep) /*unspecified*/
40
41 namespace boost
42 {
43 int report_errors();
44 }
45 ``
46
47 [endsect]
48
49 [section BOOST_TEST]
50
51 ``
52 BOOST_TEST(expression)
53 ``
54
55 If expression is false increases the error count and outputs a
56 message containing `expression`.
57
58 [endsect]
59
60 [section BOOST_TEST_NOT]
61
62 ``
63 BOOST_TEST_NOT(expression)
64 ``
65
66 If expression is true increases the error count and outputs a
67 message containing `!(expression)`.
68
69 [endsect]
70
71 [section BOOST_ERROR]
72
73 ``
74 BOOST_ERROR(message)
75 ``
76
77 Increases error count and outputs a message containing
78 `message`.
79
80 [endsect]
81
82 [section BOOST_TEST_EQ]
83
84 ``
85 BOOST_TEST_EQ(expr1, expr2)
86 ``
87
88 If `expr1 != expr2` increases the error count and outputs a
89 message containing both expressions.
90
91 [endsect]
92
93 [section BOOST_TEST_NE]
94
95 ``
96 BOOST_TEST_NE(expr1, expr2)
97 ``
98
99 If `expr1 == expr2` increases the error count and outputs a
100 message containing both expressions.
101
102 [endsect]
103
104 [section BOOST_TEST_THROWS]
105
106 ``
107 BOOST_TEST_THROWS(expr, excep)
108 ``
109
110 If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not
111 throw an exception of type `excep`, increases the error count
112 and outputs a message containing the expression.
113
114 If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to
115 nothing and `expr` is not evaluated.
116
117 [endsect]
118
119 [section report_errors]
120
121 ``
122 int boost::report_errors()
123 ``
124
125 Return the error count from `main`.
126
127 [endsect]
128
129 [section Example]
130
131 ``
132 #include <boost/core/lightweight_test.hpp>
133
134 int sqr( int x )
135 {
136 return x * x;
137 }
138
139 int main()
140 {
141 BOOST_TEST( sqr(2) == 4 );
142 BOOST_TEST_EQ( sqr(-3), 9 );
143
144 return boost::report_errors();
145 }
146 ``
147
148 [endsect]
149
150 [endsect]
151
152 [section Header <boost/core/lightweight_test_trait.hpp>]
153
154 The header `<boost/core/lightweight_test_trait.hpp>` defines
155 a couple of extra macros for testing compile-time traits that
156 return a boolean value.
157
158 [section Synopsis]
159
160 ``
161 #define BOOST_TEST_TRAIT_TRUE((Trait)) /*unspecified*/
162 #define BOOST_TEST_TRAIT_FALSE((Trait)) /*unspecified*/
163 ``
164
165 [endsect]
166
167 [section BOOST_TEST_TRAIT_TRUE]
168
169 ``
170 BOOST_TEST_TRAIT_TRUE((Trait))
171 ``
172
173 If `Trait::value != true` increases the error count and outputs a
174 message containing `Trait`. Note the double set of parentheses; these
175 enable `Trait` to contain a comma, which is common for templates.
176
177 [endsect]
178
179 [section BOOST_TEST_TRAIT_FALSE]
180
181 ``
182 BOOST_TEST_TRAIT_FALSE((Trait))
183 ``
184
185 If `Trait::value != false` increases the error count and outputs a
186 message containing `Trait`. Note the double set of parentheses.
187
188 [endsect]
189
190 [section Example]
191
192 ``
193 #include <boost/core/lightweight_test_trait.hpp>
194 #include <boost/core/is_same.hpp>
195
196 template<class T, class U> struct X
197 {
198 typedef T type;
199 };
200
201 using boost::core::is_same;
202
203 int main()
204 {
205 BOOST_TEST_TRAIT_TRUE(( is_same<X<int, long>::type, int> ));
206
207 return boost::report_errors();
208 }
209 ``
210
211 [endsect]
212
213 [endsect]
214
215 [endsect]