test/list_tests.c

changeset 308
d6f580621512
parent 259
2f5dea574a75
child 323
b8c49e7a1dba
equal deleted inserted replaced
306:90b6d69bb499 308:d6f580621512
68 ucx_list_free(list); 68 ucx_list_free(list);
69 } 69 }
70 70
71 UCX_TEST(test_ucx_list_append_once) { 71 UCX_TEST(test_ucx_list_append_once) {
72 UcxList *list, *first; 72 UcxList *list, *first;
73 list = first = ucx_list_append_once(NULL, (void*)"Hello", ucx_strcmp, NULL); 73 list = first = ucx_list_append_once(NULL, (void*)"Hello", ucx_cmp_str, NULL);
74 UCX_TEST_BEGIN 74 UCX_TEST_BEGIN
75 75
76 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, 76 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
77 "failed"); 77 "failed");
78 78
79 list = ucx_list_append_once(list, (void*)"Hello", ucx_strcmp, NULL); 79 list = ucx_list_append_once(list, (void*)"Hello", ucx_cmp_str, NULL);
80 list = ucx_list_append_once(list, (void*)" World!", ucx_strcmp, NULL); 80 list = ucx_list_append_once(list, (void*)" World!", ucx_cmp_str, NULL);
81 81
82 UCX_TEST_ASSERT(list == first, "does not return first element"); 82 UCX_TEST_ASSERT(list == first, "does not return first element");
83 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, 83 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
84 "'Hello' was not inserted _once_"); 84 "'Hello' was not inserted _once_");
85 UCX_TEST_ASSERT(list->next->prev == list, "failed"); 85 UCX_TEST_ASSERT(list->next->prev == list, "failed");
100 list3 = ucx_list_prepend(list3, (void*)"Hallo"); 100 list3 = ucx_list_prepend(list3, (void*)"Hallo");
101 UcxList *list4 = ucx_list_prepend(NULL, (void*)" World!"); 101 UcxList *list4 = ucx_list_prepend(NULL, (void*)" World!");
102 list4 = ucx_list_prepend(list4, (void*)"Hello"); 102 list4 = ucx_list_prepend(list4, (void*)"Hello");
103 UCX_TEST_BEGIN 103 UCX_TEST_BEGIN
104 104
105 UCX_TEST_ASSERT(ucx_list_equals(list, list4, ucx_strcmp, NULL), "failed"); 105 UCX_TEST_ASSERT(ucx_list_equals(list, list4, ucx_cmp_str, NULL), "failed");
106 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_strcmp, NULL), "failed"); 106 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, ucx_cmp_str, NULL), "failed");
107 UCX_TEST_ASSERT(ucx_list_equals(list, list2, NULL, NULL), "failed"); 107 UCX_TEST_ASSERT(ucx_list_equals(list, list2, NULL, NULL), "failed");
108 108
109 UCX_TEST_END 109 UCX_TEST_END
110 ucx_list_free(list4); 110 ucx_list_free(list4);
111 ucx_list_free(list3); 111 ucx_list_free(list3);
243 l = ucx_list_append(l, (void*)"some "); 243 l = ucx_list_append(l, (void*)"some ");
244 l = ucx_list_append(l, (void*)teststr); 244 l = ucx_list_append(l, (void*)teststr);
245 245
246 UCX_TEST_BEGIN 246 UCX_TEST_BEGIN
247 247
248 UCX_TEST_ASSERT(ucx_list_find(l,(void*)"some ",ucx_strcmp,NULL) == 1, 248 UCX_TEST_ASSERT(ucx_list_find(l,(void*)"some ",ucx_cmp_str,NULL) == 1,
249 "doesn't find string"); 249 "doesn't find string");
250 UCX_TEST_ASSERT(ucx_list_find(l,(void*)"a",ucx_strcmp,NULL) == -1, 250 UCX_TEST_ASSERT(ucx_list_find(l,(void*)"a",ucx_cmp_str,NULL) == -1,
251 "finds non-existing string"); 251 "finds non-existing string");
252 252
253 UCX_TEST_ASSERT(ucx_list_find(l,(void*)teststr,NULL,NULL) == 2, 253 UCX_TEST_ASSERT(ucx_list_find(l,(void*)teststr,NULL,NULL) == 2,
254 "doesn't find integer without cmp_func"); 254 "doesn't find integer without cmp_func");
255 255
256 UCX_TEST_ASSERT(ucx_list_find(NULL, (void*)"some ",ucx_strcmp,NULL) == -1, 256 UCX_TEST_ASSERT(ucx_list_find(NULL, (void*)"some ",ucx_cmp_str,NULL) == -1,
257 "empty list"); 257 "empty list");
258 258
259 UCX_TEST_END 259 UCX_TEST_END
260 ucx_list_free(l); 260 ucx_list_free(l);
261 } 261 }
265 l = ucx_list_append(l, (void*)"a "); 265 l = ucx_list_append(l, (void*)"a ");
266 l = ucx_list_append(l, (void*)"string!"); 266 l = ucx_list_append(l, (void*)"string!");
267 267
268 UCX_TEST_BEGIN 268 UCX_TEST_BEGIN
269 269
270 UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL), 270 UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_cmp_str,NULL),
271 "false negative"); 271 "false negative");
272 UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL), 272 UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_cmp_str,NULL),
273 "false positive"); 273 "false positive");
274 274
275 UCX_TEST_END 275 UCX_TEST_END
276 ucx_list_free(l); 276 ucx_list_free(l);
277 } 277 }
354 list = ucx_list_append(list, world); 354 list = ucx_list_append(list, world);
355 355
356 UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL); 356 UcxList *copy = ucx_list_clone(list, ucx_strcpy, NULL);
357 UCX_TEST_BEGIN 357 UCX_TEST_BEGIN
358 358
359 UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_strcmp, NULL), "failed"); 359 UCX_TEST_ASSERT(ucx_list_equals(list, copy, ucx_cmp_str, NULL), "failed");
360 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy"); 360 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
361 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy"); 361 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
362 362
363 UCX_TEST_END 363 UCX_TEST_END
364 364
403 expected = ucx_list_append(expected, (void*)"that"); 403 expected = ucx_list_append(expected, (void*)"that");
404 expected = ucx_list_append(expected, (void*)"the"); 404 expected = ucx_list_append(expected, (void*)"the");
405 expected = ucx_list_append(expected, (void*)"this"); 405 expected = ucx_list_append(expected, (void*)"this");
406 expected = ucx_list_append(expected, (void*)"this"); 406 expected = ucx_list_append(expected, (void*)"this");
407 407
408 list = ucx_list_sort(list, ucx_strcmp, NULL); 408 list = ucx_list_sort(list, ucx_cmp_str, NULL);
409 409
410 UCX_TEST_BEGIN 410 UCX_TEST_BEGIN
411 UCX_TEST_ASSERT( 411 UCX_TEST_ASSERT(
412 ucx_list_equals(list, expected, ucx_strcmp, NULL), "failed"); 412 ucx_list_equals(list, expected, ucx_cmp_str, NULL), "failed");
413 UCX_TEST_ASSERT(ucx_list_size(list) == 16, "list has now a wrong size"); 413 UCX_TEST_ASSERT(ucx_list_size(list) == 16, "list has now a wrong size");
414 UcxList *l = list; 414 UcxList *l = list;
415 UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null"); 415 UCX_TEST_ASSERT(l->prev == NULL, "prev field of first entry is not null");
416 while (l->next != NULL) { 416 while (l->next != NULL) {
417 UCX_TEST_ASSERT(l->next->prev == l, "next or prev pointer corrupted"); 417 UCX_TEST_ASSERT(l->next->prev == l, "next or prev pointer corrupted");
418 l = l->next; 418 l = l->next;
419 } 419 }
420 UCX_TEST_ASSERT(!ucx_list_sort(NULL, ucx_strcmp, NULL), 420 UCX_TEST_ASSERT(!ucx_list_sort(NULL, ucx_cmp_str, NULL),
421 "failed to sort empty list"); 421 "failed to sort empty list");
422 UCX_TEST_END 422 UCX_TEST_END
423 423
424 ucx_list_free(expected); 424 ucx_list_free(expected);
425 ucx_list_free(list); 425 ucx_list_free(list);

mercurial