test/dlist_tests.c

changeset 69
fb59270b1de3
parent 40
583718dd4cf3
child 71
303dabadff1c
equal deleted inserted replaced
68:88dbea299440 69:fb59270b1de3
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((const char*)list->data, "Hello", 5) == 0,
12 "failed");
12 13
13 list = ucx_dlist_append(list, " World!"); 14 list = ucx_dlist_append(list, " World!");
14 15
15 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); 16 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
17 "failed");
16 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 18 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
17 UCX_TEST_END 19 UCX_TEST_END
18 20
19 ucx_dlist_free(list); 21 ucx_dlist_free(list);
20 } 22 }
23 UcxDlist *list = ucx_dlist_prepend(NULL, " World!"); 25 UcxDlist *list = ucx_dlist_prepend(NULL, " World!");
24 UCX_TEST_BEGIN 26 UCX_TEST_BEGIN
25 27
26 list = ucx_dlist_prepend(list, "Hello"); 28 list = ucx_dlist_prepend(list, "Hello");
27 29
28 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); 30 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
29 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); 31 "failed");
32 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
33 "failed");
30 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 34 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
31 35
32 UCX_TEST_END 36 UCX_TEST_END
33 ucx_dlist_free(list); 37 ucx_dlist_free(list);
34 } 38 }
56 UcxDlist *list2 = ucx_dlist_prepend(NULL, " World!"); 60 UcxDlist *list2 = ucx_dlist_prepend(NULL, " World!");
57 UCX_TEST_BEGIN 61 UCX_TEST_BEGIN
58 62
59 list = ucx_dlist_concat(list, list2); 63 list = ucx_dlist_concat(list, list2);
60 64
61 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); 65 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
62 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); 66 "failed");
67 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
68 "failed");
63 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 69 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
64 70
65 UCX_TEST_END 71 UCX_TEST_END
66 ucx_dlist_free(list); 72 ucx_dlist_free(list);
67 } 73 }
84 UcxDlist *list = ucx_dlist_append(NULL, "Find "); 90 UcxDlist *list = ucx_dlist_append(NULL, "Find ");
85 UCX_TEST_BEGIN 91 UCX_TEST_BEGIN
86 list = ucx_dlist_append(list, "the "); 92 list = ucx_dlist_append(list, "the ");
87 list = ucx_dlist_append(list, "first!"); 93 list = ucx_dlist_append(list, "first!");
88 94
89 char* first = (char*) (ucx_dlist_first(list)->data); 95 const char* first = (const char*) (ucx_dlist_first(list)->data);
90 96
91 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed"); 97 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed");
92 98
93 UCX_TEST_END 99 UCX_TEST_END
94 ucx_dlist_free(list); 100 ucx_dlist_free(list);
98 UcxDlist *list = ucx_dlist_append(NULL, "Find "); 104 UcxDlist *list = ucx_dlist_append(NULL, "Find ");
99 UCX_TEST_BEGIN 105 UCX_TEST_BEGIN
100 list = ucx_dlist_append(list, "the "); 106 list = ucx_dlist_append(list, "the ");
101 list = ucx_dlist_append(list, "last!"); 107 list = ucx_dlist_append(list, "last!");
102 108
103 char* last = (char*) (ucx_dlist_last(list)->data); 109 const char* last = (const char*) (ucx_dlist_last(list)->data);
104 110
105 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); 111 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed");
106 112
107 UCX_TEST_END 113 UCX_TEST_END
108 ucx_dlist_free(list); 114 ucx_dlist_free(list);
112 UcxDlist *list = ucx_dlist_append(NULL, "Find "); 118 UcxDlist *list = ucx_dlist_append(NULL, "Find ");
113 UCX_TEST_BEGIN 119 UCX_TEST_BEGIN
114 list = ucx_dlist_append(list, "the "); 120 list = ucx_dlist_append(list, "the ");
115 list = ucx_dlist_append(list, "mid!"); 121 list = ucx_dlist_append(list, "mid!");
116 122
117 char* mid = (char*) (ucx_dlist_get(list, 1)->data); 123 const char* mid = (const char*) (ucx_dlist_get(list, 1)->data);
118 124
119 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); 125 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed");
120 126
121 UCX_TEST_END 127 UCX_TEST_END
122 ucx_dlist_free(list); 128 ucx_dlist_free(list);
128 list = ucx_dlist_append(list, " fucking"); 134 list = ucx_dlist_append(list, " fucking");
129 list = ucx_dlist_append(list, " World!"); 135 list = ucx_dlist_append(list, " World!");
130 136
131 list = ucx_dlist_remove(list, ucx_dlist_get(list, 1)); 137 list = ucx_dlist_remove(list, ucx_dlist_get(list, 1));
132 138
133 UCX_TEST_ASSERT(strncmp(list->data, "Hello", 5) == 0, "failed"); 139 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0,
134 UCX_TEST_ASSERT(strncmp(list->next->data, " World!", 7) == 0, "failed"); 140 "failed");
141 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0,
142 "failed");
135 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); 143 UCX_TEST_ASSERT(list->next->next == NULL, "failed");
136 144
137 UCX_TEST_END 145 UCX_TEST_END
138 ucx_dlist_free(list); 146 ucx_dlist_free(list);
139 } 147 }

mercurial