172 cxLinkedListDestroy(list); |
172 cxLinkedListDestroy(list); |
173 |
173 |
174 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
174 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
175 } |
175 } |
176 |
176 |
|
177 void test_hl_linked_list_add(void) { |
|
178 cxTestingAllocatorReset(); |
|
179 |
|
180 int data; |
|
181 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
|
182 |
|
183 data = 5; |
|
184 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) |
|
185 data = 47; |
|
186 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) |
|
187 data = 13; |
|
188 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) |
|
189 |
|
190 CU_ASSERT_EQUAL(list->size, 3) |
|
191 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
192 |
|
193 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 5) |
|
194 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 47) |
|
195 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 13) |
|
196 |
|
197 cxLinkedListDestroy(list); |
|
198 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
199 } |
|
200 |
|
201 void test_hl_linked_list_last(void) { |
|
202 cxTestingAllocatorReset(); |
|
203 |
|
204 int data; |
|
205 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
|
206 |
|
207 CU_ASSERT_PTR_NULL(cxTypedListLast(int, list)) |
|
208 |
|
209 data = 5; |
|
210 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) |
|
211 CU_ASSERT_EQUAL(*cxTypedListLast(int, list), 5) |
|
212 |
|
213 data = 47; |
|
214 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) |
|
215 CU_ASSERT_EQUAL(*cxTypedListLast(int, list), 47) |
|
216 |
|
217 cxLinkedListDestroy(list); |
|
218 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
219 } |
|
220 |
|
221 void test_hl_linked_list_insert(void) { |
|
222 cxTestingAllocatorReset(); |
|
223 |
|
224 int data; |
|
225 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
|
226 |
|
227 data = 5; |
|
228 CU_ASSERT_NOT_EQUAL(cxTypedListInsert(int, list, 1, &data), 0) |
|
229 CU_ASSERT_EQUAL(list->size, 0) |
|
230 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 0, &data), 0) |
|
231 CU_ASSERT_EQUAL(list->size, 1) |
|
232 data = 47; |
|
233 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 0, &data), 0) |
|
234 CU_ASSERT_EQUAL(list->size, 2) |
|
235 data = 13; |
|
236 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 1, &data), 0) |
|
237 CU_ASSERT_EQUAL(list->size, 3) |
|
238 data = 42; |
|
239 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 3, &data), 0) |
|
240 |
|
241 CU_ASSERT_EQUAL(list->size, 4) |
|
242 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
243 |
|
244 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) |
|
245 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 13) |
|
246 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 5) |
|
247 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 3), 42) |
|
248 |
|
249 cxLinkedListDestroy(list); |
|
250 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
251 } |
|
252 |
|
253 void test_hl_linked_list_remove(void) { |
|
254 cxTestingAllocatorReset(); |
|
255 |
|
256 int data; |
|
257 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
|
258 |
|
259 data = 5; |
|
260 cxTypedListAdd(int, list, &data); |
|
261 data = 47; |
|
262 cxTypedListAdd(int, list, &data); |
|
263 data = 42; |
|
264 cxTypedListAdd(int, list, &data); |
|
265 data = 13; |
|
266 cxTypedListAdd(int, list, &data); |
|
267 |
|
268 CU_ASSERT_EQUAL(list->size, 4) |
|
269 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
270 |
|
271 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
|
272 |
|
273 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
|
274 CU_ASSERT_EQUAL(list->size, 3) |
|
275 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
276 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 5) |
|
277 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 47) |
|
278 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 13) |
|
279 |
|
280 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
|
281 CU_ASSERT_EQUAL(list->size, 2) |
|
282 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
283 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) |
|
284 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 13) |
|
285 |
|
286 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
|
287 CU_ASSERT_EQUAL(list->size, 1) |
|
288 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
289 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) |
|
290 |
|
291 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
|
292 CU_ASSERT_EQUAL(list->size, 0) |
|
293 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
294 |
|
295 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) |
|
296 |
|
297 cxLinkedListDestroy(list); |
|
298 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
299 } |
|
300 |
|
301 void test_hl_linked_list_find(void) { |
|
302 cxTestingAllocatorReset(); |
|
303 |
|
304 int data, criteria; |
|
305 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
|
306 |
|
307 data = 5; |
|
308 cxTypedListAdd(int, list, &data); |
|
309 data = 47; |
|
310 cxTypedListAdd(int, list, &data); |
|
311 data = 13; |
|
312 cxTypedListAdd(int, list, &data); |
|
313 |
|
314 CU_ASSERT_EQUAL(list->size, 3) |
|
315 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
316 |
|
317 criteria = 5; |
|
318 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 0) |
|
319 criteria = 47; |
|
320 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 1) |
|
321 criteria = 13; |
|
322 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 2) |
|
323 criteria = 9000; |
|
324 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 3) |
|
325 criteria = -5; |
|
326 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 3) |
|
327 |
|
328 cxLinkedListDestroy(list); |
|
329 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
330 } |
|
331 |
177 int main() { |
332 int main() { |
178 CU_pSuite suite = NULL; |
333 CU_pSuite suite = NULL; |
179 |
334 |
180 if (CUE_SUCCESS != CU_initialize_registry()) { |
335 if (CUE_SUCCESS != CU_initialize_registry()) { |
181 return CU_get_error(); |
336 return CU_get_error(); |
182 } |
337 } |
183 |
338 |
184 suite = CU_add_suite("low level linked list suite", NULL, NULL); |
339 suite = CU_add_suite("low level linked list", NULL, NULL); |
185 |
340 |
186 cu_add_test(suite, test_linked_list_at); |
341 cu_add_test(suite, test_linked_list_at); |
187 cu_add_test(suite, test_linked_list_add); |
342 cu_add_test(suite, test_linked_list_add); |
188 cu_add_test(suite, test_linked_list_last); |
343 cu_add_test(suite, test_linked_list_last); |
189 |
344 |
190 suite = CU_add_suite("high level linked list suite", NULL, NULL); |
345 suite = CU_add_suite("high level linked list", NULL, NULL); |
191 |
346 |
192 cu_add_test(suite, test_hl_linked_list_create); |
347 cu_add_test(suite, test_hl_linked_list_create); |
193 /* |
|
194 cu_add_test(suite, test_hl_linked_list_add); |
348 cu_add_test(suite, test_hl_linked_list_add); |
195 cu_add_test(suite, test_hl_linked_list_last); |
349 cu_add_test(suite, test_hl_linked_list_last); |
196 cu_add_test(suite, test_hl_linked_list_insert); |
350 cu_add_test(suite, test_hl_linked_list_insert); |
197 cu_add_test(suite, test_hl_linked_list_remove); |
351 cu_add_test(suite, test_hl_linked_list_remove); |
198 cu_add_test(suite, test_hl_linked_list_find);*/ |
352 cu_add_test(suite, test_hl_linked_list_find); |
199 |
353 |
200 CU_basic_set_mode(UCX_CU_BRM); |
354 CU_basic_set_mode(UCX_CU_BRM); |
201 |
355 |
202 int exitcode; |
356 int exitcode; |
203 if (CU_basic_run_tests()) { |
357 if (CU_basic_run_tests()) { |