test/list_tests.c

changeset 40
583718dd4cf3
parent 36
a9d656e4f7ce
child 69
fb59270b1de3
equal deleted inserted replaced
39:bf8ab7bb74ff 40:583718dd4cf3
5 #include "list_tests.h" 5 #include "list_tests.h"
6 6
7 UCX_TEST_IMPLEMENT(test_ucx_list_append) { 7 UCX_TEST_IMPLEMENT(test_ucx_list_append) {
8 UcxList *list = ucx_list_append(NULL, "Hello"); 8 UcxList *list = ucx_list_append(NULL, "Hello");
9 UCX_TEST_BEGIN 9 UCX_TEST_BEGIN
10 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") 10 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed");
11 11
12 list = ucx_list_append(list, " World!"); 12 list = ucx_list_append(list, " World!");
13 13
14 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") 14 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed");
15 UCX_TEST_ASSERT(list->next->next == NULL, "failed") 15 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
16 16
17 UCX_TEST_END 17 UCX_TEST_END
18 ucx_list_free(list); 18 ucx_list_free(list);
19 } 19 }
20 20
21 UCX_TEST_IMPLEMENT(test_ucx_list_prepend) { 21 UCX_TEST_IMPLEMENT(test_ucx_list_prepend) {
22 UcxList *list = ucx_list_prepend(NULL, " World!"); 22 UcxList *list = ucx_list_prepend(NULL, " World!");
23 UCX_TEST_BEGIN 23 UCX_TEST_BEGIN
24 list = ucx_list_prepend(list, "Hello"); 24 list = ucx_list_prepend(list, "Hello");
25 25
26 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") 26 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed");
27 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") 27 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed");
28 UCX_TEST_ASSERT(list->next->next == NULL, "failed") 28 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
29 29
30 UCX_TEST_END 30 UCX_TEST_END
31 ucx_list_free(list); 31 ucx_list_free(list);
32 } 32 }
33 33
38 list2 = ucx_list_prepend(list2, "Hello"); 38 list2 = ucx_list_prepend(list2, "Hello");
39 UcxList *list3 = ucx_list_prepend(NULL, " Welt!"); 39 UcxList *list3 = ucx_list_prepend(NULL, " Welt!");
40 list3 = ucx_list_prepend(list3, "Hallo"); 40 list3 = ucx_list_prepend(list3, "Hallo");
41 41
42 UCX_TEST_BEGIN 42 UCX_TEST_BEGIN
43 UCX_TEST_ASSERT(ucx_list_equals(list, list2, cmp_string, NULL), "failed") 43 UCX_TEST_ASSERT(ucx_list_equals(list, list2, cmp_string, NULL), "failed");
44 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, cmp_string, NULL), "failed") 44 UCX_TEST_ASSERT(!ucx_list_equals(list, list3, cmp_string, NULL), "failed");
45 UCX_TEST_END 45 UCX_TEST_END
46 46
47 ucx_list_free(list3); 47 ucx_list_free(list3);
48 ucx_list_free(list2); 48 ucx_list_free(list2);
49 ucx_list_free(list); 49 ucx_list_free(list);
54 UcxList *list2 = ucx_list_prepend(NULL, " World!"); 54 UcxList *list2 = ucx_list_prepend(NULL, " World!");
55 55
56 list = ucx_list_concat(list, list2); 56 list = ucx_list_concat(list, list2);
57 UCX_TEST_BEGIN 57 UCX_TEST_BEGIN
58 58
59 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") 59 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed");
60 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") 60 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed");
61 UCX_TEST_ASSERT(list->next->next == NULL, "failed") 61 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
62 62
63 UCX_TEST_END 63 UCX_TEST_END
64 if (list->next == NULL) { 64 if (list->next == NULL) {
65 ucx_list_free(list2); 65 ucx_list_free(list2);
66 } 66 }
116 list = ucx_list_append(list, " fucking"); 116 list = ucx_list_append(list, " fucking");
117 list = ucx_list_append(list, " World!"); 117 list = ucx_list_append(list, " World!");
118 118
119 list = ucx_list_remove(list, ucx_list_get(list, 1)); 119 list = ucx_list_remove(list, ucx_list_get(list, 1));
120 120
121 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") 121 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed");
122 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") 122 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed");
123 UCX_TEST_ASSERT(list->next->next == NULL, "failed") 123 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
124 UCX_TEST_END 124 UCX_TEST_END
125 125
126 ucx_list_free(list); 126 ucx_list_free(list);
127 } 127 }
128 128
138 list = ucx_list_append(list, world); 138 list = ucx_list_append(list, world);
139 139
140 UcxList *copy = ucx_list_clone(list, copy_string, NULL); 140 UcxList *copy = ucx_list_clone(list, copy_string, NULL);
141 UCX_TEST_BEGIN 141 UCX_TEST_BEGIN
142 142
143 UCX_TEST_ASSERT(ucx_list_equals(list, copy, cmp_string, NULL), "failed") 143 UCX_TEST_ASSERT(ucx_list_equals(list, copy, cmp_string, NULL), "failed");
144 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy") 144 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy");
145 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy") 145 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy");
146 146
147 UCX_TEST_END 147 UCX_TEST_END
148 free(copy->next->data); 148 free(copy->next->data);
149 free(copy->data); 149 free(copy->data);
150 150

mercurial