1.1 --- a/test/test_list.c Tue Sep 28 18:49:12 2021 +0200 1.2 +++ b/test/test_list.c Sun Oct 03 10:43:31 2021 +0200 1.3 @@ -80,96 +80,96 @@ 1.4 d.prev = &c; 1.5 d.next = NULL; 1.6 1.7 - CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&a, 0, loc_next, 0)); 1.8 - CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&a, 0, loc_next, 1)); 1.9 - CU_ASSERT_PTR_EQUAL(&c, cx_linked_list_at(&a, 0, loc_next, 2)); 1.10 - CU_ASSERT_PTR_EQUAL(&d, cx_linked_list_at(&a, 0, loc_next, 3)); 1.11 - CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4)); 1.12 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 0), &a) 1.13 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 1), &b) 1.14 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 2), &c) 1.15 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 3), &d) 1.16 + CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4)) 1.17 1.18 - CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&b, 1, loc_prev, 0)); 1.19 - CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&b, 1, loc_next, 1)); 1.20 - CU_ASSERT_PTR_EQUAL(&c, cx_linked_list_at(&b, 1, loc_next, 2)); 1.21 - CU_ASSERT_PTR_EQUAL(&d, cx_linked_list_at(&b, 1, loc_next, 3)); 1.22 - CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4)); 1.23 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_prev, 0), &a) 1.24 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 1), &b) 1.25 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 2), &c) 1.26 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 3), &d) 1.27 + CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4)) 1.28 1.29 - CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&d, 3, loc_prev, 0)); 1.30 - CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&d, 3, loc_prev, 1)); 1.31 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a) 1.32 + CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b) 1.33 } 1.34 1.35 void test_linked_list_add(void) { 1.36 struct node { 1.37 void *prev; 1.38 void *next; 1.39 - int value; 1.40 }; 1.41 - 1.42 + 1.43 struct node nodes[4]; 1.44 - 1.45 + 1.46 // test with begin, end / prev, next 1.47 - memset(nodes, 0, 4*sizeof(struct node)); 1.48 + memset(nodes, 0, 4 * sizeof(struct node)); 1.49 void *begin = NULL; 1.50 void *end = NULL; 1.51 - 1.52 + 1.53 ptrdiff_t loc_prev = offsetof(struct node, prev); 1.54 ptrdiff_t loc_next = offsetof(struct node, next); 1.55 - 1.56 + 1.57 int ret; 1.58 ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]); 1.59 - CU_ASSERT_EQUAL(ret, 0); 1.60 - CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); 1.61 - CU_ASSERT_PTR_EQUAL(end, &nodes[0]); 1.62 - CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL); 1.63 - CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL); 1.64 - 1.65 + CU_ASSERT_EQUAL(ret, 0) 1.66 + CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 1.67 + CU_ASSERT_PTR_EQUAL(end, &nodes[0]) 1.68 + CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL) 1.69 + CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL) 1.70 + 1.71 ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]); 1.72 - CU_ASSERT_EQUAL(ret, 0); 1.73 - CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); 1.74 - CU_ASSERT_PTR_EQUAL(end, &nodes[1]); 1.75 - CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]); 1.76 - CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]); 1.77 - 1.78 + CU_ASSERT_EQUAL(ret, 0) 1.79 + CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 1.80 + CU_ASSERT_PTR_EQUAL(end, &nodes[1]) 1.81 + CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 1.82 + CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) 1.83 + 1.84 // test with begin only / prev, next 1.85 - memset(nodes, 0, 4*sizeof(struct node)); 1.86 + memset(nodes, 0, 4 * sizeof(struct node)); 1.87 begin = NULL; 1.88 end = NULL; 1.89 - 1.90 + 1.91 ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]); 1.92 - CU_ASSERT_EQUAL(ret, 0); 1.93 - CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); 1.94 + CU_ASSERT_EQUAL(ret, 0) 1.95 + CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 1.96 ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]); 1.97 - CU_ASSERT_EQUAL(ret, 0); 1.98 - CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); 1.99 - CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]); 1.100 - CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]); 1.101 - 1.102 + CU_ASSERT_EQUAL(ret, 0) 1.103 + CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 1.104 + CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 1.105 + CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) 1.106 + 1.107 ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]); 1.108 - CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]); 1.109 - CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]); 1.110 - 1.111 + CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) 1.112 + CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) 1.113 + 1.114 // test with begin, end / next 1.115 - memset(nodes, 0, 4*sizeof(struct node)); 1.116 + memset(nodes, 0, 4 * sizeof(struct node)); 1.117 begin = NULL; 1.118 end = NULL; 1.119 - 1.120 + 1.121 ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]); 1.122 - CU_ASSERT_EQUAL(ret, 0); 1.123 - CU_ASSERT_PTR_EQUAL(begin, &nodes[0]); 1.124 - CU_ASSERT_PTR_EQUAL(end, &nodes[0]); 1.125 + CU_ASSERT_EQUAL(ret, 0) 1.126 + CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 1.127 + CU_ASSERT_PTR_EQUAL(end, &nodes[0]) 1.128 ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]); 1.129 - CU_ASSERT_PTR_EQUAL(end, &nodes[1]); 1.130 - CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]); 1.131 - CU_ASSERT_PTR_EQUAL(nodes[1].prev, NULL); 1.132 + CU_ASSERT_EQUAL(ret, 0) 1.133 + CU_ASSERT_PTR_EQUAL(end, &nodes[1]) 1.134 + CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 1.135 + CU_ASSERT_PTR_NULL(nodes[1].prev) 1.136 } 1.137 1.138 int main() { 1.139 CU_pSuite suite = NULL; 1.140 - 1.141 + 1.142 if (CUE_SUCCESS != CU_initialize_registry()) { 1.143 return CU_get_error(); 1.144 } 1.145 1.146 suite = CU_add_suite("linked list suite", NULL, NULL); 1.147 - 1.148 + 1.149 CU_add_test(suite, "linked list: create and destroy", test_linked_list_create); 1.150 CU_add_test(suite, "linked list: get node at index", test_linked_list_at); 1.151 CU_add_test(suite, "linked list: add", test_linked_list_add);