test/list_tests.c

changeset 89
47f7fdbddb62
parent 71
303dabadff1c
child 90
ef3163857e88
equal deleted inserted replaced
88:18823857ce79 89:47f7fdbddb62
1 /* 1 /*
2 * tests of list implementation 2 * tests of list implementation
3 */ 3 */
4 4
5 #include "list_tests.h" 5 #include "list_tests.h"
6 #include "ucx/comparator.h"
6 7
7 UCX_TEST_IMPLEMENT(test_ucx_list_append) { 8 UCX_TEST_IMPLEMENT(test_ucx_list_append) {
8 UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 9 UcxList *list = ucx_list_append(NULL, (void*)"Hello");
9 UCX_TEST_BEGIN 10 UCX_TEST_BEGIN
10 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 11 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
42 list2 = ucx_list_prepend(list2, (void*)"Hello"); 43 list2 = ucx_list_prepend(list2, (void*)"Hello");
43 UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!"); 44 UcxList *list3 = ucx_list_prepend(NULL, (void*)" Welt!");
44 list3 = ucx_list_prepend(list3, (void*)"Hallo"); 45 list3 = ucx_list_prepend(list3, (void*)"Hallo");
45 46
46 UCX_TEST_BEGIN 47 UCX_TEST_BEGIN
47 UCX_TEST_ASSERT(ucx_list_equals(list, list2, cmp_string, NULL), "failed"); 48 UCX_TEST_ASSERT(ucx_list_equals(list, list2, ucx_strcmp, NULL), "failed");
48 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, cmp_string, NULL), "failed"); 49 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_strcmp, NULL), "failed");
49 UCX_TEST_END 50 UCX_TEST_END
50 51
51 ucx_list_free(list3); 52 ucx_list_free(list3);
52 ucx_list_free(list2); 53 ucx_list_free(list2);
53 ucx_list_free(list); 54 ucx_list_free(list);
146 list = ucx_list_append(list, world); 147 list = ucx_list_append(list, world);
147 148
148 UcxList *copy = ucx_list_clone(list, copy_string, NULL); 149 UcxList *copy = ucx_list_clone(list, copy_string, NULL);
149 UCX_TEST_BEGIN 150 UCX_TEST_BEGIN
150 151
151 UCX_TEST_ASSERT(ucx_list_equals(list, copy, cmp_string, NULL), "failed"); 152 UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_strcmp, NULL), "failed");
152 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy"); 153 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
153 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy"); 154 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
154 155
155 UCX_TEST_END 156 UCX_TEST_END
156 free(copy->next->data); 157 free(copy->next->data);
177 expected = ucx_list_append(expected, (void*)"is"); 178 expected = ucx_list_append(expected, (void*)"is");
178 expected = ucx_list_append(expected, (void*)"partial"); 179 expected = ucx_list_append(expected, (void*)"partial");
179 expected = ucx_list_append(expected, (void*)"test"); 180 expected = ucx_list_append(expected, (void*)"test");
180 expected = ucx_list_append(expected, (void*)"this"); 181 expected = ucx_list_append(expected, (void*)"this");
181 182
182 list = ucx_list_sort(list, cmp_string, NULL); 183 list = ucx_list_sort(list, ucx_strcmp, NULL);
183 184
184 UCX_TEST_BEGIN 185 UCX_TEST_BEGIN
185 UCX_TEST_ASSERT( 186 UCX_TEST_ASSERT(
186 ucx_list_equals(list, expected, cmp_string, NULL), "failed"); 187 ucx_list_equals(list, expected, ucx_strcmp, NULL), "failed");
187 UCX_TEST_END 188 UCX_TEST_END
188 189
189 ucx_list_free(expected); 190 ucx_list_free(expected);
190 ucx_list_free(list); 191 ucx_list_free(list);
191 } 192 }

mercurial