Mon, 27 Dec 2021 17:02:32 +0100
add common.h include to all other header files
390 | 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 | */ | |
28 | ||
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
29 | #include "cx/linked_list.h" |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
30 | #include "test_config.h" |
422
afd87df80b13
add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
413
diff
changeset
|
31 | #include "util_allocator.h" |
398
8d506ed6c1c0
adds first draft for linked list implementation
Mike Becker <universe@uap-core.de>
parents:
390
diff
changeset
|
32 | |
412
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
33 | int cmp_int(int const *l, int const *r) { |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
34 | int left = *l, right = *r; |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
35 | return left == right ? 0 : (left < right ? -1 : 1); |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
36 | } |
af766caea48d
removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents:
411
diff
changeset
|
37 | |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
38 | void test_linked_list_link_unlink(void) { |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
39 | struct node { |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
40 | void *next; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
41 | void *prev; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
42 | }; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
43 | const ptrdiff_t loc_prev = offsetof(struct node, prev); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
44 | const ptrdiff_t loc_next = offsetof(struct node, next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
45 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
46 | struct node a = {NULL, NULL}, b = {NULL, NULL}; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
47 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
48 | cx_linked_list_link(&a, &b, loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
49 | CU_ASSERT_PTR_NULL(a.prev) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
50 | CU_ASSERT_PTR_EQUAL(a.next, &b) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
51 | CU_ASSERT_PTR_EQUAL(b.prev, &a) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
52 | CU_ASSERT_PTR_NULL(b.next) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
53 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
54 | cx_linked_list_unlink(&a, &b, loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
55 | CU_ASSERT_PTR_NULL(a.prev) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
56 | CU_ASSERT_PTR_NULL(a.next) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
57 | CU_ASSERT_PTR_NULL(b.prev) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
58 | CU_ASSERT_PTR_NULL(b.next) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
59 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
60 | struct node c = {NULL, NULL}; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
61 | cx_linked_list_link(&b, &c, loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
62 | cx_linked_list_link(&a, &b, loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
63 | cx_linked_list_unlink(&b, &c, loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
64 | CU_ASSERT_PTR_NULL(a.prev) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
65 | CU_ASSERT_PTR_EQUAL(a.next, &b) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
66 | CU_ASSERT_PTR_EQUAL(b.prev, &a) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
67 | CU_ASSERT_PTR_NULL(b.next) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
68 | CU_ASSERT_PTR_NULL(c.prev) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
69 | CU_ASSERT_PTR_NULL(c.next) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
70 | } |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
71 | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
72 | void test_linked_list_at(void) { |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
73 | struct node { |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
74 | void *next; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
75 | void *prev; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
76 | }; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
77 | const ptrdiff_t loc_prev = offsetof(struct node, prev); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
78 | const ptrdiff_t loc_next = offsetof(struct node, next); |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
79 | |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
80 | struct node a, b, c, d; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
81 | a.prev = NULL; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
82 | a.next = &b; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
83 | b.prev = &a; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
84 | b.next = &c; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
85 | c.prev = &b; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
86 | c.next = &d; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
87 | d.prev = &c; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
88 | d.next = NULL; |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
89 | |
449 | 90 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 0), &a) |
91 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 1), &b) | |
92 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 2), &c) | |
93 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 3), &d) | |
94 | CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4)) | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
95 | |
449 | 96 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_prev, 0), &a) |
97 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 1), &b) | |
98 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 2), &c) | |
99 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 3), &d) | |
100 | CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4)) | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
101 | |
449 | 102 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a) |
103 | CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b) | |
438
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
104 | } |
cd3069757010
add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents:
435
diff
changeset
|
105 | |
444
cb944fa1852a
rename test_cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
106 | void test_linked_list_add(void) { |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
107 | struct node { |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
108 | void *prev; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
109 | void *next; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
110 | }; |
449 | 111 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
112 | struct node nodes[4]; |
449 | 113 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
114 | // test with begin, end / prev, next |
449 | 115 | memset(nodes, 0, 4 * sizeof(struct node)); |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
116 | void *begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
117 | void *end = NULL; |
449 | 118 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
119 | ptrdiff_t loc_prev = offsetof(struct node, prev); |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
120 | ptrdiff_t loc_next = offsetof(struct node, next); |
449 | 121 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
122 | cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]); |
449 | 123 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
124 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) | |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
125 | CU_ASSERT_PTR_NULL(nodes[0].prev) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
126 | CU_ASSERT_PTR_NULL(nodes[0].next) |
449 | 127 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
128 | cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]); |
449 | 129 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
130 | CU_ASSERT_PTR_EQUAL(end, &nodes[1]) | |
131 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) | |
132 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) | |
133 | ||
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
134 | // test with begin only / prev, next |
449 | 135 | memset(nodes, 0, 4 * sizeof(struct node)); |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
136 | begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
137 | end = NULL; |
449 | 138 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
139 | cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]); |
449 | 140 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
141 | cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]); |
449 | 142 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
143 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) | |
144 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) | |
145 | ||
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
146 | cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]); |
449 | 147 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) |
148 | CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) | |
149 | ||
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
150 | // test with end only / prev, next |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
151 | memset(nodes, 0, 4 * sizeof(struct node)); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
152 | begin = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
153 | end = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
154 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
155 | cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
156 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
157 | cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
158 | CU_ASSERT_PTR_EQUAL(end, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
159 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
160 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
161 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
162 | cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
163 | CU_ASSERT_PTR_EQUAL(end, &nodes[2]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
164 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
165 | CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
166 | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
167 | // test with begin, end / next |
449 | 168 | memset(nodes, 0, 4 * sizeof(struct node)); |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
169 | begin = NULL; |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
170 | end = NULL; |
449 | 171 | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
172 | cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]); |
449 | 173 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
174 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) | |
453
bb144d08cd44
add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents:
449
diff
changeset
|
175 | cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]); |
449 | 176 | CU_ASSERT_PTR_EQUAL(end, &nodes[1]) |
177 | CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]) | |
178 | CU_ASSERT_PTR_NULL(nodes[1].prev) | |
442
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
179 | } |
310019ddfe4e
add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
438
diff
changeset
|
180 | |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
181 | void test_linked_list_prepend(void) { |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
182 | struct node { |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
183 | void *prev; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
184 | void *next; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
185 | }; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
186 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
187 | struct node nodes[4]; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
188 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
189 | // test with begin, end / prev, next |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
190 | memset(nodes, 0, 4 * sizeof(struct node)); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
191 | void *begin = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
192 | void *end = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
193 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
194 | ptrdiff_t loc_prev = offsetof(struct node, prev); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
195 | ptrdiff_t loc_next = offsetof(struct node, next); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
196 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
197 | cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[0]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
198 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
199 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
200 | CU_ASSERT_PTR_NULL(nodes[0].prev) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
201 | CU_ASSERT_PTR_NULL(nodes[0].next) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
202 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
203 | cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[1]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
204 | CU_ASSERT_PTR_EQUAL(begin, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
205 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
206 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
207 | CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
208 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
209 | // test with begin only / prev, next |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
210 | memset(nodes, 0, 4 * sizeof(struct node)); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
211 | begin = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
212 | end = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
213 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
214 | cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[0]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
215 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
216 | cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[1]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
217 | CU_ASSERT_PTR_EQUAL(begin, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
218 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
219 | CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
220 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
221 | cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[2]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
222 | CU_ASSERT_PTR_EQUAL(begin, &nodes[2]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
223 | CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
224 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[2]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
225 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
226 | // test with end only / prev, next |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
227 | memset(nodes, 0, 4 * sizeof(struct node)); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
228 | begin = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
229 | end = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
230 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
231 | cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[0]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
232 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
233 | cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[1]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
234 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
235 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
236 | CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
237 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
238 | cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[2]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
239 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
240 | CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
241 | CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[2]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
242 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
243 | // test with begin, end / next |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
244 | memset(nodes, 0, 4 * sizeof(struct node)); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
245 | begin = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
246 | end = NULL; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
247 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
248 | cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[0]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
249 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
250 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
251 | cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[1]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
252 | cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[2]); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
253 | CU_ASSERT_PTR_EQUAL(begin, &nodes[2]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
254 | CU_ASSERT_PTR_EQUAL(end, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
255 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[0]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
256 | CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[1]) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
257 | CU_ASSERT_PTR_NULL(nodes[1].prev) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
258 | CU_ASSERT_PTR_NULL(nodes[0].prev) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
259 | } |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
260 | |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
261 | void test_linked_list_insert(void) { |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
262 | struct node { |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
263 | void *prev; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
264 | void *next; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
265 | }; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
266 | ptrdiff_t loc_prev = offsetof(struct node, prev); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
267 | ptrdiff_t loc_next = offsetof(struct node, next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
268 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
269 | struct node nodes[4]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
270 | void *begin, *end; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
271 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
272 | // insert mid list |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
273 | memset(nodes, 0, 4 * sizeof(struct node)); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
274 | begin = &nodes[0]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
275 | end = &nodes[2]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
276 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
277 | cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
278 | cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
279 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
280 | cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3]); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
281 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
282 | CU_ASSERT_PTR_EQUAL(end, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
283 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
284 | CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
285 | CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[1]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
286 | CU_ASSERT_PTR_EQUAL(nodes[3].next, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
287 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
288 | // insert end |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
289 | memset(nodes, 0, 4 * sizeof(struct node)); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
290 | begin = &nodes[0]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
291 | end = &nodes[2]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
292 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
293 | cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
294 | cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
295 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
296 | cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3]); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
297 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
298 | CU_ASSERT_PTR_EQUAL(end, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
299 | CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
300 | CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
301 | CU_ASSERT_PTR_NULL(nodes[3].next) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
302 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
303 | // insert begin |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
304 | memset(nodes, 0, 4 * sizeof(struct node)); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
305 | begin = &nodes[0]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
306 | end = &nodes[2]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
307 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
308 | cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
309 | cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
310 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
311 | cx_linked_list_insert(&begin, &end, loc_prev, loc_next, NULL, &nodes[3]); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
312 | CU_ASSERT_PTR_EQUAL(begin, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
313 | CU_ASSERT_PTR_EQUAL(end, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
314 | CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
315 | CU_ASSERT_PTR_NULL(nodes[3].prev) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
316 | CU_ASSERT_PTR_EQUAL(nodes[3].next, &nodes[0]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
317 | } |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
318 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
319 | void test_linked_list_insert_chain(void) { |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
320 | struct node { |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
321 | void *prev; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
322 | void *next; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
323 | }; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
324 | ptrdiff_t loc_prev = offsetof(struct node, prev); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
325 | ptrdiff_t loc_next = offsetof(struct node, next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
326 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
327 | struct node nodes[5]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
328 | void *begin, *end; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
329 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
330 | // insert mid list |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
331 | memset(nodes, 0, 5 * sizeof(struct node)); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
332 | begin = &nodes[0]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
333 | end = &nodes[2]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
334 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
335 | cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
336 | cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
337 | cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
338 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
339 | cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3], NULL); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
340 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
341 | CU_ASSERT_PTR_EQUAL(end, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
342 | CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
343 | CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[4]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
344 | CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[1]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
345 | CU_ASSERT_PTR_EQUAL(nodes[4].next, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
346 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
347 | // insert end |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
348 | memset(nodes, 0, 5 * sizeof(struct node)); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
349 | begin = &nodes[0]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
350 | end = &nodes[2]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
351 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
352 | cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
353 | cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
354 | cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
355 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
356 | cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3], NULL); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
357 | CU_ASSERT_PTR_EQUAL(begin, &nodes[0]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
358 | CU_ASSERT_PTR_EQUAL(end, &nodes[4]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
359 | CU_ASSERT_PTR_EQUAL(nodes[2].next, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
360 | CU_ASSERT_PTR_EQUAL(nodes[3].prev, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
361 | CU_ASSERT_PTR_NULL(nodes[4].next) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
362 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
363 | // insert begin |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
364 | memset(nodes, 0, 5 * sizeof(struct node)); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
365 | begin = &nodes[0]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
366 | end = &nodes[2]; |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
367 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
368 | cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
369 | cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
370 | cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
371 | |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
372 | cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, NULL, &nodes[3], NULL); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
373 | CU_ASSERT_PTR_EQUAL(begin, &nodes[3]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
374 | CU_ASSERT_PTR_EQUAL(end, &nodes[2]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
375 | CU_ASSERT_PTR_EQUAL(nodes[0].prev, &nodes[4]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
376 | CU_ASSERT_PTR_NULL(nodes[3].prev) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
377 | CU_ASSERT_PTR_EQUAL(nodes[4].next, &nodes[0]) |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
378 | } |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
379 | |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
380 | void test_linked_list_first(void) { |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
381 | struct node { |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
382 | int data; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
383 | void *prev; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
384 | }; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
385 | ptrdiff_t loc = offsetof(struct node, prev); |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
386 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
387 | struct node first = {1, NULL}; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
388 | struct node second = {2, &first}; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
389 | struct node third = {3, &second}; |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
390 | |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
391 | CU_ASSERT_PTR_EQUAL(cx_linked_list_first(&first, loc), &first) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
392 | CU_ASSERT_PTR_EQUAL(cx_linked_list_first(&second, loc), &first) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
393 | CU_ASSERT_PTR_EQUAL(cx_linked_list_first(&third, loc), &first) |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
394 | } |
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
395 | |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
396 | void test_linked_list_last(void) { |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
397 | struct node { |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
398 | int data; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
399 | void *next; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
400 | }; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
401 | ptrdiff_t loc = offsetof(struct node, next); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
402 | |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
403 | struct node third = {3, NULL}; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
404 | struct node second = {2, &third}; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
405 | struct node first = {1, &second}; |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
406 | |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
407 | CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&first, loc), &third) |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
408 | CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&second, loc), &third) |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
409 | CU_ASSERT_PTR_EQUAL(cx_linked_list_last(&third, loc), &third) |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
410 | } |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
411 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
412 | void test_linked_list_prev(void) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
413 | struct node { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
414 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
415 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
416 | ptrdiff_t loc = offsetof(struct node, next); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
417 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
418 | struct node third = {NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
419 | struct node second = {&third}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
420 | struct node first = {&second}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
421 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
422 | CU_ASSERT_PTR_NULL(cx_linked_list_prev(&first, loc, &first)) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
423 | CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(&first, loc, &second), &first) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
424 | CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(&first, loc, &third), &second) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
425 | } |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
426 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
427 | void test_linked_list_remove(void) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
428 | struct node { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
429 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
430 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
431 | struct dnode { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
432 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
433 | void *prev; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
434 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
435 | ptrdiff_t loc = offsetof(struct node, next); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
436 | ptrdiff_t ploc = offsetof(struct dnode, prev); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
437 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
438 | void *begin; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
439 | void *end; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
440 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
441 | // single linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
442 | struct node third = {NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
443 | struct node second = {&third}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
444 | struct node first = {&second}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
445 | begin = &first; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
446 | |
476
60ff4561dc04
change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents:
475
diff
changeset
|
447 | cx_linked_list_remove(&begin, NULL, -1, loc, &second); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
448 | CU_ASSERT_PTR_EQUAL(begin, &first) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
449 | CU_ASSERT_PTR_EQUAL(first.next, &third) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
450 | CU_ASSERT_PTR_NULL(third.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
451 | |
476
60ff4561dc04
change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents:
475
diff
changeset
|
452 | cx_linked_list_remove(&begin, NULL, -1, loc, &first); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
453 | CU_ASSERT_PTR_EQUAL(begin, &third) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
454 | CU_ASSERT_PTR_NULL(third.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
455 | |
476
60ff4561dc04
change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents:
475
diff
changeset
|
456 | cx_linked_list_remove(&begin, NULL, -1, loc, &third); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
457 | CU_ASSERT_PTR_NULL(begin) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
458 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
459 | // doubly linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
460 | struct dnode dthird = {NULL , NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
461 | struct dnode dsecond = {&dthird, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
462 | struct dnode dfirst = {&dsecond, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
463 | dthird.prev = &dsecond; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
464 | dsecond.prev = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
465 | begin = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
466 | end = &dthird; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
467 | |
476
60ff4561dc04
change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents:
475
diff
changeset
|
468 | cx_linked_list_remove(&begin, &end, ploc, loc, &dsecond); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
469 | CU_ASSERT_PTR_EQUAL(begin, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
470 | CU_ASSERT_PTR_EQUAL(end, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
471 | CU_ASSERT_PTR_NULL(dfirst.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
472 | CU_ASSERT_PTR_EQUAL(dfirst.next, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
473 | CU_ASSERT_PTR_EQUAL(dthird.prev, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
474 | CU_ASSERT_PTR_NULL(dthird.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
475 | |
476
60ff4561dc04
change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents:
475
diff
changeset
|
476 | cx_linked_list_remove(&begin, &end, ploc, loc, &dthird); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
477 | CU_ASSERT_PTR_EQUAL(begin, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
478 | CU_ASSERT_PTR_EQUAL(end, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
479 | CU_ASSERT_PTR_NULL(dfirst.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
480 | CU_ASSERT_PTR_NULL(dfirst.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
481 | |
476
60ff4561dc04
change contract of cx_linked_list_remove()
Mike Becker <universe@uap-core.de>
parents:
475
diff
changeset
|
482 | cx_linked_list_remove(&begin, &end, ploc, loc, &dfirst); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
483 | CU_ASSERT_PTR_NULL(begin) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
484 | CU_ASSERT_PTR_NULL(end) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
485 | } |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
486 | |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
487 | void test_linked_list_size(void) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
488 | struct node { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
489 | void *next; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
490 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
491 | ptrdiff_t loc = offsetof(struct node, next); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
492 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
493 | struct node first = {NULL}; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
494 | struct node second = {NULL}; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
495 | struct node third = {NULL}; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
496 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
497 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(NULL, loc), 0) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
498 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&first, loc), 1) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
499 | first.next = &second; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
500 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&first, loc), 2) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
501 | second.next = &third; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
502 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&first, loc), 3) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
503 | CU_ASSERT_PTR_EQUAL(cx_linked_list_size(&second, loc), 2) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
504 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
505 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
506 | void test_linked_list_sort(void) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
507 | struct node { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
508 | void *prev; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
509 | void *next; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
510 | int data; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
511 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
512 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
513 | int expected[] = { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
514 | 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
515 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
516 | 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
517 | 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
518 | 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
519 | 4785, 4791, 4801, 4859, 4903, 4973 |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
520 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
521 | int scrambled[] = { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
522 | 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
523 | 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
524 | 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
525 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
526 | 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
527 | 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
528 | }; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
529 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
530 | struct node *nodes = calloc(100, sizeof(struct node)); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
531 | for (int i = 0; i < 100; i++) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
532 | nodes[i].prev = i == 0 ? NULL : &nodes[i - 1]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
533 | nodes[i].next = i == 99 ? NULL : &nodes[i + 1]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
534 | nodes[i].data = scrambled[i]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
535 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
536 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
537 | struct node *begin = &nodes[0]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
538 | struct node *end = &nodes[99]; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
539 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
540 | cx_linked_list_sort((void **) &begin, (void **) &end, |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
541 | offsetof(struct node, prev), |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
542 | offsetof(struct node, next), |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
543 | offsetof(struct node, data), |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
544 | 0, (CxListComparator) cmp_int); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
545 | |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
546 | CU_ASSERT_PTR_NULL(begin->prev) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
547 | CU_ASSERT_EQUAL(begin->data, expected[0]) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
548 | struct node *check = begin; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
549 | struct node *check_last = NULL; |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
550 | for (int i = 0; i < 100; i++) { |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
551 | CU_ASSERT_EQUAL(check->data, expected[i]) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
552 | CU_ASSERT_PTR_EQUAL(check->prev, check_last) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
553 | if (i < 99) { |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
554 | CU_ASSERT_PTR_NOT_NULL(check->next) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
555 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
556 | check_last = check; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
557 | check = check->next; |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
558 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
559 | CU_ASSERT_PTR_NULL(check) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
560 | CU_ASSERT_EQUAL(end->data, expected[99]) |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
561 | } |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
562 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
563 | void test_linked_list_reverse(void) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
564 | struct node { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
565 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
566 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
567 | struct dnode { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
568 | void *next; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
569 | void *prev; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
570 | }; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
571 | ptrdiff_t loc = offsetof(struct node, next); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
572 | ptrdiff_t ploc = offsetof(struct dnode, prev); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
573 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
574 | void *begin; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
575 | void *end; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
576 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
577 | // single linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
578 | struct node third = {NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
579 | struct node second = {&third}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
580 | struct node first = {&second}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
581 | begin = &first; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
582 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
583 | cx_linked_list_reverse(&begin, NULL, -1, loc); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
584 | CU_ASSERT_PTR_EQUAL(begin, &third) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
585 | CU_ASSERT_PTR_EQUAL(third.next, &second) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
586 | CU_ASSERT_PTR_EQUAL(second.next, &first) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
587 | CU_ASSERT_PTR_NULL(first.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
588 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
589 | // doubly linked list |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
590 | struct dnode dthird = {NULL , NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
591 | struct dnode dsecond = {&dthird, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
592 | struct dnode dfirst = {&dsecond, NULL}; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
593 | dthird.prev = &dsecond; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
594 | dsecond.prev = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
595 | begin = &dfirst; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
596 | end = &dthird; |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
597 | |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
598 | cx_linked_list_reverse(&begin, &end, ploc, loc); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
599 | CU_ASSERT_PTR_EQUAL(begin, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
600 | CU_ASSERT_PTR_EQUAL(end, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
601 | CU_ASSERT_PTR_EQUAL(dthird.next, &dsecond) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
602 | CU_ASSERT_PTR_EQUAL(dsecond.next, &dfirst) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
603 | CU_ASSERT_PTR_NULL(dfirst.next) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
604 | CU_ASSERT_PTR_NULL(dthird.prev) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
605 | CU_ASSERT_PTR_EQUAL(dsecond.prev, &dthird) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
606 | CU_ASSERT_PTR_EQUAL(dfirst.prev, &dsecond) |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
607 | } |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
608 | |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
609 | void test_hl_linked_list_create(void) { |
455 | 610 | cxTestingAllocatorReset(); |
611 | ||
612 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); | |
613 | ||
614 | CU_ASSERT_EQUAL(list->size, 0) | |
615 | CU_ASSERT_EQUAL(list->capacity, (size_t) -1) | |
616 | CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) | |
617 | CU_ASSERT_EQUAL(list->itemsize, sizeof(int)) | |
618 | CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) | |
619 | ||
620 | cxLinkedListDestroy(list); | |
621 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) | |
622 | } | |
623 | ||
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
624 | void test_hl_linked_list_add(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
625 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
626 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
627 | int data; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
628 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
629 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
630 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
631 | CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
632 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
633 | CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
634 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
635 | CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
636 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
637 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
638 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
639 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
640 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
641 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
642 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
643 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
644 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
645 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
646 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
647 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
648 | void test_hl_linked_list_insert(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
649 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
650 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
651 | int data; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
652 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
653 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
654 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
655 | CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
656 | CU_ASSERT_EQUAL(list->size, 0) |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
657 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
658 | CU_ASSERT_EQUAL(list->size, 1) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
659 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
660 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
661 | CU_ASSERT_EQUAL(list->size, 2) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
662 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
663 | CU_ASSERT_EQUAL(cxListInsert(list, 1, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
664 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
665 | data = 42; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
666 | CU_ASSERT_EQUAL(cxListInsert(list, 3, &data), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
667 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
668 | CU_ASSERT_EQUAL(list->size, 4) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
669 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
670 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
671 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
672 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
673 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
674 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
675 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
676 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
677 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
678 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
679 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
680 | void test_hl_linked_list_remove(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
681 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
682 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
683 | int data; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
684 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
685 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
686 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
687 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
688 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
689 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
690 | data = 42; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
691 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
692 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
693 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
694 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
695 | CU_ASSERT_EQUAL(list->size, 4) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
696 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
697 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
698 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
699 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
700 | CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
701 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
702 | CU_ASSERT_TRUE(list->capacity >= list->size) |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
703 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
704 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
705 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
706 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
707 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
708 | CU_ASSERT_EQUAL(list->size, 2) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
709 | CU_ASSERT_TRUE(list->capacity >= list->size) |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
710 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
711 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
712 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
713 | CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
714 | CU_ASSERT_EQUAL(list->size, 1) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
715 | CU_ASSERT_TRUE(list->capacity >= list->size) |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
716 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
717 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
718 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
719 | CU_ASSERT_EQUAL(list->size, 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
720 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
721 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
722 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
723 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
724 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
725 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
726 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
727 | |
479
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
728 | void test_hl_linked_list_at(void) { |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
729 | cxTestingAllocatorReset(); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
730 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
731 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
732 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
733 | int data; |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
734 | data = 5; |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
735 | cxListAdd(list, &data); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
736 | data = 47; |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
737 | cxListAdd(list, &data); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
738 | data = 13; |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
739 | cxListAdd(list, &data); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
740 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
741 | CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
742 | CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
743 | CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
744 | CU_ASSERT_PTR_NULL(cxListAt(list, 3)) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
745 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
746 | cxLinkedListDestroy(list); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
747 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
748 | } |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
749 | |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
750 | void test_hl_linked_list_find(void) { |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
751 | cxTestingAllocatorReset(); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
752 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
753 | int data, criteria; |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
754 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
755 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
756 | data = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
757 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
758 | data = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
759 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
760 | data = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
761 | cxListAdd(list, &data); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
762 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
763 | CU_ASSERT_EQUAL(list->size, 3) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
764 | CU_ASSERT_TRUE(list->capacity >= list->size) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
765 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
766 | criteria = 5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
767 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
768 | criteria = 47; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
769 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
770 | criteria = 13; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
771 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
772 | criteria = 9000; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
773 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
774 | criteria = -5; |
460
e075009b33b7
remove convenience macros
Mike Becker <universe@uap-core.de>
parents:
459
diff
changeset
|
775 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
776 | |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
777 | cxLinkedListDestroy(list); |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
778 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
779 | } |
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
780 | |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
781 | void test_hl_linked_list_sort(void) { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
782 | int expected[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
783 | 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
784 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
785 | 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
786 | 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
787 | 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
788 | 4785, 4791, 4801, 4859, 4903, 4973 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
789 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
790 | int scrambled[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
791 | 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
792 | 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
793 | 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
794 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
795 | 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
796 | 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
797 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
798 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
799 | cxTestingAllocatorReset(); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
800 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
801 | CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
802 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
803 | for (int i = 0; i < 100; i++) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
804 | cxListAdd(list, &scrambled[i]); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
805 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
806 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
807 | cxListSort(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
808 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
809 | for (int i = 0; i < 100; i++) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
810 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i]) |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
811 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
812 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
813 | cxLinkedListDestroy(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
814 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
815 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
816 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
817 | void test_hl_ptr_linked_list_create(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
818 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
819 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
820 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
821 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
822 | CU_ASSERT_EQUAL(list->size, 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
823 | CU_ASSERT_EQUAL(list->capacity, (size_t) -1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
824 | CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
825 | CU_ASSERT_EQUAL(list->itemsize, sizeof(void *)) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
826 | CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
827 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
828 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
829 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
830 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
831 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
832 | void test_hl_ptr_linked_list_add(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
833 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
834 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
835 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
836 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
837 | int a = 5, b = 47, c = 13; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
838 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
839 | CU_ASSERT_EQUAL(cxListAdd(list, &a), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
840 | CU_ASSERT_EQUAL(cxListAdd(list, &b), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
841 | CU_ASSERT_EQUAL(cxListAdd(list, &c), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
842 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
843 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
844 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
845 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
846 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
847 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
848 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
849 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
850 | a = 9; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
851 | b = 10; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
852 | c = 11; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
853 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
854 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
855 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
856 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
857 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
858 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
859 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
860 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
861 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
862 | void test_hl_ptr_linked_list_insert(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
863 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
864 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
865 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
866 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
867 | int a = 5, b = 47, c = 13, d = 42; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
868 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
869 | CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
870 | CU_ASSERT_EQUAL(list->size, 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
871 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &a), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
872 | CU_ASSERT_EQUAL(list->size, 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
873 | CU_ASSERT_EQUAL(cxListInsert(list, 0, &b), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
874 | CU_ASSERT_EQUAL(list->size, 2) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
875 | CU_ASSERT_EQUAL(cxListInsert(list, 1, &c), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
876 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
877 | CU_ASSERT_EQUAL(cxListInsert(list, 3, &d), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
878 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
879 | CU_ASSERT_EQUAL(list->size, 4) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
880 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
881 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
882 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
883 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
884 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
885 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
886 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
887 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
888 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
889 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
890 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
891 | void test_hl_ptr_linked_list_remove(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
892 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
893 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
894 | int a = 5, b = 47, c = 42, d = 13; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
895 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
896 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
897 | cxListAdd(list, &a); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
898 | cxListAdd(list, &b); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
899 | cxListAdd(list, &c); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
900 | cxListAdd(list, &d); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
901 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
902 | CU_ASSERT_EQUAL(list->size, 4) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
903 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
904 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
905 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
906 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
907 | CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
908 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
909 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
910 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
911 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
912 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
913 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
914 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
915 | CU_ASSERT_EQUAL(list->size, 2) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
916 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
917 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
918 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
919 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
920 | CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
921 | CU_ASSERT_EQUAL(list->size, 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
922 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
923 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
924 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
925 | CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
926 | CU_ASSERT_EQUAL(list->size, 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
927 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
928 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
929 | CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
930 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
931 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
932 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
933 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
934 | |
479
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
935 | void test_hl_ptr_linked_list_at(void) { |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
936 | cxTestingAllocatorReset(); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
937 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
938 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
939 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
940 | int a = 5, b = 47, c = 13; |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
941 | cxListAdd(list, &a); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
942 | cxListAdd(list, &b); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
943 | cxListAdd(list, &c); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
944 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
945 | CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
946 | CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
947 | CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
948 | CU_ASSERT_PTR_NULL(cxListAt(list, 3)) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
949 | |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
950 | cxLinkedListDestroy(list); |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
951 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
952 | } |
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
953 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
954 | void test_hl_ptr_linked_list_find(void) { |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
955 | cxTestingAllocatorReset(); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
956 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
957 | int a = 5, b = 47, c = 13, criteria; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
958 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
959 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
960 | cxListAdd(list, &a); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
961 | cxListAdd(list, &b); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
962 | cxListAdd(list, &c); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
963 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
964 | CU_ASSERT_EQUAL(list->size, 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
965 | CU_ASSERT_TRUE(list->capacity >= list->size) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
966 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
967 | criteria = 5; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
968 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
969 | criteria = 47; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
970 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
971 | criteria = 13; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
972 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
973 | criteria = 9000; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
974 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
975 | criteria = -5; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
976 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
977 | b = -5; |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
978 | CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
979 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
980 | cxLinkedListDestroy(list); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
981 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
982 | } |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
983 | |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
984 | void test_hl_ptr_linked_list_sort(void) { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
985 | int expected[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
986 | 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
987 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
988 | 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
989 | 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
990 | 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
991 | 4785, 4791, 4801, 4859, 4903, 4973 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
992 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
993 | int scrambled[] = { |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
994 | 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
995 | 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
996 | 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
997 | 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
998 | 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973, |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
999 | 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681 |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1000 | }; |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1001 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1002 | cxTestingAllocatorReset(); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1003 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1004 | CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1005 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
1006 | for (int i = 0; i < 100; i++) { |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1007 | cxListAdd(list, &scrambled[i]); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1008 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1009 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1010 | cxListSort(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1011 | |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
1012 | for (int i = 0; i < 100; i++) { |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
1013 | CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i]) |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1014 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1015 | |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1016 | cxLinkedListDestroy(list); |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1017 | CU_ASSERT_TRUE(cxTestingAllocatorVerify()) |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1018 | } |
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1019 | |
390 | 1020 | int main() { |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1021 | CU_pSuite suite = NULL; |
449 | 1022 | |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1023 | if (CUE_SUCCESS != CU_initialize_registry()) { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1024 | return CU_get_error(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1025 | } |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1026 | |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
1027 | suite = CU_add_suite("low level linked list", NULL, NULL); |
449 | 1028 | |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
1029 | cu_add_test(suite, test_linked_list_link_unlink); |
455 | 1030 | cu_add_test(suite, test_linked_list_at); |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
1031 | cu_add_test(suite, test_linked_list_prepend); |
455 | 1032 | cu_add_test(suite, test_linked_list_add); |
482
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
1033 | cu_add_test(suite, test_linked_list_insert); |
0d998f19d130
add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents:
479
diff
changeset
|
1034 | cu_add_test(suite, test_linked_list_insert_chain); |
475
31bf97fdbf71
add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents:
474
diff
changeset
|
1035 | cu_add_test(suite, test_linked_list_first); |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
1036 | cu_add_test(suite, test_linked_list_last); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
1037 | cu_add_test(suite, test_linked_list_prev); |
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
1038 | cu_add_test(suite, test_linked_list_remove); |
468
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
1039 | cu_add_test(suite, test_linked_list_size); |
75ae1dccd101
add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents:
466
diff
changeset
|
1040 | cu_add_test(suite, test_linked_list_sort); |
473
1bd4b8c28722
add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents:
469
diff
changeset
|
1041 | cu_add_test(suite, test_linked_list_reverse); |
455 | 1042 | |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
1043 | suite = CU_add_suite("high level linked list", NULL, NULL); |
455 | 1044 | |
456
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
1045 | cu_add_test(suite, test_hl_linked_list_create); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
1046 | cu_add_test(suite, test_hl_linked_list_add); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
1047 | cu_add_test(suite, test_hl_linked_list_insert); |
227c2eabbef8
change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents:
455
diff
changeset
|
1048 | cu_add_test(suite, test_hl_linked_list_remove); |
479
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
1049 | cu_add_test(suite, test_hl_linked_list_at); |
459
c0e2e9f83399
add tests for high level functions
Mike Becker <universe@uap-core.de>
parents:
456
diff
changeset
|
1050 | cu_add_test(suite, test_hl_linked_list_find); |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1051 | cu_add_test(suite, test_hl_linked_list_sort); |
413
0f4aa9fc75d9
perform array and list tests in the same test binary (use the same assertions, later)
Mike Becker <universe@uap-core.de>
parents:
412
diff
changeset
|
1052 | |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1053 | suite = CU_add_suite("high level pointer linked list", NULL, NULL); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1054 | |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1055 | cu_add_test(suite, test_hl_ptr_linked_list_create); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1056 | cu_add_test(suite, test_hl_ptr_linked_list_add); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1057 | cu_add_test(suite, test_hl_ptr_linked_list_insert); |
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1058 | cu_add_test(suite, test_hl_ptr_linked_list_remove); |
479
a29bdd703e02
add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents:
478
diff
changeset
|
1059 | cu_add_test(suite, test_hl_ptr_linked_list_at); |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1060 | cu_add_test(suite, test_hl_ptr_linked_list_find); |
469
0458bff0b1cd
add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents:
468
diff
changeset
|
1061 | cu_add_test(suite, test_hl_ptr_linked_list_sort); |
466
28bc3e10ac28
add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents:
460
diff
changeset
|
1062 | |
411
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1063 | CU_basic_set_mode(UCX_CU_BRM); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1064 | |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1065 | int exitcode; |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1066 | if (CU_basic_run_tests()) { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1067 | exitcode = CU_get_error(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1068 | } else { |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1069 | exitcode = CU_get_number_of_failures() == 0 ? 0 : 1; |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1070 | } |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1071 | CU_cleanup_registry(); |
2842f729caab
add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents:
398
diff
changeset
|
1072 | return exitcode; |
390 | 1073 | } |