test/main.c

changeset 27
22644e2572bc
parent 26
59f147baea31
child 28
1666cbeb1db8
equal deleted inserted replaced
26:59f147baea31 27:22644e2572bc
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include "ucx/test.h" 32 #include "ucx/test.h"
33 33
34 #include "main.h"
35
34 #include "list_tests.h" 36 #include "list_tests.h"
37 #include "dlist_tests.h"
38
35 #include "mpool_tests.h" 39 #include "mpool_tests.h"
36 #include "map_tests.h" 40 #include "map_tests.h"
41
42 int cmp_string(void* o1, void* o2, void* data) {
43 return strcmp((char*)o1, (char*)o2);
44 }
45
46 void* copy_string(void* e, void* data) {
47 char *str = (char*) e;
48 size_t n = 1+strlen(str);
49 char *cpy = (char*) malloc(n);
50 memcpy(cpy, str, n);
51 return cpy;
52 }
37 53
38 UCX_TEST_BEGIN(testTestSuitePositive) { 54 UCX_TEST_BEGIN(testTestSuitePositive) {
39 UCX_TEST_ASSERT(2*2 == 4, "the test framework fails") 55 UCX_TEST_ASSERT(2*2 == 4, "the test framework fails")
40 UCX_TEST_END 56 UCX_TEST_END
41 } 57 }
46 } 62 }
47 63
48 int main(int argc, char **argv) { 64 int main(int argc, char **argv) {
49 printf("UCX Tests\n---------\n"); 65 printf("UCX Tests\n---------\n");
50 66
51 printf("\nUcxTestSuite Tests\n"); 67 printf("\nUcxTestSuite Tests (1 failure is intended!)\n");
52 UcxTestSuite* suite = ucx_test_suite_new(); 68 UcxTestSuite* suite = ucx_test_suite_new();
53 ucx_test_register(suite, testTestSuitePositive); 69 ucx_test_register(suite, testTestSuitePositive);
54 ucx_test_register(suite, testTestSuiteNegative); 70 ucx_test_register(suite, testTestSuiteNegative);
55 ucx_test_run(suite, stdout); 71 ucx_test_run(suite, stdout);
56 if (suite->failure == 1 && suite->success == 1) { 72 if (suite->failure == 1 && suite->success == 1) {
57 ucx_test_suite_free(suite); 73 ucx_test_suite_free(suite);
58 74
75 suite = ucx_test_suite_new();
76 /* UcxList Tests */
77 ucx_test_register(suite, test_ucx_list_append);
78 ucx_test_register(suite, test_ucx_list_prepend);
79 ucx_test_register(suite, test_ucx_list_equals);
80 ucx_test_register(suite, test_ucx_list_concat);
81 ucx_test_register(suite, test_ucx_list_size);
82 ucx_test_register(suite, test_ucx_list_last);
83 ucx_test_register(suite, test_ucx_list_get);
84 ucx_test_register(suite, test_ucx_list_remove);
85 ucx_test_register(suite, test_ucx_list_clone);
86
87 /* UcxDlist Tests */
88 ucx_test_register(suite, test_ucx_dlist_append);
89 ucx_test_register(suite, test_ucx_dlist_prepend);
90 ucx_test_register(suite, test_ucx_dlist_equals);
91 ucx_test_register(suite, test_ucx_dlist_concat);
92 ucx_test_register(suite, test_ucx_dlist_size);
93 ucx_test_register(suite, test_ucx_dlist_first);
94 ucx_test_register(suite, test_ucx_dlist_last);
95 ucx_test_register(suite, test_ucx_dlist_get);
96 ucx_test_register(suite, test_ucx_dlist_remove);
97 ucx_test_register(suite, test_ucx_dlist_clone);
98
59 /* TODO: replace these tests with "real" tests */ 99 /* TODO: replace these tests with "real" tests */
60 printf("\nUcxDlist Tests\n");
61 if(dlist_tests()) {
62 fprintf(stderr, "dlist_tests failed\n");
63 }
64
65 printf("\nUcxList Tests\n Assumed to be correct\n");
66
67 printf("\nUcxMemPool Tests\n"); 100 printf("\nUcxMemPool Tests\n");
68 if(mpool_tests()) { 101 if(mpool_tests()) {
69 fprintf(stderr, "mpool_tests failed\n"); 102 fprintf(stderr, "mpool_tests failed\n");
70 } 103 }
71 104
72 printf("\nUcxMap Tests\n"); 105 printf("\nUcxMap Tests\n");
73 if(map_tests()) { 106 if(map_tests()) {
74 fprintf(stderr, "map_tests failed\n"); 107 fprintf(stderr, "map_tests failed\n");
75 } 108 }
76 109
110 ucx_test_run(suite, stdout);
111 ucx_test_suite_free(suite);
112
77 return EXIT_SUCCESS; 113 return EXIT_SUCCESS;
78 } else { 114 } else {
79 ucx_test_suite_free(suite); 115 ucx_test_suite_free(suite);
80 return EXIT_FAILURE; 116 return EXIT_FAILURE;
81 } 117 }

mercurial