Tue, 28 Dec 2021 14:16:04 +0100
add cx_linked_list_compare() and simplifies some tests
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
29 #include "cx/linked_list.h"
30 #include "test_config.h"
31 #include "util_allocator.h"
33 int cmp_int(
34 int const *l,
35 int const *r
36 ) {
37 int left = *l, right = *r;
38 return left == right ? 0 : (left < right ? -1 : 1);
39 }
41 struct node {
42 struct node *next;
43 struct node *prev;
44 int data;
45 };
47 #define nd(name) name = {0}
49 const ptrdiff_t loc_prev = offsetof(struct node, prev);
50 const ptrdiff_t loc_next = offsetof(struct node, next);
51 const ptrdiff_t loc_data = offsetof(struct node, data);
53 struct node *create_test_data(
54 size_t n,
55 const int data[]
56 ) {
57 if (n == 0) return NULL;
58 struct node *begin = calloc(1, sizeof(struct node));
59 struct node *prev = begin;
60 if (data) begin->data = data[0];
61 for (size_t i = 1; i < n; i++) {
62 struct node *node = calloc(1, sizeof(struct node));
63 if (data) node->data = data[i];
64 cx_linked_list_link(prev, node, loc_prev, loc_next);
65 prev = node;
66 }
67 return begin;
68 }
70 void destroy_test_data(struct node *begin) {
71 struct node *node = begin;
72 while (node) {
73 struct node *next = node->next;
74 free(node);
75 node = next;
76 }
77 }
79 void test_linked_list_link_unlink(void) {
81 struct node nd(a), nd(b), nd(c);
83 cx_linked_list_link(&a, &b, loc_prev, loc_next);
84 CU_ASSERT_PTR_NULL(a.prev)
85 CU_ASSERT_PTR_EQUAL(a.next, &b)
86 CU_ASSERT_PTR_EQUAL(b.prev, &a)
87 CU_ASSERT_PTR_NULL(b.next)
89 cx_linked_list_unlink(&a, &b, loc_prev, loc_next);
90 CU_ASSERT_PTR_NULL(a.prev)
91 CU_ASSERT_PTR_NULL(a.next)
92 CU_ASSERT_PTR_NULL(b.prev)
93 CU_ASSERT_PTR_NULL(b.next)
95 cx_linked_list_link(&b, &c, loc_prev, loc_next);
96 cx_linked_list_link(&a, &b, loc_prev, loc_next);
97 cx_linked_list_unlink(&b, &c, loc_prev, loc_next);
98 CU_ASSERT_PTR_NULL(a.prev)
99 CU_ASSERT_PTR_EQUAL(a.next, &b)
100 CU_ASSERT_PTR_EQUAL(b.prev, &a)
101 CU_ASSERT_PTR_NULL(b.next)
102 CU_ASSERT_PTR_NULL(c.prev)
103 CU_ASSERT_PTR_NULL(c.next)
104 }
106 void test_linked_list_at(void) {
107 struct node nd(a), nd(b), nd(c), nd(d);
108 cx_linked_list_link(&a, &b, loc_prev, loc_next);
109 cx_linked_list_link(&b, &c, loc_prev, loc_next);
110 cx_linked_list_link(&c, &d, loc_prev, loc_next);
112 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 0), &a)
113 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 1), &b)
114 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 2), &c)
115 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 3), &d)
116 CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4))
118 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_prev, 0), &a)
119 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 1), &b)
120 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 2), &c)
121 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 3), &d)
122 CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4))
124 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a)
125 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b)
126 }
128 void test_linked_list_compare(void) {
129 int a[] = {2, 4, 6, 8};
130 int b[] = {2, 4, 6};
131 int c[] = {2, 4, 6, 9};
133 void *la = create_test_data(4, a);
134 void *lb = create_test_data(3, b);
135 void *lc = create_test_data(4, c);
137 CU_ASSERT_TRUE(0 < cx_linked_list_compare(la, lb, loc_next, loc_data,
138 0, (CxListComparator) cmp_int)
139 )
140 CU_ASSERT_TRUE(0 > cx_linked_list_compare(lb, la, loc_next, loc_data,
141 0, (CxListComparator) cmp_int)
142 )
143 CU_ASSERT_TRUE(0 < cx_linked_list_compare(lc, la, loc_next, loc_data,
144 0, (CxListComparator) cmp_int)
145 )
146 CU_ASSERT_TRUE(0 > cx_linked_list_compare(la, lc, loc_next, loc_data,
147 0, (CxListComparator) cmp_int)
148 )
149 CU_ASSERT_TRUE(0 == cx_linked_list_compare(la, la, loc_next, loc_data,
150 0, (CxListComparator) cmp_int)
151 )
153 destroy_test_data(la);
154 destroy_test_data(lb);
155 destroy_test_data(lc);
156 }
158 void test_linked_list_add(void) {
159 struct node nodes[4];
160 void *begin, *end;
162 // test with begin, end / prev, next
163 memset(nodes, 0, 4 * sizeof(struct node));
164 begin = end = NULL;
166 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]);
167 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
168 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
169 CU_ASSERT_PTR_NULL(nodes[0].prev)
170 CU_ASSERT_PTR_NULL(nodes[0].next)
172 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]);
173 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
174 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
175 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
176 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
178 // test with begin only / prev, next
179 memset(nodes, 0, 4 * sizeof(struct node));
180 begin = end = NULL;
182 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]);
183 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
184 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]);
185 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
186 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
187 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
189 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]);
190 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2])
191 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1])
193 // test with end only / prev, next
194 memset(nodes, 0, 4 * sizeof(struct node));
195 begin = end = NULL;
197 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]);
198 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
199 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]);
200 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
201 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
202 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
204 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]);
205 CU_ASSERT_PTR_EQUAL(end, &nodes[2])
206 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2])
207 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1])
209 // test with begin, end / next
210 memset(nodes, 0, 4 * sizeof(struct node));
211 begin = end = NULL;
213 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]);
214 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
215 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
216 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]);
217 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
218 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
219 CU_ASSERT_PTR_NULL(nodes[1].prev)
220 }
222 void test_linked_list_prepend(void) {
223 struct node nodes[4];
224 void *begin, *end;
226 // test with begin, end / prev, next
227 memset(nodes, 0, 4 * sizeof(struct node));
228 begin = end = NULL;
230 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[0]);
231 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
232 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
233 CU_ASSERT_PTR_NULL(nodes[0].prev)
234 CU_ASSERT_PTR_NULL(nodes[0].next)
236 cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[1]);
237 CU_ASSERT_PTR_EQUAL(begin, &nodes[1])
238 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
239 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0])
240 CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[1])
242 // test with begin only / prev, next
243 memset(nodes, 0, 4 * sizeof(struct node));
244 begin = end = NULL;
246 cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[0]);
247 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
248 cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[1]);
249 CU_ASSERT_PTR_EQUAL(begin, &nodes[1])
250 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0])
251 CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[1])
253 cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[2]);
254 CU_ASSERT_PTR_EQUAL(begin, &nodes[2])
255 CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[1])
256 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[2])
258 // test with end only / prev, next
259 memset(nodes, 0, 4 * sizeof(struct node));
260 begin = end = NULL;
262 cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[0]);
263 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
264 cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[1]);
265 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
266 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0])
267 CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[1])
269 cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[2]);
270 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
271 CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[1])
272 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[2])
274 // test with begin, end / next
275 memset(nodes, 0, 4 * sizeof(struct node));
276 begin = end = NULL;
278 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[0]);
279 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
280 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
281 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[1]);
282 cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[2]);
283 CU_ASSERT_PTR_EQUAL(begin, &nodes[2])
284 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
285 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0])
286 CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[1])
287 CU_ASSERT_PTR_NULL(nodes[1].prev)
288 CU_ASSERT_PTR_NULL(nodes[0].prev)
289 }
291 void test_linked_list_insert(void) {
292 struct node nodes[4];
293 void *begin, *end;
295 // insert mid list
296 memset(nodes, 0, 4 * sizeof(struct node));
297 begin = &nodes[0];
298 end = &nodes[2];
300 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
301 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
303 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3]);
304 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
305 CU_ASSERT_PTR_EQUAL(end, &nodes[2])
306 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[3])
307 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[3])
308 CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[1])
309 CU_ASSERT_PTR_EQUAL(nodes[3].next, &nodes[2])
311 // insert end
312 memset(nodes, 0, 4 * sizeof(struct node));
313 begin = &nodes[0];
314 end = &nodes[2];
316 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
317 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
319 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3]);
320 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
321 CU_ASSERT_PTR_EQUAL(end, &nodes[3])
322 CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[3])
323 CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[2])
324 CU_ASSERT_PTR_NULL(nodes[3].next)
326 // insert begin
327 memset(nodes, 0, 4 * sizeof(struct node));
328 begin = &nodes[0];
329 end = &nodes[2];
331 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
332 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
334 cx_linked_list_insert(&begin, &end, loc_prev, loc_next, NULL, &nodes[3]);
335 CU_ASSERT_PTR_EQUAL(begin, &nodes[3])
336 CU_ASSERT_PTR_EQUAL(end, &nodes[2])
337 CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[3])
338 CU_ASSERT_PTR_NULL(nodes[3].prev)
339 CU_ASSERT_PTR_EQUAL(nodes[3].next, &nodes[0])
340 }
342 void test_linked_list_insert_chain(void) {
343 struct node nodes[5];
344 void *begin, *end;
346 // insert mid list
347 memset(nodes, 0, 5 * sizeof(struct node));
348 begin = &nodes[0];
349 end = &nodes[2];
351 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
352 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
353 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
355 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3], NULL);
356 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
357 CU_ASSERT_PTR_EQUAL(end, &nodes[2])
358 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[3])
359 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[4])
360 CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[1])
361 CU_ASSERT_PTR_EQUAL(nodes[4].next, &nodes[2])
363 // insert end
364 memset(nodes, 0, 5 * sizeof(struct node));
365 begin = &nodes[0];
366 end = &nodes[2];
368 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
369 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
370 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
372 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3], NULL);
373 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
374 CU_ASSERT_PTR_EQUAL(end, &nodes[4])
375 CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[3])
376 CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[2])
377 CU_ASSERT_PTR_NULL(nodes[4].next)
379 // insert begin
380 memset(nodes, 0, 5 * sizeof(struct node));
381 begin = &nodes[0];
382 end = &nodes[2];
384 cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next);
385 cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next);
386 cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next);
388 cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, NULL, &nodes[3], NULL);
389 CU_ASSERT_PTR_EQUAL(begin, &nodes[3])
390 CU_ASSERT_PTR_EQUAL(end, &nodes[2])
391 CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[4])
392 CU_ASSERT_PTR_NULL(nodes[3].prev)
393 CU_ASSERT_PTR_EQUAL(nodes[4].next, &nodes[0])
394 }
396 void test_linked_list_first(void) {
397 struct node *begin = create_test_data(3, NULL);
398 CU_ASSERT_PTR_EQUAL(cx_linked_list_first(begin, loc_prev), begin)
399 CU_ASSERT_PTR_EQUAL(cx_linked_list_first(begin->next, loc_prev), begin)
400 CU_ASSERT_PTR_EQUAL(cx_linked_list_first(begin->next->next, loc_prev), begin)
401 destroy_test_data(begin);
402 }
404 void test_linked_list_last(void) {
405 struct node *begin = create_test_data(3, NULL);
406 struct node *end = begin->next->next;
407 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(begin, loc_next), end)
408 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(begin->next, loc_next), end)
409 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(begin->next->next, loc_next), end)
410 destroy_test_data(begin);
411 }
413 void test_linked_list_prev(void) {
414 struct node *begin = create_test_data(3, NULL);
415 CU_ASSERT_PTR_NULL(cx_linked_list_prev(begin, loc_next, begin))
416 CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(begin, loc_next, begin->next), begin)
417 CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(begin, loc_next, begin->next->next), begin->next)
418 destroy_test_data(begin);
419 }
421 void test_linked_list_remove(void) {
422 void *begin, *end;
424 int data[] = {2, 4, 6};
425 begin = create_test_data(3, data);
426 struct node *first = begin;
427 struct node *second = first->next;
428 struct node *third = second->next;
429 end = third;
431 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, second);
432 CU_ASSERT_PTR_EQUAL(begin, first)
433 CU_ASSERT_PTR_EQUAL(end, third)
434 CU_ASSERT_PTR_NULL(first->prev)
435 CU_ASSERT_PTR_EQUAL(first->next, third)
436 CU_ASSERT_PTR_EQUAL(third->prev, first)
437 CU_ASSERT_PTR_NULL(third->next)
439 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, third);
440 CU_ASSERT_PTR_EQUAL(begin, first)
441 CU_ASSERT_PTR_EQUAL(end, first)
442 CU_ASSERT_PTR_NULL(first->prev)
443 CU_ASSERT_PTR_NULL(first->next)
445 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, first);
446 CU_ASSERT_PTR_NULL(begin)
447 CU_ASSERT_PTR_NULL(end)
449 free(first);
450 free(second);
451 free(third);
452 }
454 void test_linked_list_size(void) {
455 struct node *list;
457 CU_ASSERT_PTR_EQUAL(cx_linked_list_size(NULL, loc_next), 0)
459 list = create_test_data(5, NULL);
460 CU_ASSERT_EQUAL(cx_linked_list_size(list, loc_next), 5)
461 destroy_test_data(list);
463 list = create_test_data(13, NULL);
464 CU_ASSERT_EQUAL(cx_linked_list_size(list, loc_next), 13)
465 destroy_test_data(list);
466 }
468 void test_linked_list_sort(void) {
469 int expected[] = {
470 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
471 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
472 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
473 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
474 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
475 4785, 4791, 4801, 4859, 4903, 4973
476 };
477 int scrambled[] = {
478 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
479 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
480 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
481 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
482 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
483 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
484 };
486 void *begin = create_test_data(100, scrambled);
487 void *end = cx_linked_list_last(begin, loc_next);
489 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data,
490 0, (CxListComparator) cmp_int);
492 struct node *check = begin;
493 struct node *check_last = NULL;
494 CU_ASSERT_PTR_NULL(check->prev)
495 CU_ASSERT_EQUAL(check->data, expected[0])
496 for (int i = 0; i < 100; i++) {
497 CU_ASSERT_EQUAL(check->data, expected[i])
498 CU_ASSERT_PTR_EQUAL(check->prev, check_last)
499 if (i < 99) {
500 CU_ASSERT_PTR_NOT_NULL(check->next)
501 }
502 check_last = check;
503 check = check->next;
504 }
505 CU_ASSERT_PTR_NULL(check)
506 CU_ASSERT_PTR_EQUAL(end, check_last)
508 destroy_test_data(begin);
509 }
511 void test_linked_list_reverse(void) {
512 void *begin, *end;
514 int data[] = {2, 4, 6, 8};
515 int reversed[] = {8, 6, 4, 2};
517 void *list = create_test_data(4, data);
518 void *expected = create_test_data(4, reversed);
520 begin = list;
521 end = cx_linked_list_last(list, loc_next);
523 cx_linked_list_reverse(&begin, &end, loc_prev, loc_next);
524 CU_ASSERT_PTR_EQUAL(end, list)
525 CU_ASSERT_PTR_EQUAL(begin, cx_linked_list_first(end, loc_prev))
526 CU_ASSERT_TRUE(0 == cx_linked_list_compare(begin, expected, loc_next, loc_data,
527 0, (CxListComparator) cmp_int))
529 destroy_test_data(begin);
530 destroy_test_data(expected);
531 }
533 void test_hl_linked_list_create(void) {
534 cxTestingAllocatorReset();
536 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
538 CU_ASSERT_EQUAL(list->size, 0)
539 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
540 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
541 CU_ASSERT_EQUAL(list->itemsize, sizeof(int))
542 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int)
544 cxLinkedListDestroy(list);
545 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
546 }
548 void test_hl_linked_list_add(void) {
549 cxTestingAllocatorReset();
551 int data;
552 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
554 data = 5;
555 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
556 data = 47;
557 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
558 data = 13;
559 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
561 CU_ASSERT_EQUAL(list->size, 3)
562 CU_ASSERT_TRUE(list->capacity >= list->size)
564 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
565 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
566 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
568 cxLinkedListDestroy(list);
569 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
570 }
572 void test_hl_linked_list_insert(void) {
573 cxTestingAllocatorReset();
575 int data;
576 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
578 data = 5;
579 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0)
580 CU_ASSERT_EQUAL(list->size, 0)
581 CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0)
582 CU_ASSERT_EQUAL(list->size, 1)
583 data = 47;
584 CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0)
585 CU_ASSERT_EQUAL(list->size, 2)
586 data = 13;
587 CU_ASSERT_EQUAL(cxListInsert(list, 1, &data), 0)
588 CU_ASSERT_EQUAL(list->size, 3)
589 data = 42;
590 CU_ASSERT_EQUAL(cxListInsert(list, 3, &data), 0)
592 CU_ASSERT_EQUAL(list->size, 4)
593 CU_ASSERT_TRUE(list->capacity >= list->size)
595 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
596 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
597 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5)
598 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42)
600 cxLinkedListDestroy(list);
601 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
602 }
604 void test_hl_linked_list_remove(void) {
605 cxTestingAllocatorReset();
607 int data;
608 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
610 data = 5;
611 cxListAdd(list, &data);
612 data = 47;
613 cxListAdd(list, &data);
614 data = 42;
615 cxListAdd(list, &data);
616 data = 13;
617 cxListAdd(list, &data);
619 CU_ASSERT_EQUAL(list->size, 4)
620 CU_ASSERT_TRUE(list->capacity >= list->size)
622 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0)
624 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0)
625 CU_ASSERT_EQUAL(list->size, 3)
626 CU_ASSERT_TRUE(list->capacity >= list->size)
627 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
628 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
629 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
631 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
632 CU_ASSERT_EQUAL(list->size, 2)
633 CU_ASSERT_TRUE(list->capacity >= list->size)
634 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
635 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
637 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0)
638 CU_ASSERT_EQUAL(list->size, 1)
639 CU_ASSERT_TRUE(list->capacity >= list->size)
640 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
642 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
643 CU_ASSERT_EQUAL(list->size, 0)
644 CU_ASSERT_TRUE(list->capacity >= list->size)
646 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0)
648 cxLinkedListDestroy(list);
649 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
650 }
652 void test_hl_linked_list_at(void) {
653 cxTestingAllocatorReset();
655 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
657 int data;
658 data = 5;
659 cxListAdd(list, &data);
660 data = 47;
661 cxListAdd(list, &data);
662 data = 13;
663 cxListAdd(list, &data);
665 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5)
666 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47)
667 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13)
668 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
670 cxLinkedListDestroy(list);
671 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
672 }
674 void test_hl_linked_list_find(void) {
675 cxTestingAllocatorReset();
677 int data, criteria;
678 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
680 data = 5;
681 cxListAdd(list, &data);
682 data = 47;
683 cxListAdd(list, &data);
684 data = 13;
685 cxListAdd(list, &data);
687 CU_ASSERT_EQUAL(list->size, 3)
688 CU_ASSERT_TRUE(list->capacity >= list->size)
690 criteria = 5;
691 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0)
692 criteria = 47;
693 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
694 criteria = 13;
695 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2)
696 criteria = 9000;
697 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
698 criteria = -5;
699 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
701 cxLinkedListDestroy(list);
702 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
703 }
705 void test_hl_linked_list_sort(void) {
706 int expected[] = {
707 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
708 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
709 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
710 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
711 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
712 4785, 4791, 4801, 4859, 4903, 4973
713 };
714 int scrambled[] = {
715 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
716 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
717 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
718 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
719 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
720 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
721 };
723 cxTestingAllocatorReset();
725 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
727 for (int i = 0; i < 100; i++) {
728 cxListAdd(list, &scrambled[i]);
729 }
731 cxListSort(list);
733 for (int i = 0; i < 100; i++) {
734 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i])
735 }
737 cxLinkedListDestroy(list);
738 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
739 }
741 void test_hl_ptr_linked_list_create(void) {
742 cxTestingAllocatorReset();
744 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
746 CU_ASSERT_EQUAL(list->size, 0)
747 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
748 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
749 CU_ASSERT_EQUAL(list->itemsize, sizeof(void *))
750 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int)
752 cxLinkedListDestroy(list);
753 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
754 }
756 void test_hl_ptr_linked_list_add(void) {
757 cxTestingAllocatorReset();
759 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
761 int a = 5, b = 47, c = 13;
763 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0)
764 CU_ASSERT_EQUAL(cxListAdd(list, &b), 0)
765 CU_ASSERT_EQUAL(cxListAdd(list, &c), 0)
767 CU_ASSERT_EQUAL(list->size, 3)
768 CU_ASSERT_TRUE(list->capacity >= list->size)
770 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
771 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
772 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
774 a = 9;
775 b = 10;
776 c = 11;
778 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9)
779 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10)
780 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11)
782 cxLinkedListDestroy(list);
783 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
784 }
786 void test_hl_ptr_linked_list_insert(void) {
787 cxTestingAllocatorReset();
789 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
791 int a = 5, b = 47, c = 13, d = 42;
793 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0)
794 CU_ASSERT_EQUAL(list->size, 0)
795 CU_ASSERT_EQUAL(cxListInsert(list, 0, &a), 0)
796 CU_ASSERT_EQUAL(list->size, 1)
797 CU_ASSERT_EQUAL(cxListInsert(list, 0, &b), 0)
798 CU_ASSERT_EQUAL(list->size, 2)
799 CU_ASSERT_EQUAL(cxListInsert(list, 1, &c), 0)
800 CU_ASSERT_EQUAL(list->size, 3)
801 CU_ASSERT_EQUAL(cxListInsert(list, 3, &d), 0)
803 CU_ASSERT_EQUAL(list->size, 4)
804 CU_ASSERT_TRUE(list->capacity >= list->size)
806 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
807 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
808 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5)
809 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42)
811 cxLinkedListDestroy(list);
812 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
813 }
815 void test_hl_ptr_linked_list_remove(void) {
816 cxTestingAllocatorReset();
818 int a = 5, b = 47, c = 42, d = 13;
819 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
821 cxListAdd(list, &a);
822 cxListAdd(list, &b);
823 cxListAdd(list, &c);
824 cxListAdd(list, &d);
826 CU_ASSERT_EQUAL(list->size, 4)
827 CU_ASSERT_TRUE(list->capacity >= list->size)
829 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0)
831 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0)
832 CU_ASSERT_EQUAL(list->size, 3)
833 CU_ASSERT_TRUE(list->capacity >= list->size)
834 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
835 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
836 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
838 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
839 CU_ASSERT_EQUAL(list->size, 2)
840 CU_ASSERT_TRUE(list->capacity >= list->size)
841 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
842 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
844 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0)
845 CU_ASSERT_EQUAL(list->size, 1)
846 CU_ASSERT_TRUE(list->capacity >= list->size)
847 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
849 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
850 CU_ASSERT_EQUAL(list->size, 0)
851 CU_ASSERT_TRUE(list->capacity >= list->size)
853 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0)
855 cxLinkedListDestroy(list);
856 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
857 }
859 void test_hl_ptr_linked_list_at(void) {
860 cxTestingAllocatorReset();
862 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
864 int a = 5, b = 47, c = 13;
865 cxListAdd(list, &a);
866 cxListAdd(list, &b);
867 cxListAdd(list, &c);
869 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5)
870 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47)
871 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13)
872 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
874 cxLinkedListDestroy(list);
875 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
876 }
878 void test_hl_ptr_linked_list_find(void) {
879 cxTestingAllocatorReset();
881 int a = 5, b = 47, c = 13, criteria;
882 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
884 cxListAdd(list, &a);
885 cxListAdd(list, &b);
886 cxListAdd(list, &c);
888 CU_ASSERT_EQUAL(list->size, 3)
889 CU_ASSERT_TRUE(list->capacity >= list->size)
891 criteria = 5;
892 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0)
893 criteria = 47;
894 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
895 criteria = 13;
896 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2)
897 criteria = 9000;
898 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
899 criteria = -5;
900 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
901 b = -5;
902 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
904 cxLinkedListDestroy(list);
905 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
906 }
908 void test_hl_ptr_linked_list_sort(void) {
909 int expected[] = {
910 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
911 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
912 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
913 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
914 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
915 4785, 4791, 4801, 4859, 4903, 4973
916 };
917 int scrambled[] = {
918 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
919 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
920 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
921 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
922 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
923 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
924 };
926 cxTestingAllocatorReset();
928 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
930 for (int i = 0; i < 100; i++) {
931 cxListAdd(list, &scrambled[i]);
932 }
934 cxListSort(list);
936 for (int i = 0; i < 100; i++) {
937 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i])
938 }
940 cxLinkedListDestroy(list);
941 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
942 }
944 int main() {
945 CU_pSuite suite = NULL;
947 if (CUE_SUCCESS != CU_initialize_registry()) {
948 return CU_get_error();
949 }
951 suite = CU_add_suite("low level linked list", NULL, NULL);
953 cu_add_test(suite, test_linked_list_link_unlink);
954 cu_add_test(suite, test_linked_list_at);
955 cu_add_test(suite, test_linked_list_compare);
956 cu_add_test(suite, test_linked_list_prepend);
957 cu_add_test(suite, test_linked_list_add);
958 cu_add_test(suite, test_linked_list_insert);
959 cu_add_test(suite, test_linked_list_insert_chain);
960 cu_add_test(suite, test_linked_list_first);
961 cu_add_test(suite, test_linked_list_last);
962 cu_add_test(suite, test_linked_list_prev);
963 cu_add_test(suite, test_linked_list_remove);
964 cu_add_test(suite, test_linked_list_size);
965 cu_add_test(suite, test_linked_list_sort);
966 cu_add_test(suite, test_linked_list_reverse);
968 suite = CU_add_suite("high level linked list", NULL, NULL);
970 cu_add_test(suite, test_hl_linked_list_create);
971 cu_add_test(suite, test_hl_linked_list_add);
972 cu_add_test(suite, test_hl_linked_list_insert);
973 cu_add_test(suite, test_hl_linked_list_remove);
974 cu_add_test(suite, test_hl_linked_list_at);
975 cu_add_test(suite, test_hl_linked_list_find);
976 cu_add_test(suite, test_hl_linked_list_sort);
978 suite = CU_add_suite("high level pointer linked list", NULL, NULL);
980 cu_add_test(suite, test_hl_ptr_linked_list_create);
981 cu_add_test(suite, test_hl_ptr_linked_list_add);
982 cu_add_test(suite, test_hl_ptr_linked_list_insert);
983 cu_add_test(suite, test_hl_ptr_linked_list_remove);
984 cu_add_test(suite, test_hl_ptr_linked_list_at);
985 cu_add_test(suite, test_hl_ptr_linked_list_find);
986 cu_add_test(suite, test_hl_ptr_linked_list_sort);
988 CU_basic_set_mode(UCX_CU_BRM);
990 int exitcode;
991 if (CU_basic_run_tests()) {
992 exitcode = CU_get_error();
993 } else {
994 exitcode = CU_get_number_of_failures() == 0 ? 0 : 1;
995 }
996 CU_cleanup_registry();
997 return exitcode;
998 }