CppTest home page CppTest project page

cpptest-assert.h
Go to the documentation of this file.
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 
29 #ifndef CPPTEST_ASSERT_H
30 #define CPPTEST_ASSERT_H
31 
56 #define TEST_FAIL(msg) \
57  { \
58  assertment(::Test::Source(__FILE__, __LINE__, (msg) != 0 ? #msg : "")); \
59  if (!continue_after_failure()) return; \
60  }
61 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
329 
330 #endif // #ifndef CPPTEST_ASSERT_H
331 

Supported by:

SourceForge Logo