27 */ |
27 */ |
28 |
28 |
29 #include "cx/linked_list.h" |
29 #include "cx/linked_list.h" |
30 #include "test_config.h" |
30 #include "test_config.h" |
31 |
31 |
32 void test_linked_list_wrap() { |
32 int cmp_int(int const *l, int const *r) { |
33 CU_FAIL("test not implemented") |
33 int left = *l, right = *r; |
|
34 return left == right ? 0 : (left < right ? -1 : 1); |
|
35 } |
|
36 |
|
37 void test_linked_list_create() { |
|
38 CxList list = cxLinkedListCreate(cxDefaultAllocator, (CxListComparator) cmp_int, sizeof(int)); |
|
39 |
|
40 CU_ASSERT_EQUAL(list->data.size, 0) |
|
41 CU_ASSERT_EQUAL(list->data.capacity, (size_t) -1) |
|
42 CU_ASSERT_PTR_EQUAL(list->data.allocator, cxDefaultAllocator) |
|
43 CU_ASSERT_EQUAL(list->data.itemsize, sizeof(int)) |
|
44 CU_ASSERT_PTR_EQUAL(list->data.cmpfunc, cmp_int) |
|
45 |
|
46 struct node { |
|
47 void* begin; void* end; ptrdiff_t ploc; ptrdiff_t nloc; |
|
48 }; |
|
49 |
|
50 struct node* actual = (struct node*) list->data.listdata; |
|
51 CU_ASSERT_PTR_NULL(actual->begin) |
|
52 CU_ASSERT_PTR_NULL(actual->end) |
|
53 CU_ASSERT_EQUAL(0, actual->ploc) |
|
54 CU_ASSERT_EQUAL(sizeof(void*), actual->nloc) |
|
55 |
|
56 cxLinkedListDestroy(list); |
34 } |
57 } |
35 |
58 |
36 int main() { |
59 int main() { |
37 CU_pSuite suite = NULL; |
60 CU_pSuite suite = NULL; |
38 |
61 |
39 if (CUE_SUCCESS != CU_initialize_registry()) { |
62 if (CUE_SUCCESS != CU_initialize_registry()) { |
40 return CU_get_error(); |
63 return CU_get_error(); |
41 } |
64 } |
42 |
65 |
43 suite = CU_add_suite("linked list creation", NULL, NULL); |
66 suite = CU_add_suite("linked list memory management", NULL, NULL); |
44 if (NULL == suite) { |
67 if (NULL == suite) { |
45 CU_cleanup_registry(); |
68 CU_cleanup_registry(); |
46 return CU_get_error(); |
69 return CU_get_error(); |
47 } |
70 } |
48 |
71 |
49 if ( |
72 if ( |
50 !CU_add_test(suite, "wrapping of custom linked list", test_linked_list_wrap) |
73 !CU_add_test(suite, "create linked list", test_linked_list_create) |
51 ) { |
74 ) { |
52 CU_cleanup_registry(); |
75 CU_cleanup_registry(); |
53 return CU_get_error(); |
76 return CU_get_error(); |
54 } |
77 } |
55 |
78 |