--- a/test/list_tests.c Mon Jul 22 11:53:39 2013 +0200 +++ b/test/list_tests.c Mon Jul 22 13:45:49 2013 +0200 @@ -99,12 +99,13 @@ UCX_TEST_IMPLEMENT(test_ucx_list_size) { UcxList *list = ucx_list_append(NULL, (void*)"This "); - UCX_TEST_BEGIN list = ucx_list_append(list, (void*)"list "); list = ucx_list_append(list, (void*)"has "); list = ucx_list_append(list, (void*)"size "); list = ucx_list_append(list, (void*)"5!"); + UCX_TEST_BEGIN + UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed"); UCX_TEST_END @@ -113,10 +114,11 @@ UCX_TEST_IMPLEMENT(test_ucx_list_first) { UcxList *list = ucx_list_append(NULL, (void*)"Find "); - UCX_TEST_BEGIN list = ucx_list_append(list, (void*)"the "); list = ucx_list_append(list, (void*)"first!"); + UCX_TEST_BEGIN + const char* first = (const char*) (ucx_list_first(list)->data); UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed"); @@ -127,10 +129,11 @@ UCX_TEST_IMPLEMENT(test_ucx_list_last) { UcxList *list = ucx_list_append(NULL, (void*)"Find "); - UCX_TEST_BEGIN list = ucx_list_append(list, (void*)"the "); list = ucx_list_append(list, (void*)"last!"); + UCX_TEST_BEGIN + const char* last = (const char*) (ucx_list_last(list)->data); UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); @@ -141,10 +144,11 @@ UCX_TEST_IMPLEMENT(test_ucx_list_get) { UcxList *list = ucx_list_append(NULL, (void*)"Find "); - UCX_TEST_BEGIN list = ucx_list_append(list, (void*)"the "); list = ucx_list_append(list, (void*)"mid!"); + UCX_TEST_BEGIN + const char* mid = (const char*) (ucx_list_get(list, 1)->data); UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); @@ -153,14 +157,53 @@ ucx_list_free(list); } +UCX_TEST_IMPLEMENT(test_ucx_list_indexof) { + UcxList *list = ucx_list_append(NULL, (void*)"Find "); + list = ucx_list_append(list, (void*)"the "); + list = ucx_list_append(list, (void*)"mid!"); + + UCX_TEST_BEGIN + + UCX_TEST_ASSERT(ucx_list_indexof(list, list) == 0, "failed"); + UCX_TEST_ASSERT(ucx_list_indexof(list, list->next) == 1, "failed"); + UCX_TEST_ASSERT(ucx_list_indexof(list, ucx_list_get(list, 2)) == 2, + "failed"); + + UcxList *otherlist = ucx_list_append(NULL, (void*) "foobar"); + UCX_TEST_ASSERT(ucx_list_indexof(list, otherlist) == -1, "failed"); + ucx_list_free(otherlist); + + UCX_TEST_END + ucx_list_free(list); +} + +UCX_TEST_IMPLEMENT(test_ucx_list_find) { + UcxList *l = ucx_list_append(NULL, (void*)"find "); + l = ucx_list_append(l, (void*)"some "); + l = ucx_list_append(l, (void*)"string!"); + + UCX_TEST_BEGIN + + UCX_TEST_ASSERT(ucx_list_find(l,(void*)"some ",ucx_strcmp,NULL) == 1, + "doesn't find string"); + UCX_TEST_ASSERT(ucx_list_find(l,(void*)"a",ucx_strcmp,NULL) == -1, + "finds non-existing string"); + + UCX_TEST_END + ucx_list_free(l); +} + UCX_TEST_IMPLEMENT(test_ucx_list_contains) { UcxList *l = ucx_list_append(NULL, (void*)"Contains "); - UCX_TEST_BEGIN l = ucx_list_append(l, (void*)"a "); l = ucx_list_append(l, (void*)"string!"); - UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL),"failed"); - UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL),"failed"); + UCX_TEST_BEGIN + + UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL), + "false negative"); + UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL), + "false positive"); UCX_TEST_END ucx_list_free(l); @@ -168,10 +211,11 @@ UCX_TEST_IMPLEMENT(test_ucx_list_remove) { UcxList *list = ucx_list_append(NULL, (void*)"Hello"); - UCX_TEST_BEGIN list = ucx_list_append(list, (void*)" fucking"); list = ucx_list_append(list, (void*)" World!"); + UCX_TEST_BEGIN + list = ucx_list_remove(list, ucx_list_get(list, 1)); UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,