test/test_list.c

changeset 456
227c2eabbef8
parent 455
8168e16cd1e9
child 459
c0e2e9f83399
equal deleted inserted replaced
455:8168e16cd1e9 456:227c2eabbef8
125 CU_ASSERT_PTR_EQUAL(end, &nodes[1]) 125 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
126 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 126 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
127 CU_ASSERT_PTR_NULL(nodes[1].prev) 127 CU_ASSERT_PTR_NULL(nodes[1].prev)
128 } 128 }
129 129
130 130 void test_linked_list_last(void) {
131 void test_linked_list_create(void) { 131 CU_ASSERT_PTR_NULL(cx_linked_list_last(NULL, -1))
132 CU_ASSERT_PTR_NULL(cx_linked_list_last(NULL, 0))
133
134 struct node {
135 int data;
136 void *next;
137 };
138 ptrdiff_t loc = offsetof(struct node, next);
139
140 struct node third = {3, NULL};
141 struct node second = {2, &third};
142 struct node first = {1, &second};
143
144 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&first, loc), &third)
145 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&second, loc), &third)
146 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&third, loc), &third)
147 }
148
149
150 void test_hl_linked_list_create(void) {
132 cxTestingAllocatorReset(); 151 cxTestingAllocatorReset();
133 152
134 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); 153 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
135 154
136 CU_ASSERT_EQUAL(list->size, 0) 155 CU_ASSERT_EQUAL(list->size, 0)
164 183
165 suite = CU_add_suite("low level linked list suite", NULL, NULL); 184 suite = CU_add_suite("low level linked list suite", NULL, NULL);
166 185
167 cu_add_test(suite, test_linked_list_at); 186 cu_add_test(suite, test_linked_list_at);
168 cu_add_test(suite, test_linked_list_add); 187 cu_add_test(suite, test_linked_list_add);
188 cu_add_test(suite, test_linked_list_last);
169 189
170 suite = CU_add_suite("high level linked list suite", NULL, NULL); 190 suite = CU_add_suite("high level linked list suite", NULL, NULL);
171 191
172 cu_add_test(suite, test_linked_list_create); 192 cu_add_test(suite, test_hl_linked_list_create);
193 /*
194 cu_add_test(suite, test_hl_linked_list_add);
195 cu_add_test(suite, test_hl_linked_list_last);
196 cu_add_test(suite, test_hl_linked_list_insert);
197 cu_add_test(suite, test_hl_linked_list_remove);
198 cu_add_test(suite, test_hl_linked_list_find);*/
173 199
174 CU_basic_set_mode(UCX_CU_BRM); 200 CU_basic_set_mode(UCX_CU_BRM);
175 201
176 int exitcode; 202 int exitcode;
177 if (CU_basic_run_tests()) { 203 if (CU_basic_run_tests()) {

mercurial