1.1 --- a/test/list_tests.c Mon Jul 22 11:53:39 2013 +0200 1.2 +++ b/test/list_tests.c Mon Jul 22 13:45:49 2013 +0200 1.3 @@ -99,12 +99,13 @@ 1.4 1.5 UCX_TEST_IMPLEMENT(test_ucx_list_size) { 1.6 UcxList *list = ucx_list_append(NULL, (void*)"This "); 1.7 - UCX_TEST_BEGIN 1.8 list = ucx_list_append(list, (void*)"list "); 1.9 list = ucx_list_append(list, (void*)"has "); 1.10 list = ucx_list_append(list, (void*)"size "); 1.11 list = ucx_list_append(list, (void*)"5!"); 1.12 1.13 + UCX_TEST_BEGIN 1.14 + 1.15 UCX_TEST_ASSERT(ucx_list_size(list) == 5, "failed"); 1.16 1.17 UCX_TEST_END 1.18 @@ -113,10 +114,11 @@ 1.19 1.20 UCX_TEST_IMPLEMENT(test_ucx_list_first) { 1.21 UcxList *list = ucx_list_append(NULL, (void*)"Find "); 1.22 - UCX_TEST_BEGIN 1.23 list = ucx_list_append(list, (void*)"the "); 1.24 list = ucx_list_append(list, (void*)"first!"); 1.25 1.26 + UCX_TEST_BEGIN 1.27 + 1.28 const char* first = (const char*) (ucx_list_first(list)->data); 1.29 1.30 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed"); 1.31 @@ -127,10 +129,11 @@ 1.32 1.33 UCX_TEST_IMPLEMENT(test_ucx_list_last) { 1.34 UcxList *list = ucx_list_append(NULL, (void*)"Find "); 1.35 - UCX_TEST_BEGIN 1.36 list = ucx_list_append(list, (void*)"the "); 1.37 list = ucx_list_append(list, (void*)"last!"); 1.38 1.39 + UCX_TEST_BEGIN 1.40 + 1.41 const char* last = (const char*) (ucx_list_last(list)->data); 1.42 1.43 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); 1.44 @@ -141,10 +144,11 @@ 1.45 1.46 UCX_TEST_IMPLEMENT(test_ucx_list_get) { 1.47 UcxList *list = ucx_list_append(NULL, (void*)"Find "); 1.48 - UCX_TEST_BEGIN 1.49 list = ucx_list_append(list, (void*)"the "); 1.50 list = ucx_list_append(list, (void*)"mid!"); 1.51 1.52 + UCX_TEST_BEGIN 1.53 + 1.54 const char* mid = (const char*) (ucx_list_get(list, 1)->data); 1.55 1.56 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); 1.57 @@ -153,14 +157,53 @@ 1.58 ucx_list_free(list); 1.59 } 1.60 1.61 +UCX_TEST_IMPLEMENT(test_ucx_list_indexof) { 1.62 + UcxList *list = ucx_list_append(NULL, (void*)"Find "); 1.63 + list = ucx_list_append(list, (void*)"the "); 1.64 + list = ucx_list_append(list, (void*)"mid!"); 1.65 + 1.66 + UCX_TEST_BEGIN 1.67 + 1.68 + UCX_TEST_ASSERT(ucx_list_indexof(list, list) == 0, "failed"); 1.69 + UCX_TEST_ASSERT(ucx_list_indexof(list, list->next) == 1, "failed"); 1.70 + UCX_TEST_ASSERT(ucx_list_indexof(list, ucx_list_get(list, 2)) == 2, 1.71 + "failed"); 1.72 + 1.73 + UcxList *otherlist = ucx_list_append(NULL, (void*) "foobar"); 1.74 + UCX_TEST_ASSERT(ucx_list_indexof(list, otherlist) == -1, "failed"); 1.75 + ucx_list_free(otherlist); 1.76 + 1.77 + UCX_TEST_END 1.78 + ucx_list_free(list); 1.79 +} 1.80 + 1.81 +UCX_TEST_IMPLEMENT(test_ucx_list_find) { 1.82 + UcxList *l = ucx_list_append(NULL, (void*)"find "); 1.83 + l = ucx_list_append(l, (void*)"some "); 1.84 + l = ucx_list_append(l, (void*)"string!"); 1.85 + 1.86 + UCX_TEST_BEGIN 1.87 + 1.88 + UCX_TEST_ASSERT(ucx_list_find(l,(void*)"some ",ucx_strcmp,NULL) == 1, 1.89 + "doesn't find string"); 1.90 + UCX_TEST_ASSERT(ucx_list_find(l,(void*)"a",ucx_strcmp,NULL) == -1, 1.91 + "finds non-existing string"); 1.92 + 1.93 + UCX_TEST_END 1.94 + ucx_list_free(l); 1.95 +} 1.96 + 1.97 UCX_TEST_IMPLEMENT(test_ucx_list_contains) { 1.98 UcxList *l = ucx_list_append(NULL, (void*)"Contains "); 1.99 - UCX_TEST_BEGIN 1.100 l = ucx_list_append(l, (void*)"a "); 1.101 l = ucx_list_append(l, (void*)"string!"); 1.102 1.103 - UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL),"failed"); 1.104 - UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL),"failed"); 1.105 + UCX_TEST_BEGIN 1.106 + 1.107 + UCX_TEST_ASSERT(ucx_list_contains(l,(void*)"a ",ucx_strcmp,NULL), 1.108 + "false negative"); 1.109 + UCX_TEST_ASSERT(!ucx_list_contains(l,(void*)"a",ucx_strcmp,NULL), 1.110 + "false positive"); 1.111 1.112 UCX_TEST_END 1.113 ucx_list_free(l); 1.114 @@ -168,10 +211,11 @@ 1.115 1.116 UCX_TEST_IMPLEMENT(test_ucx_list_remove) { 1.117 UcxList *list = ucx_list_append(NULL, (void*)"Hello"); 1.118 - UCX_TEST_BEGIN 1.119 list = ucx_list_append(list, (void*)" fucking"); 1.120 list = ucx_list_append(list, (void*)" World!"); 1.121 1.122 + UCX_TEST_BEGIN 1.123 + 1.124 list = ucx_list_remove(list, ucx_list_get(list, 1)); 1.125 1.126 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,