tests/test_tree.c

Sat, 19 Oct 2024 13:08:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 19 Oct 2024 13:08:06 +0200
changeset 930
6540096c17b7
parent 918
ec1f2015ec79
child 931
be71809e69d1
permissions
-rw-r--r--

add max depth for tree search - closes #459

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 {
895
ea1ac0e8225c provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents: 893
diff changeset
44 CX_TREE_NODE_BASE(struct tree_node2);
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
45 int data;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
46 } tree_node2;
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
47
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
48 typedef struct tree_node_file {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
49 struct tree_node_file *parent;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
50 struct tree_node_file *next;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
51 struct tree_node_file *prev;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
52 struct tree_node_file *children;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
53 struct tree_node_file *last_child;
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
54 const char *path;
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
55 } tree_node_file;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
56
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
57 static void *tree_node_file_create(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
58 const void *dptr,
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
59 void *allocator) {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
60 if (allocator == NULL) allocator = cxDefaultAllocator;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
61
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
62 tree_node_file *node = cxMalloc(allocator, sizeof(tree_node_file));
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
63 node->path = dptr;
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
64
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
65 // intentionally write garbage into the pointers, it's part of the test
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
66 node->parent = (void *) 0xf00ba1;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
67 node->next = (void *) 0xf00ba2;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
68 node->prev = (void *) 0xf00ba3;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
69 node->children = (void *) 0xf00ba4;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
70 node->last_child = (void *) 0xf00ba5;
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
71
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
72 return node;
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
73 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
74
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
75 static void *tree_node_file_create_hl(
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
76 const void *dptr,
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
77 void *tree) {
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
78 return tree_node_file_create(dptr, (void*)((CxTree*)tree)->allocator);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
79 }
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
80
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
81 static int tree_node_file_search(const void *l, const void *r) {
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
82 const tree_node_file *left = l;
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
83 const tree_node_file *right = r;
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
84 size_t len1 = strlen(left->path);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
85 size_t len2 = strlen(right->path);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
86 if (len1 <= len2) {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
87 if (memcmp(left->path, right->path, len1) == 0) {
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
88 return (int) (len2 - len1);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
89 } else {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
90 return -1;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
91 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
92 } else {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
93 return -1;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
94 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
95 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
96
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
97 static int tree_node_file_search_data(const void *l, const void *d) {
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
98 tree_node_file r;
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
99 r.path = d;
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
100 return tree_node_file_search(l, &r);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
101 }
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
102
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 #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
104 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
105 offsetof(tree_node, prev), offsetof(tree_node, next)
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
106 #define tree_node_full_layout(structname) \
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
107 offsetof(structname, parent), offsetof(structname, children),\
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
108 offsetof(structname, last_child), \
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
109 offsetof(structname, prev), offsetof(structname, next)
895
ea1ac0e8225c provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents: 893
diff changeset
110 #define tree_node2_layout cx_tree_node_base_layout
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
111 #define tree_node_file_layout tree_node_full_layout(tree_node_file)
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
113 #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
114
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 CX_TEST(test_tree_link_new_child) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 tree_node child = {0};
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(&parent, &child, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 CX_TEST_ASSERT(parent.parent == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 CX_TEST_ASSERT(parent.children == &child);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 CX_TEST_ASSERT(child.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 CX_TEST_ASSERT(child.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 CX_TEST_ASSERT(child.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 CX_TEST_ASSERT(child.children == NULL);
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
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 CX_TEST(test_tree_link_add_child) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 tree_node child1 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 tree_node child2 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 tree_node child3 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 CX_TEST_DO {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 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
140 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
141 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
142 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 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
145 CX_TEST_ASSERT(parent.children == &child1);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 CX_TEST_ASSERT(child1.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 CX_TEST_ASSERT(child2.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 CX_TEST_ASSERT(child3.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 CX_TEST_ASSERT(child1.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 CX_TEST_ASSERT(child2.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 CX_TEST_ASSERT(child3.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
154 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
155 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
156 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
157 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
158 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
159 CX_TEST_ASSERT(child3.next == NULL);
816
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 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 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
164 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 tree_node child1 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 tree_node child2 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 tree_node child3 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 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
169 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
170 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
171
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 CX_TEST_DO {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 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
174
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 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
178 CX_TEST_ASSERT(parent.children == &child1);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 CX_TEST_ASSERT(child1.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 CX_TEST_ASSERT(child2.parent == &child3);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 CX_TEST_ASSERT(child3.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 CX_TEST_ASSERT(child1.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 CX_TEST_ASSERT(child2.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 CX_TEST_ASSERT(child3.children == &child2);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
187 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
188 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
189 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
190 CX_TEST_ASSERT(child3.next == NULL);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 CX_TEST_ASSERT(child2.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 CX_TEST_ASSERT(child2.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 CX_TEST(test_tree_unlink) {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 tree_node parent = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 tree_node child1 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 tree_node child2 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 tree_node child3 = {0};
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 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
203 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
204 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
205
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 CX_TEST_DO {
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 cx_tree_unlink(&child3, tree_node_layout);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 CX_TEST_ASSERT(parent.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 CX_TEST_ASSERT(parent.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 CX_TEST_ASSERT(parent.parent == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 CX_TEST_ASSERT(parent.children == &child1);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 CX_TEST_ASSERT(child1.parent == &parent);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 CX_TEST_ASSERT(child1.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 CX_TEST_ASSERT(child1.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 CX_TEST_ASSERT(child1.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 // child 3 is unlinked
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 CX_TEST_ASSERT(child3.parent == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 CX_TEST_ASSERT(child3.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 CX_TEST_ASSERT(child3.next == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 // 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
225 CX_TEST_ASSERT(child3.children == &child2);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 CX_TEST_ASSERT(child2.parent == &child3);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 CX_TEST_ASSERT(child2.children == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 CX_TEST_ASSERT(child2.prev == NULL);
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 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
230
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
231 // 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
232 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
233 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
234 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
235 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
236 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
237 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
238 }
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 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
242 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
243 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
244
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
245 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
246 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
258 }
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(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
261 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
262 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
263 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
264 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
265
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_DO {
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
267 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
268 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
269 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
270 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
271 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
272 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
273 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
274 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
275
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(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
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284 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
285
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
286 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
287 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
288 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
289 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
290 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
291 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
292 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
293 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
294
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(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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
304 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
305 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
306
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(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
308 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
309 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
310 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
311 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
312
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(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
314 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322
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(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
324 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
325 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
326 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
327
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
328 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
329 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
330 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
331 }
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
332
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 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
341
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
342 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
343 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
344
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
345 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
346 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
347 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
348 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
349 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
350
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
351 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
352 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
353 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
354 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
355 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
356
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
357 // 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
358 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
359 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
360 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
361
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
362 // 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
363 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
364 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
365 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
366 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
367 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
368 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
369 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
370
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
371 // 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
372 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
373 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
374 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
375 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
376 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
377 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
378 CX_TEST_ASSERT(child1.parent == NULL);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
379 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
380 }
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
382 static int test_tree_search_function(const void *n, const void *d) {
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
383 const tree_node *node = n;
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
384 int data = *((const int *)d);
826
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
385
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
386 if (data < node->data) return -1;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
387 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
388 else return data - node->data;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
389 }
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 CX_TEST(test_tree_search) {
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
392 tree_node root = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
393 tree_node a = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
394 tree_node b = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
395 tree_node c = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
396 tree_node aa = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
397 tree_node ab = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
398 tree_node ba = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
399 tree_node ca = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
400 tree_node cb = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
401 tree_node cc = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
402 tree_node cba = {0};
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
403
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
404 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
405 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
406
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
407 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
408 testnodes[i]->data = testdata[i];
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
409 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
410
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
411 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
412 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
413 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
414
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
415 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
416 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
417
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
418 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
419
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
420 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
421 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
422 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
423
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
424 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
425
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
426 int s;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
427 int r;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
428 tree_node *n;
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
429 CX_TEST_DO {
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
430 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
431 s = testdata[i];
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
432 r = cx_tree_search_data(&root, 0, &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
433 (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
434 CX_TEST_ASSERT(r == 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
435 CX_TEST_ASSERT(n == testnodes[i]);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
436 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
437
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
438 s = -5;
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
439 r = cx_tree_search_data(&root, 0, &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
440 (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
441 CX_TEST_ASSERT(r < 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
442 CX_TEST_ASSERT(n == NULL);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
443
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
444 s = 26;
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
445 r = cx_tree_search_data(&root, 0, &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
446 (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
447 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
448 CX_TEST_ASSERT(n == &ba);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
449
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
450 s = 35;
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
451 r = cx_tree_search_data(&root, 0, &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
452 (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
453 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
454 CX_TEST_ASSERT(n == &cb);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
455
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
456 s = 38;
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
457 r = cx_tree_search_data(&root, 0, &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
458 (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
459 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
460 CX_TEST_ASSERT(n == &cba);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
461
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
462 s = 42;
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
463 r = cx_tree_search_data(&root, 0, &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
464 (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
465 CX_TEST_ASSERT(r > 0);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
466 CX_TEST_ASSERT(n == &cc);
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
467 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
468 }
21840975d541 add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents: 816
diff changeset
469
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
470 CX_TEST(test_tree_search_with_max_depth) {
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
471 tree_node_file root = {0};
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
472 root.path = "/";
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
473 tree_node_file usr = {0};
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
474 usr.path = "/usr/";
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
475 cx_tree_link(&root, &usr, tree_node_file_layout);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
476 tree_node_file home = {0};
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
477 home.path = "/home/";
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
478 cx_tree_link(&root, &home, tree_node_file_layout);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
479 tree_node_file doe = {0};
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
480 doe.path = "/home/doe/";
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
481 cx_tree_link(&home, &doe, tree_node_file_layout);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
482 tree_node_file lib = {0};
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
483 lib.path = "/usr/lib/";
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
484 cx_tree_link(&usr, &lib, tree_node_file_layout);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
485 tree_node_file modules = {0};
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
486 modules.path = "/usr/lib/modules/";
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
487 cx_tree_link(&lib, &modules, tree_node_file_layout);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
488
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
489 CX_TEST_DO {
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
490 int result;
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
491 void *found;
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
492
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
493 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
494 &root, 1, "/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
495 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
496 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
497 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
498 CX_TEST_ASSERTM(result == 0, "root not found");
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
499 CX_TEST_ASSERT(found == &root);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
500
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
501 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
502 &root, 1, "/usr/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
503 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
504 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
505 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
506 CX_TEST_ASSERT(result > 0);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
507 CX_TEST_ASSERT(found == &root);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
508
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
509 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
510 &root, 2, "/usr/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
511 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
512 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
513 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
514 CX_TEST_ASSERT(result == 0);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
515 CX_TEST_ASSERT(found == &usr);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
516
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
517 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
518 &root, 2, "/usr/lib/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
519 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
520 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
521 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
522 CX_TEST_ASSERT(result > 0);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
523 CX_TEST_ASSERT(found == &usr);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
524
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
525 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
526 &root, 3, "/usr/lib/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
527 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
528 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
529 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
530 CX_TEST_ASSERTM(result == 0, "lib not found");
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
531 CX_TEST_ASSERT(found == &lib);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
532
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
533 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
534 &root, 1, "/home/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
535 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
536 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
537 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
538 CX_TEST_ASSERT(result > 0);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
539 CX_TEST_ASSERT(found == &root);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
540
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
541 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
542 &root, 2, "/home/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
543 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
544 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
545 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
546 CX_TEST_ASSERTM(result == 0, "home not found");
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
547 CX_TEST_ASSERT(found == &home);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
548
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
549 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
550 &root, 2, "/home/doe/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
551 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
552 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
553 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
554 CX_TEST_ASSERT(result > 0);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
555 CX_TEST_ASSERT(found == &home);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
556
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
557 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
558 &root, 3, "/home/doe/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
559 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
560 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
561 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
562 CX_TEST_ASSERTM(result == 0, "doe not found");
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
563 CX_TEST_ASSERT(found == &doe);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
564
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
565 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
566 &root, 3, "/usr/lib/modules/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
567 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
568 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
569 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
570 CX_TEST_ASSERT(result > 0);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
571 CX_TEST_ASSERT(found == &lib);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
572
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
573 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
574 &root, 4, "/usr/lib/modules/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
575 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
576 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
577 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
578 CX_TEST_ASSERTM(result == 0, "modules not found (start=root)");
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
579 CX_TEST_ASSERT(found == &modules);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
580
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
581 result = cx_tree_search_data(
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
582 &usr, 3, "/usr/lib/modules/",
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
583 tree_node_file_search_data, &found,
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
584 tree_children(tree_node_file)
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
585 );
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
586 CX_TEST_ASSERTM(result == 0, "modules not found (start=usr)");
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
587 CX_TEST_ASSERT(found == &modules);
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
588 }
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
589 }
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
590
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
591 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
592 tree_node root;
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
593 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
594 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
595 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
596 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
597 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
598 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
599 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
600 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
601 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
602 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
603 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
604 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
605 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
606 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
607 cxTreeIteratorDispose(&iter);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
608 CX_TEST_ASSERT(iter.stack == NULL);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
609 }
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
610 }
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
611
915
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
612 CX_TEST(test_tree_iterator_create_for_empty_tree) {
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
613 CX_TEST_DO {
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
614 CxTreeIterator iter = cx_tree_iterator(NULL, false, tree_children(tree_node));
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
615 CX_TEST_ASSERT(!iter.visit_on_exit);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
616 CX_TEST_ASSERT(!iter.exiting);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
617 CX_TEST_ASSERT(iter.counter == 0);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
618 CX_TEST_ASSERT(iter.node == NULL);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
619 CX_TEST_ASSERT(!iter.base.mutating);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
620 CX_TEST_ASSERT(!iter.base.remove);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
621 CX_TEST_ASSERT(iter.stack == NULL);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
622 CX_TEST_ASSERT(iter.stack_capacity == 0);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
623 CX_TEST_ASSERT(iter.stack_size == 0);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
624 CX_TEST_ASSERT(iter.depth == 0);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
625 CX_TEST_ASSERT(iter.loc_next == offsetof(tree_node, next));
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
626 CX_TEST_ASSERT(iter.loc_children == offsetof(tree_node, children));
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
627 CX_TEST_ASSERT(!cxIteratorValid(iter));
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
628 // disposing this iterator should also be harmless
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
629 cxTreeIteratorDispose(&iter);
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
630 }
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
631 }
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
632
838
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
633 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
634 tree_node root = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
635 tree_node a = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
636 tree_node b = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
637 tree_node c = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
638 tree_node aa = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
639 tree_node ab = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
640 tree_node ba = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
641 tree_node ca = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
642 tree_node cb = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
643 tree_node cc = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
644 tree_node cba = {0};
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
645
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
646 tree_node* expected_order[] = {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
647 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
648 &a, &aa, &ab,
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
649 &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
650 &c, &ca, &cb, &cba, &cc,
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
651 };
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
652 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
653
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
654 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
655 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
656 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
657 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
658 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
659 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
660 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
661 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
662 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
663 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
664 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
665 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
666 unsigned chk = 0;
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
667 cx_foreach(tree_node*, node, iter) {
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
668 CX_TEST_ASSERT(node->data == 0);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
669 node->data++;
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
670 actual_order[chk] = node;
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
671 chk++;
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
672 CX_TEST_ASSERT(node == iter.node);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
673 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
674 if (node == &root) {
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
675 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
676 } 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
677 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
678 } else if (node == &cba) {
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
679 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
680 } else {
7c15fea5cbea add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents: 836
diff changeset
681 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
682 }
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
683 }
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
684 CX_TEST_ASSERT(iter.counter == 11);
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
685 CX_TEST_ASSERT(chk == 11);
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
686 for (unsigned i = 0 ; i < chk ; i++) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
687 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
688 CX_TEST_ASSERT(actual_order[i]->data == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
689 }
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
690 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
691 }
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
692 }
5c926801f052 vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents: 826
diff changeset
693
838
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
694 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
695 tree_node root = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
696 tree_node a = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
697 tree_node b = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
698 tree_node c = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
699 tree_node aa = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
700 tree_node ab = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
701 tree_node ba = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
702 tree_node ca = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
703 tree_node cb = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
704 tree_node cc = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
705 tree_node cba = {0};
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
706
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
707 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
708 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
709 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
710 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
711 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
712 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
713 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
714 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
715 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
716 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
717 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
718 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
719 unsigned chk = 0;
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
720 cx_foreach(tree_node*, node, iter) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
721 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
722 node->data++;
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
723 chk++;
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
724 CX_TEST_ASSERT(node == iter.node);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
725 if (node == &root) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
726 CX_TEST_ASSERT(iter.depth == 1);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
727 } 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
728 CX_TEST_ASSERT(iter.depth == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
729 } else if (node == &cba) {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
730 CX_TEST_ASSERT(iter.depth == 4);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
731 } else {
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
732 CX_TEST_ASSERT(iter.depth == 3);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
733 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
734 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
735 CX_TEST_ASSERT(iter.counter == 11);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
736 CX_TEST_ASSERT(chk == 22);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
737 CX_TEST_ASSERT(iter.stack == NULL);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
738 CX_TEST_ASSERT(root.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
739 CX_TEST_ASSERT(a.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
740 CX_TEST_ASSERT(b.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
741 CX_TEST_ASSERT(c.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
742 CX_TEST_ASSERT(aa.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
743 CX_TEST_ASSERT(ab.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
744 CX_TEST_ASSERT(ba.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
745 CX_TEST_ASSERT(ca.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
746 CX_TEST_ASSERT(cb.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
747 CX_TEST_ASSERT(cc.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
748 CX_TEST_ASSERT(cba.data == 2);
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
749 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
750 }
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
751
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
752 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
753 struct tree_node base;
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
754 const char *name;
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
755 } test_xml_node;
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
756
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
757 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
758 test_xml_node project = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
759 test_xml_node config = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
760 test_xml_node var1 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
761 test_xml_node var2 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
762 test_xml_node var3 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
763 test_xml_node dependency1 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
764 test_xml_node dependency1make = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
765 test_xml_node dependency2 = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
766 test_xml_node dependency2lang = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
767 test_xml_node dependency2make = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
768 test_xml_node target = {0};
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
769 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
770 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
771 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
772
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
773 project.name = "project";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
774 config.name = "config";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
775 var1.name = "var";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
776 var2.name = "var";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
777 var3.name = "var";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
778 dependency1.name = "dependency";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
779 dependency1make.name = "make";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
780 dependency2.name = "dependency";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
781 dependency2lang.name = "lang";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
782 dependency2make.name = "make";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
783 target.name = "target";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
784 target_feature.name = "feature";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
785 target_dependencies.name = "dependencies";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
786 target_feature_dependencies.name = "dependencies";
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
787
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
788 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
789 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
790 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
791 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
792 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
793 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
794 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
795 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
796 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
797 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
798 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
799 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
800 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
801
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
802 const char *expected =
839
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
803 "<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
804 "<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
805 "<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
806 char *actual = malloc(512);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
807 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
808 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
809 size_t i = 0;
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
810 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
811 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
812 actual[i++] = '<';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
813 if (iter.exiting) {
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
814 actual[i++] = '/';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
815 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
816 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
817 i += len;
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
818 actual[i++] = '>';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
819 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
820 actual[i] = '\0';
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
821 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
822 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
823 free(actual);
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
824 }
62d3aecc5bb7 add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents: 838
diff changeset
825
840
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
826 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
827 CxTestingAllocator talloc;
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
828 cx_testing_allocator_init(&talloc);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
829 CxAllocator *alloc = &talloc.base;
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
830 CX_TEST_DO {
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
831 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
832 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
833 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
834 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
835 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
836 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
837 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
838 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
839 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
840 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
841 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
842
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
843 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
844 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
845 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
846 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
847 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
848 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
849 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
850 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
851 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
852 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
853
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
854 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
855 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
856 if (iter.exiting) {
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
857 cxFree(alloc,node);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
858 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
859 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
860
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
861 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
862 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
863 cx_testing_allocator_destroy(&talloc);
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
864 }
4f02995ce44e allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents: 839
diff changeset
865
847
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
866 CX_TEST(test_tree_visitor_create_and_dispose) {
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
867 tree_node root;
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
868 tree_node child;
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
869 cx_tree_link(&root, &child, tree_node_layout);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
870 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
871 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
872 CX_TEST_ASSERT(iter.counter == 1);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
873 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
874 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
875 CX_TEST_ASSERT(!iter.base.remove);
847
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
876 CX_TEST_ASSERT(iter.queue_next != NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
877 CX_TEST_ASSERT(iter.queue_last != NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
878 CX_TEST_ASSERT(iter.depth == 1);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
879 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
880 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
881 cxTreeVisitorDispose(&iter);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
882 CX_TEST_ASSERT(iter.queue_next == NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
883 CX_TEST_ASSERT(iter.queue_last == NULL);
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
884 }
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
885 }
a39e410a05e6 add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents: 845
diff changeset
886
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
887 CX_TEST(test_tree_visitor) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
888 tree_node root = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
889 tree_node a = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
890 tree_node b = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
891 tree_node c = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
892 tree_node aa = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
893 tree_node ab = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
894 tree_node ba = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
895 tree_node ca = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
896 tree_node cb = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
897 tree_node cc = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
898 tree_node cba = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
899
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
900 tree_node* expected_order[] = {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
901 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
902 &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
903 &aa, &ab, &ba, &ca, &cb, &cc,
845
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
904 &cba
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
905 };
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
906 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
907
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
908 cx_tree_link(&root, &a, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
909 cx_tree_link(&root, &b, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
910 cx_tree_link(&root, &c, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
911 cx_tree_link(&a, &aa, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
912 cx_tree_link(&a, &ab, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
913 cx_tree_link(&b, &ba, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
914 cx_tree_link(&c, &ca, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
915 cx_tree_link(&c, &cb, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
916 cx_tree_link(&c, &cc, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
917 cx_tree_link(&cb, &cba, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
918 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
919 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
920 unsigned chk = 0;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
921 cx_foreach(tree_node*, node, iter) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
922 CX_TEST_ASSERT(node->data == 0);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
923 node->data++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
924 actual_order[chk] = node;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
925 chk++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
926 CX_TEST_ASSERT(node == iter.node);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
927 if (node == &root) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
928 CX_TEST_ASSERT(iter.depth == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
929 } else if (node == &a || node == &b || node == &c) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
930 CX_TEST_ASSERT(iter.depth == 2);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
931 } else if (node == &cba) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
932 CX_TEST_ASSERT(iter.depth == 4);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
933 } else {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
934 CX_TEST_ASSERT(iter.depth == 3);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
935 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
936 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
937 CX_TEST_ASSERT(iter.counter == 11);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
938 CX_TEST_ASSERT(chk == 11);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
939 for (unsigned i = 0 ; i < chk ; i++) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
940 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
941 CX_TEST_ASSERT(actual_order[i]->data == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
942 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
943 CX_TEST_ASSERT(iter.queue_next == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
944 CX_TEST_ASSERT(iter.queue_last == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
945 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
946 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
947
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
948 CX_TEST(test_tree_visitor_no_children) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
949 tree_node root = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
950
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
951 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
952 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
953 unsigned chk = 0;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
954 cx_foreach(tree_node*, node, iter) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
955 CX_TEST_ASSERT(node == iter.node);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
956 chk++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
957 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
958 CX_TEST_ASSERT(iter.counter == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
959 CX_TEST_ASSERT(chk == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
960 CX_TEST_ASSERT(iter.queue_next == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
961 CX_TEST_ASSERT(iter.queue_last == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
962 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
963 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
964
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
965 CX_TEST(test_tree_visitor_no_branching) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
966 tree_node root = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
967 tree_node a = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
968 tree_node b = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
969 tree_node c = {0};
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
970
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
971 tree_node* expected_order[] = {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
972 &root, &a, &b, &c
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
973 };
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
974 tree_node* actual_order[4];
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
975
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
976 cx_tree_link(&root, &a, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
977 cx_tree_link(&a, &b, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
978 cx_tree_link(&b, &c, tree_node_layout);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
979
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
980 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
981 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
982 unsigned chk = 0;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
983 cx_foreach(tree_node*, node, iter) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
984 CX_TEST_ASSERT(node == iter.node);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
985 CX_TEST_ASSERT(node->data == 0);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
986 node->data++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
987 actual_order[chk] = node;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
988 chk++;
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
989 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
990 CX_TEST_ASSERT(iter.counter == 4);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
991 CX_TEST_ASSERT(chk == 4);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
992 CX_TEST_ASSERT(iter.queue_next == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
993 CX_TEST_ASSERT(iter.queue_last == NULL);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
994 for (unsigned i = 0 ; i < chk ; i++) {
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
995 CX_TEST_ASSERT(actual_order[i] == expected_order[i]);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
996 CX_TEST_ASSERT(actual_order[i]->data == 1);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
997 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
998 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
999 }
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
1000
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1001 CX_TEST(test_tree_visitor_continue) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1002 tree_node root = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1003 tree_node a = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1004 tree_node b = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1005 tree_node c = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1006 tree_node aa = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1007 tree_node ab = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1008 tree_node ba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1009 tree_node ca = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1010 tree_node cb = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1011 tree_node cc = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1012 tree_node cba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1013
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1014 tree_node* expected_order[] = {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1015 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
1016 &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
1017 &aa, &ab, &ba
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1018 };
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1019 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
1020
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1021 cx_tree_link(&root, &a, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1022 cx_tree_link(&root, &b, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1023 cx_tree_link(&root, &c, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1024 cx_tree_link(&a, &aa, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1025 cx_tree_link(&a, &ab, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1026 cx_tree_link(&b, &ba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1027 cx_tree_link(&c, &ca, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1028 cx_tree_link(&c, &cb, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1029 cx_tree_link(&c, &cc, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1030 cx_tree_link(&cb, &cba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1031 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
1032 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
1033 unsigned chk = 0;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1034 cx_foreach(tree_node*, node, iter) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1035 CX_TEST_ASSERT(node->data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1036 node->data++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1037 actual_order[chk] = node;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1038 chk++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1039 CX_TEST_ASSERT(node == iter.node);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1040 if (node == &root) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1041 CX_TEST_ASSERT(iter.depth == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1042 } else if (node == &a || node == &b || node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1043 CX_TEST_ASSERT(iter.depth == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1044 } else {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1045 CX_TEST_ASSERT(iter.depth == 3);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1046 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1047 if (node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1048 cxTreeVisitorContinue(iter);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1049 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1050 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1051 CX_TEST_ASSERT(iter.counter == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1052 CX_TEST_ASSERT(chk == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1053 for (unsigned i = 0 ; i < chk ; i++) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1054 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
1055 CX_TEST_ASSERT(actual_order[i]->data == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1056 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1057 CX_TEST_ASSERT(ca.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1058 CX_TEST_ASSERT(cb.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1059 CX_TEST_ASSERT(cc.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1060 CX_TEST_ASSERT(cba.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1061 CX_TEST_ASSERT(iter.queue_next == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1062 CX_TEST_ASSERT(iter.queue_last == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1063 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1064 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1065
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1066 CX_TEST(test_tree_iterator_continue) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1067 tree_node root = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1068 tree_node a = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1069 tree_node b = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1070 tree_node c = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1071 tree_node aa = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1072 tree_node ab = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1073 tree_node ba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1074 tree_node ca = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1075 tree_node cb = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1076 tree_node cc = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1077 tree_node cba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1078
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
1079 tree_node *expected_order[] = {
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1080 &root,
862
387414a7afd8 change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents: 854
diff changeset
1081 &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
1082 &b, &ba,
848
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1083 &c,
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1084 };
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1085 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
1086
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1087 cx_tree_link(&root, &a, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1088 cx_tree_link(&root, &b, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1089 cx_tree_link(&root, &c, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1090 cx_tree_link(&a, &aa, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1091 cx_tree_link(&a, &ab, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1092 cx_tree_link(&b, &ba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1093 cx_tree_link(&c, &ca, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1094 cx_tree_link(&c, &cb, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1095 cx_tree_link(&c, &cc, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1096 cx_tree_link(&cb, &cba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1097 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
1098 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
1099 unsigned chk = 0;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1100 cx_foreach(tree_node*, node, iter) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1101 CX_TEST_ASSERT(node->data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1102 node->data++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1103 actual_order[chk] = node;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1104 chk++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1105 CX_TEST_ASSERT(node == iter.node);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1106 CX_TEST_ASSERT(!iter.exiting);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1107 if (node == &root) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1108 CX_TEST_ASSERT(iter.depth == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1109 } else if (node == &a || node == &b || node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1110 CX_TEST_ASSERT(iter.depth == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1111 } else {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1112 CX_TEST_ASSERT(iter.depth == 3);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1113 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1114 if (node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1115 cxTreeIteratorContinue(iter);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1116 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1117 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1118 CX_TEST_ASSERT(iter.counter == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1119 CX_TEST_ASSERT(chk == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1120 for (unsigned i = 0 ; i < chk ; i++) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1121 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
1122 CX_TEST_ASSERT(actual_order[i]->data == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1123 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1124 CX_TEST_ASSERT(ca.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1125 CX_TEST_ASSERT(cb.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1126 CX_TEST_ASSERT(cc.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1127 CX_TEST_ASSERT(cba.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1128 CX_TEST_ASSERT(iter.stack == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1129 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1130 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1131
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1132 CX_TEST(test_tree_iterator_continue_with_exit) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1133 tree_node root = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1134 tree_node a = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1135 tree_node b = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1136 tree_node c = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1137 tree_node aa = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1138 tree_node ab = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1139 tree_node ba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1140 tree_node ca = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1141 tree_node cb = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1142 tree_node cc = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1143 tree_node cba = {0};
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1144
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1145 cx_tree_link(&root, &a, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1146 cx_tree_link(&root, &b, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1147 cx_tree_link(&root, &c, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1148 cx_tree_link(&a, &aa, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1149 cx_tree_link(&a, &ab, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1150 cx_tree_link(&b, &ba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1151 cx_tree_link(&c, &ca, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1152 cx_tree_link(&c, &cb, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1153 cx_tree_link(&c, &cc, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1154 cx_tree_link(&cb, &cba, tree_node_layout);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1155 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
1156 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
1157 unsigned chk = 0;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1158 cx_foreach(tree_node*, node, iter) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1159 CX_TEST_ASSERT(iter.exiting || node->data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1160 node->data++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1161 chk++;
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1162 CX_TEST_ASSERT(node == iter.node);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1163 if (node == &root) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1164 CX_TEST_ASSERT(iter.depth == 1);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1165 } else if (node == &a || node == &b || node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1166 CX_TEST_ASSERT(iter.depth == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1167 } else {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1168 CX_TEST_ASSERT(iter.depth == 3);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1169 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1170 if (node == &c) {
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1171 cxTreeIteratorContinue(iter);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1172 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1173 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1174 CX_TEST_ASSERT(iter.counter == 7);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1175 CX_TEST_ASSERT(chk == 14);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1176 CX_TEST_ASSERT(iter.stack == NULL);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1177 CX_TEST_ASSERT(root.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1178 CX_TEST_ASSERT(a.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1179 CX_TEST_ASSERT(b.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1180 CX_TEST_ASSERT(c.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1181 CX_TEST_ASSERT(aa.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1182 CX_TEST_ASSERT(ab.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1183 CX_TEST_ASSERT(ba.data == 2);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1184 CX_TEST_ASSERT(ca.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1185 CX_TEST_ASSERT(cb.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1186 CX_TEST_ASSERT(cc.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1187 CX_TEST_ASSERT(cba.data == 0);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1188 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1189 }
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
1190
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1191 CX_TEST(test_tree_add_one) {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1192 CxTestingAllocator talloc;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1193 cx_testing_allocator_init(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1194 CxAllocator *alloc = &talloc.base;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1195
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1196 tree_node_file root = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1197 root.path = "/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1198 tree_node_file usr = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1199 usr.path = "/usr/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1200 cx_tree_link(&root, &usr, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1201 tree_node_file home = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1202 home.path = "/home/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1203 cx_tree_link(&root, &home, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1204 tree_node_file lib = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1205 lib.path = "/usr/lib/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1206 cx_tree_link(&usr, &lib, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1207
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1208 CX_TEST_DO {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1209 tree_node_file *foo;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1210 int result;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1211 result = cx_tree_add(
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1212 "/home/foo/",
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1213 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1214 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1215 (void **) &foo, &root,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1216 tree_node_file_layout
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1217 );
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1218 CX_TEST_ASSERT(result == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1219 CX_TEST_ASSERT(foo != NULL);
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1220 const char *bar_path = "/home/foo/bar/";
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1221 void *failed;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1222 size_t added = cx_tree_add_array(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1223 bar_path, 1, sizeof(const char *),
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1224 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1225 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1226 &failed, &root,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1227 tree_node_file_layout
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1228 );
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1229 CX_TEST_ASSERT(added == 1);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1230 CX_TEST_ASSERT(failed == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1231 tree_node_file *bar = foo->children;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1232 CX_TEST_ASSERT(bar != NULL);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1233 CX_TEST_ASSERT(bar->parent == foo);
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1234 CX_TEST_ASSERT(bar->path == bar_path);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1235 CX_TEST_ASSERT(foo->parent == &home);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1236
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1237 tree_node_file *new_node;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1238 result = cx_tree_add(
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1239 "newroot",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1240 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1241 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1242 (void **) &new_node, &root,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1243 tree_node_file_layout
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1244 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1245 CX_TEST_ASSERT(0 != result);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1246 CX_TEST_ASSERT(NULL != new_node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1247 CX_TEST_ASSERT(new_node->children == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1248 CX_TEST_ASSERT(new_node->parent == NULL);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1249
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1250 CX_TEST_ASSERT(talloc.alloc_total == 3);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1251
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1252 cxFree(alloc, foo);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1253 cxFree(alloc, bar);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1254 cxFree(alloc, new_node);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1255
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1256 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1257 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1258 cx_testing_allocator_destroy(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1259 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1260
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1261 CX_TEST(test_tree_add_one_existing) {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1262 CxTestingAllocator talloc;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1263 cx_testing_allocator_init(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1264 CxAllocator *alloc = &talloc.base;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1265
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1266 tree_node_file root = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1267 root.path = "/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1268 tree_node_file usr = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1269 usr.path = "/usr/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1270 cx_tree_link(&root, &usr, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1271 tree_node_file home = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1272 home.path = "/home/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1273 cx_tree_link(&root, &home, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1274 tree_node_file lib = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1275 lib.path = "/usr/lib/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1276 cx_tree_link(&usr, &lib, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1277
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1278 CX_TEST_DO {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1279 tree_node_file *node;
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1280 int result = cx_tree_add(
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1281 "/usr/lib/",
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1282 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1283 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1284 (void **) &node, &root,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1285 tree_node_file_layout
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1286 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1287 CX_TEST_ASSERT(result == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1288 CX_TEST_ASSERT(node != &lib);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1289 CX_TEST_ASSERT(node->prev == &lib);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1290 CX_TEST_ASSERT(lib.next == node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1291 CX_TEST_ASSERT(node->parent == &usr);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1292 CX_TEST_ASSERT(talloc.alloc_total == 1);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1293 cxFree(alloc, node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1294 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1295 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1296 cx_testing_allocator_destroy(&talloc);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1297 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1298
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1299 CX_TEST(test_tree_add_one_no_match) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1300 tree_node_file root = {0};
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1301 root.path = "/mnt/";
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1302
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1303 CX_TEST_DO {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1304 tree_node_file *node = NULL;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1305 int result = cx_tree_add(
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1306 "/usr/lib/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1307 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1308 tree_node_file_create, NULL,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1309 (void **) &node, &root,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1310 tree_node_file_layout
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1311 );
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1312 CX_TEST_ASSERT(result != 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1313 CX_TEST_ASSERT(node != NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1314 CX_TEST_ASSERT(node->parent == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1315 CX_TEST_ASSERT(node->children == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1316 free(node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1317 node = NULL;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1318 size_t added = cx_tree_add_array(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1319 "/", 1, sizeof(const char *),
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1320 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1321 tree_node_file_create, NULL,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1322 (void **) &node, &root,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1323 tree_node_file_layout
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1324 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1325 CX_TEST_ASSERT(added == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1326 CX_TEST_ASSERT(node != NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1327 CX_TEST_ASSERT(node->parent == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1328 CX_TEST_ASSERT(node->children == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1329 free(node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1330 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1331 }
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1332
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1333 CX_TEST(test_tree_add_duplicate_root) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1334 tree_node_file root = {0};
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1335 root.path = "/";
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1336 CX_TEST_DO {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1337 tree_node_file *node;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1338 int result = cx_tree_add(
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1339 "/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1340 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1341 tree_node_file_create, NULL,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1342 (void **) &node, &root,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1343 tree_node_file_layout
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1344 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1345 CX_TEST_ASSERT(result == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1346 CX_TEST_ASSERT(root.children == node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1347 CX_TEST_ASSERT(node->parent == &root);
911
db829e54539e fix missing free() in test_tree_add_duplicate_root
Mike Becker <universe@uap-core.de>
parents: 909
diff changeset
1348 free(node);
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1349 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1350 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1351
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1352 CX_TEST(test_tree_add_zero) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1353 CxTestingAllocator talloc;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1354 cx_testing_allocator_init(&talloc);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1355 CxAllocator *alloc = &talloc.base;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1356
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1357 tree_node_file root = {0};
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1358 root.path = "/";
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1359 CX_TEST_DO {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1360 void *failed;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1361
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1362 size_t processed = cx_tree_add_array(
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1363 (void *) 0xc0ffee, 0, sizeof(void *),
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1364 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1365 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1366 &failed, &root, tree_node_file_layout
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1367 );
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1368 CX_TEST_ASSERT(failed == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1369 CX_TEST_ASSERT(processed == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1370 CX_TEST_ASSERT(talloc.alloc_total == 0);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1371
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1372 CxIterator iter = cxIterator(NULL, sizeof(void *), 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1373 processed = cx_tree_add_iter(
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1374 cxIteratorRef(iter),
893
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1375 10, // deliberately specify more than the iter has
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1376 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1377 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1378 &failed, &root, tree_node_file_layout
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1379 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1380 CX_TEST_ASSERT(processed == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1381 CX_TEST_ASSERT(failed == NULL);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1382 CX_TEST_ASSERT(talloc.alloc_total == 0);
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1383
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1384 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1385 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1386 cx_testing_allocator_destroy(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1387 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1388
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1389 CX_TEST(test_tree_add_many) {
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1390 // adds many elements to an existing tree
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1391
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1392 CxTestingAllocator talloc;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1393 cx_testing_allocator_init(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1394 CxAllocator *alloc = &talloc.base;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1395
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1396 tree_node_file root = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1397 root.path = "/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1398 tree_node_file usr = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1399 usr.path = "/usr/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1400 cx_tree_link(&root, &usr, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1401 tree_node_file home = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1402 home.path = "/home/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1403 cx_tree_link(&root, &home, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1404 tree_node_file lib = {0};
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1405 lib.path = "/usr/lib/";
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1406 cx_tree_link(&usr, &lib, tree_node_file_layout);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1407
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1408 CX_TEST_DO {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1409 void *failed;
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1410
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1411 const char *paths[] = {
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1412 "/home/foo/",
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1413 "/home/foo/bar",
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1414 "/usr/lib64/",
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1415 "/usr/lib/foo.so"
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1416 };
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1417
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1418 size_t processed = cx_tree_add_array(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1419 paths, 4, sizeof(const char *),
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1420 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1421 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1422 &failed, &root, tree_node_file_layout
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1423 );
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1424
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1425 CX_TEST_ASSERT(failed == NULL);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1426 CX_TEST_ASSERT(processed == 4);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1427 CX_TEST_ASSERT(talloc.alloc_total == 4);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1428
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1429 CX_TEST_ASSERT(home.children == home.last_child);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1430 tree_node_file *foo = home.children;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1431 CX_TEST_ASSERT(foo != NULL && foo->path == paths[0]);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1432 CX_TEST_ASSERT(foo->children == foo->last_child);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1433 tree_node_file *bar = foo->children;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1434 CX_TEST_ASSERT(bar != NULL && bar->path == paths[1]);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1435 CX_TEST_ASSERT(usr.children != usr.last_child);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1436 tree_node_file *lib64 = usr.last_child;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1437 CX_TEST_ASSERT(lib64 != NULL);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1438 CX_TEST_ASSERT(lib64->path == paths[2]);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1439 CX_TEST_ASSERT(lib64->prev == &lib);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1440 CX_TEST_ASSERT(lib64->parent == &usr);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1441 CX_TEST_ASSERT(lib.children != NULL);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1442 tree_node_file *libfoo = lib.children;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1443 CX_TEST_ASSERT(libfoo != NULL && libfoo->path == paths[3]);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1444
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1445 cxFree(alloc, foo);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1446 cxFree(alloc, bar);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1447 cxFree(alloc, lib64);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1448 cxFree(alloc, libfoo);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1449
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1450 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1451 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1452 cx_testing_allocator_destroy(&talloc);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1453 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1454
893
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1455 CX_TEST(test_tree_add_many_but_not_all) {
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1456 CxTestingAllocator talloc;
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1457 cx_testing_allocator_init(&talloc);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1458 CxAllocator *alloc = &talloc.base;
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1459
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1460 tree_node_file root = {0};
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1461 root.path = "/";
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1462 tree_node_file usr = {0};
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1463 usr.path = "/usr/";
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1464 cx_tree_link(&root, &usr, tree_node_file_layout);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1465 tree_node_file home = {0};
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1466 home.path = "/home/";
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1467 cx_tree_link(&root, &home, tree_node_file_layout);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1468 tree_node_file lib = {0};
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1469 lib.path = "/usr/lib/";
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1470 cx_tree_link(&usr, &lib, tree_node_file_layout);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1471
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1472 CX_TEST_DO {
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1473 void *failed;
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1474
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1475 const char *paths[] = {
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1476 "/home/foo/",
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1477 "/home/foo/bar",
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1478 "/usr/lib64/",
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1479 "/usr/lib/foo.so"
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1480 };
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1481 // create iterator for 4 elements, but choose to insert only 3 of them
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1482 CxIterator iter = cxIterator(paths, sizeof(const char*), 4);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1483 size_t processed = cx_tree_add_iter(
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1484 cxIteratorRef(iter), 3,
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1485 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1486 tree_node_file_create, alloc,
893
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1487 &failed, &root, tree_node_file_layout
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1488 );
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1489
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1490 CX_TEST_ASSERT(cxIteratorValid(iter));
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1491 CX_TEST_ASSERT(cxIteratorCurrent(iter) == &paths[3]);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1492
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1493 CX_TEST_ASSERT(failed == NULL);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1494 CX_TEST_ASSERT(processed == 3);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1495 CX_TEST_ASSERT(talloc.alloc_total == 3);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1496
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1497 CX_TEST_ASSERT(home.children == home.last_child);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1498 tree_node_file *foo = home.children;
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1499 CX_TEST_ASSERT(foo != NULL && foo->path == paths[0]);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1500 CX_TEST_ASSERT(foo->children == foo->last_child);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1501 tree_node_file *bar = foo->children;
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1502 CX_TEST_ASSERT(bar != NULL && bar->path == paths[1]);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1503 CX_TEST_ASSERT(usr.children != usr.last_child);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1504 tree_node_file *lib64 = usr.last_child;
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1505 CX_TEST_ASSERT(lib64 != NULL);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1506 CX_TEST_ASSERT(lib64->path == paths[2]);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1507 CX_TEST_ASSERT(lib64->prev == &lib);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1508 CX_TEST_ASSERT(lib64->parent == &usr);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1509 CX_TEST_ASSERT(lib.children == NULL);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1510
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1511 cxFree(alloc, foo);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1512 cxFree(alloc, bar);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1513 cxFree(alloc, lib64);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1514
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1515 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1516 }
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1517 cx_testing_allocator_destroy(&talloc);
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1518 }
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
1519
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1520 CX_TEST(test_tree_add_many_with_dupl_and_no_match) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1521 CxTestingAllocator talloc;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1522 cx_testing_allocator_init(&talloc);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1523 CxAllocator *alloc = &talloc.base;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1524
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1525 tree_node_file root = {0};
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1526 root.path = "/mnt/";
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1527
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1528 CX_TEST_DO {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1529 tree_node_file *failed;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1530
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1531 const char *paths[] = {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1532 "/mnt/sdcard/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1533 "/mnt/foo/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1534 "/mnt/sdcard/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1535 "/home/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1536 "/usr/"
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1537 };
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1538
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1539 size_t processed = cx_tree_add_array(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1540 paths, 5, sizeof(const char *),
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1541 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1542 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1543 (void **) &failed, &root, tree_node_file_layout
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1544 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1545
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1546 CX_TEST_ASSERT(processed == 3);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1547 CX_TEST_ASSERT(failed != NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1548 CX_TEST_ASSERT(failed->parent == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1549 CX_TEST_ASSERT(failed->children == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1550 CX_TEST_ASSERT(strcmp(failed->path, "/home/") == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1551 cxFree(alloc, failed);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1552
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1553 CX_TEST_ASSERT(root.children != root.last_child);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1554 CX_TEST_ASSERT(strcmp(root.children->path, "/mnt/sdcard/") == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1555 CX_TEST_ASSERT(strcmp(root.last_child->path, "/mnt/sdcard/") == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1556 CX_TEST_ASSERT(strcmp(root.children->next->path, "/mnt/foo/") == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1557 CX_TEST_ASSERT(strcmp(root.last_child->prev->path, "/mnt/foo/") == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1558
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1559 CxTreeIterator iter = cx_tree_iterator(
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1560 &root, true,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1561 offsetof(tree_node_file, children),
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1562 offsetof(tree_node_file, next)
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1563 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1564 cx_foreach(tree_node_file *, node, iter) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1565 if (iter.exiting) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1566 if (node != &root) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1567 cxFree(alloc, node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1568 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1569 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1570 }
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1571
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1572 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1573 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1574 cx_testing_allocator_destroy(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1575 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1576
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1577 static CX_TEST_SUBROUTINE(test_tree_add_create_from_array_impl,
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1578 CxAllocator *alloc, const char **paths) {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1579 tree_node_file root = {0};
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1580 root.path = "/";
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1581
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1582 void *failed;
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1583 size_t processed = cx_tree_add_array(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1584 paths, 10, sizeof(const char *),
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1585 tree_node_file_search,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1586 tree_node_file_create, alloc,
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1587 &failed, &root, tree_node_file_layout
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1588 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1589
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1590 CX_TEST_ASSERT(failed == NULL);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1591 CX_TEST_ASSERT(processed == 10);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1592
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1593 const char *exp_order[] = {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1594 "/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1595 "/usr/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1596 "/usr/lib/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1597 "/usr/lib/libbumm.so",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1598 "/home/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1599 "/home/foo/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1600 "/var/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1601 "/var/www/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1602 "/var/www/vhosts/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1603 "/var/www/vhosts/live/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1604 "/var/www/vhosts/live/htdocs/"
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1605 };
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1606 unsigned exp_depth[] = {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1607 1,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1608 2,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1609 3,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1610 4,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1611 2,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1612 3,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1613 2,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1614 3,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1615 4,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1616 5,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1617 6
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1618 };
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1619
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1620 CxTreeIterator iter = cx_tree_iterator(
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1621 &root, true,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1622 offsetof(tree_node_file, children),
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1623 offsetof(tree_node_file, next)
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1624 );
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1625 cx_foreach(tree_node_file *, node, iter) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1626 if (iter.exiting) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1627 if (node != &root) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1628 cxFree(alloc, node);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1629 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1630 } else {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1631 CX_TEST_ASSERT(iter.counter <= 11);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1632 CX_TEST_ASSERT(iter.depth == exp_depth[iter.counter - 1]);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1633 CX_TEST_ASSERT(strcmp(node->path, exp_order[iter.counter - 1]) == 0);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1634 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1635 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1636 }
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1637
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1638 CX_TEST(test_tree_add_create_from_array) {
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1639 // creates an entirely new tree from an array
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1640
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1641 CxTestingAllocator talloc;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1642 cx_testing_allocator_init(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1643 CxAllocator *alloc = &talloc.base;
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1644
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1645 CX_TEST_DO {
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1646 const char *paths[] = {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1647 "/usr/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1648 "/home/",
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1649 "/usr/lib/",
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1650 "/usr/lib/libbumm.so",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1651 "/var/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1652 "/var/www/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1653 "/var/www/vhosts/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1654 "/var/www/vhosts/live/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1655 "/var/www/vhosts/live/htdocs/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1656 "/home/foo/"
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1657 };
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1658
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 871
diff changeset
1659 const char *scrambled_paths[] = {
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1660 "/usr/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1661 "/home/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1662 "/var/www/vhosts/live/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1663 "/usr/lib/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1664 "/var/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1665 "/var/www/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1666 "/usr/lib/libbumm.so",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1667 "/var/www/vhosts/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1668 "/var/www/vhosts/live/htdocs/",
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1669 "/home/foo/"
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1670 };
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1671
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1672 // no matter how the original array is sorted,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1673 // the resulting tree should be the same
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1674 CX_TEST_CALL_SUBROUTINE(test_tree_add_create_from_array_impl, alloc,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1675 paths);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1676 CX_TEST_CALL_SUBROUTINE(test_tree_add_create_from_array_impl, alloc,
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
1677 scrambled_paths);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1678
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1679 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1680 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1681 cx_testing_allocator_destroy(&talloc);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1682 }
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1683
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1684 CX_TEST(test_tree_high_create) {
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1685 CxTestingAllocator talloc;
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1686 cx_testing_allocator_init(&talloc);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1687 CX_TEST_DO {
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1688 CxTree *tree = cxTreeCreate(
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1689 &talloc.base,
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1690 tree_node_file_create_hl,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1691 tree_node_file_search,
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1692 tree_node_file_search_data,
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1693 tree_node_file_layout
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1694 );
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1695 CX_TEST_ASSERT(tree->cl != NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1696 CX_TEST_ASSERT(tree->allocator == &talloc.base);
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1697 CX_TEST_ASSERT(tree->node_create == tree_node_file_create_hl);
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1698 CX_TEST_ASSERT(tree->search == tree_node_file_search);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1699 CX_TEST_ASSERT(tree->search_data == tree_node_file_search_data);
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1700 CX_TEST_ASSERT(tree->size == 0);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1701 CX_TEST_ASSERT(tree->simple_destructor == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1702 CX_TEST_ASSERT(tree->advanced_destructor == (cx_destructor_func2) cxFree);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1703 CX_TEST_ASSERT(tree->destructor_data == &talloc.base);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1704 CX_TEST_ASSERT(tree->root == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1705 CX_TEST_ASSERT(tree->loc_parent == offsetof(tree_node_file, parent));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1706 CX_TEST_ASSERT(tree->loc_children == offsetof(tree_node_file, children));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1707 CX_TEST_ASSERT(tree->loc_last_child == offsetof(tree_node_file, last_child));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1708 CX_TEST_ASSERT(tree->loc_prev == offsetof(tree_node_file, prev));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1709 CX_TEST_ASSERT(tree->loc_next == offsetof(tree_node_file, next));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1710
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1711 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1712 CX_TEST_ASSERT(talloc.alloc_total == 1);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1713
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1714 cxTreeDestroy(tree);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1715 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1716 }
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1717 cx_testing_allocator_destroy(&talloc);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1718 }
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1719
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1720 CX_TEST(test_tree_high_create_simple) {
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1721 CX_TEST_DO {
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1722 CxTree *tree = cxTreeCreateSimple(
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1723 cxDefaultAllocator,
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1724 tree_node_file_create_hl,
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1725 tree_node_file_search,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1726 tree_node_file_search_data
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1727 );
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1728 CX_TEST_ASSERT(tree->cl != NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1729 CX_TEST_ASSERT(tree->allocator == cxDefaultAllocator);
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1730 CX_TEST_ASSERT(tree->node_create == tree_node_file_create_hl);
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1731 CX_TEST_ASSERT(tree->search == tree_node_file_search);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1732 CX_TEST_ASSERT(tree->search_data == tree_node_file_search_data);
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1733 CX_TEST_ASSERT(tree->size == 0);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1734 CX_TEST_ASSERT(tree->simple_destructor == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1735 CX_TEST_ASSERT(tree->advanced_destructor == (cx_destructor_func2) cxFree);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1736 CX_TEST_ASSERT(tree->destructor_data == cxDefaultAllocator);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1737 CX_TEST_ASSERT(tree->root == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1738 CX_TEST_ASSERT(tree->loc_parent == offsetof(struct cx_tree_node_base_s, parent));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1739 CX_TEST_ASSERT(tree->loc_children == offsetof(struct cx_tree_node_base_s, children));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1740 CX_TEST_ASSERT(tree->loc_last_child == offsetof(struct cx_tree_node_base_s, last_child));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1741 CX_TEST_ASSERT(tree->loc_prev == offsetof(struct cx_tree_node_base_s, prev));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1742 CX_TEST_ASSERT(tree->loc_next == offsetof(struct cx_tree_node_base_s, next));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1743 cxTreeDestroy(tree);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1744 }
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1745 }
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1746
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1747 CX_TEST(test_tree_high_create_wrapped) {
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1748 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0};
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1749 cx_tree_link(&root, &child1, tree_node_layout);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1750 cx_tree_link(&root, &child2, tree_node_layout);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1751 cx_tree_link(&child1, &child3, tree_node_layout);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1752 CX_TEST_DO {
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1753 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout);
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1754 CX_TEST_ASSERT(tree->cl != NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1755 CX_TEST_ASSERT(tree->allocator == cxDefaultAllocator);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1756 CX_TEST_ASSERT(tree->node_create == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1757 CX_TEST_ASSERT(tree->search == NULL);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1758 CX_TEST_ASSERT(tree->search_data == NULL);
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1759 CX_TEST_ASSERT(tree->root == &root);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1760 CX_TEST_ASSERT(tree->size == 4);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1761 CX_TEST_ASSERT(tree->simple_destructor == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1762 CX_TEST_ASSERT(tree->advanced_destructor == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1763 CX_TEST_ASSERT(tree->destructor_data == NULL);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1764 CX_TEST_ASSERT(tree->loc_parent == offsetof(tree_node, parent));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1765 CX_TEST_ASSERT(tree->loc_children == offsetof(tree_node, children));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1766 CX_TEST_ASSERT(tree->loc_last_child == -1);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1767 CX_TEST_ASSERT(tree->loc_prev == offsetof(tree_node, prev));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1768 CX_TEST_ASSERT(tree->loc_next == offsetof(tree_node, next));
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1769 cxTreeDestroy(tree);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1770 }
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
1771 }
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
1772
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1773 CX_TEST(test_tree_high_tree_depth) {
903
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1774 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0};
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1775 cx_tree_link(&root, &child1, tree_node_layout);
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1776 cx_tree_link(&root, &child2, tree_node_layout);
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1777 cx_tree_link(&child1, &child3, tree_node_layout);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1778 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout);
903
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1779 CX_TEST_DO {
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1780 CX_TEST_ASSERT(cxTreeDepth(tree) == 3);
903
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1781 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &root) == 3);
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1782 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child1) == 2);
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1783 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child2) == 1);
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1784 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child3) == 1);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1785
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1786 CxTree *empty = cxTreeCreate(
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1787 cxDefaultAllocator,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1788 tree_node_file_create_hl,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1789 tree_node_file_search,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1790 tree_node_file_search_data,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1791 tree_node_file_layout
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1792 );
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1793 CX_TEST_ASSERT(cxTreeDepth(empty) == 0);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1794 cxTreeDestroy(empty);
903
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1795 }
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1796 cxTreeDestroy(tree);
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1797 }
a018f5916d3b add cxTreeSubtreeDepth()
Mike Becker <universe@uap-core.de>
parents: 902
diff changeset
1798
918
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1799 CX_TEST(test_tree_high_set_parent) {
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1800 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0};
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1801 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1802 CX_TEST_DO {
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1803 cxTreeSetParent(tree, &root, &child1);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1804 cxTreeSetParent(tree, &root, &child2);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1805 cxTreeSetParent(tree, &child1, &child3);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1806 CX_TEST_ASSERT(cxTreeDepth(tree) == 3);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1807 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &root) == 3);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1808 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child1) == 2);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1809 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child2) == 1);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1810 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child3) == 1);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1811
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1812 cxTreeSetParent(tree, &child2, &child3);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1813 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &root) == 3);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1814 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child1) == 1);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1815 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child2) == 2);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1816 CX_TEST_ASSERT(cxTreeSubtreeDepth(tree, &child3) == 1);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1817
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1818 CxTree *empty = cxTreeCreate(
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1819 cxDefaultAllocator,
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1820 tree_node_file_create_hl,
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1821 tree_node_file_search,
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1822 tree_node_file_search_data,
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1823 tree_node_file_layout
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1824 );
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1825 CX_TEST_ASSERT(cxTreeDepth(empty) == 0);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1826 cxTreeDestroy(empty);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1827 }
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1828 cxTreeDestroy(tree);
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1829 }
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
1830
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1831 CX_TEST(test_tree_high_insert_one) {
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1832 CxTestingAllocator talloc;
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1833 cx_testing_allocator_init(&talloc);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1834 CxAllocator *alloc = &talloc.base;
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1835
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1836 CX_TEST_DO {
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1837 CxTree *tree = cxTreeCreate(
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1838 alloc, tree_node_file_create_hl,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1839 tree_node_file_search, tree_node_file_search_data,
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1840 tree_node_file_layout
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1841 );
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1842
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1843 int result = 0;
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1844 result |= cxTreeInsert(tree, "/");
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1845 result |= cxTreeInsert(tree, "/usr/");
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1846 result |= cxTreeInsert(tree, "/home/");
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1847 result |= cxTreeInsert(tree, "/usr/lib/");
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1848 result |= cxTreeInsert(tree, "/home/foo/");
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1849 CX_TEST_ASSERT(result == 0);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1850 CX_TEST_ASSERT(1 == cxTreeInsertArray(tree, "/home/foo/bar/", sizeof(const char*), 1));
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1851 CX_TEST_ASSERT(tree->size == 6);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1852 CX_TEST_ASSERT(0 != cxTreeInsert(tree, "newroot"));
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1853 CX_TEST_ASSERT(tree->size == 6);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1854
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1855 CX_TEST_ASSERT(talloc.alloc_total == 8);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1856 CX_TEST_ASSERT(talloc.free_total == 1); // the one that could not be added
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1857
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1858 cxTreeDestroy(tree);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1859 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1860 }
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1861 cx_testing_allocator_destroy(&talloc);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1862 }
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1863
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1864 CX_TEST(test_tree_high_insert_many) {
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1865 CxTestingAllocator talloc;
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1866 cx_testing_allocator_init(&talloc);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1867 CxAllocator *alloc = &talloc.base;
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1868
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1869 CX_TEST_DO {
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1870 CxTree *tree = cxTreeCreate(
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1871 alloc, tree_node_file_create_hl,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1872 tree_node_file_search, tree_node_file_search_data,
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1873 tree_node_file_layout
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1874 );
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1875
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1876 const char *paths[] = {
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1877 "/",
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1878 "/usr/",
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1879 "/home/",
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1880 "/usr/lib/",
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1881 "/home/foo/",
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1882 "/home/foo/bar/",
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1883 "newroot"
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1884 };
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1885 CX_TEST_ASSERT(6 == cxTreeInsertArray(tree, paths, sizeof(const char*), 7));
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1886 CX_TEST_ASSERT(tree->size == 6);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1887
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1888 CX_TEST_ASSERT(talloc.alloc_total == 8);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1889 CX_TEST_ASSERT(talloc.free_total == 1); // the one that could not be added
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1890
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1891 cxTreeDestroy(tree);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1892 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1893 }
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1894 cx_testing_allocator_destroy(&talloc);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1895 }
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
1896
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1897 static void test_tree_remove_node_relink_mock(
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1898 void *node,
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1899 __attribute__((__unused__)) const void *oldp,
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1900 __attribute__((__unused__)) const void *newp
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1901 ) {
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1902 tree_node_file * n = node;
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1903 // this function fakes the relink logic in below test
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1904 if (strcmp(n->path, "/usr/share/") == 0) {
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1905 n->path = "/share/";
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1906 } else if (strcmp(n->path, "/usr/lib/") == 0) {
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1907 n->path = "/lib/";
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1908 }
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1909 }
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1910
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1911 CX_TEST(test_tree_high_add_find_remove_nodes) {
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1912 CxTestingAllocator talloc;
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1913 cx_testing_allocator_init(&talloc);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1914 CxAllocator *alloc = &talloc.base;
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1915
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1916 CX_TEST_DO {
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1917 CxTree *tree = cxTreeCreate(
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1918 alloc, tree_node_file_create_hl,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1919 tree_node_file_search, tree_node_file_search_data,
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1920 tree_node_file_layout
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1921 );
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1922
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1923 const char *paths[] = {
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1924 "/",
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1925 "/usr/",
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1926 "/home/",
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1927 "/usr/lib/",
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1928 "/home/foo/",
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1929 "/home/foo/bar/"
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1930 };
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1931 cxTreeInsertArray(tree, paths, sizeof(const char*), 6);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1932
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1933 tree_node_file *foo = cxTreeFind(tree, "/home/foo/");
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1934 CX_TEST_ASSERT(NULL != foo);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1935 CX_TEST_ASSERT(0 == strcmp("/home/foo/", foo->path));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1936 CX_TEST_ASSERT(NULL != foo->parent);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1937 CX_TEST_ASSERT(0 == strcmp("/home/", foo->parent->path));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1938 CX_TEST_ASSERT(tree->size == 6);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1939
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1940 CX_TEST_ASSERT(0 == cxTreeAddChild(tree, foo->parent, "/home/baz/"));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1941 tree_node_file *baz = cxTreeFind(tree, "/home/baz/");
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1942 CX_TEST_ASSERT(NULL != baz);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1943 CX_TEST_ASSERT(0 == strcmp("/home/baz/", baz->path));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1944 CX_TEST_ASSERT(NULL != baz->parent);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1945 CX_TEST_ASSERT(0 == strcmp("/home/", baz->parent->path));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1946 CX_TEST_ASSERT(tree->size == 7);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1947
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1948 tree_node_file *home = cxTreeFind(tree, "/home/");
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
1949 CX_TEST_ASSERT(NULL == cxTreeFindInSubtree(tree, "/usr/", foo, 0));
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
1950 tree_node_file *bar = cxTreeFindInSubtree(tree, "/home/foo/bar/", home, 0);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1951 CX_TEST_ASSERT(NULL != bar);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1952 CX_TEST_ASSERT(0 == strcmp("/home/foo/bar/", bar->path));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1953 CX_TEST_ASSERT(bar->parent == foo);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1954
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1955 tree_node_file *share = cxCalloc(alloc, 1, sizeof(tree_node_file));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1956 share->path = "/usr/share/";
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1957 tree_node_file *usr = cxTreeFind(tree, "/usr/");
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1958 cxTreeAddChildNode(tree, usr, share);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1959 CX_TEST_ASSERT(tree->size == 8);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1960
908
f49f8a7060aa rename cxTreeRemove() to cxTreeRemoveSubtree()
Mike Becker <universe@uap-core.de>
parents: 907
diff changeset
1961 cxTreeRemoveSubtree(tree, foo);
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1962 CX_TEST_ASSERT(tree->size == 6);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1963 CX_TEST_ASSERT(foo->children == bar);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1964 CX_TEST_ASSERT(foo->last_child == bar);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1965 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/"));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1966 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/bar/"));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1967 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/bar/"));
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1968
913
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
1969 CX_TEST_ASSERT(0 == cxTreeRemoveNode(tree, usr, test_tree_remove_node_relink_mock));
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1970 CX_TEST_ASSERT(tree->size == 5);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1971 CX_TEST_ASSERT(usr->parent == NULL);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1972 CX_TEST_ASSERT(usr->children == NULL);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1973 CX_TEST_ASSERT(usr->last_child == NULL);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1974 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/"));
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1975 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/lib/"));
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1976 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/share/"));
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1977 tree_node_file *relinked_share = cxTreeFind(tree, "/share/");
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1978 tree_node_file *relinked_lib = cxTreeFind(tree, "/lib/");
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1979 CX_TEST_ASSERT(relinked_share != NULL);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1980 CX_TEST_ASSERT(relinked_share->parent == tree->root);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1981 CX_TEST_ASSERT(relinked_lib != NULL);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1982 CX_TEST_ASSERT(relinked_lib->parent == tree->root);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1983 CX_TEST_ASSERT(NULL != cxTreeFind(tree, "/home/"));
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1984
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1985
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1986 cxTreeDestroy(tree);
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1987 // we are not done yet, because we need to free the removed stuff
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1988 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1989
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1990 cxFree(alloc, usr);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
1991 // for the subtree, we use a little trick and wrap it in a new tree
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1992 CxTree *foo_tree = cxTreeCreateWrapped(alloc, foo, tree_node_file_layout);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1993 foo_tree->allocator = alloc;
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1994 foo_tree->advanced_destructor = (cx_destructor_func2 ) cxFree;
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1995 foo_tree->destructor_data = alloc;
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1996 cxTreeDestroy(foo_tree);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1997 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1998 }
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
1999 cx_testing_allocator_destroy(&talloc);
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
2000 }
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
2001
913
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2002 CX_TEST(test_tree_high_add_find_destroy_nodes) {
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2003 CxTestingAllocator talloc;
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2004 cx_testing_allocator_init(&talloc);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2005 CxAllocator *alloc = &talloc.base;
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2006
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2007 CX_TEST_DO {
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2008 CxTree *tree = cxTreeCreate(
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2009 alloc, tree_node_file_create_hl,
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2010 tree_node_file_search, tree_node_file_search_data,
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2011 tree_node_file_layout
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2012 );
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2013
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2014 const char *paths[] = {
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2015 "/",
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2016 "/usr/",
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2017 "/home/",
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2018 "/usr/lib/",
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2019 "/home/foo/",
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2020 "/home/foo/bar/"
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2021 };
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2022 cxTreeInsertArray(tree, paths, sizeof(const char*), 6);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2023
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2024 tree_node_file *foo = cxTreeFind(tree, "/home/foo/");
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2025 CX_TEST_ASSERT(NULL != foo);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2026 CX_TEST_ASSERT(0 == strcmp("/home/foo/", foo->path));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2027 CX_TEST_ASSERT(NULL != foo->parent);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2028 CX_TEST_ASSERT(0 == strcmp("/home/", foo->parent->path));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2029 CX_TEST_ASSERT(tree->size == 6);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2030
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2031 CX_TEST_ASSERT(0 == cxTreeAddChild(tree, foo->parent, "/home/baz/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2032 tree_node_file *baz = cxTreeFind(tree, "/home/baz/");
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2033 CX_TEST_ASSERT(NULL != baz);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2034 CX_TEST_ASSERT(0 == strcmp("/home/baz/", baz->path));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2035 CX_TEST_ASSERT(NULL != baz->parent);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2036 CX_TEST_ASSERT(0 == strcmp("/home/", baz->parent->path));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2037 CX_TEST_ASSERT(tree->size == 7);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2038
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2039 tree_node_file *home = cxTreeFind(tree, "/home/");
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
2040 CX_TEST_ASSERT(NULL == cxTreeFindInSubtree(tree, "/usr/", foo, 0));
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
2041 tree_node_file *bar = cxTreeFindInSubtree(tree, "/home/foo/bar/", home, 0);
913
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2042 CX_TEST_ASSERT(NULL != bar);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2043 CX_TEST_ASSERT(0 == strcmp("/home/foo/bar/", bar->path));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2044 CX_TEST_ASSERT(bar->parent == foo);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2045
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2046 tree_node_file *share = cxCalloc(alloc, 1, sizeof(tree_node_file));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2047 share->path = "/usr/share/";
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2048 tree_node_file *usr = cxTreeFind(tree, "/usr/");
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2049 cxTreeAddChildNode(tree, usr, share);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2050 CX_TEST_ASSERT(tree->size == 8);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2051
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2052 cxTreeDestroySubtree(tree, foo);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2053 CX_TEST_ASSERT(tree->size == 6);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2054 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2055 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/bar/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2056 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/bar/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2057
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2058 CX_TEST_ASSERT(0 == cxTreeDestroyNode(tree, usr, test_tree_remove_node_relink_mock));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2059 CX_TEST_ASSERT(tree->size == 5);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2060 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2061 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/lib/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2062 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/share/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2063 tree_node_file *relinked_share = cxTreeFind(tree, "/share/");
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2064 tree_node_file *relinked_lib = cxTreeFind(tree, "/lib/");
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2065 CX_TEST_ASSERT(relinked_share != NULL);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2066 CX_TEST_ASSERT(relinked_share->parent == tree->root);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2067 CX_TEST_ASSERT(relinked_lib != NULL);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2068 CX_TEST_ASSERT(relinked_lib->parent == tree->root);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2069 CX_TEST_ASSERT(NULL != cxTreeFind(tree, "/home/"));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2070
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2071 cxTreeDestroy(tree);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2072 // all memory should be free when using destroy instead of remove
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2073 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2074 }
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2075 cx_testing_allocator_destroy(&talloc);
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2076 }
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2077
916
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2078 CX_TEST(test_tree_high_remove_or_destroy_root) {
907
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2079 CxTestingAllocator talloc;
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2080 cx_testing_allocator_init(&talloc);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2081 CxAllocator *alloc = &talloc.base;
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2082
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2083 CX_TEST_DO {
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2084 CxTree *tree = cxTreeCreate(
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2085 alloc, tree_node_file_create_hl,
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2086 tree_node_file_search, tree_node_file_search_data,
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2087 tree_node_file_layout
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2088 );
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2089
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2090 const char *paths[] = {
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2091 "/",
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2092 "/usr/",
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2093 "/home/",
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2094 "/usr/lib/",
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2095 "/home/foo/",
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2096 "/home/foo/bar/"
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2097 };
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2098 cxTreeInsertArray(tree, paths, sizeof(const char*), 6);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2099 void *root = tree->root;
913
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2100 CX_TEST_ASSERT(0 != cxTreeRemoveNode(tree, root, NULL));
909
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
2101 CX_TEST_ASSERT(tree->root == root);
f4e00bb3f3b2 implement cxTreeRemove() with re-link function
Mike Becker <universe@uap-core.de>
parents: 908
diff changeset
2102 CX_TEST_ASSERT(tree->size == 6);
916
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2103 CX_TEST_ASSERT(0 != cxTreeDestroyNode(tree, root, NULL));
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2104 CX_TEST_ASSERT(tree->root == root);
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2105 CX_TEST_ASSERT(tree->size == 6);
908
f49f8a7060aa rename cxTreeRemove() to cxTreeRemoveSubtree()
Mike Becker <universe@uap-core.de>
parents: 907
diff changeset
2106 cxTreeRemoveSubtree(tree, root);
907
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2107 CX_TEST_ASSERT(tree->size == 0);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2108 CX_TEST_ASSERT(tree->root == NULL);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2109 CX_TEST_ASSERT(cxTreeDepth(tree) == 0);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2110 cxTreeDestroy(tree);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2111 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2112 CxTree *w = cxTreeCreateWrapped(alloc, root, tree_node_file_layout);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2113 w->advanced_destructor = (cx_destructor_func2) cxFree;
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2114 w->destructor_data = alloc;
916
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2115 cxTreeDestroySubtree(w, w->root);
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2116 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2117 cxFree(alloc, w);
907
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2118 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2119 }
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2120 cx_testing_allocator_destroy(&talloc);
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2121 }
1f72fb9af87e fix bug when removing the root node of a tree
Mike Becker <universe@uap-core.de>
parents: 906
diff changeset
2122
906
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2123 static void test_tree_high_simple_destructor_func(void *node) {
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2124 ((tree_node *)node)->data++;
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2125 }
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2126
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2127 CX_TEST(test_tree_high_simple_destructor) {
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2128 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0};
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2129 cx_tree_link(&root, &child1, tree_node_layout);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2130 cx_tree_link(&root, &child2, tree_node_layout);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2131 cx_tree_link(&child1, &child3, tree_node_layout);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2132 CX_TEST_DO {
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2133 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2134 tree->simple_destructor = test_tree_high_simple_destructor_func;
916
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2135 cxTreeDestroyNode(tree, &child1, NULL);
906
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2136 cxTreeDestroy(tree);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2137 CX_TEST_ASSERT(root.data == 1);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2138 CX_TEST_ASSERT(child1.data == 1);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2139 CX_TEST_ASSERT(child2.data == 1);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2140 CX_TEST_ASSERT(child3.data == 1);
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2141 }
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2142 }
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2143
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2144 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
2145 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
2146
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2147 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
2148 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
2149 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
2150 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
2151 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
2152 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
2153 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
2154 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
2155 cx_test_register(suite, test_tree_search);
930
6540096c17b7 add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents: 918
diff changeset
2156 cx_test_register(suite, test_tree_search_with_max_depth);
836
2672a2f79484 implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents: 833
diff changeset
2157 cx_test_register(suite, test_tree_iterator_create_and_dispose);
915
23db9f0c1acd add test for creating an iterator over an empty tree
Mike Becker <universe@uap-core.de>
parents: 913
diff changeset
2158 cx_test_register(suite, test_tree_iterator_create_for_empty_tree);
838
1ce90ab4fab9 add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents: 837
diff changeset
2159 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
2160 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
2161 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
2162 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
2163 cx_test_register(suite, test_tree_visitor);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
2164 cx_test_register(suite, test_tree_visitor_no_children);
2615317311b7 add cx_tree_visitor()
Mike Becker <universe@uap-core.de>
parents: 840
diff changeset
2165 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
2166 cx_test_register(suite, test_tree_visitor_continue);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
2167 cx_test_register(suite, test_tree_iterator_continue);
6456036bbb37 implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents: 847
diff changeset
2168 cx_test_register(suite, test_tree_iterator_continue_with_exit);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
2169 cx_test_register(suite, test_tree_add_one);
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
2170 cx_test_register(suite, test_tree_add_one_existing);
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
2171 cx_test_register(suite, test_tree_add_one_no_match);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
2172 cx_test_register(suite, test_tree_add_duplicate_root);
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
2173 cx_test_register(suite, test_tree_add_zero);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
2174 cx_test_register(suite, test_tree_add_many);
893
0a2b328f5b91 add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
2175 cx_test_register(suite, test_tree_add_many_but_not_all);
871
e29c1f96646d rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents: 866
diff changeset
2176 cx_test_register(suite, test_tree_add_many_with_dupl_and_no_match);
866
1f636de4a63f complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents: 862
diff changeset
2177 cx_test_register(suite, test_tree_add_create_from_array);
816
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2178
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2179 return suite;
425234b05dff add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2180 }
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2181
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2182 CxTestSuite *cx_test_suite_tree_high_level(void) {
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2183 CxTestSuite *suite = cx_test_suite_new("tree (high level)");
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2184
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2185 cx_test_register(suite, test_tree_high_create);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2186 cx_test_register(suite, test_tree_high_create_simple);
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2187 cx_test_register(suite, test_tree_high_create_wrapped);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
2188 cx_test_register(suite, test_tree_high_tree_depth);
918
ec1f2015ec79 add cxTreeSetParent()
Mike Becker <universe@uap-core.de>
parents: 916
diff changeset
2189 cx_test_register(suite, test_tree_high_set_parent);
904
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
2190 cx_test_register(suite, test_tree_high_insert_one);
cdc49211d87f implement cxTreeInsert family of functions
Mike Becker <universe@uap-core.de>
parents: 903
diff changeset
2191 cx_test_register(suite, test_tree_high_insert_many);
905
39aa4f106a71 complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents: 904
diff changeset
2192 cx_test_register(suite, test_tree_high_add_find_remove_nodes);
913
72db8e42b95e implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents: 911
diff changeset
2193 cx_test_register(suite, test_tree_high_add_find_destroy_nodes);
916
526ed389c3d2 add missing details for 100% test coverage in tree.c
Mike Becker <universe@uap-core.de>
parents: 915
diff changeset
2194 cx_test_register(suite, test_tree_high_remove_or_destroy_root);
906
b51e5268bd9b add test for simple destructor in trees - fixes #436
Mike Becker <universe@uap-core.de>
parents: 905
diff changeset
2195 cx_test_register(suite, test_tree_high_simple_destructor);
902
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2196
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2197 return suite;
5ed7f634f046 implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents: 895
diff changeset
2198 }

mercurial