test/list_tests.c

changeset 228
9f385abc72fb
parent 225
a1a068c2c4ef
child 229
9db71925eaa8
     1.1 --- a/test/list_tests.c	Thu Oct 13 16:25:21 2016 +0200
     1.2 +++ b/test/list_tests.c	Fri Nov 18 15:17:04 2016 +0100
     1.3 @@ -68,6 +68,49 @@
     1.4      ucx_list_free(list);
     1.5  }
     1.6  
     1.7 +UCX_TEST(test_ucx_list_append_once) {
     1.8 +    UcxList *list, *first;
     1.9 +    list = first = ucx_list_append_once(NULL, (void*)"Hello", ucx_strcmp, NULL);
    1.10 +    UCX_TEST_BEGIN
    1.11 +    
    1.12 +    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    1.13 +            "failed");
    1.14 +    
    1.15 +    list = ucx_list_append_once(list, (void*)"Hello", ucx_strcmp, NULL);
    1.16 +    list = ucx_list_append_once(list, (void*)" World!", ucx_strcmp, NULL);
    1.17 +    
    1.18 +    UCX_TEST_ASSERT(list == first, "does not return first element");
    1.19 +    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    1.20 +            "'Hello' was not inserted _once_");
    1.21 +    UCX_TEST_ASSERT(list->next->prev == list, "failed");
    1.22 +    UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
    1.23 +    UCX_TEST_END
    1.24 +    
    1.25 +    ucx_list_free(list);
    1.26 +}
    1.27 +
    1.28 +UCX_TEST(test_ucx_list_prepend_once) {
    1.29 +    UcxList *list, *last, *first;
    1.30 +    list = last = ucx_list_prepend_once(NULL, (void*)" World!",
    1.31 +            ucx_strcmp, NULL);
    1.32 +    UCX_TEST_BEGIN
    1.33 +
    1.34 +    list = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
    1.35 +    first = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
    1.36 +    
    1.37 +    UCX_TEST_ASSERT(list == first, "'Hello' was not prepended _once_");
    1.38 +    UCX_TEST_ASSERT(first == last->prev, "does not return first element");
    1.39 +    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
    1.40 +            "failed");
    1.41 +    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
    1.42 +            "failed");
    1.43 +    UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
    1.44 +    UCX_TEST_ASSERT(list->prev == NULL, "left not terminated");
    1.45 +    
    1.46 +    UCX_TEST_END
    1.47 +    ucx_list_free(list);
    1.48 +}
    1.49 +
    1.50  UCX_TEST(test_ucx_list_equals) {
    1.51      const char *hello = "Hello";
    1.52      const char *world = " World!";

mercurial