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((const char*)list->data, "Hello", 5) == 0, |
|
11 "failed"); |
11 |
12 |
12 list = ucx_list_append(list, " World!"); |
13 list = ucx_list_append(list, " World!"); |
13 |
14 |
14 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
15 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
|
16 "failed"); |
15 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
17 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
16 |
18 |
17 UCX_TEST_END |
19 UCX_TEST_END |
18 ucx_list_free(list); |
20 ucx_list_free(list); |
19 } |
21 } |
21 UCX_TEST_IMPLEMENT(test_ucx_list_prepend) { |
23 UCX_TEST_IMPLEMENT(test_ucx_list_prepend) { |
22 UcxList *list = ucx_list_prepend(NULL, " World!"); |
24 UcxList *list = ucx_list_prepend(NULL, " World!"); |
23 UCX_TEST_BEGIN |
25 UCX_TEST_BEGIN |
24 list = ucx_list_prepend(list, "Hello"); |
26 list = ucx_list_prepend(list, "Hello"); |
25 |
27 |
26 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); |
28 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
27 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
29 "failed"); |
|
30 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
|
31 "failed"); |
28 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
32 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
29 |
33 |
30 UCX_TEST_END |
34 UCX_TEST_END |
31 ucx_list_free(list); |
35 ucx_list_free(list); |
32 } |
36 } |
54 UcxList *list2 = ucx_list_prepend(NULL, " World!"); |
58 UcxList *list2 = ucx_list_prepend(NULL, " World!"); |
55 |
59 |
56 list = ucx_list_concat(list, list2); |
60 list = ucx_list_concat(list, list2); |
57 UCX_TEST_BEGIN |
61 UCX_TEST_BEGIN |
58 |
62 |
59 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); |
63 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
60 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
64 "failed"); |
|
65 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
|
66 "failed"); |
61 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
67 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
62 |
68 |
63 UCX_TEST_END |
69 UCX_TEST_END |
64 if (list->next == NULL) { |
70 if (list->next == NULL) { |
65 ucx_list_free(list2); |
71 ucx_list_free(list2); |
85 UcxList *list = ucx_list_append(NULL, "Find "); |
91 UcxList *list = ucx_list_append(NULL, "Find "); |
86 UCX_TEST_BEGIN |
92 UCX_TEST_BEGIN |
87 list = ucx_list_append(list, "the "); |
93 list = ucx_list_append(list, "the "); |
88 list = ucx_list_append(list, "last!"); |
94 list = ucx_list_append(list, "last!"); |
89 |
95 |
90 char* last = (char*) (ucx_list_last(list)->data); |
96 const char* last = (const char*) (ucx_list_last(list)->data); |
91 |
97 |
92 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); |
98 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); |
93 |
99 |
94 UCX_TEST_END |
100 UCX_TEST_END |
95 ucx_list_free(list); |
101 ucx_list_free(list); |
100 UcxList *list = ucx_list_append(NULL, "Find "); |
106 UcxList *list = ucx_list_append(NULL, "Find "); |
101 UCX_TEST_BEGIN |
107 UCX_TEST_BEGIN |
102 list = ucx_list_append(list, "the "); |
108 list = ucx_list_append(list, "the "); |
103 list = ucx_list_append(list, "mid!"); |
109 list = ucx_list_append(list, "mid!"); |
104 |
110 |
105 char* mid = (char*) (ucx_list_get(list, 1)->data); |
111 const char* mid = (const char*) (ucx_list_get(list, 1)->data); |
106 |
112 |
107 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); |
113 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); |
108 |
114 |
109 UCX_TEST_END |
115 UCX_TEST_END |
110 ucx_list_free(list); |
116 ucx_list_free(list); |
116 list = ucx_list_append(list, " fucking"); |
122 list = ucx_list_append(list, " fucking"); |
117 list = ucx_list_append(list, " World!"); |
123 list = ucx_list_append(list, " World!"); |
118 |
124 |
119 list = ucx_list_remove(list, ucx_list_get(list, 1)); |
125 list = ucx_list_remove(list, ucx_list_get(list, 1)); |
120 |
126 |
121 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); |
127 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
122 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); |
128 "failed"); |
|
129 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
|
130 "failed"); |
123 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
131 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
124 UCX_TEST_END |
132 UCX_TEST_END |
125 |
133 |
126 ucx_list_free(list); |
134 ucx_list_free(list); |
127 } |
135 } |