tests/test_tree.c

Mon, 19 Aug 2024 18:46:49 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 19 Aug 2024 18:46:49 +0200
branch
feature/tree_add
changeset 865
4b325b639117
parent 862
387414a7afd8
child 866
1f636de4a63f
permissions
-rw-r--r--

fix return type of cx_tree_node_create_func

relates to #390

816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
425234b05dff add first basic low level tree functions
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
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/tree.h"
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 #include "cx/test.h"
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
840
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
33 #include "util_allocator.h"
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
34
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 typedef struct tree_node {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 struct tree_node *parent;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 struct tree_node *next;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 struct tree_node *prev;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 struct tree_node *children;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 int data;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 } tree_node;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
43 typedef struct tree_node2 {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
44 struct tree_node2 *parent;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
45 struct tree_node2 *next;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
46 struct tree_node2 *prev;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
47 struct tree_node2 *children;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
48 struct tree_node2 *last_child;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
49 int data;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
50 } tree_node2;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
51
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 #define tree_node_layout \
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
53 offsetof(tree_node, parent), offsetof(tree_node, children), -1, \
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 offsetof(tree_node, prev), offsetof(tree_node, next)
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
55 #define tree_node2_layout \
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
56 offsetof(tree_node2, parent), offsetof(tree_node2, children),\
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
57 offsetof(tree_node2, last_child), \
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
58 offsetof(tree_node2, prev), offsetof(tree_node2, next)
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
60 #define tree_children(type) offsetof(type, children), offsetof(type, next)
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
61
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 CX_TEST(test_tree_link_new_child) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 tree_node child = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 CX_TEST_DO {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 cx_tree_link(&parent, &child, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 CX_TEST_ASSERT(parent.parent == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 CX_TEST_ASSERT(parent.children == &child);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 CX_TEST_ASSERT(child.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 CX_TEST_ASSERT(child.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 CX_TEST_ASSERT(child.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 CX_TEST_ASSERT(child.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 CX_TEST(test_tree_link_add_child) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 tree_node child1 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 tree_node child2 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 tree_node child3 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 CX_TEST_DO {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 cx_tree_link(&parent, &child1, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 cx_tree_link(&parent, &child2, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 cx_tree_link(&parent, &child3, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 CX_TEST_ASSERT(parent.parent == NULL);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
92 CX_TEST_ASSERT(parent.children == &child1);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 CX_TEST_ASSERT(child1.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 CX_TEST_ASSERT(child2.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 CX_TEST_ASSERT(child3.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 CX_TEST_ASSERT(child1.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 CX_TEST_ASSERT(child2.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 CX_TEST_ASSERT(child3.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
101 CX_TEST_ASSERT(child1.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
102 CX_TEST_ASSERT(child1.next == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
103 CX_TEST_ASSERT(child2.prev == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
104 CX_TEST_ASSERT(child2.next == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
105 CX_TEST_ASSERT(child3.prev == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
106 CX_TEST_ASSERT(child3.next == NULL);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 CX_TEST(test_tree_link_move_to_other_parent) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 tree_node child1 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 tree_node child2 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 tree_node child3 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 cx_tree_link(&parent, &child1, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 cx_tree_link(&parent, &child2, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 cx_tree_link(&parent, &child3, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 CX_TEST_DO {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 cx_tree_link(&child3, &child2, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 CX_TEST_ASSERT(parent.parent == NULL);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
125 CX_TEST_ASSERT(parent.children == &child1);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 CX_TEST_ASSERT(child1.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 CX_TEST_ASSERT(child2.parent == &child3);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 CX_TEST_ASSERT(child3.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 CX_TEST_ASSERT(child1.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 CX_TEST_ASSERT(child2.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 CX_TEST_ASSERT(child3.children == &child2);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
134 CX_TEST_ASSERT(child1.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
135 CX_TEST_ASSERT(child1.next == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
136 CX_TEST_ASSERT(child3.prev == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
137 CX_TEST_ASSERT(child3.next == NULL);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 CX_TEST_ASSERT(child2.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 CX_TEST_ASSERT(child2.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 CX_TEST(test_tree_unlink) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 tree_node child1 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 tree_node child2 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 tree_node child3 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 cx_tree_link(&parent, &child1, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 cx_tree_link(&parent, &child3, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 cx_tree_link(&child3, &child2, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 CX_TEST_DO {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 cx_tree_unlink(&child3, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 CX_TEST_ASSERT(parent.parent == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 CX_TEST_ASSERT(parent.children == &child1);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 CX_TEST_ASSERT(child1.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 CX_TEST_ASSERT(child1.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 CX_TEST_ASSERT(child1.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 CX_TEST_ASSERT(child1.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 // child 3 is unlinked
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 CX_TEST_ASSERT(child3.parent == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 CX_TEST_ASSERT(child3.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 CX_TEST_ASSERT(child3.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 // child 2 is still child of the unlinked child 3
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 CX_TEST_ASSERT(child3.children == &child2);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 CX_TEST_ASSERT(child2.parent == &child3);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 CX_TEST_ASSERT(child2.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 CX_TEST_ASSERT(child2.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 CX_TEST_ASSERT(child2.next == NULL);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
177
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
178 // unlink last child from parent
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
179 cx_tree_unlink(&child1, tree_node_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
180 CX_TEST_ASSERT(parent.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
181 CX_TEST_ASSERT(parent.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
182 CX_TEST_ASSERT(parent.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
183 CX_TEST_ASSERT(parent.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
184 CX_TEST_ASSERT(child1.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
185 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
186 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
187
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
188 CX_TEST(test_tree2_link_new_child) {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
189 tree_node2 parent = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
190 tree_node2 child = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
191
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
192 CX_TEST_DO {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
193 cx_tree_link(&parent, &child, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
194 CX_TEST_ASSERT(parent.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
195 CX_TEST_ASSERT(parent.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
196 CX_TEST_ASSERT(parent.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
197 CX_TEST_ASSERT(parent.children == &child);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
198 CX_TEST_ASSERT(parent.last_child == &child);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
199 CX_TEST_ASSERT(child.parent == &parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
200 CX_TEST_ASSERT(child.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
201 CX_TEST_ASSERT(child.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
202 CX_TEST_ASSERT(child.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
203 CX_TEST_ASSERT(child.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
204 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
205 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
206
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
207 CX_TEST(test_tree2_link_add_child) {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
208 tree_node2 parent = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
209 tree_node2 child1 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
210 tree_node2 child2 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
211 tree_node2 child3 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
212
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
213 CX_TEST_DO {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
214 cx_tree_link(&parent, &child1, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
215 cx_tree_link(&parent, &child2, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
216 cx_tree_link(&parent, &child3, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
217 CX_TEST_ASSERT(parent.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
218 CX_TEST_ASSERT(parent.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
219 CX_TEST_ASSERT(parent.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
220 CX_TEST_ASSERT(parent.children == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
221 CX_TEST_ASSERT(parent.last_child == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
222
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
223 CX_TEST_ASSERT(child1.parent == &parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
224 CX_TEST_ASSERT(child2.parent == &parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
225 CX_TEST_ASSERT(child3.parent == &parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
226 CX_TEST_ASSERT(child1.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
227 CX_TEST_ASSERT(child2.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
228 CX_TEST_ASSERT(child3.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
229 CX_TEST_ASSERT(child1.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
230 CX_TEST_ASSERT(child2.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
231 CX_TEST_ASSERT(child3.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
232
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
233 CX_TEST_ASSERT(child1.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
234 CX_TEST_ASSERT(child1.next == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
235 CX_TEST_ASSERT(child2.prev == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
236 CX_TEST_ASSERT(child2.next == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
237 CX_TEST_ASSERT(child3.prev == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
238 CX_TEST_ASSERT(child3.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
239 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
240 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
241
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
242 CX_TEST(test_tree2_link_move_to_other_parent) {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
243 tree_node2 parent = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
244 tree_node2 child1 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
245 tree_node2 child2 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
246 tree_node2 child3 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
247 cx_tree_link(&parent, &child1, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
248 cx_tree_link(&parent, &child2, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
249 cx_tree_link(&parent, &child3, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
250
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
251 CX_TEST_DO {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
252 cx_tree_link(&child3, &child2, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
253
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
254 CX_TEST_ASSERT(parent.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
255 CX_TEST_ASSERT(parent.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
256 CX_TEST_ASSERT(parent.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
257 CX_TEST_ASSERT(parent.children == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
258 CX_TEST_ASSERT(parent.last_child == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
259
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
260 CX_TEST_ASSERT(child1.parent == &parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
261 CX_TEST_ASSERT(child2.parent == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
262 CX_TEST_ASSERT(child3.parent == &parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
263 CX_TEST_ASSERT(child1.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
264 CX_TEST_ASSERT(child2.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
265 CX_TEST_ASSERT(child3.children == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
266 CX_TEST_ASSERT(child1.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
267 CX_TEST_ASSERT(child2.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
268 CX_TEST_ASSERT(child3.last_child == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
269
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
270 CX_TEST_ASSERT(child1.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
271 CX_TEST_ASSERT(child1.next == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
272 CX_TEST_ASSERT(child3.prev == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
273 CX_TEST_ASSERT(child3.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
274
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
275 CX_TEST_ASSERT(child2.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
276 CX_TEST_ASSERT(child2.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
277 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
278 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
279
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
280 CX_TEST(test_tree2_unlink) {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
281 tree_node2 parent = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
282 tree_node2 child1 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
283 tree_node2 child2 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
284 tree_node2 child3 = {0};
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
285 cx_tree_link(&parent, &child1, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
286 cx_tree_link(&parent, &child3, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
287 cx_tree_link(&child3, &child2, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
288
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
289 CX_TEST_DO {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
290 cx_tree_unlink(&child3, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
291
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
292 CX_TEST_ASSERT(parent.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
293 CX_TEST_ASSERT(parent.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
294 CX_TEST_ASSERT(parent.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
295 CX_TEST_ASSERT(parent.children == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
296 CX_TEST_ASSERT(parent.last_child == &child1);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
297
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
298 CX_TEST_ASSERT(child1.parent == &parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
299 CX_TEST_ASSERT(child1.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
300 CX_TEST_ASSERT(child1.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
301 CX_TEST_ASSERT(child1.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
302 CX_TEST_ASSERT(child1.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
303
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
304 // child 3 is unlinked
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
305 CX_TEST_ASSERT(child3.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
306 CX_TEST_ASSERT(child3.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
307 CX_TEST_ASSERT(child3.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
308
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
309 // child 2 is still child of the unlinked child 3
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
310 CX_TEST_ASSERT(child3.children == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
311 CX_TEST_ASSERT(child3.last_child == &child2);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
312 CX_TEST_ASSERT(child2.parent == &child3);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
313 CX_TEST_ASSERT(child2.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
314 CX_TEST_ASSERT(child2.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
315 CX_TEST_ASSERT(child2.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
316 CX_TEST_ASSERT(child2.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
317
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
318 // unlink last child from parent
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
319 cx_tree_unlink(&child1, tree_node2_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
320 CX_TEST_ASSERT(parent.next == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
321 CX_TEST_ASSERT(parent.prev == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
322 CX_TEST_ASSERT(parent.parent == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
323 CX_TEST_ASSERT(parent.children == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
324 CX_TEST_ASSERT(parent.last_child == NULL);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
325 CX_TEST_ASSERT(child1.parent == NULL);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
329 static int test_tree_search_function(void const *n, void const *d) {
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
330 tree_node const *node = n;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
331 int data = *((int const*)d);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
332
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
333 if (data < node->data) return -1;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
334 else if (data == node->data) return 0;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
335 else return data - node->data;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
336 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
337
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
338 CX_TEST(test_tree_search) {
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
339 tree_node root = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
340 tree_node a = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
341 tree_node b = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
342 tree_node c = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
343 tree_node aa = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
344 tree_node ab = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
345 tree_node ba = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
346 tree_node ca = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
347 tree_node cb = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
348 tree_node cc = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
349 tree_node cba = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
350
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
351 int testdata[] = {0, 10, 14, 18, 20, 25, 30, 32, 34, 36, 40};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
352 tree_node* testnodes[] = {&root, &a, &aa, &ab, &b, &ba, &c, &ca, &cb, &cba, &cc};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
353
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
354 for (unsigned i = 0 ; i <= 10 ; i++) {
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
355 testnodes[i]->data = testdata[i];
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
356 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
357
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
358 cx_tree_link(&root, &a, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
359 cx_tree_link(&root, &b, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
360 cx_tree_link(&root, &c, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
361
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
362 cx_tree_link(&a, &aa, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
363 cx_tree_link(&a, &ab, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
364
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
365 cx_tree_link(&b, &ba, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
366
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
367 cx_tree_link(&c, &ca, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
368 cx_tree_link(&c, &cb, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
369 cx_tree_link(&c, &cc, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
370
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
371 cx_tree_link(&cb, &cba, tree_node_layout);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
372
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
373 int s;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
374 int r;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
375 tree_node *n;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
376 CX_TEST_DO {
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
377 for (unsigned i = 0 ; i <= 10 ; i++) {
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
378 s = testdata[i];
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
379 r = cx_tree_search(&root, &s, test_tree_search_function,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
380 (void **) &n, tree_children(tree_node));
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
381 CX_TEST_ASSERT(r == 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
382 CX_TEST_ASSERT(n == testnodes[i]);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
383 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
384
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
385 s = -5;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
386 r = cx_tree_search(&root, &s, test_tree_search_function,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
387 (void **) &n, tree_children(tree_node));
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
388 CX_TEST_ASSERT(r < 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
389 CX_TEST_ASSERT(n == NULL);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
390
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
391 s = 26;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
392 r = cx_tree_search(&root, &s, test_tree_search_function,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
393 (void **) &n, tree_children(tree_node));
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
394 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
395 CX_TEST_ASSERT(n == &ba);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
396
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
397 s = 35;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
398 r = cx_tree_search(&root, &s, test_tree_search_function,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
399 (void **) &n, tree_children(tree_node));
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
400 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
401 CX_TEST_ASSERT(n == &cb);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
402
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
403 s = 38;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
404 r = cx_tree_search(&root, &s, test_tree_search_function,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
405 (void **) &n, tree_children(tree_node));
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
406 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
407 CX_TEST_ASSERT(n == &cba);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
408
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
409 s = 42;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
410 r = cx_tree_search(&root, &s, test_tree_search_function,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
411 (void **) &n, tree_children(tree_node));
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
412 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
413 CX_TEST_ASSERT(n == &cc);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
414 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
415 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
416
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
417 CX_TEST(test_tree_iterator_create_and_dispose) {
833
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
418 tree_node root;
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
419 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
420 CxTreeIterator iter = cx_tree_iterator(&root, false, tree_children(tree_node));
833
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
421 CX_TEST_ASSERT(!iter.visit_on_exit);
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
422 CX_TEST_ASSERT(!iter.exiting);
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
423 CX_TEST_ASSERT(iter.counter == 1);
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
424 CX_TEST_ASSERT(iter.node == &root);
854
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
425 CX_TEST_ASSERT(!iter.base.mutating);
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
426 CX_TEST_ASSERT(!iter.base.remove);
833
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
427 CX_TEST_ASSERT(iter.stack != NULL);
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
428 CX_TEST_ASSERT(iter.stack_capacity > 0);
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
429 CX_TEST_ASSERT(iter.stack_size == 1);
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
430 CX_TEST_ASSERT(iter.depth == 1);
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
431 CX_TEST_ASSERT(iter.loc_next == offsetof(tree_node, next));
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
432 CX_TEST_ASSERT(iter.loc_children == offsetof(tree_node, children));
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
433 cxTreeIteratorDispose(&iter);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
434 CX_TEST_ASSERT(iter.stack == NULL);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
435 }
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
436 }
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
437
838
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
438 CX_TEST(test_tree_iterator_basic_only_enter) {
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
439 tree_node root = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
440 tree_node a = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
441 tree_node b = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
442 tree_node c = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
443 tree_node aa = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
444 tree_node ab = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
445 tree_node ba = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
446 tree_node ca = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
447 tree_node cb = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
448 tree_node cc = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
449 tree_node cba = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
450
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
451 tree_node* expected_order[] = {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
452 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
453 &a, &aa, &ab,
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
454 &b, &ba,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
455 &c, &ca, &cb, &cba, &cc,
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
456 };
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
457 tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
458
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
459 cx_tree_link(&root, &a, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
460 cx_tree_link(&root, &b, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
461 cx_tree_link(&root, &c, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
462 cx_tree_link(&a, &aa, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
463 cx_tree_link(&a, &ab, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
464 cx_tree_link(&b, &ba, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
465 cx_tree_link(&c, &ca, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
466 cx_tree_link(&c, &cb, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
467 cx_tree_link(&c, &cc, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
468 cx_tree_link(&cb, &cba, tree_node_layout);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
469 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
470 CxTreeIterator iter = cx_tree_iterator(&root, false, tree_children(tree_node));
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
471 unsigned chk = 0;
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
472 cx_foreach(tree_node*, node, iter) {
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
473 CX_TEST_ASSERT(node->data == 0);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
474 node->data++;
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
475 actual_order[chk] = node;
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
476 chk++;
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
477 CX_TEST_ASSERT(node == iter.node);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
478 CX_TEST_ASSERT(!iter.exiting);
837
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
479 if (node == &root) {
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
480 CX_TEST_ASSERT(iter.depth == 1);
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
481 } else if (node == &a || node == &b || node == &c) {
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
482 CX_TEST_ASSERT(iter.depth == 2);
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
483 } else if (node == &cba) {
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
484 CX_TEST_ASSERT(iter.depth == 4);
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
485 } else {
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
486 CX_TEST_ASSERT(iter.depth == 3);
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
487 }
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
488 }
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
489 CX_TEST_ASSERT(iter.counter == 11);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
490 CX_TEST_ASSERT(chk == 11);
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
491 for (unsigned i = 0 ; i < chk ; i++) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
492 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
493 CX_TEST_ASSERT(actual_order[i]->data == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
494 }
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
495 CX_TEST_ASSERT(iter.stack == NULL);
833
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
496 }
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
497 }
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
498
838
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
499 CX_TEST(test_tree_iterator_basic_enter_and_exit) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
500 tree_node root = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
501 tree_node a = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
502 tree_node b = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
503 tree_node c = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
504 tree_node aa = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
505 tree_node ab = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
506 tree_node ba = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
507 tree_node ca = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
508 tree_node cb = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
509 tree_node cc = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
510 tree_node cba = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
511
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
512 cx_tree_link(&root, &a, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
513 cx_tree_link(&root, &b, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
514 cx_tree_link(&root, &c, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
515 cx_tree_link(&a, &aa, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
516 cx_tree_link(&a, &ab, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
517 cx_tree_link(&b, &ba, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
518 cx_tree_link(&c, &ca, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
519 cx_tree_link(&c, &cb, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
520 cx_tree_link(&c, &cc, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
521 cx_tree_link(&cb, &cba, tree_node_layout);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
522 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
523 CxTreeIterator iter = cx_tree_iterator(&root, true, tree_children(tree_node));
838
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
524 unsigned chk = 0;
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
525 cx_foreach(tree_node*, node, iter) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
526 CX_TEST_ASSERT(iter.exiting || node->data == 0);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
527 node->data++;
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
528 chk++;
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
529 CX_TEST_ASSERT(node == iter.node);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
530 if (node == &root) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
531 CX_TEST_ASSERT(iter.depth == 1);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
532 } else if (node == &a || node == &b || node == &c) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
533 CX_TEST_ASSERT(iter.depth == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
534 } else if (node == &cba) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
535 CX_TEST_ASSERT(iter.depth == 4);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
536 } else {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
537 CX_TEST_ASSERT(iter.depth == 3);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
538 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
539 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
540 CX_TEST_ASSERT(iter.counter == 11);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
541 CX_TEST_ASSERT(chk == 22);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
542 CX_TEST_ASSERT(iter.stack == NULL);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
543 CX_TEST_ASSERT(root.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
544 CX_TEST_ASSERT(a.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
545 CX_TEST_ASSERT(b.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
546 CX_TEST_ASSERT(c.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
547 CX_TEST_ASSERT(aa.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
548 CX_TEST_ASSERT(ab.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
549 CX_TEST_ASSERT(ba.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
550 CX_TEST_ASSERT(ca.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
551 CX_TEST_ASSERT(cb.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
552 CX_TEST_ASSERT(cc.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
553 CX_TEST_ASSERT(cba.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
554 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
555 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
556
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
557 typedef struct test_xml_node {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
558 struct tree_node base;
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
559 char const* name;
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
560 } test_xml_node;
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
561
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
562 CX_TEST(test_tree_iterator_xml) {
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
563 test_xml_node project = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
564 test_xml_node config = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
565 test_xml_node var1 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
566 test_xml_node var2 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
567 test_xml_node var3 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
568 test_xml_node dependency1 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
569 test_xml_node dependency1make = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
570 test_xml_node dependency2 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
571 test_xml_node dependency2lang = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
572 test_xml_node dependency2make = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
573 test_xml_node target = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
574 test_xml_node target_feature = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
575 test_xml_node target_feature_dependencies = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
576 test_xml_node target_dependencies = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
577
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
578 project.name = "project";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
579 config.name = "config";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
580 var1.name = "var";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
581 var2.name = "var";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
582 var3.name = "var";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
583 dependency1.name = "dependency";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
584 dependency1make.name = "make";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
585 dependency2.name = "dependency";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
586 dependency2lang.name = "lang";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
587 dependency2make.name = "make";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
588 target.name = "target";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
589 target_feature.name = "feature";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
590 target_dependencies.name = "dependencies";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
591 target_feature_dependencies.name = "dependencies";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
592
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
593 cx_tree_link(&project, &config, tree_node_layout);
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
594 cx_tree_link(&project, &dependency1, tree_node_layout);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
595 cx_tree_link(&project, &dependency2, tree_node_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
596 cx_tree_link(&project, &target, tree_node_layout);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
597 cx_tree_link(&config, &var1, tree_node_layout);
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
598 cx_tree_link(&config, &var2, tree_node_layout);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
599 cx_tree_link(&config, &var3, tree_node_layout);
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
600 cx_tree_link(&dependency1, &dependency1make, tree_node_layout);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
601 cx_tree_link(&dependency2, &dependency2lang, tree_node_layout);
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
602 cx_tree_link(&dependency2, &dependency2make, tree_node_layout);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
603 cx_tree_link(&target, &target_feature, tree_node_layout);
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
604 cx_tree_link(&target, &target_dependencies, tree_node_layout);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
605 cx_tree_link(&target_feature, &target_feature_dependencies, tree_node_layout);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
606
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
607 char const *expected =
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
608 "<project><config><var></var><var></var><var></var></config>"
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
609 "<dependency><make></make></dependency><dependency><lang></lang><make></make></dependency>"
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
610 "<target><feature><dependencies></dependencies></feature><dependencies></dependencies></target></project>";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
611 char *actual = malloc(512);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
612 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
613 CxTreeIterator iter = cx_tree_iterator(&project, true, tree_children(tree_node));
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
614 size_t i = 0;
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
615 cx_foreach(test_xml_node*, node, iter) {
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
616 size_t len = strlen(node->name);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
617 actual[i++] = '<';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
618 if (iter.exiting) {
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
619 actual[i++] = '/';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
620 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
621 memcpy(actual+i, node->name, len);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
622 i += len;
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
623 actual[i++] = '>';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
624 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
625 actual[i] = '\0';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
626 CX_TEST_ASSERT(0 == strcmp(expected, actual));
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
627 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
628 free(actual);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
629 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
630
840
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
631 CX_TEST(test_tree_iterator_free_nodes) {
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
632 CxTestingAllocator talloc;
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
633 cx_testing_allocator_init(&talloc);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
634 CxAllocator *alloc = &talloc.base;
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
635 CX_TEST_DO {
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
636 tree_node *root = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
637 tree_node *a = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
638 tree_node *b = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
639 tree_node *c = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
640 tree_node *aa = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
641 tree_node *ab = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
642 tree_node *ba = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
643 tree_node *ca = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
644 tree_node *cb = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
645 tree_node *cc = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
646 tree_node *cba = cxCalloc(alloc, 1, sizeof(tree_node));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
647
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
648 cx_tree_link(root, a, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
649 cx_tree_link(root, b, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
650 cx_tree_link(root, c, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
651 cx_tree_link(a, aa, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
652 cx_tree_link(a, ab, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
653 cx_tree_link(b, ba, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
654 cx_tree_link(c, ca, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
655 cx_tree_link(c, cb, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
656 cx_tree_link(c, cc, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
657 cx_tree_link(cb, cba, tree_node_layout);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
658
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
659 CxTreeIterator iter = cx_tree_iterator(root, true, tree_children(tree_node));
840
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
660 cx_foreach(tree_node *, node, iter) {
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
661 if (iter.exiting) {
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
662 cxFree(alloc,node);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
663 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
664 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
665
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
666 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
667 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
668 cx_testing_allocator_destroy(&talloc);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
669 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
670
847
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
671 CX_TEST(test_tree_visitor_create_and_dispose) {
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
672 tree_node root;
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
673 tree_node child;
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
674 cx_tree_link(&root, &child, tree_node_layout);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
675 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
676 CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node));
847
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
677 CX_TEST_ASSERT(iter.counter == 1);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
678 CX_TEST_ASSERT(iter.node == &root);
854
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
679 CX_TEST_ASSERT(!iter.base.mutating);
fe0d69d72bcd fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents: 853
diff changeset
680 CX_TEST_ASSERT(!iter.base.remove);
847
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
681 CX_TEST_ASSERT(iter.queue_next != NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
682 CX_TEST_ASSERT(iter.queue_last != NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
683 CX_TEST_ASSERT(iter.depth == 1);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
684 CX_TEST_ASSERT(iter.loc_next == offsetof(tree_node, next));
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
685 CX_TEST_ASSERT(iter.loc_children == offsetof(tree_node, children));
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
686 cxTreeVisitorDispose(&iter);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
687 CX_TEST_ASSERT(iter.queue_next == NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
688 CX_TEST_ASSERT(iter.queue_last == NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
689 }
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
690 }
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
691
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
692 CX_TEST(test_tree_visitor) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
693 tree_node root = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
694 tree_node a = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
695 tree_node b = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
696 tree_node c = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
697 tree_node aa = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
698 tree_node ab = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
699 tree_node ba = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
700 tree_node ca = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
701 tree_node cb = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
702 tree_node cc = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
703 tree_node cba = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
704
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
705 tree_node* expected_order[] = {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
706 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
707 &a, &b, &c,
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
708 &aa, &ab, &ba, &ca, &cb, &cc,
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
709 &cba
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
710 };
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
711 tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
712
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
713 cx_tree_link(&root, &a, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
714 cx_tree_link(&root, &b, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
715 cx_tree_link(&root, &c, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
716 cx_tree_link(&a, &aa, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
717 cx_tree_link(&a, &ab, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
718 cx_tree_link(&b, &ba, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
719 cx_tree_link(&c, &ca, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
720 cx_tree_link(&c, &cb, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
721 cx_tree_link(&c, &cc, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
722 cx_tree_link(&cb, &cba, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
723 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
724 CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node));
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
725 unsigned chk = 0;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
726 cx_foreach(tree_node*, node, iter) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
727 CX_TEST_ASSERT(node->data == 0);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
728 node->data++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
729 actual_order[chk] = node;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
730 chk++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
731 CX_TEST_ASSERT(node == iter.node);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
732 if (node == &root) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
733 CX_TEST_ASSERT(iter.depth == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
734 } else if (node == &a || node == &b || node == &c) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
735 CX_TEST_ASSERT(iter.depth == 2);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
736 } else if (node == &cba) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
737 CX_TEST_ASSERT(iter.depth == 4);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
738 } else {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
739 CX_TEST_ASSERT(iter.depth == 3);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
740 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
741 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
742 CX_TEST_ASSERT(iter.counter == 11);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
743 CX_TEST_ASSERT(chk == 11);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
744 for (unsigned i = 0 ; i < chk ; i++) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
745 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
746 CX_TEST_ASSERT(actual_order[i]->data == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
747 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
748 CX_TEST_ASSERT(iter.queue_next == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
749 CX_TEST_ASSERT(iter.queue_last == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
750 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
751 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
752
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
753 CX_TEST(test_tree_visitor_no_children) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
754 tree_node root = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
755
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
756 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
757 CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node));
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
758 unsigned chk = 0;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
759 cx_foreach(tree_node*, node, iter) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
760 CX_TEST_ASSERT(node == iter.node);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
761 chk++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
762 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
763 CX_TEST_ASSERT(iter.counter == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
764 CX_TEST_ASSERT(chk == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
765 CX_TEST_ASSERT(iter.queue_next == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
766 CX_TEST_ASSERT(iter.queue_last == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
767 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
768 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
769
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
770 CX_TEST(test_tree_visitor_no_branching) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
771 tree_node root = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
772 tree_node a = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
773 tree_node b = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
774 tree_node c = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
775
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
776 tree_node* expected_order[] = {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
777 &root, &a, &b, &c
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
778 };
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
779 tree_node* actual_order[4];
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
780
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
781 cx_tree_link(&root, &a, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
782 cx_tree_link(&a, &b, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
783 cx_tree_link(&b, &c, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
784
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
785 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
786 CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node));
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
787 unsigned chk = 0;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
788 cx_foreach(tree_node*, node, iter) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
789 CX_TEST_ASSERT(node == iter.node);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
790 CX_TEST_ASSERT(node->data == 0);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
791 node->data++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
792 actual_order[chk] = node;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
793 chk++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
794 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
795 CX_TEST_ASSERT(iter.counter == 4);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
796 CX_TEST_ASSERT(chk == 4);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
797 CX_TEST_ASSERT(iter.queue_next == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
798 CX_TEST_ASSERT(iter.queue_last == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
799 for (unsigned i = 0 ; i < chk ; i++) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
800 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
801 CX_TEST_ASSERT(actual_order[i]->data == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
802 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
803 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
804 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
805
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
806 CX_TEST(test_tree_visitor_continue) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
807 tree_node root = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
808 tree_node a = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
809 tree_node b = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
810 tree_node c = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
811 tree_node aa = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
812 tree_node ab = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
813 tree_node ba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
814 tree_node ca = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
815 tree_node cb = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
816 tree_node cc = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
817 tree_node cba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
818
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
819 tree_node* expected_order[] = {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
820 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
821 &a, &b, &c,
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
822 &aa, &ab, &ba
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
823 };
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
824 tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
825
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
826 cx_tree_link(&root, &a, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
827 cx_tree_link(&root, &b, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
828 cx_tree_link(&root, &c, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
829 cx_tree_link(&a, &aa, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
830 cx_tree_link(&a, &ab, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
831 cx_tree_link(&b, &ba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
832 cx_tree_link(&c, &ca, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
833 cx_tree_link(&c, &cb, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
834 cx_tree_link(&c, &cc, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
835 cx_tree_link(&cb, &cba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
836 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
837 CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node));
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
838 unsigned chk = 0;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
839 cx_foreach(tree_node*, node, iter) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
840 CX_TEST_ASSERT(node->data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
841 node->data++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
842 actual_order[chk] = node;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
843 chk++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
844 CX_TEST_ASSERT(node == iter.node);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
845 if (node == &root) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
846 CX_TEST_ASSERT(iter.depth == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
847 } else if (node == &a || node == &b || node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
848 CX_TEST_ASSERT(iter.depth == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
849 } else {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
850 CX_TEST_ASSERT(iter.depth == 3);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
851 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
852 if (node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
853 cxTreeVisitorContinue(iter);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
854 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
855 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
856 CX_TEST_ASSERT(iter.counter == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
857 CX_TEST_ASSERT(chk == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
858 for (unsigned i = 0 ; i < chk ; i++) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
859 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
860 CX_TEST_ASSERT(actual_order[i]->data == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
861 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
862 CX_TEST_ASSERT(ca.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
863 CX_TEST_ASSERT(cb.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
864 CX_TEST_ASSERT(cc.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
865 CX_TEST_ASSERT(cba.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
866 CX_TEST_ASSERT(iter.queue_next == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
867 CX_TEST_ASSERT(iter.queue_last == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
868 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
869 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
870
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
871 CX_TEST(test_tree_iterator_continue) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
872 tree_node root = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
873 tree_node a = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
874 tree_node b = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
875 tree_node c = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
876 tree_node aa = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
877 tree_node ab = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
878 tree_node ba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
879 tree_node ca = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
880 tree_node cb = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
881 tree_node cc = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
882 tree_node cba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
883
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
884 tree_node *expected_order[] = {
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
885 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
886 &a, &aa, &ab,
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
887 &b, &ba,
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
888 &c,
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
889 };
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
890 tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
891
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
892 cx_tree_link(&root, &a, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
893 cx_tree_link(&root, &b, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
894 cx_tree_link(&root, &c, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
895 cx_tree_link(&a, &aa, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
896 cx_tree_link(&a, &ab, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
897 cx_tree_link(&b, &ba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
898 cx_tree_link(&c, &ca, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
899 cx_tree_link(&c, &cb, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
900 cx_tree_link(&c, &cc, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
901 cx_tree_link(&cb, &cba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
902 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
903 CxTreeIterator iter = cx_tree_iterator(&root, false, tree_children(tree_node));
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
904 unsigned chk = 0;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
905 cx_foreach(tree_node*, node, iter) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
906 CX_TEST_ASSERT(node->data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
907 node->data++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
908 actual_order[chk] = node;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
909 chk++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
910 CX_TEST_ASSERT(node == iter.node);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
911 CX_TEST_ASSERT(!iter.exiting);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
912 if (node == &root) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
913 CX_TEST_ASSERT(iter.depth == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
914 } else if (node == &a || node == &b || node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
915 CX_TEST_ASSERT(iter.depth == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
916 } else {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
917 CX_TEST_ASSERT(iter.depth == 3);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
918 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
919 if (node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
920 cxTreeIteratorContinue(iter);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
921 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
922 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
923 CX_TEST_ASSERT(iter.counter == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
924 CX_TEST_ASSERT(chk == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
925 for (unsigned i = 0 ; i < chk ; i++) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
926 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
927 CX_TEST_ASSERT(actual_order[i]->data == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
928 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
929 CX_TEST_ASSERT(ca.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
930 CX_TEST_ASSERT(cb.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
931 CX_TEST_ASSERT(cc.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
932 CX_TEST_ASSERT(cba.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
933 CX_TEST_ASSERT(iter.stack == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
934 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
935 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
936
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
937 CX_TEST(test_tree_iterator_continue_with_exit) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
938 tree_node root = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
939 tree_node a = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
940 tree_node b = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
941 tree_node c = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
942 tree_node aa = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
943 tree_node ab = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
944 tree_node ba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
945 tree_node ca = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
946 tree_node cb = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
947 tree_node cc = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
948 tree_node cba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
949
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
950 cx_tree_link(&root, &a, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
951 cx_tree_link(&root, &b, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
952 cx_tree_link(&root, &c, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
953 cx_tree_link(&a, &aa, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
954 cx_tree_link(&a, &ab, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
955 cx_tree_link(&b, &ba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
956 cx_tree_link(&c, &ca, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
957 cx_tree_link(&c, &cb, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
958 cx_tree_link(&c, &cc, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
959 cx_tree_link(&cb, &cba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
960 CX_TEST_DO {
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
961 CxTreeIterator iter = cx_tree_iterator(&root, true, tree_children(tree_node));
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
962 unsigned chk = 0;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
963 cx_foreach(tree_node*, node, iter) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
964 CX_TEST_ASSERT(iter.exiting || node->data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
965 node->data++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
966 chk++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
967 CX_TEST_ASSERT(node == iter.node);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
968 if (node == &root) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
969 CX_TEST_ASSERT(iter.depth == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
970 } else if (node == &a || node == &b || node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
971 CX_TEST_ASSERT(iter.depth == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
972 } else {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
973 CX_TEST_ASSERT(iter.depth == 3);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
974 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
975 if (node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
976 cxTreeIteratorContinue(iter);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
977 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
978 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
979 CX_TEST_ASSERT(iter.counter == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
980 CX_TEST_ASSERT(chk == 14);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
981 CX_TEST_ASSERT(iter.stack == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
982 CX_TEST_ASSERT(root.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
983 CX_TEST_ASSERT(a.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
984 CX_TEST_ASSERT(b.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
985 CX_TEST_ASSERT(c.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
986 CX_TEST_ASSERT(aa.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
987 CX_TEST_ASSERT(ab.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
988 CX_TEST_ASSERT(ba.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
989 CX_TEST_ASSERT(ca.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
990 CX_TEST_ASSERT(cb.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
991 CX_TEST_ASSERT(cc.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
992 CX_TEST_ASSERT(cba.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
993 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
994 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
995
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
996 CxTestSuite *cx_test_suite_tree_low_level(void) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
997 CxTestSuite *suite = cx_test_suite_new("tree (low level)");
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
998
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
999 cx_test_register(suite, test_tree_link_new_child);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1000 cx_test_register(suite, test_tree_link_add_child);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1001 cx_test_register(suite, test_tree_link_move_to_other_parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1002 cx_test_register(suite, test_tree_unlink);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
1003 cx_test_register(suite, test_tree2_link_new_child);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
1004 cx_test_register(suite, test_tree2_link_add_child);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
1005 cx_test_register(suite, test_tree2_link_move_to_other_parent);
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
1006 cx_test_register(suite, test_tree2_unlink);
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
1007 cx_test_register(suite, test_tree_search);
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
1008 cx_test_register(suite, test_tree_iterator_create_and_dispose);
838
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
1009 cx_test_register(suite, test_tree_iterator_basic_only_enter);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
1010 cx_test_register(suite, test_tree_iterator_basic_enter_and_exit);
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
1011 cx_test_register(suite, test_tree_iterator_xml);
840
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
1012 cx_test_register(suite, test_tree_iterator_free_nodes);
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
1013 cx_test_register(suite, test_tree_visitor);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
1014 cx_test_register(suite, test_tree_visitor_no_children);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
1015 cx_test_register(suite, test_tree_visitor_no_branching);
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1016 cx_test_register(suite, test_tree_visitor_continue);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1017 cx_test_register(suite, test_tree_iterator_continue);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1018 cx_test_register(suite, test_tree_iterator_continue_with_exit);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1019
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1020 return suite;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1021 }

mercurial