diff -r 4b3219fab71c -r 8168e16cd1e9 test/test_list.c --- a/test/test_list.c Sun Oct 03 15:40:38 2021 +0200 +++ b/test/test_list.c Sun Oct 03 16:02:53 2021 +0200 @@ -35,33 +35,6 @@ return left == right ? 0 : (left < right ? -1 : 1); } -void test_linked_list_create(void) { - cxTestingAllocatorReset(); - - CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); - - CU_ASSERT_EQUAL(list->size, 0) - CU_ASSERT_EQUAL(list->capacity, (size_t) -1) - CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) - CU_ASSERT_EQUAL(list->itemsize, sizeof(int)) - CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) - - // assume this structure for a linked list - struct ll_check { - cx_list_s base; - void *begin; - void *end; - }; - - struct ll_check *actual = (struct ll_check *) list; - CU_ASSERT_PTR_NULL(actual->begin) - CU_ASSERT_PTR_NULL(actual->end) - - cxLinkedListDestroy(list); - - CU_ASSERT_TRUE(cxTestingAllocatorVerify()) -} - void test_linked_list_at(void) { struct node { void *next; @@ -154,6 +127,34 @@ CU_ASSERT_PTR_NULL(nodes[1].prev) } + +void test_linked_list_create(void) { + cxTestingAllocatorReset(); + + CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); + + CU_ASSERT_EQUAL(list->size, 0) + CU_ASSERT_EQUAL(list->capacity, (size_t) -1) + CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) + CU_ASSERT_EQUAL(list->itemsize, sizeof(int)) + CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) + + // assume this structure for a linked list + struct ll_check { + cx_list_s base; + void *begin; + void *end; + }; + + struct ll_check *actual = (struct ll_check *) list; + CU_ASSERT_PTR_NULL(actual->begin) + CU_ASSERT_PTR_NULL(actual->end) + + cxLinkedListDestroy(list); + + CU_ASSERT_TRUE(cxTestingAllocatorVerify()) +} + int main() { CU_pSuite suite = NULL; @@ -161,11 +162,14 @@ return CU_get_error(); } - suite = CU_add_suite("linked list suite", NULL, NULL); + suite = CU_add_suite("low level linked list suite", NULL, NULL); - CU_add_test(suite, "linked list: create and destroy", test_linked_list_create); - CU_add_test(suite, "linked list: get node at index", test_linked_list_at); - CU_add_test(suite, "linked list: add", test_linked_list_add); + cu_add_test(suite, test_linked_list_at); + cu_add_test(suite, test_linked_list_add); + + suite = CU_add_suite("high level linked list suite", NULL, NULL); + + cu_add_test(suite, test_linked_list_create); CU_basic_set_mode(UCX_CU_BRM);