16 } |
16 } |
17 return suite; |
17 return suite; |
18 } |
18 } |
19 |
19 |
20 void ucx_test_suite_free(UcxTestSuite* suite) { |
20 void ucx_test_suite_free(UcxTestSuite* suite) { |
21 ucx_list_free(suite->tests); |
21 UcxTestList *l = suite->tests; |
|
22 while (l != NULL) { |
|
23 UcxTestList *e = l; |
|
24 l = l->next; |
|
25 free(e); |
|
26 } |
22 free(suite); |
27 free(suite); |
23 } |
28 } |
24 |
29 |
25 void ucx_test_register(UcxTestSuite* suite, UcxTest test) { |
30 int ucx_test_register(UcxTestSuite* suite, UcxTest test) { |
26 suite->tests = ucx_list_append(suite->tests, (void*) test); |
31 if (suite->tests) { |
|
32 UcxTestList *list = (UcxTestList*) malloc(sizeof(UcxTestList)); |
|
33 if (list) { |
|
34 list->test = test; |
|
35 list->next = suite->tests; |
|
36 suite->tests = list; |
|
37 |
|
38 return EXIT_SUCCESS; |
|
39 } else { |
|
40 return EXIT_FAILURE; |
|
41 } |
|
42 } else { |
|
43 suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList)); |
|
44 if (suite->tests) { |
|
45 suite->tests->test = test; |
|
46 suite->tests->next = NULL; |
|
47 |
|
48 return EXIT_SUCCESS; |
|
49 } else { |
|
50 return EXIT_FAILURE; |
|
51 } |
|
52 } |
27 } |
53 } |
28 |
54 |
29 void ucx_test_run(UcxTestSuite* suite, FILE* output) { |
55 void ucx_test_run(UcxTestSuite* suite, FILE* output) { |
30 suite->success = 0; |
56 suite->success = 0; |
31 suite->failure = 0; |
57 suite->failure = 0; |
32 UCX_FOREACH (UcxList*, suite->tests, e) { |
58 UCX_FOREACH (UcxTestList*, suite->tests, e) { |
33 UcxTest test = (UcxTest) (e->data); |
59 e->test(suite, output); |
34 test(suite, output); |
|
35 } |
60 } |
36 fwrite("\nAll test completed.\n", 1, 21, output); |
61 fwrite("\nAll test completed.\n", 1, 21, output); |
37 fprintf(output, " Total: %d\n Success: %d\n Failure: %d\n", |
62 fprintf(output, " Total: %d\n Success: %d\n Failure: %d\n", |
38 suite->success+suite->failure, suite->success, suite->failure); |
63 suite->success+suite->failure, suite->success, suite->failure); |
39 } |
64 } |