1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include "ucx/test.h"
30
31 UcxTestSuite* ucx_test_suite_new() {
32 UcxTestSuite* suite = (UcxTestSuite*) malloc(
sizeof(UcxTestSuite));
33 if (suite !=
NULL) {
34 suite->success =
0;
35 suite->failure =
0;
36 suite->tests =
NULL;
37 }
38
39 return suite;
40 }
41
42 void ucx_test_suite_free(UcxTestSuite* suite) {
43 UcxTestList *l = suite->tests;
44 while (l !=
NULL) {
45 UcxTestList *e = l;
46 l = l->next;
47 free(e);
48 }
49 free(suite);
50 }
51
52 int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
53 if (suite->tests) {
54 UcxTestList *newelem = (UcxTestList*) malloc(
sizeof(UcxTestList));
55 if (newelem) {
56 newelem->test = test;
57 newelem->next =
NULL;
58
59 UcxTestList *last = suite->tests;
60 while (last->next) {
61 last = last->next;
62 }
63 last->next = newelem;
64
65 return EXIT_SUCCESS;
66 }
else {
67 return EXIT_FAILURE;
68 }
69 }
else {
70 suite->tests = (UcxTestList*) malloc(
sizeof(UcxTestList));
71 if (suite->tests) {
72 suite->tests->test = test;
73 suite->tests->next =
NULL;
74
75 return EXIT_SUCCESS;
76 }
else {
77 return EXIT_FAILURE;
78 }
79 }
80 }
81
82 void ucx_test_run(UcxTestSuite* suite,
FILE* output) {
83 suite->success =
0;
84 suite->failure =
0;
85 for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) {
86 elem->test(suite, output);
87 }
88 fwrite(
"\nAll test completed.\n",
1,
21, output);
89 fprintf(output,
" Total: %u\n Success: %u\n Failure: %u\n",
90 suite->success+suite->failure, suite->success, suite->failure);
91 }
92