--- a/test/list_tests.c Thu Apr 10 11:18:12 2014 +0200 +++ b/test/list_tests.c Thu Apr 10 11:32:59 2014 +0200 @@ -211,8 +211,16 @@ UCX_TEST(test_ucx_list_remove) { UcxList *list = ucx_list_append(NULL, (void*)"Hello"); - list = ucx_list_append(list, (void*)" fucking"); - list = ucx_list_append(list, (void*)" World!"); + list = ucx_list_append(list, (void*)"fucking"); + list = ucx_list_append(list, (void*)"World!"); + + UcxList *list2 = ucx_list_append(NULL, (void*)"A"); + list2 = ucx_list_append(list2, (void*)"B"); + list2 = ucx_list_append(list2, (void*)"C"); + list2 = ucx_list_append(list2, (void*)"D"); + list2 = ucx_list_append(list2, (void*)"E"); + list2 = ucx_list_append(list2, (void*)"F"); + list2 = ucx_list_append(list2, (void*)"G"); UCX_TEST_BEGIN @@ -220,10 +228,49 @@ UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, "failed"); - UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, + UCX_TEST_ASSERT(strncmp((const char*)list->next->data, "World!", 7) == 0, "failed"); UCX_TEST_ASSERT(list->next->next == NULL, "failed"); + // remove first element: B, C, D, E, F, G + list2 = ucx_list_remove(list2, list2); + + UCX_TEST_ASSERT(ucx_list_size(list2) == 6, "list2 has wrong size"); + UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0, + "wrong first element"); + UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 5)->data, "G", 1) + == 0, "wrong last element"); + + // remove second element: B, D, E, F, G + list2 = ucx_list_remove(list2, list2->next); + + UCX_TEST_ASSERT(ucx_list_size(list2) == 5, "list2 has wrong size"); + UCX_TEST_ASSERT(strncmp((const char*)list2->next->data, "D", 1) == 0, + "wrong second element"); + + UcxList *last = ucx_list_get(list2, 4); + list2 = ucx_list_remove(list2, last->prev); + + UCX_TEST_ASSERT(ucx_list_size(list2) == 4, "list2 has wrong size"); + UCX_TEST_ASSERT(strncmp((const char*)last->prev->data, "E", 1) == 0, + "wrong element"); + + // remove last element: B, D, E, F + list2 = ucx_list_remove(list2, last); + UCX_TEST_ASSERT(ucx_list_size(list2) == 3, "list2 has wrong size"); + UCX_TEST_ASSERT(strncmp((const char*)ucx_list_get(list2, 2)->data, "E", 1) + == 0, "wrong last element"); + + UCX_TEST_ASSERT(strncmp((const char*)list2->data, "B", 1) == 0, + "wrong element"); + + list2 = ucx_list_remove(list2, list2); + UCX_TEST_ASSERT(ucx_list_size(list2) == 2, "list2 has wrong size"); + list2 = ucx_list_remove(list2, list2); + UCX_TEST_ASSERT(ucx_list_size(list2) == 1, "list2 has wrong size"); + list2 = ucx_list_remove(list2, list2); + UCX_TEST_ASSERT(list2 == NULL, "list2 is not null"); + UCX_TEST_END ucx_list_free(list); }