]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/core/doc/lightweight_test.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / core / doc / lightweight_test.qbk
CommitLineData
7c673cae
FG
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
23The header `<boost/core/lightweight_test.hpp>` is a
24lightweight test framework. It's useful for writing
25Boost regression tests for components that are dependencies
26of Boost.Test.
27
28When 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
41namespace boost
42{
43 int report_errors();
44}
45``
46
47[endsect]
48
49[section BOOST_TEST]
50
51``
52BOOST_TEST(expression)
53``
54
55If expression is false increases the error count and outputs a
56message containing `expression`.
57
58[endsect]
59
60[section BOOST_TEST_NOT]
61
62``
63BOOST_TEST_NOT(expression)
64``
65
66If expression is true increases the error count and outputs a
67message containing `!(expression)`.
68
69[endsect]
70
71[section BOOST_ERROR]
72
73``
74BOOST_ERROR(message)
75``
76
77Increases error count and outputs a message containing
78`message`.
79
80[endsect]
81
82[section BOOST_TEST_EQ]
83
84``
85BOOST_TEST_EQ(expr1, expr2)
86``
87
88If `expr1 != expr2` increases the error count and outputs a
89message containing both expressions.
90
91[endsect]
92
93[section BOOST_TEST_NE]
94
95``
96BOOST_TEST_NE(expr1, expr2)
97``
98
99If `expr1 == expr2` increases the error count and outputs a
100message containing both expressions.
101
102[endsect]
103
104[section BOOST_TEST_THROWS]
105
106``
107BOOST_TEST_THROWS(expr, excep)
108``
109
110If `BOOST_NO_EXCEPTIONS` is *not* defined and if `expr` does not
111throw an exception of type `excep`, increases the error count
112and outputs a message containing the expression.
113
114If `BOOST_NO_EXCEPTIONS` is defined, this macro expands to
115nothing and `expr` is not evaluated.
116
117[endsect]
118
119[section report_errors]
120
121``
122int boost::report_errors()
123``
124
125Return the error count from `main`.
126
127[endsect]
128
129[section Example]
130
131``
132#include <boost/core/lightweight_test.hpp>
133
134int sqr( int x )
135{
136 return x * x;
137}
138
139int 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
154The header `<boost/core/lightweight_test_trait.hpp>` defines
155a couple of extra macros for testing compile-time traits that
156return 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``
170BOOST_TEST_TRAIT_TRUE((Trait))
171``
172
173If `Trait::value != true` increases the error count and outputs a
174message containing `Trait`. Note the double set of parentheses; these
175enable `Trait` to contain a comma, which is common for templates.
176
177[endsect]
178
179[section BOOST_TEST_TRAIT_FALSE]
180
181``
182BOOST_TEST_TRAIT_FALSE((Trait))
183``
184
185If `Trait::value != false` increases the error count and outputs a
186message 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
196template<class T, class U> struct X
197{
198 typedef T type;
199};
200
201using boost::core::is_same;
202
203int 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]