1.1 --- a/test/test_linked_list.c Sun Feb 14 11:31:13 2021 +0100 1.2 +++ b/test/test_linked_list.c Sun Feb 14 15:13:53 2021 +0100 1.3 @@ -29,8 +29,31 @@ 1.4 #include "cx/linked_list.h" 1.5 #include "test_config.h" 1.6 1.7 -void test_linked_list_wrap() { 1.8 - CU_FAIL("test not implemented") 1.9 +int cmp_int(int const *l, int const *r) { 1.10 + int left = *l, right = *r; 1.11 + return left == right ? 0 : (left < right ? -1 : 1); 1.12 +} 1.13 + 1.14 +void test_linked_list_create() { 1.15 + CxList list = cxLinkedListCreate(cxDefaultAllocator, (CxListComparator) cmp_int, sizeof(int)); 1.16 + 1.17 + CU_ASSERT_EQUAL(list->data.size, 0) 1.18 + CU_ASSERT_EQUAL(list->data.capacity, (size_t) -1) 1.19 + CU_ASSERT_PTR_EQUAL(list->data.allocator, cxDefaultAllocator) 1.20 + CU_ASSERT_EQUAL(list->data.itemsize, sizeof(int)) 1.21 + CU_ASSERT_PTR_EQUAL(list->data.cmpfunc, cmp_int) 1.22 + 1.23 + struct node { 1.24 + void* begin; void* end; ptrdiff_t ploc; ptrdiff_t nloc; 1.25 + }; 1.26 + 1.27 + struct node* actual = (struct node*) list->data.listdata; 1.28 + CU_ASSERT_PTR_NULL(actual->begin) 1.29 + CU_ASSERT_PTR_NULL(actual->end) 1.30 + CU_ASSERT_EQUAL(0, actual->ploc) 1.31 + CU_ASSERT_EQUAL(sizeof(void*), actual->nloc) 1.32 + 1.33 + cxLinkedListDestroy(list); 1.34 } 1.35 1.36 int main() { 1.37 @@ -40,14 +63,14 @@ 1.38 return CU_get_error(); 1.39 } 1.40 1.41 - suite = CU_add_suite("linked list creation", NULL, NULL); 1.42 + suite = CU_add_suite("linked list memory management", NULL, NULL); 1.43 if (NULL == suite) { 1.44 CU_cleanup_registry(); 1.45 return CU_get_error(); 1.46 } 1.47 1.48 if ( 1.49 - !CU_add_test(suite, "wrapping of custom linked list", test_linked_list_wrap) 1.50 + !CU_add_test(suite, "create linked list", test_linked_list_create) 1.51 ) { 1.52 CU_cleanup_registry(); 1.53 return CU_get_error();