Wed, 20 Mar 2024 23:35:18 +0100
add missing header dependencies
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 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | #define tree_node_layout \ |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | offsetof(tree_node, parent), offsetof(tree_node, children), \ |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | offsetof(tree_node, prev), offsetof(tree_node, next) |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
47 | #define tree_child_list offsetof(tree_node, children),offsetof(tree_node, next) |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
48 | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | CX_TEST(test_tree_link_new_child) { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | tree_node child = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | 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
|
55 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | CX_TEST_ASSERT(parent.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | CX_TEST_ASSERT(parent.children == &child); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | CX_TEST_ASSERT(child.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | CX_TEST_ASSERT(child.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | CX_TEST_ASSERT(child.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | CX_TEST_ASSERT(child.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | } |
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(test_tree_link_add_child) { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | tree_node child1 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | tree_node child2 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | tree_node child3 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | 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
|
74 | 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
|
75 | 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
|
76 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | CX_TEST_ASSERT(parent.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | CX_TEST_ASSERT(parent.children == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | CX_TEST_ASSERT(child1.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | CX_TEST_ASSERT(child2.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | CX_TEST_ASSERT(child3.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | CX_TEST_ASSERT(child1.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | CX_TEST_ASSERT(child2.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | CX_TEST_ASSERT(child3.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | CX_TEST_ASSERT(child3.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | CX_TEST_ASSERT(child3.next == &child2); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | CX_TEST_ASSERT(child2.prev == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | CX_TEST_ASSERT(child2.next == &child1); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | CX_TEST_ASSERT(child1.prev == &child2); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | CX_TEST_ASSERT(child1.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | 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
|
98 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | tree_node child1 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | tree_node child2 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | tree_node child3 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | 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
|
108 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | CX_TEST_ASSERT(parent.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | CX_TEST_ASSERT(parent.children == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | CX_TEST_ASSERT(child1.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | CX_TEST_ASSERT(child2.parent == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | CX_TEST_ASSERT(child3.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | CX_TEST_ASSERT(child1.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | CX_TEST_ASSERT(child2.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
119 | CX_TEST_ASSERT(child3.children == &child2); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | CX_TEST_ASSERT(child3.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | CX_TEST_ASSERT(child3.next == &child1); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | CX_TEST_ASSERT(child1.prev == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | CX_TEST_ASSERT(child1.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | CX_TEST_ASSERT(child2.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | CX_TEST_ASSERT(child2.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | CX_TEST(test_tree_unlink) { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
133 | tree_node child1 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | tree_node child2 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | tree_node child3 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | 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
|
137 | 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
|
138 | 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
|
139 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | cx_tree_unlink(&child3, tree_node_layout); |
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 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | CX_TEST_ASSERT(parent.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | CX_TEST_ASSERT(parent.children == &child1); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | CX_TEST_ASSERT(child1.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | CX_TEST_ASSERT(child1.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | CX_TEST_ASSERT(child1.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | CX_TEST_ASSERT(child1.next == NULL); |
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 | // child 3 is unlinked |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | CX_TEST_ASSERT(child3.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | CX_TEST_ASSERT(child3.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | CX_TEST_ASSERT(child3.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | // 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
|
159 | CX_TEST_ASSERT(child3.children == &child2); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | CX_TEST_ASSERT(child2.parent == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | CX_TEST_ASSERT(child2.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | CX_TEST_ASSERT(child2.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | CX_TEST_ASSERT(child2.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | } |
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 | |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
167 | 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
|
168 | tree_node const *node = n; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
169 | int data = *((int const*)d); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
170 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
171 | if (data < node->data) return -1; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
172 | 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
|
173 | else return data - node->data; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
174 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
175 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
176 | CX_TEST(test_tree_search) { |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
177 | tree_node root = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
178 | tree_node a = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
179 | tree_node b = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
180 | tree_node c = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
181 | tree_node aa = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
182 | tree_node ab = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
183 | tree_node ba = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
184 | tree_node ca = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
185 | tree_node cb = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
186 | tree_node cc = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
187 | tree_node cba = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
188 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
189 | 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
|
190 | 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
|
191 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
192 | 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
|
193 | testnodes[i]->data = testdata[i]; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
194 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
195 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
196 | 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
|
197 | 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
|
198 | 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
|
199 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
200 | 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
|
201 | 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
|
202 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
203 | 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
|
204 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
205 | 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
|
206 | 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
|
207 | 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
|
208 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
209 | 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
|
210 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
211 | int s; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
212 | int r; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
213 | tree_node *n; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
214 | CX_TEST_DO { |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
215 | 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
|
216 | s = testdata[i]; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
217 | r = cx_tree_search(&root, &s, test_tree_search_function, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
218 | (void **) &n, tree_child_list); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
219 | CX_TEST_ASSERT(r == 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
220 | CX_TEST_ASSERT(n == testnodes[i]); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
221 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
222 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
223 | s = -5; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
224 | r = cx_tree_search(&root, &s, test_tree_search_function, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
225 | (void **) &n, tree_child_list); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
226 | CX_TEST_ASSERT(r < 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
227 | CX_TEST_ASSERT(n == NULL); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
228 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
229 | s = 26; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
230 | r = cx_tree_search(&root, &s, test_tree_search_function, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
231 | (void **) &n, tree_child_list); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
232 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
233 | CX_TEST_ASSERT(n == &ba); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
234 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
235 | s = 35; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
236 | r = cx_tree_search(&root, &s, test_tree_search_function, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
237 | (void **) &n, tree_child_list); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
238 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
239 | CX_TEST_ASSERT(n == &cb); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
240 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
241 | s = 38; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
242 | r = cx_tree_search(&root, &s, test_tree_search_function, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
243 | (void **) &n, tree_child_list); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
244 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
245 | CX_TEST_ASSERT(n == &cba); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
246 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
247 | s = 42; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
248 | r = cx_tree_search(&root, &s, test_tree_search_function, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
249 | (void **) &n, tree_child_list); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
250 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
251 | CX_TEST_ASSERT(n == &cc); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
252 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
253 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
254 | |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
255 | 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
|
256 | tree_node root; |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
257 | CX_TEST_DO { |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
258 | CxTreeIterator iter = cx_tree_iterator(&root, false, tree_child_list); |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
259 | 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
|
260 | 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
|
261 | 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
|
262 | CX_TEST_ASSERT(iter.node == &root); |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
263 | CX_TEST_ASSERT(!iter.base.mutating); |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
264 | CX_TEST_ASSERT(!iter.base.remove); |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
265 | 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
|
266 | 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
|
267 | 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
|
268 | 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
|
269 | 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
|
270 | 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
|
271 | cxTreeIteratorDispose(&iter); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
272 | CX_TEST_ASSERT(iter.stack == NULL); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
273 | } |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
274 | } |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
275 | |
838
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
276 | 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
|
277 | tree_node root = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
278 | tree_node a = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
279 | tree_node b = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
280 | tree_node c = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
281 | tree_node aa = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
282 | tree_node ab = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
283 | tree_node ba = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
284 | tree_node ca = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
285 | tree_node cb = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
286 | tree_node cc = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
287 | tree_node cba = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
288 | |
845 | 289 | tree_node* expected_order[] = { |
290 | &root, | |
291 | &c, &cc,&cb, &cba,&ca, | |
292 | &b, &ba, | |
293 | &a, &ab, &aa, | |
294 | }; | |
295 | tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong | |
296 | ||
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
297 | 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
|
298 | 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
|
299 | 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
|
300 | 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
|
301 | 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
|
302 | 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
|
303 | 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
|
304 | 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
|
305 | 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
|
306 | 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
|
307 | CX_TEST_DO { |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
308 | CxTreeIterator iter = cx_tree_iterator(&root, false, tree_child_list); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
309 | unsigned chk = 0; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
310 | cx_foreach(tree_node*, node, iter) { |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
311 | CX_TEST_ASSERT(node->data == 0); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
312 | node->data++; |
845 | 313 | actual_order[chk] = node; |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
314 | chk++; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
315 | CX_TEST_ASSERT(node == iter.node); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
316 | 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
|
317 | if (node == &root) { |
7c15fea5cbea
add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents:
836
diff
changeset
|
318 | 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
|
319 | } 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
|
320 | 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
|
321 | } else if (node == &cba) { |
7c15fea5cbea
add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents:
836
diff
changeset
|
322 | 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
|
323 | } else { |
7c15fea5cbea
add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents:
836
diff
changeset
|
324 | 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
|
325 | } |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
326 | } |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
327 | CX_TEST_ASSERT(iter.counter == 11); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
328 | CX_TEST_ASSERT(chk == 11); |
845 | 329 | for (unsigned i = 0 ; i < chk ; i++) { |
330 | CX_TEST_ASSERT(actual_order[i] == expected_order[i]); | |
331 | CX_TEST_ASSERT(actual_order[i]->data == 1); | |
332 | } | |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
333 | 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
|
334 | } |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
335 | } |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
336 | |
838
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
337 | 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
|
338 | tree_node root = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
339 | tree_node a = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
340 | tree_node b = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
341 | tree_node c = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
342 | tree_node aa = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
343 | tree_node ab = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
344 | tree_node ba = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
345 | tree_node ca = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
346 | tree_node cb = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
347 | tree_node cc = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
348 | tree_node cba = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
349 | |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
350 | 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
|
351 | 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
|
352 | 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
|
353 | 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
|
354 | 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
|
355 | 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
|
356 | 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
|
357 | 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
|
358 | 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
|
359 | 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
|
360 | CX_TEST_DO { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
361 | CxTreeIterator iter = cx_tree_iterator(&root, true, tree_child_list); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
362 | unsigned chk = 0; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
363 | cx_foreach(tree_node*, node, iter) { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
364 | 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
|
365 | node->data++; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
366 | chk++; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
367 | CX_TEST_ASSERT(node == iter.node); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
368 | if (node == &root) { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
369 | CX_TEST_ASSERT(iter.depth == 1); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
370 | } 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
|
371 | CX_TEST_ASSERT(iter.depth == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
372 | } else if (node == &cba) { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
373 | CX_TEST_ASSERT(iter.depth == 4); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
374 | } else { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
375 | CX_TEST_ASSERT(iter.depth == 3); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
376 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
377 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
378 | CX_TEST_ASSERT(iter.counter == 11); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
379 | CX_TEST_ASSERT(chk == 22); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
380 | CX_TEST_ASSERT(iter.stack == NULL); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
381 | CX_TEST_ASSERT(root.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
382 | CX_TEST_ASSERT(a.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
383 | CX_TEST_ASSERT(b.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
384 | CX_TEST_ASSERT(c.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
385 | CX_TEST_ASSERT(aa.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
386 | CX_TEST_ASSERT(ab.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
387 | CX_TEST_ASSERT(ba.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
388 | CX_TEST_ASSERT(ca.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
389 | CX_TEST_ASSERT(cb.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
390 | CX_TEST_ASSERT(cc.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
391 | CX_TEST_ASSERT(cba.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
392 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
393 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
394 | |
839
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
395 | typedef struct test_xml_node { |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
396 | struct test_xml_node *parent; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
397 | struct test_xml_node *next; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
398 | struct test_xml_node *prev; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
399 | struct test_xml_node *children; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
400 | char const* name; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
401 | } test_xml_node; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
402 | |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
403 | 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
|
404 | test_xml_node project = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
405 | test_xml_node config = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
406 | test_xml_node var1 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
407 | test_xml_node var2 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
408 | test_xml_node var3 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
409 | test_xml_node dependency1 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
410 | test_xml_node dependency1make = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
411 | test_xml_node dependency2 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
412 | test_xml_node dependency2lang = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
413 | test_xml_node dependency2make = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
414 | test_xml_node target = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
415 | 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
|
416 | 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
|
417 | 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
|
418 | |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
419 | project.name = "project"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
420 | config.name = "config"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
421 | var1.name = "var"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
422 | var2.name = "var"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
423 | var3.name = "var"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
424 | dependency1.name = "dependency"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
425 | dependency1make.name = "make"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
426 | dependency2.name = "dependency"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
427 | dependency2lang.name = "lang"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
428 | dependency2make.name = "make"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
429 | target.name = "target"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
430 | target_feature.name = "feature"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
431 | target_dependencies.name = "dependencies"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
432 | target_feature_dependencies.name = "dependencies"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
433 | |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
434 | cx_tree_link(&project, &target, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
435 | cx_tree_link(&project, &dependency2, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
436 | cx_tree_link(&project, &dependency1, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
437 | cx_tree_link(&project, &config, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
438 | cx_tree_link(&config, &var3, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
439 | cx_tree_link(&config, &var2, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
440 | cx_tree_link(&config, &var1, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
441 | cx_tree_link(&dependency1, &dependency1make, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
442 | cx_tree_link(&dependency2, &dependency2make, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
443 | cx_tree_link(&dependency2, &dependency2lang, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
444 | 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
|
445 | cx_tree_link(&target, &target_feature, tree_node_layout); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
446 | 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
|
447 | |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
448 | char const *expected = |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
449 | "<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
|
450 | "<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
|
451 | "<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
|
452 | char *actual = malloc(512); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
453 | CX_TEST_DO { |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
454 | CxTreeIterator iter = cx_tree_iterator(&project, true, tree_child_list); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
455 | size_t i = 0; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
456 | 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
|
457 | 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
|
458 | actual[i++] = '<'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
459 | if (iter.exiting) { |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
460 | actual[i++] = '/'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
461 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
462 | 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
|
463 | i += len; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
464 | actual[i++] = '>'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
465 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
466 | actual[i] = '\0'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
467 | 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
|
468 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
469 | free(actual); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
470 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
471 | |
840
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
472 | 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
|
473 | CxTestingAllocator talloc; |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
474 | cx_testing_allocator_init(&talloc); |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
475 | CxAllocator *alloc = &talloc.base; |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
476 | CX_TEST_DO { |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
477 | 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
|
478 | 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
|
479 | 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
|
480 | 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
|
481 | 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
|
482 | 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
|
483 | 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
|
484 | 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
|
485 | 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
|
486 | 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
|
487 | 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
|
488 | |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
489 | 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
|
490 | 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
|
491 | 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
|
492 | 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
|
493 | 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
|
494 | 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
|
495 | 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
|
496 | 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
|
497 | 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
|
498 | 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
|
499 | |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
500 | CxTreeIterator iter = cx_tree_iterator(root, true, tree_child_list); |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
501 | 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
|
502 | if (iter.exiting) { |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
503 | cxFree(alloc,node); |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
504 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
505 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
506 | |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
507 | 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
|
508 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
509 | cx_testing_allocator_destroy(&talloc); |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
510 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
511 | |
845 | 512 | CX_TEST(test_tree_visitor) { |
513 | tree_node root = {0}; | |
514 | tree_node a = {0}; | |
515 | tree_node b = {0}; | |
516 | tree_node c = {0}; | |
517 | tree_node aa = {0}; | |
518 | tree_node ab = {0}; | |
519 | tree_node ba = {0}; | |
520 | tree_node ca = {0}; | |
521 | tree_node cb = {0}; | |
522 | tree_node cc = {0}; | |
523 | tree_node cba = {0}; | |
524 | ||
525 | tree_node* expected_order[] = { | |
526 | &root, | |
527 | &c, &b, &a, | |
528 | &cc, &cb, &ca, &ba, &ab, &aa, | |
529 | &cba | |
530 | }; | |
531 | tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong | |
532 | ||
533 | cx_tree_link(&root, &a, tree_node_layout); | |
534 | cx_tree_link(&root, &b, tree_node_layout); | |
535 | cx_tree_link(&root, &c, tree_node_layout); | |
536 | cx_tree_link(&a, &aa, tree_node_layout); | |
537 | cx_tree_link(&a, &ab, tree_node_layout); | |
538 | cx_tree_link(&b, &ba, tree_node_layout); | |
539 | cx_tree_link(&c, &ca, tree_node_layout); | |
540 | cx_tree_link(&c, &cb, tree_node_layout); | |
541 | cx_tree_link(&c, &cc, tree_node_layout); | |
542 | cx_tree_link(&cb, &cba, tree_node_layout); | |
543 | CX_TEST_DO { | |
544 | CxTreeVisitor iter = cx_tree_visitor(&root, tree_child_list); | |
545 | unsigned chk = 0; | |
546 | cx_foreach(tree_node*, node, iter) { | |
547 | CX_TEST_ASSERT(node->data == 0); | |
548 | node->data++; | |
549 | actual_order[chk] = node; | |
550 | chk++; | |
551 | CX_TEST_ASSERT(node == iter.node); | |
552 | if (node == &root) { | |
553 | CX_TEST_ASSERT(iter.depth == 1); | |
554 | } else if (node == &a || node == &b || node == &c) { | |
555 | CX_TEST_ASSERT(iter.depth == 2); | |
556 | } else if (node == &cba) { | |
557 | CX_TEST_ASSERT(iter.depth == 4); | |
558 | } else { | |
559 | CX_TEST_ASSERT(iter.depth == 3); | |
560 | } | |
561 | } | |
562 | CX_TEST_ASSERT(iter.counter == 11); | |
563 | CX_TEST_ASSERT(chk == 11); | |
564 | for (unsigned i = 0 ; i < chk ; i++) { | |
565 | CX_TEST_ASSERT(actual_order[i] == expected_order[i]); | |
566 | CX_TEST_ASSERT(actual_order[i]->data == 1); | |
567 | } | |
568 | CX_TEST_ASSERT(iter.queue_next == NULL); | |
569 | CX_TEST_ASSERT(iter.queue_last == NULL); | |
570 | } | |
571 | } | |
572 | ||
573 | CX_TEST(test_tree_visitor_no_children) { | |
574 | tree_node root = {0}; | |
575 | ||
576 | CX_TEST_DO { | |
577 | CxTreeVisitor iter = cx_tree_visitor(&root, tree_child_list); | |
578 | unsigned chk = 0; | |
579 | cx_foreach(tree_node*, node, iter) { | |
580 | CX_TEST_ASSERT(node == iter.node); | |
581 | chk++; | |
582 | } | |
583 | CX_TEST_ASSERT(iter.counter == 1); | |
584 | CX_TEST_ASSERT(chk == 1); | |
585 | CX_TEST_ASSERT(iter.queue_next == NULL); | |
586 | CX_TEST_ASSERT(iter.queue_last == NULL); | |
587 | } | |
588 | } | |
589 | ||
590 | CX_TEST(test_tree_visitor_no_branching) { | |
591 | tree_node root = {0}; | |
592 | tree_node a = {0}; | |
593 | tree_node b = {0}; | |
594 | tree_node c = {0}; | |
595 | ||
596 | tree_node* expected_order[] = { | |
597 | &root, &a, &b, &c | |
598 | }; | |
599 | tree_node* actual_order[4]; | |
600 | ||
601 | cx_tree_link(&root, &a, tree_node_layout); | |
602 | cx_tree_link(&a, &b, tree_node_layout); | |
603 | cx_tree_link(&b, &c, tree_node_layout); | |
604 | ||
605 | CX_TEST_DO { | |
606 | CxTreeVisitor iter = cx_tree_visitor(&root, tree_child_list); | |
607 | unsigned chk = 0; | |
608 | cx_foreach(tree_node*, node, iter) { | |
609 | CX_TEST_ASSERT(node == iter.node); | |
610 | CX_TEST_ASSERT(node->data == 0); | |
611 | node->data++; | |
612 | actual_order[chk] = node; | |
613 | chk++; | |
614 | } | |
615 | CX_TEST_ASSERT(iter.counter == 4); | |
616 | CX_TEST_ASSERT(chk == 4); | |
617 | CX_TEST_ASSERT(iter.queue_next == NULL); | |
618 | CX_TEST_ASSERT(iter.queue_last == NULL); | |
619 | for (unsigned i = 0 ; i < chk ; i++) { | |
620 | CX_TEST_ASSERT(actual_order[i] == expected_order[i]); | |
621 | CX_TEST_ASSERT(actual_order[i]->data == 1); | |
622 | } | |
623 | } | |
624 | } | |
625 | ||
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
626 | 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
|
627 | 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
|
628 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
629 | 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
|
630 | 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
|
631 | 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
|
632 | cx_test_register(suite, test_tree_unlink); |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
633 | 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
|
634 | 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
|
635 | 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
|
636 | 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
|
637 | 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
|
638 | cx_test_register(suite, test_tree_iterator_free_nodes); |
845 | 639 | cx_test_register(suite, test_tree_visitor); |
640 | cx_test_register(suite, test_tree_visitor_no_children); | |
641 | cx_test_register(suite, test_tree_visitor_no_branching); | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
642 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
643 | return suite; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
644 | } |