Mon, 27 Sep 2021 17:00:19 +0200
add node destruction in cxLinkedListDestroy()
425
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "cx/tree.h" |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include "test_config.h" |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <stddef.h> |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | typedef struct TestNode TestNode; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | struct TestNode { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | TestNode *parent; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | TestNode *prev; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | TestNode *next; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | TestNode *children_begin; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | TestNode *children_end; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | int content; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | }; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | void test_cx_tree_add_node() { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | // prepare test tree |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | TestNode root; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | memset(&root, 0, sizeof(TestNode)); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | TestNode a; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | memset(&a, 0, sizeof(TestNode)); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | root.children_begin = &a; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | root.children_end = &a; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | a.parent = &root; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | a.content = 1; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | // new test nodes |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | TestNode b; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | memset(&b, 0, sizeof(TestNode)); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | TestNode c; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | memset(&c, 0, sizeof(TestNode)); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | // test |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | b.content = 2; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | int ret = cx_tree_add_node(&a, offsetof(TestNode, parent), offsetof(TestNode, prev), offsetof(TestNode, next), &b); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | CU_ASSERT_EQUAL(ret, 0); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | CU_ASSERT_PTR_EQUAL(b.parent, &root); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | CU_ASSERT_PTR_EQUAL(b.prev, &a); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | CU_ASSERT_PTR_EQUAL(b.next, NULL); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | CU_ASSERT_PTR_EQUAL(a.next, &b); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | c.content = 3; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | ret = cx_tree_add_node(&a, -1, -1, offsetof(TestNode, next), &c); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | CU_ASSERT_EQUAL(ret, 0); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | CU_ASSERT_PTR_EQUAL(c.parent, NULL); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | CU_ASSERT_PTR_EQUAL(c.prev, NULL); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | CU_ASSERT_PTR_EQUAL(c.next, NULL); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | CU_ASSERT_PTR_EQUAL(b.next, &c); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | } |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | |
430
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
83 | void test_cx_tree_add_child_node() { |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
84 | // prepare test tree |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
85 | TestNode root; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
86 | memset(&root, 0, sizeof(TestNode)); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
87 | |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
88 | TestNode a; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
89 | memset(&a, 0, sizeof(TestNode)); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
90 | TestNode b; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
91 | memset(&b, 0, sizeof(TestNode)); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
92 | TestNode c; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
93 | memset(&c, 0, sizeof(TestNode)); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
94 | TestNode a1; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
95 | memset(&a1, 0, sizeof(TestNode)); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
96 | |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
97 | int ret; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
98 | |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
99 | // test |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
100 | a.content = 1; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
101 | ret = cx_tree_add_child_node( |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
102 | &root, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
103 | offsetof(TestNode, parent), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
104 | offsetof(TestNode, prev), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
105 | offsetof(TestNode, next), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
106 | (void**)&root.children_begin, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
107 | (void**)&root.children_end, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
108 | &a); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
109 | CU_ASSERT_EQUAL(ret, 0); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
110 | CU_ASSERT_PTR_EQUAL(root.children_begin, &a); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
111 | CU_ASSERT_PTR_EQUAL(root.children_end, &a); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
112 | CU_ASSERT_PTR_EQUAL(a.parent, &root); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
113 | CU_ASSERT_PTR_EQUAL(a.prev, NULL); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
114 | CU_ASSERT_PTR_EQUAL(a.next, NULL); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
115 | |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
116 | b.content = 2; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
117 | ret = cx_tree_add_child_node( |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
118 | &root, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
119 | offsetof(TestNode, parent), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
120 | offsetof(TestNode, prev), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
121 | offsetof(TestNode, next), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
122 | (void**)&root.children_begin, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
123 | (void**)&root.children_end, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
124 | &b); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
125 | CU_ASSERT_EQUAL(ret, 0); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
126 | CU_ASSERT_TRUE(root.children_begin ? root.children_begin->next == &b : 0); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
127 | CU_ASSERT_PTR_EQUAL(root.children_end, &b); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
128 | CU_ASSERT_PTR_EQUAL(b.parent, &root); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
129 | CU_ASSERT_PTR_EQUAL(b.prev, &a); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
130 | |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
131 | c.content = 3; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
132 | ret = cx_tree_add_child_node( |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
133 | &root, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
134 | -1, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
135 | -1, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
136 | offsetof(TestNode, next), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
137 | (void**)&root.children_begin, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
138 | NULL, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
139 | &c); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
140 | CU_ASSERT_EQUAL(ret, 0); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
141 | CU_ASSERT_PTR_EQUAL(root.children_end, &b); // children_end unchanged |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
142 | CU_ASSERT_PTR_EQUAL(b.next, &c); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
143 | CU_ASSERT_PTR_EQUAL(c.prev, NULL); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
144 | CU_ASSERT_PTR_EQUAL(c.next, NULL); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
145 | CU_ASSERT_PTR_EQUAL(c.parent, NULL); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
146 | |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
147 | a1.content = 11; |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
148 | ret = cx_tree_add_child_node( |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
149 | &a, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
150 | offsetof(TestNode, parent), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
151 | offsetof(TestNode, prev), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
152 | offsetof(TestNode, next), |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
153 | (void**)&a.children_begin, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
154 | (void**)&a.children_end, |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
155 | &a1); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
156 | CU_ASSERT_EQUAL(ret, 0); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
157 | CU_ASSERT_PTR_EQUAL(a.children_begin, &a1); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
158 | CU_ASSERT_PTR_EQUAL(a1.parent, &a); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
159 | CU_ASSERT_TRUE(root.children_begin ? root.children_begin->children_begin == &a1 : 0); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
160 | } |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
161 | |
425
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | int main() { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | CU_pSuite suite = NULL; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | if (CUE_SUCCESS != CU_initialize_registry()) { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | return CU_get_error(); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | } |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | suite = CU_add_suite("tree suite", NULL, NULL); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | if (NULL == suite) { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | CU_cleanup_registry(); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | return CU_get_error(); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | } |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | if ( |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | !CU_add_test(suite, "ll add tree node", test_cx_tree_add_node) |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | ) { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | CU_cleanup_registry(); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | return CU_get_error(); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | } |
430
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
181 | if ( |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
182 | !CU_add_test(suite, "ll add tree child node", test_cx_tree_add_child_node) |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
183 | ) { |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
184 | CU_cleanup_registry(); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
185 | return CU_get_error(); |
d4d643def2ac
add cx_tree_add_child_node tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
425
diff
changeset
|
186 | } |
425
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | CU_basic_set_mode(UCX_CU_BRM); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | int exitcode; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | if (CU_basic_run_tests()) { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | exitcode = CU_get_error(); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | } else { |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | exitcode = CU_get_number_of_failures() == 0 ? 0 : 1; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | } |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | CU_cleanup_registry(); |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | return exitcode; |
a75b808d653b
add cx_tree_add_node test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | } |