271 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
259 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
272 |
260 |
273 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
261 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
274 CU_ASSERT_EQUAL(list->size, 3) |
262 CU_ASSERT_EQUAL(list->size, 3) |
275 CU_ASSERT_TRUE(list->capacity >= list->size) |
263 CU_ASSERT_TRUE(list->capacity >= list->size) |
276 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) |
264 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
277 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) |
265 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
278 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) |
266 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
279 |
267 |
280 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
268 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
281 CU_ASSERT_EQUAL(list->size, 2) |
269 CU_ASSERT_EQUAL(list->size, 2) |
282 CU_ASSERT_TRUE(list->capacity >= list->size) |
270 CU_ASSERT_TRUE(list->capacity >= list->size) |
283 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47) |
271 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
284 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 13) |
272 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
285 |
273 |
286 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
274 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
287 CU_ASSERT_EQUAL(list->size, 1) |
275 CU_ASSERT_EQUAL(list->size, 1) |
288 CU_ASSERT_TRUE(list->capacity >= list->size) |
276 CU_ASSERT_TRUE(list->capacity >= list->size) |
289 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47) |
277 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
290 |
278 |
291 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
279 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
292 CU_ASSERT_EQUAL(list->size, 0) |
280 CU_ASSERT_EQUAL(list->size, 0) |
293 CU_ASSERT_TRUE(list->capacity >= list->size) |
281 CU_ASSERT_TRUE(list->capacity >= list->size) |
294 |
282 |
327 |
315 |
328 cxLinkedListDestroy(list); |
316 cxLinkedListDestroy(list); |
329 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
317 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
330 } |
318 } |
331 |
319 |
|
320 void test_hl_ptr_linked_list_create(void) { |
|
321 cxTestingAllocatorReset(); |
|
322 |
|
323 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
|
324 |
|
325 CU_ASSERT_EQUAL(list->size, 0) |
|
326 CU_ASSERT_EQUAL(list->capacity, (size_t) -1) |
|
327 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) |
|
328 CU_ASSERT_EQUAL(list->itemsize, sizeof(void *)) |
|
329 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) |
|
330 |
|
331 cxLinkedListDestroy(list); |
|
332 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
333 } |
|
334 |
|
335 void test_hl_ptr_linked_list_add(void) { |
|
336 cxTestingAllocatorReset(); |
|
337 |
|
338 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
|
339 |
|
340 int a = 5, b = 47, c = 13; |
|
341 |
|
342 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0) |
|
343 CU_ASSERT_EQUAL(cxListAdd(list, &b), 0) |
|
344 CU_ASSERT_EQUAL(cxListAdd(list, &c), 0) |
|
345 |
|
346 CU_ASSERT_EQUAL(list->size, 3) |
|
347 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
348 |
|
349 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
|
350 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
|
351 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
|
352 |
|
353 a = 9; |
|
354 b = 10; |
|
355 c = 11; |
|
356 |
|
357 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9) |
|
358 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10) |
|
359 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11) |
|
360 |
|
361 cxLinkedListDestroy(list); |
|
362 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
363 } |
|
364 |
|
365 void test_hl_ptr_linked_list_last(void) { |
|
366 cxTestingAllocatorReset(); |
|
367 |
|
368 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
|
369 CU_ASSERT_PTR_NULL(cxListLast(list)) |
|
370 |
|
371 int a = 5, b = 47; |
|
372 |
|
373 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0) |
|
374 CU_ASSERT_EQUAL(*(int *) cxListLast(list), 5) |
|
375 CU_ASSERT_EQUAL(cxListAdd(list, &b), 0) |
|
376 CU_ASSERT_EQUAL(*(int *) cxListLast(list), 47) |
|
377 |
|
378 cxLinkedListDestroy(list); |
|
379 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
380 } |
|
381 |
|
382 void test_hl_ptr_linked_list_insert(void) { |
|
383 cxTestingAllocatorReset(); |
|
384 |
|
385 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
|
386 |
|
387 int a = 5, b = 47, c = 13, d = 42; |
|
388 |
|
389 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0) |
|
390 CU_ASSERT_EQUAL(list->size, 0) |
|
391 CU_ASSERT_EQUAL(cxListInsert(list, 0, &a), 0) |
|
392 CU_ASSERT_EQUAL(list->size, 1) |
|
393 CU_ASSERT_EQUAL(cxListInsert(list, 0, &b), 0) |
|
394 CU_ASSERT_EQUAL(list->size, 2) |
|
395 CU_ASSERT_EQUAL(cxListInsert(list, 1, &c), 0) |
|
396 CU_ASSERT_EQUAL(list->size, 3) |
|
397 CU_ASSERT_EQUAL(cxListInsert(list, 3, &d), 0) |
|
398 |
|
399 CU_ASSERT_EQUAL(list->size, 4) |
|
400 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
401 |
|
402 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
|
403 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
|
404 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5) |
|
405 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42) |
|
406 |
|
407 cxLinkedListDestroy(list); |
|
408 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
409 } |
|
410 |
|
411 void test_hl_ptr_linked_list_remove(void) { |
|
412 cxTestingAllocatorReset(); |
|
413 |
|
414 int a = 5, b = 47, c = 42, d = 13; |
|
415 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
|
416 |
|
417 cxListAdd(list, &a); |
|
418 cxListAdd(list, &b); |
|
419 cxListAdd(list, &c); |
|
420 cxListAdd(list, &d); |
|
421 |
|
422 CU_ASSERT_EQUAL(list->size, 4) |
|
423 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
424 |
|
425 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
|
426 |
|
427 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
|
428 CU_ASSERT_EQUAL(list->size, 3) |
|
429 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
430 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
|
431 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
|
432 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
|
433 |
|
434 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
|
435 CU_ASSERT_EQUAL(list->size, 2) |
|
436 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
437 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
|
438 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
|
439 |
|
440 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
|
441 CU_ASSERT_EQUAL(list->size, 1) |
|
442 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
443 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
|
444 |
|
445 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
|
446 CU_ASSERT_EQUAL(list->size, 0) |
|
447 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
448 |
|
449 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) |
|
450 |
|
451 cxLinkedListDestroy(list); |
|
452 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
453 } |
|
454 |
|
455 void test_hl_ptr_linked_list_find(void) { |
|
456 cxTestingAllocatorReset(); |
|
457 |
|
458 int a = 5, b = 47, c = 13, criteria; |
|
459 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
|
460 |
|
461 cxListAdd(list, &a); |
|
462 cxListAdd(list, &b); |
|
463 cxListAdd(list, &c); |
|
464 |
|
465 CU_ASSERT_EQUAL(list->size, 3) |
|
466 CU_ASSERT_TRUE(list->capacity >= list->size) |
|
467 |
|
468 criteria = 5; |
|
469 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0) |
|
470 criteria = 47; |
|
471 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
|
472 criteria = 13; |
|
473 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2) |
|
474 criteria = 9000; |
|
475 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
|
476 criteria = -5; |
|
477 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
|
478 b = -5; |
|
479 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
|
480 |
|
481 cxLinkedListDestroy(list); |
|
482 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
|
483 } |
|
484 |
332 int main() { |
485 int main() { |
333 CU_pSuite suite = NULL; |
486 CU_pSuite suite = NULL; |
334 |
487 |
335 if (CUE_SUCCESS != CU_initialize_registry()) { |
488 if (CUE_SUCCESS != CU_initialize_registry()) { |
336 return CU_get_error(); |
489 return CU_get_error(); |