| 41 * </code> |
41 * </code> |
| 42 * |
42 * |
| 43 * **** IN SOURCE FILE: **** |
43 * **** IN SOURCE FILE: **** |
| 44 * <code> |
44 * <code> |
| 45 * CX_TEST_SUBROUTINE(subroutine_name, paramlist) { |
45 * CX_TEST_SUBROUTINE(subroutine_name, paramlist) { |
| 46 * // tests with CX_TEST_ASSERT() |
46 * // tests with CX_TEST_ASSERTM() |
| 47 * } |
47 * } |
| 48 * |
48 * |
| 49 * CX_TEST(function_name) { |
49 * CX_TEST(function_name) { |
| 50 * // memory allocation and other stuff here |
50 * // memory allocation and other stuff here |
| 51 * #CX_TEST_DO { |
51 * #CX_TEST_DO { |
| 52 * // tests with CX_TEST_ASSERT() and/or |
52 * // tests with CX_TEST_ASSERTM() and/or |
| 53 * // calls with CX_TEST_CALL_SUBROUTINE() here |
53 * // calls with CX_TEST_CALL_SUBROUTINE() here |
| 54 * } |
54 * } |
| 55 * // cleanup of memory here |
55 * // cleanup of memory here |
| 56 * } |
56 * } |
| 57 * </code> |
57 * </code> |
| 58 * |
58 * |
| 59 * @attention Do not call own functions within a test that use |
59 * @attention Do not call own functions within a test that use |
| 60 * CX_TEST_ASSERT() macros and are not defined by using CX_TEST_SUBROUTINE(). |
60 * CX_TEST_ASSERTM() macros and are not defined by using CX_TEST_SUBROUTINE(). |
| 61 * |
61 * |
| 62 * @author Mike Becker |
62 * @author Mike Becker |
| 63 * @author Olaf Wintermann |
63 * @author Olaf Wintermann |
| 64 * |
64 * |
| 65 */ |
65 */ |
| 253 * } |
253 * } |
| 254 * // tear down code |
254 * // tear down code |
| 255 * } |
255 * } |
| 256 * @endcode |
256 * @endcode |
| 257 * |
257 * |
| 258 * @attention Any CX_TEST_ASSERT() calls must be performed in the scope of |
258 * @attention Any CX_TEST_ASSERTM() calls must be performed in the scope of |
| 259 * #CX_TEST_DO. |
259 * #CX_TEST_DO. |
| 260 */ |
260 */ |
| 261 #define CX_TEST_DO _writefnc_("Running ", 1, 8, _output_);\ |
261 #define CX_TEST_DO _writefnc_("Running ", 1, 8, _output_);\ |
| 262 _writefnc_(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\ |
262 _writefnc_(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\ |
| 263 _writefnc_("... ", 1, 4, _output_);\ |
263 _writefnc_("... ", 1, 4, _output_);\ |
| 273 * correct, the specified message (terminated by a dot and a line break) is |
273 * correct, the specified message (terminated by a dot and a line break) is |
| 274 * written to the test suites output stream. |
274 * written to the test suites output stream. |
| 275 * @param condition (@c bool) the condition to check |
275 * @param condition (@c bool) the condition to check |
| 276 * @param message (@c char*) the message that shall be printed out on failure |
276 * @param message (@c char*) the message that shall be printed out on failure |
| 277 */ |
277 */ |
| 278 #define CX_TEST_ASSERTM(condition,message) if (!(condition)) { \ |
278 #define CX_TEST_ASSERTMM(condition,message) if (!(condition)) { \ |
| 279 const char *_assert_msg_ = message; \ |
279 const char *_assert_msg_ = message; \ |
| 280 _writefnc_(_assert_msg_, 1, strlen(_assert_msg_), _output_); \ |
280 _writefnc_(_assert_msg_, 1, strlen(_assert_msg_), _output_); \ |
| 281 _writefnc_(".\n", 1, 2, _output_); \ |
281 _writefnc_(".\n", 1, 2, _output_); \ |
| 282 _suite_->failure++; \ |
282 _suite_->failure++; \ |
| 283 longjmp(_env_, 1);\ |
283 longjmp(_env_, 1);\ |
| 288 * If the assertion is correct, the test carries on. If the assertion is not |
288 * If the assertion is correct, the test carries on. If the assertion is not |
| 289 * correct, the specified message (terminated by a dot and a line break) is |
289 * correct, the specified message (terminated by a dot and a line break) is |
| 290 * written to the test suites output stream. |
290 * written to the test suites output stream. |
| 291 * @param condition (@c bool) the condition to check |
291 * @param condition (@c bool) the condition to check |
| 292 */ |
292 */ |
| 293 #define CX_TEST_ASSERT(condition) CX_TEST_ASSERTM(condition, #condition " failed") |
293 #define CX_TEST_ASSERTM(condition) CX_TEST_ASSERTMM(condition, #condition " failed") |
| 294 |
294 |
| 295 /** |
295 /** |
| 296 * Macro for a test subroutine function header. |
296 * Macro for a test subroutine function header. |
| 297 * |
297 * |
| 298 * Use this to declare and/or define a subroutine that can be called by using |
298 * Use this to declare and/or define a subroutine that can be called by using |