|
1 /* |
|
2 * File: test.h |
|
3 * Author: Mike |
|
4 * |
|
5 * Created on 18. Februar 2012, 14:15 |
|
6 */ |
|
7 |
|
8 #ifndef TEST_H |
|
9 #define TEST_H |
|
10 |
|
11 #include <stdio.h> |
|
12 #include <string.h> |
|
13 #include "list.h" |
|
14 |
|
15 #ifdef __cplusplus |
|
16 extern "C" { |
|
17 #endif |
|
18 |
|
19 typedef struct { |
|
20 unsigned int success; |
|
21 unsigned int failure; |
|
22 UcxList *tests; |
|
23 } UcxTestSuite; |
|
24 |
|
25 typedef void(*UcxTest)(UcxTestSuite*,FILE*); |
|
26 |
|
27 UcxTestSuite* ucx_test_suite_new(); |
|
28 void ucx_test_suite_free(UcxTestSuite*); |
|
29 |
|
30 void ucx_test_register(UcxTestSuite*, UcxTest); |
|
31 void ucx_test_run(UcxTestSuite*, FILE*); |
|
32 |
|
33 #define UCX_TEST_BEGIN(name) void name(UcxTestSuite* _suite_,FILE *_output_) {\ |
|
34 fwrite("Running "#name"... ", 1, 12+strlen(#name), _output_); |
|
35 |
|
36 #define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \ |
|
37 fwrite(message".\n", 1, 2+strlen(message), _output_); \ |
|
38 _suite_->failure++; \ |
|
39 return;\ |
|
40 } |
|
41 |
|
42 #define UCX_TEST_END } fwrite("success.\n", 1, 9, _output_); _suite_->success++; |
|
43 |
|
44 #ifdef __cplusplus |
|
45 } |
|
46 #endif |
|
47 |
|
48 #endif /* TEST_H */ |
|
49 |