Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / API_CppTest / INC / cpptest-assert.h
1 // ---
2 //
3 // $Id: cpptest-assert.h,v 1.3 2005/06/08 08:08:06 nilu Exp $
4 //
5 // CppTest - A C++ Unit Testing Framework
6 // Copyright (c) 2003 Niklas Lundell
7 //
8 // ---
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
24 //
25 // ---
26
27 /** \file */
28
29 #ifndef CPPTEST_ASSERT_H
30 #define CPPTEST_ASSERT_H
31
32 /// Unconditional failure.
33 ///
34 /// Used in conjunction with Test::Suite.
35 ///
36 /// \param msg Provided message.
37 ///
38 /// \par Example:
39 /// \code
40 /// void MySuite::test()
41 /// {
42 /// // ...
43 ///
44 /// switch (flag)
45 /// {
46 /// // handling valid cases ...
47 ///
48 /// default:
49 /// TEST_FAIL("This should not happen")
50 /// }
51 /// }
52 /// \endcode
53 ///
54 /// For a description of all asserts, see \ref asserts.
55 ///
56 #define TEST_FAIL(msg) \
57 { \
58 assertment(::Test::Source(__FILE__, __LINE__, (msg) != 0 ? #msg : "")); \
59 if (!continue_after_failure()) return; \
60 }
61
62 /// Verify an expression and issues an assertment if it fails.
63 ///
64 /// Used in conjunction with Test::Suite.
65 ///
66 /// \param expr Expression to test.
67 ///
68 /// \see TEST_ASSERT_MSG(expr, msg)
69 ///
70 /// \par Example:
71 /// \code
72 /// void MySuite::test()
73 /// {
74 /// int i;
75 ///
76 /// // ...
77 ///
78 /// TEST_ASSERT(i == 13)
79 /// }
80 /// \endcode
81 ///
82 /// For a description of all asserts, see \ref asserts.
83 ///
84 #define TEST_ASSERT(expr) \
85 { \
86 if (!(expr)) \
87 { \
88 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
89 if (!continue_after_failure()) return; \
90 } \
91 }
92
93 /// Verify an expression and issues an assertment if it fails.
94 ///
95 /// Used in conjunction with Test::Suite.
96 ///
97 /// \param expr Expression to test.
98 /// \param msg User message.
99 ///
100 /// \see TEST_ASSERT(expr)
101 ///
102 /// For a description of all asserts, see \ref asserts.
103 ///
104 #define TEST_ASSERT_MSG(expr, msg) \
105 { \
106 if (!(expr)) \
107 { \
108 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
109 if (!continue_after_failure()) return; \
110 } \
111 }
112
113 /// Verify that two expressions are equal up to a constant, issues an
114 /// assertment if it fails.
115 ///
116 /// Used in conjunction with Test::Suite.
117 ///
118 /// \param a First expression to test.
119 /// \param b Second expression to test.
120 /// \param delta Constant.
121 ///
122 /// \see TEST_ASSERT_DELTA_MSG(a, b, delta, msg)
123 ///
124 /// For a description of all asserts, see \ref asserts.
125 ///
126 #define TEST_ASSERT_DELTA(a, b, delta) \
127 { \
128 if (((b) < (a) - (delta)) || ((b) > (a) + (delta))) \
129 { \
130 assertment(::Test::Source(__FILE__, __LINE__, \
131 "delta(" #a ", " #b ", " #delta ")" )); \
132 if (!continue_after_failure()) return; \
133 } \
134 }
135
136 /// Verify that two expressions are equal up to a constant, issues an
137 /// assertment if it fails.
138 ///
139 /// Used in conjunction with Test::Suite.
140 ///
141 /// \param a First expression to test.
142 /// \param b Second expression to test.
143 /// \param delta Constant.
144 /// \param msg User message.
145 ///
146 /// \see TEST_ASSERT_DELTA(a, b, delta)
147 ///
148 /// For a description of all asserts, see \ref asserts.
149 ///
150 #define TEST_ASSERT_DELTA_MSG(a, b, delta, msg) \
151 { \
152 if (((b) < (a) - (delta)) || ((b) > (a) + (delta))) \
153 { \
154 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
155 if (!continue_after_failure()) return; \
156 } \
157 }
158
159 /// Verify an expression and expects an exception in return.
160 /// An assertment is issued if the exception is not thrown.
161 ///
162 /// Used in conjunction with Test::Suite.
163 ///
164 /// \param expr Expression to test.
165 /// \param x Expected exception.
166 ///
167 /// \see TEST_THROWS_MSG(expr, x, msg)
168 ///
169 /// For a description of all asserts, see \ref asserts.
170 ///
171 #define TEST_THROWS(expr, x) \
172 { \
173 bool __expected = false; \
174 try { expr; } \
175 catch (x) { __expected = true; } \
176 catch (...) {} \
177 if (!__expected) \
178 { \
179 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
180 if (!continue_after_failure()) return; \
181 } \
182 }
183
184 /// Verify an expression and expects an exception in return.
185 /// An assertment is issued if the exception is not thrown.
186 ///
187 /// Used in conjunction with Test::Suite.
188 ///
189 /// \param expr Expression to test.
190 /// \param x Expected exception.
191 /// \param msg User message.
192 ///
193 /// \see TEST_THROWS(expr, x)
194 ///
195 /// For a description of all asserts, see \ref asserts.
196 ///
197 #define TEST_THROWS_MSG(expr, x, msg) \
198 { \
199 bool __expected = false; \
200 try { expr; } \
201 catch (x) { __expected = true; } \
202 catch (...) {} \
203 if (!__expected) \
204 { \
205 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
206 if (!continue_after_failure()) return; \
207 } \
208 }
209
210 /// Verify an expression and expects any exception in return.
211 /// An assertment is issued if no exception is thrown.
212 ///
213 /// Used in conjunction with Test::Suite.
214 ///
215 /// \param expr Expression to test.
216 ///
217 /// \see TEST_THROWS_ANYTHING_MSG(expr, msg)
218 ///
219 /// For a description of all asserts, see \ref asserts.
220 ///
221 #define TEST_THROWS_ANYTHING(expr) \
222 { \
223 bool __expected = false; \
224 try { expr; } \
225 catch (...) { __expected = true; } \
226 if (!__expected) \
227 { \
228 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
229 if (!continue_after_failure()) return; \
230 } \
231 }
232
233 /// Verify an expression and expects any exception in return.
234 /// An assertment is issued if no exception is thrown.
235 ///
236 /// Used in conjunction with Test::Suite.
237 ///
238 /// \param expr Expression to test.
239 /// \param msg User message.
240 ///
241 /// \see TEST_THROWS_ANYTHING(expr)
242 ///
243 /// For a description of all asserts, see \ref asserts.
244 ///
245 #define TEST_THROWS_ANYTHING_MSG(expr, msg) \
246 { \
247 bool __expected = false; \
248 try { expr; } \
249 catch (...) { __expected = true; } \
250 if (!__expected) \
251 { \
252 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
253 if (!continue_after_failure()) return; \
254 } \
255 }
256
257 /// Verify an expression and expects no exception in return.
258 /// An assertment is issued if any exception is thrown.
259 ///
260 /// Used in conjunction with Test::Suite.
261 ///
262 /// \param expr Expression to test.
263 ///
264 /// \see TEST_THROWS_NOTHING_MSG(expr, msg)
265 ///
266 /// For a description of all asserts, see \ref asserts.
267 ///
268 #define TEST_THROWS_NOTHING(expr) \
269 { \
270 bool __expected = true; \
271 try { expr; } \
272 catch (...) { __expected = false; } \
273 if (!__expected) \
274 { \
275 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
276 if (!continue_after_failure()) return; \
277 } \
278 }
279
280 /// Verify an expression and expects no exception in return.
281 /// An assertment is issued if any exception is thrown.
282 ///
283 /// Used in conjunction with Test::Suite.
284 ///
285 /// \param expr Expression to test.
286 /// \param msg User message.
287 ///
288 /// \see TEST_THROWS_NOTHING(expr)
289 ///
290 /// For a description of all asserts, see \ref asserts.
291 ///
292 #define TEST_THROWS_NOTHING_MSG(expr, msg) \
293 { \
294 bool __expected = true; \
295 try { expr; } \
296 catch (...) { __expected = false; } \
297 if (!__expected) \
298 { \
299 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
300 if (!continue_after_failure()) return; \
301 } \
302 }
303
304 /// \page asserts Available asserts
305 ///
306 /// Normally, assert macros issues an assert if the given expression, if any,
307 /// fails (as defined by the macro). Assertments include information about the
308 /// current test suite, test function, source file, source file line, and a
309 /// message. The message is normally the offending expression, however, for
310 /// macros ending in _MSG it is possibly to supply a user defined message.
311 ///
312 /// <b>General asserts</b>
313 /// - TEST_FAIL(msg)
314 ///
315 /// <b>Comparision asserts</b>
316 /// - TEST_ASSERT(expr)
317 /// - TEST_ASSERT_MSG(expr, msg)
318 /// - TEST_ASSERT_DELTA(a, b, delta)
319 /// - TEST_ASSERT_DELTA_MSG(a, b, delta, msg)
320 ///
321 /// <b>Exception asserts</b>
322 /// - TEST_THROWS(expr, x)
323 /// - TEST_THROWS_MSG(expr, x, msg)
324 /// - TEST_THROWS_ANYTHING(expr)
325 /// - TEST_THROWS_ANYTHING_MSG(expr, msg)
326 /// - TEST_THROWS_NOTHING(expr)
327 /// - TEST_THROWS_NOTHING_MSG(expr, msg)
328 ///
329
330 #endif // #ifndef CPPTEST_ASSERT_H
331