6 |
6 |
7 UCX_TEST_IMPLEMENT(test_ucx_dlist_append) { |
7 UCX_TEST_IMPLEMENT(test_ucx_dlist_append) { |
8 UcxDlist *list = ucx_dlist_append(NULL, "Hello"); |
8 UcxDlist *list = ucx_dlist_append(NULL, "Hello"); |
9 UCX_TEST_BEGIN |
9 UCX_TEST_BEGIN |
10 |
10 |
11 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") |
11 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); |
12 |
12 |
13 list = ucx_dlist_append(list, " World!"); |
13 list = ucx_dlist_append(list, " World!"); |
14 |
14 |
15 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") |
15 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
16 UCX_TEST_ASSERT(list->next->next == NULL, "failed") |
16 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
17 UCX_TEST_END |
17 UCX_TEST_END |
18 |
18 |
19 ucx_dlist_free(list); |
19 ucx_dlist_free(list); |
20 } |
20 } |
21 |
21 |
23 UcxDlist *list = ucx_dlist_prepend(NULL, " World!"); |
23 UcxDlist *list = ucx_dlist_prepend(NULL, " World!"); |
24 UCX_TEST_BEGIN |
24 UCX_TEST_BEGIN |
25 |
25 |
26 list = ucx_dlist_prepend(list, "Hello"); |
26 list = ucx_dlist_prepend(list, "Hello"); |
27 |
27 |
28 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") |
28 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); |
29 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") |
29 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
30 UCX_TEST_ASSERT(list->next->next == NULL, "failed") |
30 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
31 |
31 |
32 UCX_TEST_END |
32 UCX_TEST_END |
33 ucx_dlist_free(list); |
33 ucx_dlist_free(list); |
34 } |
34 } |
35 |
35 |
40 list2 = ucx_dlist_prepend(list2, "Hello"); |
40 list2 = ucx_dlist_prepend(list2, "Hello"); |
41 UcxDlist *list3 = ucx_dlist_prepend(NULL, " Welt!"); |
41 UcxDlist *list3 = ucx_dlist_prepend(NULL, " Welt!"); |
42 list3 = ucx_dlist_prepend(list3, "Hallo"); |
42 list3 = ucx_dlist_prepend(list3, "Hallo"); |
43 UCX_TEST_BEGIN |
43 UCX_TEST_BEGIN |
44 |
44 |
45 UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, cmp_string, NULL), "failed") |
45 UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, cmp_string, NULL), "failed"); |
46 UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, cmp_string, NULL), "failed") |
46 UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, cmp_string, NULL), "failed"); |
47 |
47 |
48 UCX_TEST_END |
48 UCX_TEST_END |
49 ucx_dlist_free(list3); |
49 ucx_dlist_free(list3); |
50 ucx_dlist_free(list2); |
50 ucx_dlist_free(list2); |
51 ucx_dlist_free(list); |
51 ucx_dlist_free(list); |
56 UcxDlist *list2 = ucx_dlist_prepend(NULL, " World!"); |
56 UcxDlist *list2 = ucx_dlist_prepend(NULL, " World!"); |
57 UCX_TEST_BEGIN |
57 UCX_TEST_BEGIN |
58 |
58 |
59 list = ucx_dlist_concat(list, list2); |
59 list = ucx_dlist_concat(list, list2); |
60 |
60 |
61 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") |
61 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); |
62 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") |
62 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
63 UCX_TEST_ASSERT(list->next->next == NULL, "failed") |
63 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
64 |
64 |
65 UCX_TEST_END |
65 UCX_TEST_END |
66 ucx_dlist_free(list); |
66 ucx_dlist_free(list); |
67 } |
67 } |
68 |
68 |
128 list = ucx_dlist_append(list, " fucking"); |
128 list = ucx_dlist_append(list, " fucking"); |
129 list = ucx_dlist_append(list, " World!"); |
129 list = ucx_dlist_append(list, " World!"); |
130 |
130 |
131 list = ucx_dlist_remove(list, ucx_dlist_get(list, 1)); |
131 list = ucx_dlist_remove(list, ucx_dlist_get(list, 1)); |
132 |
132 |
133 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed") |
133 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); |
134 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed") |
134 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
135 UCX_TEST_ASSERT(list->next->next == NULL, "failed") |
135 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
136 |
136 |
137 UCX_TEST_END |
137 UCX_TEST_END |
138 ucx_dlist_free(list); |
138 ucx_dlist_free(list); |
139 } |
139 } |
140 |
140 |
150 list = ucx_dlist_append(list, world); |
150 list = ucx_dlist_append(list, world); |
151 |
151 |
152 UcxDlist *copy = ucx_dlist_clone(list, copy_string, NULL); |
152 UcxDlist *copy = ucx_dlist_clone(list, copy_string, NULL); |
153 UCX_TEST_BEGIN |
153 UCX_TEST_BEGIN |
154 |
154 |
155 UCX_TEST_ASSERT(ucx_dlist_equals(list, copy, cmp_string, NULL), "failed") |
155 UCX_TEST_ASSERT(ucx_dlist_equals(list, copy, cmp_string, NULL), "failed"); |
156 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy") |
156 UCX_TEST_ASSERT(hello != copy->data, "first element is no copy"); |
157 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy") |
157 UCX_TEST_ASSERT(world != copy->next->data, "second element is no copy"); |
158 |
158 |
159 UCX_TEST_END |
159 UCX_TEST_END |
160 free(copy->next->data); |
160 free(copy->next->data); |
161 free(copy->data); |
161 free(copy->data); |
162 |
162 |