test/list_tests.c

changeset 228
9f385abc72fb
parent 225
a1a068c2c4ef
child 229
9db71925eaa8
--- a/test/list_tests.c	Thu Oct 13 16:25:21 2016 +0200
+++ b/test/list_tests.c	Fri Nov 18 15:17:04 2016 +0100
@@ -68,6 +68,49 @@
     ucx_list_free(list);
 }
 
+UCX_TEST(test_ucx_list_append_once) {
+    UcxList *list, *first;
+    list = first = ucx_list_append_once(NULL, (void*)"Hello", ucx_strcmp, NULL);
+    UCX_TEST_BEGIN
+    
+    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
+            "failed");
+    
+    list = ucx_list_append_once(list, (void*)"Hello", ucx_strcmp, NULL);
+    list = ucx_list_append_once(list, (void*)" World!", ucx_strcmp, NULL);
+    
+    UCX_TEST_ASSERT(list == first, "does not return first element");
+    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
+            "'Hello' was not inserted _once_");
+    UCX_TEST_ASSERT(list->next->prev == list, "failed");
+    UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
+    UCX_TEST_END
+    
+    ucx_list_free(list);
+}
+
+UCX_TEST(test_ucx_list_prepend_once) {
+    UcxList *list, *last, *first;
+    list = last = ucx_list_prepend_once(NULL, (void*)" World!",
+            ucx_strcmp, NULL);
+    UCX_TEST_BEGIN
+
+    list = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
+    first = ucx_list_prepend_once(list, (void*)"Hello", ucx_strcmp, NULL);
+    
+    UCX_TEST_ASSERT(list == first, "'Hello' was not prepended _once_");
+    UCX_TEST_ASSERT(first == last->prev, "does not return first element");
+    UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
+            "failed");
+    UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
+            "failed");
+    UCX_TEST_ASSERT(list->next->next == NULL, "right not terminated");
+    UCX_TEST_ASSERT(list->prev == NULL, "left not terminated");
+    
+    UCX_TEST_END
+    ucx_list_free(list);
+}
+
 UCX_TEST(test_ucx_list_equals) {
     const char *hello = "Hello";
     const char *world = " World!";

mercurial