test/test_list.c

Sun, 30 Jan 2022 14:19:00 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 30 Jan 2022 14:19:00 +0100
changeset 500
eb9e7bd40a8e
parent 499
3dc9075df822
child 503
a89857072ace
permissions
-rw-r--r--

do not hide pointers behind typedefs

390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
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
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
33 int cmp_int_impl(
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
34 int const *l,
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
35 int const *r
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
36 ) {
412
af766caea48d removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents: 411
diff changeset
37 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
38 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
39 }
af766caea48d removes stupid high level wrapper for linked lists + adds test for cxLinkedListCreate
Mike Becker <universe@uap-core.de>
parents: 411
diff changeset
40
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
41 #define cmp_int ((CxListComparator) cmp_int_impl)
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
42
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
43 struct node {
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
44 struct node *next;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
45 struct node *prev;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
46 int data;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
47 };
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
48
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
49 #define nd(name) name = {0}
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
50
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
51 const ptrdiff_t loc_prev = offsetof(struct node, prev);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
52 const ptrdiff_t loc_next = offsetof(struct node, next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
53 const ptrdiff_t loc_data = offsetof(struct node, data);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
54
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
55 struct node *create_test_data(
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
56 size_t n,
489
af6be1e123aa add some const qualifiers
Mike Becker <universe@uap-core.de>
parents: 488
diff changeset
57 int const data[]
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
58 ) {
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
59 if (n == 0) return NULL;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
60 struct node *begin = calloc(1, sizeof(struct node));
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
61 struct node *prev = begin;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
62 if (data) begin->data = data[0];
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
63 for (size_t i = 1; i < n; i++) {
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
64 struct node *node = calloc(1, sizeof(struct node));
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
65 if (data) node->data = data[i];
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
66 cx_linked_list_link(prev, node, loc_prev, loc_next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
67 prev = node;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
68 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
69 return begin;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
70 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
71
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
72 void destroy_test_data(struct node *begin) {
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
73 struct node *node = begin;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
74 while (node) {
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
75 struct node *next = node->next;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
76 free(node);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
77 node = next;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
78 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
79 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
80
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
81 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
82
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
83 struct node nd(a), nd(b), nd(c);
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
84
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
85 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
86 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
87 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
88 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
89 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
90
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
91 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
92 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
93 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
94 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
95 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
96
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
106 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
107
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
108 void test_linked_list_at(void) {
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
109 struct node nd(a), nd(b), nd(c), nd(d);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
110 cx_linked_list_link(&a, &b, loc_prev, loc_next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
111 cx_linked_list_link(&b, &c, loc_prev, loc_next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
112 cx_linked_list_link(&c, &d, loc_prev, loc_next);
438
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
113
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
114 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 0), &a)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
115 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 1), &b)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
116 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 2), &c)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
117 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 3), &d)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
118 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
119
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
120 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_prev, 0), &a)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
121 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 1), &b)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
122 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 2), &c)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
123 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 3), &d)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
124 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
125
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
126 CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a)
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
127 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
128 }
cd3069757010 add function cx_linked_list_at()
Mike Becker <universe@uap-core.de>
parents: 435
diff changeset
129
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
130 void test_linked_list_find(void) {
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
131 int data[] = {2, 4, 6, 8};
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
132 void *list = create_test_data(4, data);
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
133 int s;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
134
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
135 s = 2;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
136 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
137 false, cmp_int, &s), 0)
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
138 s = 4;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
139 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
140 false, cmp_int, &s), 1)
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
141 s = 6;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
142 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
143 false, cmp_int, &s), 2)
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
144 s = 8;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
145 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
146 false, cmp_int, &s), 3)
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
147 s = 10;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
148 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
149 false, cmp_int, &s), 4)
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
150 s = -2;
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
151 CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
152 false, cmp_int, &s), 4)
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
153 }
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
154
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
155 void test_linked_list_compare(void) {
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
156 int a[] = {2, 4, 6, 8};
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
157 int b[] = {2, 4, 6};
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
158 int c[] = {2, 4, 6, 9};
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
159
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
160 void *la = create_test_data(4, a);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
161 void *lb = create_test_data(3, b);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
162 void *lc = create_test_data(4, c);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
163
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
164 CU_ASSERT_TRUE(0 < cx_linked_list_compare(la, lb, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
165 false, cmp_int)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
166 )
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
167 CU_ASSERT_TRUE(0 > cx_linked_list_compare(lb, la, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
168 false, cmp_int)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
169 )
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
170 CU_ASSERT_TRUE(0 < cx_linked_list_compare(lc, la, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
171 false, cmp_int)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
172 )
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
173 CU_ASSERT_TRUE(0 > cx_linked_list_compare(la, lc, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
174 false, cmp_int)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
175 )
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
176 CU_ASSERT_TRUE(0 == cx_linked_list_compare(la, la, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
177 false, cmp_int)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
178 )
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
179
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
180 destroy_test_data(la);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
181 destroy_test_data(lb);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
182 destroy_test_data(lc);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
183 }
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
184
444
cb944fa1852a rename test_cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
185 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
186 struct node nodes[4];
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
187 void *begin, *end;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
188
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
189 // test with begin, end / prev, next
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
190 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
191 begin = end = NULL;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
192
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 449
diff changeset
193 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
194 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
195 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
196 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
197 CU_ASSERT_PTR_NULL(nodes[0].next)
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
198
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 449
diff changeset
199 cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
200 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
201 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
202 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
203 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
204
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
205 // test with begin only / prev, next
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
206 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
207 begin = end = NULL;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
208
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 449
diff changeset
209 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
210 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
211 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
212 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
213 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
214 CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
215
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 449
diff changeset
216 cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
217 CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
218 CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
219
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
220 // 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
221 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
222 begin = end = NULL;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
223
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
224 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
225 CU_ASSERT_PTR_EQUAL(end, &nodes[0])
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
226 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
227 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
228 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
229 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
230
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
231 cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]);
475
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[2])
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
233 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
234 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
235
442
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
236 // test with begin, end / next
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
237 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
238 begin = end = NULL;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
239
453
bb144d08cd44 add some documentation and changes some signatures
Mike Becker <universe@uap-core.de>
parents: 449
diff changeset
240 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
241 CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
242 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
243 cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
244 CU_ASSERT_PTR_EQUAL(end, &nodes[1])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
245 CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
246 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
247 }
310019ddfe4e add test for cx_linked_list_add
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
248
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
249 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
250 struct node nodes[4];
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
251 void *begin, *end;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
252
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
253 // 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
254 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
255 begin = end = NULL;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
256
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
257 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
258 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
259 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
260 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
261 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
262
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
263 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
264 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
265 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
266 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
267 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
268
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
269 // 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
270 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
271 begin = end = NULL;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
272
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
273 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
274 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
275 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
276 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
277 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
278 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
279
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
280 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
281 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
282 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
283 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
284
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
285 // 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
286 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
287 begin = end = NULL;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
288
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
289 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
290 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
291 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
292 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
293 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
294 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
295
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
296 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
297 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
298 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
299 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
300
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
301 // 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
302 memset(nodes, 0, 4 * sizeof(struct node));
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
303 begin = end = NULL;
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
304
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 }
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
317
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
318 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
319 struct node nodes[4];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
320 void *begin, *end;
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
321
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
322 // insert mid list
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
323 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
324 begin = &nodes[0];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
325 end = &nodes[2];
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 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
328 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
329
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
330 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
331 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
332 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
333 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
334 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
335 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
336 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
337
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
338 // insert end
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
339 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
340 begin = &nodes[0];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
341 end = &nodes[2];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
342
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
343 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
344 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
345
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
346 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
347 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
348 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
349 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
350 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
351 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
352
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
353 // insert begin
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
354 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
355 begin = &nodes[0];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
356 end = &nodes[2];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
357
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
358 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
359 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
360
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
361 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
362 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
363 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
364 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
365 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
366 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
367 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
368
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
369 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
370 struct node nodes[5];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
371 void *begin, *end;
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
372
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
373 // insert mid list
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
374 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
375 begin = &nodes[0];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
376 end = &nodes[2];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
377
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
378 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
379 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
380 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
381
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
390 // insert end
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
391 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
392 begin = &nodes[0];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
393 end = &nodes[2];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
394
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
395 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
396 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
397 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
398
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
399 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
400 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
401 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
402 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
403 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
404 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
405
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
406 // insert begin
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
407 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
408 begin = &nodes[0];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
409 end = &nodes[2];
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
410
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
411 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
412 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
413 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
414
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
415 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
416 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
417 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
418 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
419 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
420 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
421 }
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
422
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
423 void test_linked_list_first(void) {
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
424 struct node *begin = create_test_data(3, NULL);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
425 CU_ASSERT_PTR_EQUAL(cx_linked_list_first(begin, loc_prev), begin)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
426 CU_ASSERT_PTR_EQUAL(cx_linked_list_first(begin->next, loc_prev), begin)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
427 CU_ASSERT_PTR_EQUAL(cx_linked_list_first(begin->next->next, loc_prev), begin)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
428 destroy_test_data(begin);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
429 }
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
430
456
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
431 void test_linked_list_last(void) {
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
432 struct node *begin = create_test_data(3, NULL);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
433 struct node *end = begin->next->next;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
434 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(begin, loc_next), end)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
435 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(begin->next, loc_next), end)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
436 CU_ASSERT_PTR_EQUAL(cx_linked_list_last(begin->next->next, loc_next), end)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
437 destroy_test_data(begin);
456
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
438 }
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
439
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
440 void test_linked_list_prev(void) {
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
441 struct node *begin = create_test_data(3, NULL);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
442 CU_ASSERT_PTR_NULL(cx_linked_list_prev(begin, loc_next, begin))
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
443 CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(begin, loc_next, begin->next), begin)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
444 CU_ASSERT_PTR_EQUAL(cx_linked_list_prev(begin, loc_next, begin->next->next), begin->next)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
445 destroy_test_data(begin);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
446 }
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
447
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
448 void test_linked_list_remove(void) {
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
449 void *begin, *end;
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
450
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
451 int data[] = {2, 4, 6};
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
452 begin = create_test_data(3, data);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
453 struct node *first = begin;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
454 struct node *second = first->next;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
455 struct node *third = second->next;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
456 end = third;
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
457
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
458 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, second);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
459 CU_ASSERT_PTR_EQUAL(begin, first)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
460 CU_ASSERT_PTR_EQUAL(end, third)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
461 CU_ASSERT_PTR_NULL(first->prev)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
462 CU_ASSERT_PTR_EQUAL(first->next, third)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
463 CU_ASSERT_PTR_EQUAL(third->prev, first)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
464 CU_ASSERT_PTR_NULL(third->next)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
465
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
466 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, third);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
467 CU_ASSERT_PTR_EQUAL(begin, first)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
468 CU_ASSERT_PTR_EQUAL(end, first)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
469 CU_ASSERT_PTR_NULL(first->prev)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
470 CU_ASSERT_PTR_NULL(first->next)
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
471
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
472 cx_linked_list_remove(&begin, &end, loc_prev, loc_next, first);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
473 CU_ASSERT_PTR_NULL(begin)
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
474 CU_ASSERT_PTR_NULL(end)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
475
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
476 free(first);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
477 free(second);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
478 free(third);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
479 }
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
480
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
481 void test_linked_list_size(void) {
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
482 struct node *list;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
483
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
484 CU_ASSERT_PTR_EQUAL(cx_linked_list_size(NULL, loc_next), 0)
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
485
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
486 list = create_test_data(5, NULL);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
487 CU_ASSERT_EQUAL(cx_linked_list_size(list, loc_next), 5)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
488 destroy_test_data(list);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
489
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
490 list = create_test_data(13, NULL);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
491 CU_ASSERT_EQUAL(cx_linked_list_size(list, loc_next), 13)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
492 destroy_test_data(list);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
493 }
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
494
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
495 void test_linked_list_sort(void) {
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
496 int expected[] = {
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
497 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
498 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
499 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
500 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
501 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
502 4785, 4791, 4801, 4859, 4903, 4973
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
503 };
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
504 int scrambled[] = {
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
505 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
506 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
507 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
508 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
509 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
510 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
511 };
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
512
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
513 void *begin = create_test_data(100, scrambled);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
514 void *end = cx_linked_list_last(begin, loc_next);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
515
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
516 cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
517 false, cmp_int);
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
518
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
519 struct node *check = begin;
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
520 struct node *check_last = NULL;
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
521 CU_ASSERT_PTR_NULL(check->prev)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
522 CU_ASSERT_EQUAL(check->data, expected[0])
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
523 for (int i = 0; i < 100; i++) {
468
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
524 CU_ASSERT_EQUAL(check->data, expected[i])
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
525 CU_ASSERT_PTR_EQUAL(check->prev, check_last)
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
526 if (i < 99) {
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
527 CU_ASSERT_PTR_NOT_NULL(check->next)
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 check_last = check;
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
530 check = check->next;
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
531 }
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
532 CU_ASSERT_PTR_NULL(check)
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
533 CU_ASSERT_PTR_EQUAL(end, check_last)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
534
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
535 destroy_test_data(begin);
468
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
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
538 void test_linked_list_reverse(void) {
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
539 void *begin, *end;
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
540
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
541 int data[] = {2, 4, 6, 8};
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
542 int reversed[] = {8, 6, 4, 2};
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
543
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
544 void *list = create_test_data(4, data);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
545 void *expected = create_test_data(4, reversed);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
546
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
547 begin = list;
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
548 end = cx_linked_list_last(list, loc_next);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
549
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
550 cx_linked_list_reverse(&begin, &end, loc_prev, loc_next);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
551 CU_ASSERT_PTR_EQUAL(end, list)
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
552 CU_ASSERT_PTR_EQUAL(begin, cx_linked_list_first(end, loc_prev))
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
553 CU_ASSERT_TRUE(0 == cx_linked_list_compare(begin, expected, loc_next, loc_data,
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
554 0, cmp_int))
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
555
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
556 destroy_test_data(begin);
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
557 destroy_test_data(expected);
473
1bd4b8c28722 add cx_linked_list_{prev, remove, reverse}
Mike Becker <universe@uap-core.de>
parents: 469
diff changeset
558 }
456
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
559
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
560 void test_hl_linked_list_create(void) {
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
561 cxTestingAllocatorReset();
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
562
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
563 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
564
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
565 CU_ASSERT_EQUAL(list->size, 0)
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
566 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
567 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
568 CU_ASSERT_EQUAL(list->itemsize, sizeof(int))
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
569 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int)
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
570
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
571 cxLinkedListDestroy(list);
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
572 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
573 }
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
574
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
575 void test_hl_ptr_linked_list_create(void) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
576 cxTestingAllocatorReset();
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
577
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
578 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
579
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
580 CU_ASSERT_EQUAL(list->size, 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
581 CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
582 CU_ASSERT_PTR_EQUAL(list->allocator, cxTestingAllocator)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
583 CU_ASSERT_EQUAL(list->itemsize, sizeof(void *))
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
584 CU_ASSERT_PTR_EQUAL(list->cmpfunc, cmp_int)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
585
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
586 cxLinkedListDestroy(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
587 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
588 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
589
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
590 void test_hl_linked_list_from_array(void) {
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
591 cxTestingAllocatorReset();
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
592
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
593 int data[] = {2, 4, 5, 7, 10, 15};
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
594
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
595 CxList *expected = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
596 for (int i = 0; i < 5; i++) cxListAdd(expected, &data[i]);
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
597
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
598 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 5, data);
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
599
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
600 CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
491
6d538177f746 fix missing cleanup in test_hl_linked_list_from_array
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
601
6d538177f746 fix missing cleanup in test_hl_linked_list_from_array
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
602 cxLinkedListDestroy(list);
6d538177f746 fix missing cleanup in test_hl_linked_list_from_array
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
603 cxLinkedListDestroy(expected);
6d538177f746 fix missing cleanup in test_hl_linked_list_from_array
Mike Becker <universe@uap-core.de>
parents: 489
diff changeset
604 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
605 }
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
606
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
607 void test_hl_linked_list_add(void) {
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
608 cxTestingAllocatorReset();
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
609
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
610 int data;
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
611 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
612
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
613 data = 5;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
614 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
615 data = 47;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
616 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
617 data = 13;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
618 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
619
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
620 CU_ASSERT_EQUAL(list->size, 3)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
621 CU_ASSERT_TRUE(list->capacity >= list->size)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
622
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
623 int exp[] = {5, 47, 13};
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
624 CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 3, exp);
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
625 CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
459
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 cxLinkedListDestroy(list);
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
628 cxLinkedListDestroy(expected);
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
629 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
630 }
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
631
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
632 void test_hl_ptr_linked_list_add(void) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
633 cxTestingAllocatorReset();
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
634
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
635 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
636
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
637 int a = 5, b = 47, c = 13;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
638
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
639 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
640 CU_ASSERT_EQUAL(cxListAdd(list, &b), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
641 CU_ASSERT_EQUAL(cxListAdd(list, &c), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
642
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
643 CU_ASSERT_EQUAL(list->size, 3)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
644 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
645
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
646 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
647 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
648 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
649
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
650 a = 9;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
651 b = 10;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
652 c = 11;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
653
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
654 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 9)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
655 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 10)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
656 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 11)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
657
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
658 cxLinkedListDestroy(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
659 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
660 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
661
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
662 void test_hl_linked_list_insert(void) {
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
663 cxTestingAllocatorReset();
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
664
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
665 int data;
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
666 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
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 data = 5;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
669 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
670 CU_ASSERT_EQUAL(list->size, 0)
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
671 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
672 CU_ASSERT_EQUAL(list->size, 1)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
673 data = 47;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
674 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
675 CU_ASSERT_EQUAL(list->size, 2)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
676 data = 13;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
677 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
678 CU_ASSERT_EQUAL(list->size, 3)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
679 data = 42;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
680 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
681
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
682 CU_ASSERT_EQUAL(list->size, 4)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
683 CU_ASSERT_TRUE(list->capacity >= list->size)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
684
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
685 int exp[] = {47, 13, 5, 42};
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
686 CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 4, exp);
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
687 CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
688
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
689 cxLinkedListDestroy(list);
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
690 cxLinkedListDestroy(expected);
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
691 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
692 }
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
693
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
694 void test_hl_ptr_linked_list_insert(void) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
695 cxTestingAllocatorReset();
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
696
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
697 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
698
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
699 int a = 5, b = 47, c = 13, d = 42;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
700
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
701 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &a), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
702 CU_ASSERT_EQUAL(list->size, 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
703 CU_ASSERT_EQUAL(cxListInsert(list, 0, &a), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
704 CU_ASSERT_EQUAL(list->size, 1)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
705 CU_ASSERT_EQUAL(cxListInsert(list, 0, &b), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
706 CU_ASSERT_EQUAL(list->size, 2)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
707 CU_ASSERT_EQUAL(cxListInsert(list, 1, &c), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
708 CU_ASSERT_EQUAL(list->size, 3)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
709 CU_ASSERT_EQUAL(cxListInsert(list, 3, &d), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
710
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
711 CU_ASSERT_EQUAL(list->size, 4)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
712 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
713
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
714 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
715 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
716 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 5)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
717 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 42)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
718
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
719 cxLinkedListDestroy(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
720 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
721 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
722
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
723 void test_hl_linked_list_remove(void) {
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
724 cxTestingAllocatorReset();
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
725
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
726 int data[] = {5, 47, 42, 13};
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
727 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
728 sizeof(int), 4, data);
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
729
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
730 CU_ASSERT_EQUAL(list->size, 4)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
731 CU_ASSERT_TRUE(list->capacity >= list->size)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
732
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
733 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
734
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
735 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
736 CU_ASSERT_EQUAL(list->size, 3)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
737 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
738 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
739 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
740 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
741
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
742 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
743 CU_ASSERT_EQUAL(list->size, 2)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
744 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
745 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
746 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
747
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
748 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
749 CU_ASSERT_EQUAL(list->size, 1)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
750 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
751 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
752
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
753 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
754 CU_ASSERT_EQUAL(list->size, 0)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
755 CU_ASSERT_TRUE(list->capacity >= list->size)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
756
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
757 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
758
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
759 cxLinkedListDestroy(list);
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
760 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
761 }
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
762
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
763 void test_hl_ptr_linked_list_remove(void) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
764 cxTestingAllocatorReset();
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
765
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
766 int a = 5, b = 47, c = 42, d = 13;
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
767 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
768
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
769 cxListAdd(list, &a);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
770 cxListAdd(list, &b);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
771 cxListAdd(list, &c);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
772 cxListAdd(list, &d);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
773
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
774 CU_ASSERT_EQUAL(list->size, 4)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
775 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
776
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
777 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
778
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
779 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
780 CU_ASSERT_EQUAL(list->size, 3)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
781 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
782 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
783 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
784 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
785
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
786 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
787 CU_ASSERT_EQUAL(list->size, 2)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
788 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
789 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
790 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 13)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
791
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
792 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
793 CU_ASSERT_EQUAL(list->size, 1)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
794 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
795 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 47)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
796
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
797 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
798 CU_ASSERT_EQUAL(list->size, 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
799 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
800
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
801 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 0), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
802
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
803 cxLinkedListDestroy(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
804 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
805 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
806
479
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
807 void test_hl_linked_list_at(void) {
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
808 cxTestingAllocatorReset();
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
809
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
810 int data[] = {5, 47, 13};
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
811 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
812 sizeof(int), 3, data);
479
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
813
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
814 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
815 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
816 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
479
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
817 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
818
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
819 cxLinkedListDestroy(list);
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
820 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
821 }
a29bdd703e02 add linked list tests for cxListAt()
Mike Becker <universe@uap-core.de>
parents: 478
diff changeset
822
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
823 void test_hl_ptr_linked_list_at(void) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
824 cxTestingAllocatorReset();
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
825
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
826 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
827
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
828 int a = 5, b = 47, c = 13;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
829 cxListAdd(list, &a);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
830 cxListAdd(list, &b);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
831 cxListAdd(list, &c);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
832
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
833 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
834 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
835 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 13)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
836 CU_ASSERT_PTR_NULL(cxListAt(list, 3))
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
837
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
838 cxLinkedListDestroy(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
839 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
840 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
841
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
842 void test_hl_linked_list_find(void) {
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
843 cxTestingAllocatorReset();
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
844
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
845 int data[] = {5, 47, 13};
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
846 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
847 sizeof(int), 3, data);
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
848 CU_ASSERT_EQUAL(list->size, 3)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
849 CU_ASSERT_TRUE(list->capacity >= list->size)
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
850
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
851 int criteria;
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
852
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
853 criteria = 5;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
854 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
855 criteria = 47;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
856 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
857 criteria = 13;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
858 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
859 criteria = 9000;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
860 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
861 criteria = -5;
460
e075009b33b7 remove convenience macros
Mike Becker <universe@uap-core.de>
parents: 459
diff changeset
862 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
863
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
864 cxLinkedListDestroy(list);
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
865 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
866 }
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
867
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
868 void test_hl_ptr_linked_list_find(void) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
869 cxTestingAllocatorReset();
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
870
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
871 int a = 5, b = 47, c = 13, criteria;
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
872 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
873
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
874 cxListAdd(list, &a);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
875 cxListAdd(list, &b);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
876 cxListAdd(list, &c);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
877
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
878 CU_ASSERT_EQUAL(list->size, 3)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
879 CU_ASSERT_TRUE(list->capacity >= list->size)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
880
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
881 criteria = 5;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
882 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
883 criteria = 47;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
884 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
885 criteria = 13;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
886 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
887 criteria = 9000;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
888 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
889 criteria = -5;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
890 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
891 b = -5;
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
892 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
893
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
894 cxLinkedListDestroy(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
895 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
896 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
897
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
898 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
899 int expected[] = {
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
900 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
901 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
902 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
903 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
904 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
905 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
906 };
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
907 int scrambled[] = {
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
908 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
909 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
910 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
911 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
912 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
913 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
914 };
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
915
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
916 cxTestingAllocatorReset();
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
917
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
918 CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, scrambled);
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
919 CxList *exp = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, expected);
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
920
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
921 cxListSort(list);
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
922 CU_ASSERT_TRUE(0 == cxListCompare(list, exp))
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
923
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
924 cxLinkedListDestroy(list);
492
188942a7308b simplifies some linked list tests
Mike Becker <universe@uap-core.de>
parents: 491
diff changeset
925 cxLinkedListDestroy(exp);
469
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
926 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
927 }
0458bff0b1cd add high level list sort and inlines method invocation functions
Mike Becker <universe@uap-core.de>
parents: 468
diff changeset
928
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
929 void test_hl_ptr_linked_list_sort(void) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
930 int expected[] = {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
931 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
932 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
933 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
934 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
935 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
936 4785, 4791, 4801, 4859, 4903, 4973
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
937 };
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
938 int scrambled[] = {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
939 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
940 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
941 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
942 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
943 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
944 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
945 };
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
946
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
947 cxTestingAllocatorReset();
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
948
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
949 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
498
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
950
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
951 for (int i = 0; i < 100; i++) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
952 cxListAdd(list, &scrambled[i]);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
953 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
954
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
955 cxListSort(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
956
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
957 for (int i = 0; i < 100; i++) {
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
958 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expected[i])
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
959 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
960
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
961 cxLinkedListDestroy(list);
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
962 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
963 }
435c9965b2dd reorder the list test functions
Mike Becker <universe@uap-core.de>
parents: 497
diff changeset
964
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
965 void test_hl_linked_list_iterator_impl(CxList *list) {
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
966 int i = 0;
496
1a07e24801a9 add cx_foreach macro
Mike Becker <universe@uap-core.de>
parents: 495
diff changeset
967 CxIterator iter = cxListBegin(list);
497
b182a8b8a1af pointer type must be explicit in cx_foreach macro
Mike Becker <universe@uap-core.de>
parents: 496
diff changeset
968 cx_foreach(int*, x, iter) {
495
2856c74e18ba add the feature to remove items during iteration
Mike Becker <universe@uap-core.de>
parents: 494
diff changeset
969 CU_ASSERT_EQUAL(iter.index, (size_t) (i + 1) / 2)
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
970 CU_ASSERT_EQUAL(*x, i)
497
b182a8b8a1af pointer type must be explicit in cx_foreach macro
Mike Becker <universe@uap-core.de>
parents: 496
diff changeset
971 if (*x % 2 == 1) iter.remove = true;
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
972 i++;
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
973 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
974 CU_ASSERT_EQUAL(i, 10)
495
2856c74e18ba add the feature to remove items during iteration
Mike Becker <universe@uap-core.de>
parents: 494
diff changeset
975 CU_ASSERT_EQUAL_FATAL(list->size, 5)
2856c74e18ba add the feature to remove items during iteration
Mike Becker <universe@uap-core.de>
parents: 494
diff changeset
976 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 0)
2856c74e18ba add the feature to remove items during iteration
Mike Becker <universe@uap-core.de>
parents: 494
diff changeset
977 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 2)
2856c74e18ba add the feature to remove items during iteration
Mike Becker <universe@uap-core.de>
parents: 494
diff changeset
978 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 2), 4)
2856c74e18ba add the feature to remove items during iteration
Mike Becker <universe@uap-core.de>
parents: 494
diff changeset
979 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 3), 6)
2856c74e18ba add the feature to remove items during iteration
Mike Becker <universe@uap-core.de>
parents: 494
diff changeset
980 CU_ASSERT_EQUAL(*(int *) cxListAt(list, 4), 8)
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
981 cxLinkedListDestroy(list);
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
982 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
983 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
984
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
985 void test_hl_linked_list_iterator(void) {
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
986 cxTestingAllocatorReset();
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
987 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
988 for (int i = 0; i < 10; i++) {
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
989 cxListAdd(list, &i);
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
990 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
991 test_hl_linked_list_iterator_impl(list);
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
992 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
993
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
994 void test_hl_ptr_linked_list_iterator(void) {
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
995 cxTestingAllocatorReset();
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
996 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
997 int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
998 for (int i = 0; i < 10; i++) {
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
999 cxListAdd(list, &data[i]);
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
1000 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
1001 test_hl_linked_list_iterator_impl(list);
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
1002 }
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
1003
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1004 void test_hl_linked_list_insert_via_iterator(void) {
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1005 cxTestingAllocatorReset();
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
1006 CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1007 for (int i = 0; i < 5; i++) {
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1008 cxListAdd(list, &i);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1009 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1010 CxIterator iter = cxListIterator(list, 2);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1011 CU_ASSERT_EQUAL(iter.index, 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1012 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1013
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1014 int data = 10;
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1015 cxListInsertAfter(&iter, &data);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1016 CU_ASSERT_EQUAL(iter.index, 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1017 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1018 data = 20;
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1019 cxListInsertBefore(&iter, &data);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1020 CU_ASSERT_EQUAL(iter.index, 3)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1021 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1022
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1023 data = 30;
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1024 iter = cxListBegin(list);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1025 cxListInsertBefore(&iter, &data);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1026 CU_ASSERT_EQUAL(iter.index, 1)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1027 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 0)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1028 data = 40;
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1029 iter = cxListIterator(list, list->size);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1030 cxListInsertBefore(&iter, &data);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1031 CU_ASSERT_EQUAL(iter.index, 9)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1032 CU_ASSERT_FALSE(cxIteratorValid(&iter))
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1033 data = 50;
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1034 iter = cxListIterator(list, list->size);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1035 cxListInsertAfter(&iter, &data);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1036 CU_ASSERT_EQUAL(iter.index, 10)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1037 CU_ASSERT_FALSE(cxIteratorValid(&iter))
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1038
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1039 int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50};
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
1040 CxList *expected = cxLinkedListFromArray(cxTestingAllocator,
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
1041 cmp_int, sizeof(int), 10, expdata);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1042
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1043 CU_ASSERT_EQUAL(0, cxListCompare(list, expected))
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1044 cxLinkedListDestroy(list);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1045 cxLinkedListDestroy(expected);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1046 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1047 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1048
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1049 void test_hl_ptr_linked_list_insert_via_iterator(void) {
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1050 int testdata[] = {0, 1, 2, 3, 4, 10, 20, 30, 40, 50};
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1051 cxTestingAllocatorReset();
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 499
diff changeset
1052 CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1053 int i;
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1054 for (i = 0; i < 5; i++) {
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1055 cxListAdd(list, &testdata[i]);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1056 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1057 CxIterator iter = cxListIterator(list, 2);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1058 CU_ASSERT_EQUAL(iter.index, 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1059 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1060
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1061 cxListInsertAfter(&iter, &testdata[i++]);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1062 CU_ASSERT_EQUAL(iter.index, 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1063 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1064 cxListInsertBefore(&iter, &testdata[i++]);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1065 CU_ASSERT_EQUAL(iter.index, 3)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1066 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 2)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1067
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1068 iter = cxListBegin(list);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1069 cxListInsertBefore(&iter, &testdata[i++]);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1070 CU_ASSERT_EQUAL(iter.index, 1)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1071 CU_ASSERT_EQUAL(*(int *) cxIteratorCurrent(&iter), 0)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1072 iter = cxListIterator(list, list->size);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1073 cxListInsertBefore(&iter, &testdata[i++]);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1074 CU_ASSERT_EQUAL(iter.index, 9)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1075 CU_ASSERT_FALSE(cxIteratorValid(&iter))
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1076 iter = cxListIterator(list, list->size);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1077 cxListInsertAfter(&iter, &testdata[i++]);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1078 CU_ASSERT_EQUAL(iter.index, 10)
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1079 CU_ASSERT_FALSE(cxIteratorValid(&iter))
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1080
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1081 int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50};
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1082 for (i = 0; i < 10; i++) {
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1083 CU_ASSERT_EQUAL(*(int *) cxListAt(list, i), expdata[i])
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1084 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1085
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1086 cxLinkedListDestroy(list);
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1087 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1088 }
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1089
390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1090 int main() {
411
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1091 CU_pSuite suite = NULL;
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
1092
411
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1093 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
1094 return CU_get_error();
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1095 }
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1096
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
1097 suite = CU_add_suite("low level linked list", NULL, NULL);
449
68ad5750ba6b minor code changes
Mike Becker <universe@uap-core.de>
parents: 446
diff changeset
1098
482
0d998f19d130 add tests for the new low level functions
Mike Becker <universe@uap-core.de>
parents: 479
diff changeset
1099 cu_add_test(suite, test_linked_list_link_unlink);
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
1100 cu_add_test(suite, test_linked_list_at);
487
4bd19279778c use c99 bool + add test for low level find
Mike Becker <universe@uap-core.de>
parents: 486
diff changeset
1101 cu_add_test(suite, test_linked_list_find);
486
d7ca126eab7f add cx_linked_list_compare() and simplifies some tests
Mike Becker <universe@uap-core.de>
parents: 482
diff changeset
1102 cu_add_test(suite, test_linked_list_compare);
475
31bf97fdbf71 add cx_linked_list_first() + cx_linked_list_prepend()
Mike Becker <universe@uap-core.de>
parents: 474
diff changeset
1103 cu_add_test(suite, test_linked_list_prepend);
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
1104 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
1105 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
1106 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
1107 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
1108 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
1109 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
1110 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
1111 cu_add_test(suite, test_linked_list_size);
75ae1dccd101 add cx_linked_list_sort()
Mike Becker <universe@uap-core.de>
parents: 466
diff changeset
1112 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
1113 cu_add_test(suite, test_linked_list_reverse);
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
1114
459
c0e2e9f83399 add tests for high level functions
Mike Becker <universe@uap-core.de>
parents: 456
diff changeset
1115 suite = CU_add_suite("high level linked list", NULL, NULL);
455
8168e16cd1e9 change test names
Mike Becker <universe@uap-core.de>
parents: 453
diff changeset
1116
456
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
1117 cu_add_test(suite, test_hl_linked_list_create);
488
9138acaa494b add cxLinkedListFromArray() and cxListCompare()
Mike Becker <universe@uap-core.de>
parents: 487
diff changeset
1118 cu_add_test(suite, test_hl_linked_list_from_array);
456
227c2eabbef8 change cx_linked_list_last() and add a test for it
Mike Becker <universe@uap-core.de>
parents: 455
diff changeset
1119 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
1120 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
1121 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
1122 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
1123 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
1124 cu_add_test(suite, test_hl_linked_list_sort);
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
1125 cu_add_test(suite, test_hl_linked_list_iterator);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1126 cu_add_test(suite, test_hl_linked_list_insert_via_iterator);
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
1127
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
1128 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
1129
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
1130 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
1131 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
1132 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
1133 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
1134 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
1135 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
1136 cu_add_test(suite, test_hl_ptr_linked_list_sort);
494
6ce8cfa10a96 add iterator interface + linked list iterator
Mike Becker <universe@uap-core.de>
parents: 492
diff changeset
1137 cu_add_test(suite, test_hl_ptr_linked_list_iterator);
499
3dc9075df822 add cxListInsertAfter() and cxListInsertBefore()
Mike Becker <universe@uap-core.de>
parents: 498
diff changeset
1138 cu_add_test(suite, test_hl_ptr_linked_list_insert_via_iterator);
466
28bc3e10ac28 add special linked list implementation for storing pointers
Mike Becker <universe@uap-core.de>
parents: 460
diff changeset
1139
411
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1140 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
1141
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1142 int exitcode;
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1143 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
1144 exitcode = CU_get_error();
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1145 } else {
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1146 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
1147 }
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1148 CU_cleanup_registry();
2842f729caab add first test suite to test_linked_list.c
Mike Becker <universe@uap-core.de>
parents: 398
diff changeset
1149 return exitcode;
390
d345541018fa starts ucx 3.0 development
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1150 }

mercurial