test/dlist_tests.c

changeset 89
47f7fdbddb62
parent 71
303dabadff1c
child 90
ef3163857e88
equal deleted inserted replaced
88:18823857ce79 89:47f7fdbddb62
1 /* 1 /*
2 * tests of dlist implementation 2 * tests of dlist implementation
3 */ 3 */
4 4
5 #include "dlist_tests.h" 5 #include "dlist_tests.h"
6 #include "ucx/comparator.h"
6 7
7 UCX_TEST_IMPLEMENT(test_ucx_dlist_append) { 8 UCX_TEST_IMPLEMENT(test_ucx_dlist_append) {
8 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); 9 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello");
9 UCX_TEST_BEGIN 10 UCX_TEST_BEGIN
10 11
44 list2 = ucx_dlist_prepend(list2, (void*)"Hello"); 45 list2 = ucx_dlist_prepend(list2, (void*)"Hello");
45 UcxDlist *list3 = ucx_dlist_prepend(NULL, (void*)" Welt!"); 46 UcxDlist *list3 = ucx_dlist_prepend(NULL, (void*)" Welt!");
46 list3 = ucx_dlist_prepend(list3, (void*)"Hallo"); 47 list3 = ucx_dlist_prepend(list3, (void*)"Hallo");
47 UCX_TEST_BEGIN 48 UCX_TEST_BEGIN
48 49
49 UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, cmp_string, NULL), "failed"); 50 UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, ucx_strcmp, NULL), "failed");
50 UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, cmp_string, NULL), "failed"); 51 UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, ucx_strcmp, NULL), "failed");
51 52
52 UCX_TEST_END 53 UCX_TEST_END
53 ucx_dlist_free(list3); 54 ucx_dlist_free(list3);
54 ucx_dlist_free(list2); 55 ucx_dlist_free(list2);
55 ucx_dlist_free(list); 56 ucx_dlist_free(list);
158 list = ucx_dlist_append(list, world); 159 list = ucx_dlist_append(list, world);
159 160
160 UcxDlist *copy = ucx_dlist_clone(list, copy_string, NULL); 161 UcxDlist *copy = ucx_dlist_clone(list, copy_string, NULL);
161 UCX_TEST_BEGIN 162 UCX_TEST_BEGIN
162 163
163 UCX_TEST_ASSERT(ucx_dlist_equals(list, copy, cmp_string, NULL), "failed"); 164 UCX_TEST_ASSERT(ucx_dlist_equals(list, copy, ucx_strcmp, NULL), "failed");
164 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy"); 165 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
165 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy"); 166 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
166 167
167 UCX_TEST_END 168 UCX_TEST_END
168 free(copy->next->data); 169 free(copy->next->data);
189 expected = ucx_dlist_append(expected, (void*)"is"); 190 expected = ucx_dlist_append(expected, (void*)"is");
190 expected = ucx_dlist_append(expected, (void*)"partial"); 191 expected = ucx_dlist_append(expected, (void*)"partial");
191 expected = ucx_dlist_append(expected, (void*)"test"); 192 expected = ucx_dlist_append(expected, (void*)"test");
192 expected = ucx_dlist_append(expected, (void*)"this"); 193 expected = ucx_dlist_append(expected, (void*)"this");
193 194
194 list = ucx_dlist_sort(list, cmp_string, NULL); 195 list = ucx_dlist_sort(list, ucx_strcmp, NULL);
195 196
196 UCX_TEST_BEGIN 197 UCX_TEST_BEGIN
197 UCX_TEST_ASSERT( 198 UCX_TEST_ASSERT(
198 ucx_dlist_equals(list, expected, cmp_string, NULL), "failed"); 199 ucx_dlist_equals(list, expected, ucx_strcmp, NULL), "failed");
199 UcxDlist *l = list; 200 UcxDlist *l = list;
200 UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null"); 201 UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null");
201 while (l->next != NULL) { 202 while (l->next != NULL) {
202 UCX_TEST_ASSERT(l->next->prev == l, "prev pointer corrupted"); 203 UCX_TEST_ASSERT(l->next->prev == l, "prev pointer corrupted");
203 l = l->next; 204 l = l->next;

mercurial