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