test/test_list.c

changeset 453
bb144d08cd44
parent 449
68ad5750ba6b
child 455
8168e16cd1e9
equal deleted inserted replaced
452:a10c3e127050 453:bb144d08cd44
110 void *end = NULL; 110 void *end = NULL;
111 111
112 ptrdiff_t loc_prev = offsetof(struct node, prev); 112 ptrdiff_t loc_prev = offsetof(struct node, prev);
113 ptrdiff_t loc_next = offsetof(struct node, next); 113 ptrdiff_t loc_next = offsetof(struct node, next);
114 114
115 int ret; 115 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]);
116 ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]);
117 CU_ASSERT_EQUAL(ret, 0)
118 CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 116 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
119 CU_ASSERT_PTR_EQUAL(end, &nodes[0]) 117 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
120 CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL) 118 CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL)
121 CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL) 119 CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL)
122 120
123 ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]); 121 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]);
124 CU_ASSERT_EQUAL(ret, 0)
125 CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 122 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
126 CU_ASSERT_PTR_EQUAL(end, &nodes[1]) 123 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
127 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 124 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
128 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) 125 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
129 126
130 // test with begin only / prev, next 127 // test with begin only / prev, next
131 memset(nodes, 0, 4 * sizeof(struct node)); 128 memset(nodes, 0, 4 * sizeof(struct node));
132 begin = NULL; 129 begin = NULL;
133 end = NULL; 130 end = NULL;
134 131
135 ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]); 132 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]);
136 CU_ASSERT_EQUAL(ret, 0)
137 CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 133 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
138 ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]); 134 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]);
139 CU_ASSERT_EQUAL(ret, 0)
140 CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 135 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
141 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 136 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
142 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) 137 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
143 138
144 ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]); 139 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]);
145 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) 140 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2])
146 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) 141 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1])
147 142
148 // test with begin, end / next 143 // test with begin, end / next
149 memset(nodes, 0, 4 * sizeof(struct node)); 144 memset(nodes, 0, 4 * sizeof(struct node));
150 begin = NULL; 145 begin = NULL;
151 end = NULL; 146 end = NULL;
152 147
153 ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]); 148 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]);
154 CU_ASSERT_EQUAL(ret, 0)
155 CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) 149 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
156 CU_ASSERT_PTR_EQUAL(end, &nodes[0]) 150 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
157 ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]); 151 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]);
158 CU_ASSERT_EQUAL(ret, 0)
159 CU_ASSERT_PTR_EQUAL(end, &nodes[1]) 152 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
160 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) 153 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
161 CU_ASSERT_PTR_NULL(nodes[1].prev) 154 CU_ASSERT_PTR_NULL(nodes[1].prev)
162 } 155 }
163 156

mercurial