test/list_tests.c

changeset 228
9f385abc72fb
parent 225
a1a068c2c4ef
child 229
9db71925eaa8
equal deleted inserted replaced
227:740fbd7bab71 228:9f385abc72fb
66 66
67 UCX_TEST_END 67 UCX_TEST_END
68 ucx_list_free(list); 68 ucx_list_free(list);
69 } 69 }
70 70
71 UCX_TEST(test_ucx_list_append_once) {
72 UcxList *list, *first;
73 list = first = ucx_list_append_once(NULL, (void*)"Hello", ucx_strcmp, NULL);
74 UCX_TEST_BEGIN
75
76 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
77 "failed");
78
79 list = ucx_list_append_once(list, (void*)"Hello", ucx_strcmp, NULL);
80 list = ucx_list_append_once(list, (void*)" World!", ucx_strcmp, NULL);
81
82 UCX_TEST_ASSERT(list == first, "does not return first element");
83 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
84 "'Hello' was not inserted _once_");
85 UCX_TEST_ASSERT(list->next->prev == list, "failed");
86 UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
87 UCX_TEST_END
88
89 ucx_list_free(list);
90 }
91
92 UCX_TEST(test_ucx_list_prepend_once) {
93 UcxList *list, *last, *first;
94 list = last = ucx_list_prepend_once(NULL, (void*)" World!",
95 ucx_strcmp, NULL);
96 UCX_TEST_BEGIN
97
98 list = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
99 first = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
100
101 UCX_TEST_ASSERT(list == first, "'Hello' was not prepended _once_");
102 UCX_TEST_ASSERT(first == last->prev, "does not return first element");
103 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
104 "failed");
105 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
106 "failed");
107 UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
108 UCX_TEST_ASSERT(list->prev == NULL, "left not terminated");
109
110 UCX_TEST_END
111 ucx_list_free(list);
112 }
113
71 UCX_TEST(test_ucx_list_equals) { 114 UCX_TEST(test_ucx_list_equals) {
72 const char *hello = "Hello"; 115 const char *hello = "Hello";
73 const char *world = " World!"; 116 const char *world = " World!";
74 UcxList *list = ucx_list_append(NULL, (void*)hello); 117 UcxList *list = ucx_list_append(NULL, (void*)hello);
75 list = ucx_list_append(list, (void*)world); 118 list = ucx_list_append(list, (void*)world);

mercurial