Sat, 28 Sep 2024 15:55:14 +0200
make all function attributes leading - fixes #425
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved. |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | #include "cx/tree.h" |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | #include "cx/test.h" |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | |
840
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
33 | #include "util_allocator.h" |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
34 | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | typedef struct tree_node { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | struct tree_node *parent; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | struct tree_node *next; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | struct tree_node *prev; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | struct tree_node *children; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | int data; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | } tree_node; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
43 | typedef struct tree_node2 { |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
44 | struct tree_node2 *parent; |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
45 | struct tree_node2 *next; |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
46 | struct tree_node2 *prev; |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
47 | struct tree_node2 *children; |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
48 | struct tree_node2 *last_child; |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
49 | int data; |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
50 | } tree_node2; |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
51 | |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
52 | typedef struct tree_node_file { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
53 | struct tree_node_file *parent; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
54 | struct tree_node_file *next; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
55 | struct tree_node_file *prev; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
56 | struct tree_node_file *children; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
57 | 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
|
58 | const char *path; |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
59 | } tree_node_file; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
60 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
61 | static void *create_tree_node_file( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
62 | const void *dptr, |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
63 | void *allocator) { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
64 | if (allocator == NULL) allocator = cxDefaultAllocator; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
65 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
66 | 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
|
67 | node->path = dptr; |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
68 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
69 | // 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
|
70 | 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
|
71 | 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
|
72 | 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
|
73 | 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
|
74 | node->last_child = (void *) 0xf00ba5; |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
75 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
76 | return node; |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
77 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
78 | |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
79 | 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
|
80 | 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
|
81 | 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
|
82 | 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
|
83 | size_t len2 = strlen(right->path); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
84 | 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
|
85 | 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
|
86 | return (int) (len2 - len1); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
87 | } else { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
88 | return -1; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
89 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
90 | } else { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
91 | return -1; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
92 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
93 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
94 | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | #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
|
96 | 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
|
97 | 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
|
98 | #define tree_node_full_layout(structname) \ |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
99 | offsetof(structname, parent), offsetof(structname, children),\ |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
100 | offsetof(structname, last_child), \ |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
101 | offsetof(structname, prev), offsetof(structname, next) |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
102 | #define tree_node2_layout tree_node_full_layout(tree_node2) |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
103 | #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
|
104 | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
105 | #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
|
106 | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | CX_TEST(test_tree_link_new_child) { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | tree_node child = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | 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
|
113 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | CX_TEST_ASSERT(parent.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | CX_TEST_ASSERT(parent.children == &child); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | CX_TEST_ASSERT(child.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | CX_TEST_ASSERT(child.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
119 | CX_TEST_ASSERT(child.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | CX_TEST_ASSERT(child.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | CX_TEST(test_tree_link_add_child) { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | tree_node child1 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | tree_node child2 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | tree_node child3 = {0}; |
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 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | 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
|
132 | 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
|
133 | 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
|
134 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | 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
|
137 | CX_TEST_ASSERT(parent.children == &child1); |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | CX_TEST_ASSERT(child1.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | CX_TEST_ASSERT(child2.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | CX_TEST_ASSERT(child3.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | CX_TEST_ASSERT(child1.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | CX_TEST_ASSERT(child2.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | CX_TEST_ASSERT(child3.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | 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
|
150 | 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
|
151 | CX_TEST_ASSERT(child3.next == NULL); |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | 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
|
156 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | tree_node child1 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | tree_node child2 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | tree_node child3 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | 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
|
161 | 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
|
162 | 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
|
163 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | 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
|
166 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | 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
|
170 | CX_TEST_ASSERT(parent.children == &child1); |
816
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_ASSERT(child1.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | CX_TEST_ASSERT(child2.parent == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | CX_TEST_ASSERT(child3.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | CX_TEST_ASSERT(child1.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
176 | CX_TEST_ASSERT(child2.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | CX_TEST_ASSERT(child3.children == &child2); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
179 | 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
|
180 | 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
|
181 | 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
|
182 | CX_TEST_ASSERT(child3.next == NULL); |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | CX_TEST_ASSERT(child2.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
185 | CX_TEST_ASSERT(child2.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
186 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
187 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
188 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
189 | CX_TEST(test_tree_unlink) { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
190 | tree_node parent = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
191 | tree_node child1 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | tree_node child2 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
193 | tree_node child3 = {0}; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | 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
|
195 | 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
|
196 | 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
|
197 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
198 | CX_TEST_DO { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
199 | cx_tree_unlink(&child3, tree_node_layout); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | CX_TEST_ASSERT(parent.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | CX_TEST_ASSERT(parent.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | CX_TEST_ASSERT(parent.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | CX_TEST_ASSERT(parent.children == &child1); |
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_ASSERT(child1.parent == &parent); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
207 | CX_TEST_ASSERT(child1.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | CX_TEST_ASSERT(child1.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
209 | CX_TEST_ASSERT(child1.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
210 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | // child 3 is unlinked |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | CX_TEST_ASSERT(child3.parent == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | CX_TEST_ASSERT(child3.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | CX_TEST_ASSERT(child3.next == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | // 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
|
217 | CX_TEST_ASSERT(child3.children == &child2); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | CX_TEST_ASSERT(child2.parent == &child3); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | CX_TEST_ASSERT(child2.children == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | CX_TEST_ASSERT(child2.prev == NULL); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | 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
|
222 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
223 | // 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
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | 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
|
228 | 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
|
229 | 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
|
230 | } |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
231 | } |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
232 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
233 | CX_TEST(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
|
234 | 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
|
235 | 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
|
236 | |
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_DO { |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
238 | 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
|
239 | 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
|
240 | 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
|
241 | 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
|
242 | 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
|
243 | 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
|
244 | 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
|
245 | 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
|
246 | 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
|
247 | 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
|
248 | 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
|
249 | } |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
250 | } |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
251 | |
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(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
|
253 | 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
|
254 | 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
|
255 | 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
|
256 | 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
|
257 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
258 | CX_TEST_DO { |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
259 | 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
|
260 | 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
|
261 | 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
|
262 | 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
|
263 | 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
|
264 | 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
|
265 | 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
|
266 | 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
|
267 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
268 | CX_TEST_ASSERT(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
|
269 | 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
|
270 | 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
|
271 | 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
|
272 | 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
|
273 | 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
|
274 | 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
|
275 | 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
|
276 | 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
|
277 | |
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(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
|
279 | 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
|
280 | 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
|
281 | 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
|
282 | 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
|
283 | 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
|
284 | } |
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 | |
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(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
|
288 | 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
|
289 | 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
|
290 | 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
|
291 | 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
|
292 | 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
|
293 | 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
|
294 | 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
|
295 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
296 | CX_TEST_DO { |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
297 | 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
|
298 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
299 | CX_TEST_ASSERT(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
|
300 | 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
|
301 | 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
|
302 | 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
|
303 | 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
|
304 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
305 | CX_TEST_ASSERT(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
|
306 | 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
|
307 | 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
|
308 | 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
|
309 | 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
|
310 | CX_TEST_ASSERT(child3.children == &child2); |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
311 | CX_TEST_ASSERT(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
|
312 | 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
|
313 | 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
|
314 | |
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(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
|
316 | 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
|
317 | 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
|
318 | 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
|
319 | |
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.prev == 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(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
|
322 | } |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
323 | } |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
324 | |
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(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
|
326 | 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
|
327 | 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
|
328 | 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
|
329 | 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
|
330 | 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
|
331 | 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
|
332 | 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
|
333 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
334 | 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
|
335 | 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
|
336 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
337 | 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
|
338 | 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
|
339 | 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
|
340 | 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
|
341 | 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
|
342 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
343 | 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
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
349 | // 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
|
350 | 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
|
351 | 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
|
352 | 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
|
353 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
354 | // 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
|
355 | 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
|
356 | 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
|
357 | 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
|
358 | 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
|
359 | 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
|
360 | 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
|
361 | 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
|
362 | |
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
363 | // 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
|
364 | 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
|
365 | 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
|
366 | 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
|
367 | 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
|
368 | 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
|
369 | 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
|
370 | CX_TEST_ASSERT(child1.parent == NULL); |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
371 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
372 | } |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
373 | |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
374 | 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
|
375 | 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
|
376 | int data = *((const int *)d); |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
377 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
378 | if (data < node->data) return -1; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
379 | 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
|
380 | else return data - node->data; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
381 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
382 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
383 | CX_TEST(test_tree_search) { |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
384 | tree_node root = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
385 | tree_node a = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
386 | tree_node b = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
387 | tree_node c = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
388 | tree_node aa = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
389 | tree_node ab = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
390 | tree_node ba = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
391 | tree_node ca = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
392 | tree_node cb = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
393 | tree_node cc = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
394 | tree_node cba = {0}; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
395 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
396 | 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
|
397 | 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
|
398 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
399 | 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
|
400 | testnodes[i]->data = testdata[i]; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
401 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
402 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
403 | 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
|
404 | 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
|
405 | 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
|
406 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
407 | 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
|
408 | 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
|
409 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
410 | 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
|
411 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
412 | 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
|
413 | 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
|
414 | 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
|
415 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
416 | 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
|
417 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
418 | int s; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
419 | int r; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
420 | tree_node *n; |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
421 | CX_TEST_DO { |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
422 | 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
|
423 | s = testdata[i]; |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
424 | r = cx_tree_search_data(&root, &s, test_tree_search_function, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
425 | (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
|
426 | CX_TEST_ASSERT(r == 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
427 | CX_TEST_ASSERT(n == testnodes[i]); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
428 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
429 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
430 | s = -5; |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
431 | r = cx_tree_search_data(&root, &s, test_tree_search_function, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
432 | (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
|
433 | CX_TEST_ASSERT(r < 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
434 | CX_TEST_ASSERT(n == NULL); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
435 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
436 | s = 26; |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
437 | r = cx_tree_search_data(&root, &s, test_tree_search_function, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
438 | (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
|
439 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
440 | CX_TEST_ASSERT(n == &ba); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
441 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
442 | s = 35; |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
443 | r = cx_tree_search_data(&root, &s, test_tree_search_function, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
444 | (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
|
445 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
446 | CX_TEST_ASSERT(n == &cb); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
447 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
448 | s = 38; |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
449 | r = cx_tree_search_data(&root, &s, test_tree_search_function, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
450 | (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
|
451 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
452 | CX_TEST_ASSERT(n == &cba); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
453 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
454 | s = 42; |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
455 | r = cx_tree_search_data(&root, &s, test_tree_search_function, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
456 | (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
|
457 | CX_TEST_ASSERT(r > 0); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
458 | CX_TEST_ASSERT(n == &cc); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
459 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
460 | } |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
461 | |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
462 | 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
|
463 | tree_node root; |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
464 | 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
|
465 | 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
|
466 | 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
|
467 | 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
|
468 | 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
|
469 | 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
|
470 | 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
|
471 | 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
|
472 | 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
|
473 | 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
|
474 | 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
|
475 | 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
|
476 | 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
|
477 | 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
|
478 | cxTreeIteratorDispose(&iter); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
479 | CX_TEST_ASSERT(iter.stack == NULL); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
480 | } |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
481 | } |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
482 | |
838
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
483 | 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
|
484 | tree_node root = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
485 | tree_node a = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
486 | tree_node b = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
487 | tree_node c = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
488 | tree_node aa = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
489 | tree_node ab = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
490 | tree_node ba = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
491 | tree_node ca = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
492 | tree_node cb = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
493 | tree_node cc = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
494 | tree_node cba = {0}; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
495 | |
845 | 496 | tree_node* expected_order[] = { |
497 | &root, | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
498 | &a, &aa, &ab, |
845 | 499 | &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
|
500 | &c, &ca, &cb, &cba, &cc, |
845 | 501 | }; |
502 | tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong | |
503 | ||
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
504 | 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
|
505 | 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
|
506 | 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
|
507 | 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
|
508 | 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
|
509 | 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
|
510 | 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
|
511 | 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
|
512 | 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
|
513 | 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
|
514 | 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
|
515 | 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
|
516 | unsigned chk = 0; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
517 | cx_foreach(tree_node*, node, iter) { |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
518 | CX_TEST_ASSERT(node->data == 0); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
519 | node->data++; |
845 | 520 | actual_order[chk] = node; |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
521 | chk++; |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
522 | CX_TEST_ASSERT(node == iter.node); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
523 | 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
|
524 | if (node == &root) { |
7c15fea5cbea
add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents:
836
diff
changeset
|
525 | 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
|
526 | } 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
|
527 | 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
|
528 | } else if (node == &cba) { |
7c15fea5cbea
add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents:
836
diff
changeset
|
529 | 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
|
530 | } else { |
7c15fea5cbea
add depth assertion to basic tree iterator test
Mike Becker <universe@uap-core.de>
parents:
836
diff
changeset
|
531 | 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
|
532 | } |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
533 | } |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
534 | CX_TEST_ASSERT(iter.counter == 11); |
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
535 | CX_TEST_ASSERT(chk == 11); |
845 | 536 | for (unsigned i = 0 ; i < chk ; i++) { |
537 | CX_TEST_ASSERT(actual_order[i] == expected_order[i]); | |
538 | CX_TEST_ASSERT(actual_order[i]->data == 1); | |
539 | } | |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
540 | 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
|
541 | } |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
542 | } |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
543 | |
838
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
544 | 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
|
545 | tree_node root = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
546 | tree_node a = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
547 | tree_node b = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
548 | tree_node c = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
549 | tree_node aa = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
550 | tree_node ab = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
551 | tree_node ba = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
552 | tree_node ca = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
553 | tree_node cb = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
554 | tree_node cc = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
555 | tree_node cba = {0}; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
556 | |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
557 | 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
|
558 | 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
|
559 | 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
|
560 | 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
|
561 | 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
|
562 | 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
|
563 | 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
|
564 | 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
|
565 | 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
|
566 | 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
|
567 | 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
|
568 | 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
|
569 | unsigned chk = 0; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
570 | cx_foreach(tree_node*, node, iter) { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
571 | 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
|
572 | node->data++; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
573 | chk++; |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
574 | CX_TEST_ASSERT(node == iter.node); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
575 | if (node == &root) { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
576 | CX_TEST_ASSERT(iter.depth == 1); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
577 | } 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
|
578 | CX_TEST_ASSERT(iter.depth == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
579 | } else if (node == &cba) { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
580 | CX_TEST_ASSERT(iter.depth == 4); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
581 | } else { |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
582 | CX_TEST_ASSERT(iter.depth == 3); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
583 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
584 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
585 | CX_TEST_ASSERT(iter.counter == 11); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
586 | CX_TEST_ASSERT(chk == 22); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
587 | CX_TEST_ASSERT(iter.stack == NULL); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
588 | CX_TEST_ASSERT(root.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
589 | CX_TEST_ASSERT(a.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
590 | CX_TEST_ASSERT(b.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
591 | CX_TEST_ASSERT(c.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
592 | CX_TEST_ASSERT(aa.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
593 | CX_TEST_ASSERT(ab.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
594 | CX_TEST_ASSERT(ba.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
595 | CX_TEST_ASSERT(ca.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
596 | CX_TEST_ASSERT(cb.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
597 | CX_TEST_ASSERT(cc.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
598 | CX_TEST_ASSERT(cba.data == 2); |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
599 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
600 | } |
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
601 | |
839
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
602 | 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
|
603 | 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
|
604 | const char *name; |
839
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
605 | } test_xml_node; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
606 | |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
607 | 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
|
608 | test_xml_node project = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
609 | test_xml_node config = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
610 | test_xml_node var1 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
611 | test_xml_node var2 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
612 | test_xml_node var3 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
613 | test_xml_node dependency1 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
614 | test_xml_node dependency1make = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
615 | test_xml_node dependency2 = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
616 | test_xml_node dependency2lang = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
617 | test_xml_node dependency2make = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
618 | test_xml_node target = {0}; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
619 | 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
|
620 | 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
|
621 | 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
|
622 | |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
623 | project.name = "project"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
624 | config.name = "config"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
625 | var1.name = "var"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
626 | var2.name = "var"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
627 | var3.name = "var"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
628 | dependency1.name = "dependency"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
629 | dependency1make.name = "make"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
630 | dependency2.name = "dependency"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
631 | dependency2lang.name = "lang"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
632 | dependency2make.name = "make"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
633 | target.name = "target"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
634 | target_feature.name = "feature"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
635 | target_dependencies.name = "dependencies"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
636 | target_feature_dependencies.name = "dependencies"; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
637 | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
638 | 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
|
639 | 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
|
640 | 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
|
641 | 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
|
642 | 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
|
643 | 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
|
644 | 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
|
645 | 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
|
646 | 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
|
647 | 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
|
648 | 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
|
649 | 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
|
650 | 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
|
651 | |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
652 | const char *expected = |
839
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
653 | "<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
|
654 | "<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
|
655 | "<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
|
656 | char *actual = malloc(512); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
657 | 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
|
658 | 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
|
659 | size_t i = 0; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
660 | 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
|
661 | 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
|
662 | actual[i++] = '<'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
663 | if (iter.exiting) { |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
664 | actual[i++] = '/'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
665 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
666 | 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
|
667 | i += len; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
668 | actual[i++] = '>'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
669 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
670 | actual[i] = '\0'; |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
671 | 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
|
672 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
673 | free(actual); |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
674 | } |
62d3aecc5bb7
add xml test case for the tree iterator
Mike Becker <universe@uap-core.de>
parents:
838
diff
changeset
|
675 | |
840
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
676 | 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
|
677 | CxTestingAllocator talloc; |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
678 | cx_testing_allocator_init(&talloc); |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
679 | CxAllocator *alloc = &talloc.base; |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
680 | CX_TEST_DO { |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
681 | 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
|
682 | 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
|
683 | 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
|
684 | 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
|
685 | 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
|
686 | 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
|
687 | 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
|
688 | 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
|
689 | 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
|
690 | 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
|
691 | 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
|
692 | |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
693 | 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
|
694 | 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
|
695 | 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
|
696 | 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
|
697 | 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
|
698 | 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
|
699 | 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
|
700 | 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
|
701 | 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
|
702 | 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
|
703 | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
704 | 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
|
705 | 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
|
706 | if (iter.exiting) { |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
707 | cxFree(alloc,node); |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
708 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
709 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
710 | |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
711 | 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
|
712 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
713 | cx_testing_allocator_destroy(&talloc); |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
714 | } |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
839
diff
changeset
|
715 | |
847
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
716 | CX_TEST(test_tree_visitor_create_and_dispose) { |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
717 | tree_node root; |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
718 | tree_node child; |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
719 | cx_tree_link(&root, &child, tree_node_layout); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
720 | 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
|
721 | 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
|
722 | CX_TEST_ASSERT(iter.counter == 1); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
723 | 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
|
724 | 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
|
725 | CX_TEST_ASSERT(!iter.base.remove); |
847
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
726 | CX_TEST_ASSERT(iter.queue_next != NULL); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
727 | CX_TEST_ASSERT(iter.queue_last != NULL); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
728 | CX_TEST_ASSERT(iter.depth == 1); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
729 | 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
|
730 | 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
|
731 | cxTreeVisitorDispose(&iter); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
732 | CX_TEST_ASSERT(iter.queue_next == NULL); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
733 | CX_TEST_ASSERT(iter.queue_last == NULL); |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
734 | } |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
735 | } |
a39e410a05e6
add missing cxTreeVisitorDispose() test
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
736 | |
845 | 737 | CX_TEST(test_tree_visitor) { |
738 | tree_node root = {0}; | |
739 | tree_node a = {0}; | |
740 | tree_node b = {0}; | |
741 | tree_node c = {0}; | |
742 | tree_node aa = {0}; | |
743 | tree_node ab = {0}; | |
744 | tree_node ba = {0}; | |
745 | tree_node ca = {0}; | |
746 | tree_node cb = {0}; | |
747 | tree_node cc = {0}; | |
748 | tree_node cba = {0}; | |
749 | ||
750 | tree_node* expected_order[] = { | |
751 | &root, | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
752 | &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
|
753 | &aa, &ab, &ba, &ca, &cb, &cc, |
845 | 754 | &cba |
755 | }; | |
756 | tree_node* actual_order[16]; // reserve more space in case s.t. goes wrong | |
757 | ||
758 | cx_tree_link(&root, &a, tree_node_layout); | |
759 | cx_tree_link(&root, &b, tree_node_layout); | |
760 | cx_tree_link(&root, &c, tree_node_layout); | |
761 | cx_tree_link(&a, &aa, tree_node_layout); | |
762 | cx_tree_link(&a, &ab, tree_node_layout); | |
763 | cx_tree_link(&b, &ba, tree_node_layout); | |
764 | cx_tree_link(&c, &ca, tree_node_layout); | |
765 | cx_tree_link(&c, &cb, tree_node_layout); | |
766 | cx_tree_link(&c, &cc, tree_node_layout); | |
767 | cx_tree_link(&cb, &cba, tree_node_layout); | |
768 | 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
|
769 | CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node)); |
845 | 770 | unsigned chk = 0; |
771 | cx_foreach(tree_node*, node, iter) { | |
772 | CX_TEST_ASSERT(node->data == 0); | |
773 | node->data++; | |
774 | actual_order[chk] = node; | |
775 | chk++; | |
776 | CX_TEST_ASSERT(node == iter.node); | |
777 | if (node == &root) { | |
778 | CX_TEST_ASSERT(iter.depth == 1); | |
779 | } else if (node == &a || node == &b || node == &c) { | |
780 | CX_TEST_ASSERT(iter.depth == 2); | |
781 | } else if (node == &cba) { | |
782 | CX_TEST_ASSERT(iter.depth == 4); | |
783 | } else { | |
784 | CX_TEST_ASSERT(iter.depth == 3); | |
785 | } | |
786 | } | |
787 | CX_TEST_ASSERT(iter.counter == 11); | |
788 | CX_TEST_ASSERT(chk == 11); | |
789 | for (unsigned i = 0 ; i < chk ; i++) { | |
790 | CX_TEST_ASSERT(actual_order[i] == expected_order[i]); | |
791 | CX_TEST_ASSERT(actual_order[i]->data == 1); | |
792 | } | |
793 | CX_TEST_ASSERT(iter.queue_next == NULL); | |
794 | CX_TEST_ASSERT(iter.queue_last == NULL); | |
795 | } | |
796 | } | |
797 | ||
798 | CX_TEST(test_tree_visitor_no_children) { | |
799 | tree_node root = {0}; | |
800 | ||
801 | 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
|
802 | CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node)); |
845 | 803 | unsigned chk = 0; |
804 | cx_foreach(tree_node*, node, iter) { | |
805 | CX_TEST_ASSERT(node == iter.node); | |
806 | chk++; | |
807 | } | |
808 | CX_TEST_ASSERT(iter.counter == 1); | |
809 | CX_TEST_ASSERT(chk == 1); | |
810 | CX_TEST_ASSERT(iter.queue_next == NULL); | |
811 | CX_TEST_ASSERT(iter.queue_last == NULL); | |
812 | } | |
813 | } | |
814 | ||
815 | CX_TEST(test_tree_visitor_no_branching) { | |
816 | tree_node root = {0}; | |
817 | tree_node a = {0}; | |
818 | tree_node b = {0}; | |
819 | tree_node c = {0}; | |
820 | ||
821 | tree_node* expected_order[] = { | |
822 | &root, &a, &b, &c | |
823 | }; | |
824 | tree_node* actual_order[4]; | |
825 | ||
826 | cx_tree_link(&root, &a, tree_node_layout); | |
827 | cx_tree_link(&a, &b, tree_node_layout); | |
828 | cx_tree_link(&b, &c, tree_node_layout); | |
829 | ||
830 | 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
|
831 | CxTreeVisitor iter = cx_tree_visitor(&root, tree_children(tree_node)); |
845 | 832 | unsigned chk = 0; |
833 | cx_foreach(tree_node*, node, iter) { | |
834 | CX_TEST_ASSERT(node == iter.node); | |
835 | CX_TEST_ASSERT(node->data == 0); | |
836 | node->data++; | |
837 | actual_order[chk] = node; | |
838 | chk++; | |
839 | } | |
840 | CX_TEST_ASSERT(iter.counter == 4); | |
841 | CX_TEST_ASSERT(chk == 4); | |
842 | CX_TEST_ASSERT(iter.queue_next == NULL); | |
843 | CX_TEST_ASSERT(iter.queue_last == NULL); | |
844 | for (unsigned i = 0 ; i < chk ; i++) { | |
845 | CX_TEST_ASSERT(actual_order[i] == expected_order[i]); | |
846 | CX_TEST_ASSERT(actual_order[i]->data == 1); | |
847 | } | |
848 | } | |
849 | } | |
850 | ||
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
851 | CX_TEST(test_tree_visitor_continue) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
852 | tree_node root = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
853 | tree_node a = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
854 | tree_node b = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
855 | tree_node c = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
856 | tree_node aa = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
857 | tree_node ab = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
858 | tree_node ba = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
859 | tree_node ca = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
860 | tree_node cb = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
861 | tree_node cc = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
862 | tree_node cba = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
863 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
864 | tree_node* expected_order[] = { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
865 | &root, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
866 | &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
|
867 | &aa, &ab, &ba |
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
868 | }; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
869 | 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
|
870 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
871 | cx_tree_link(&root, &a, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
872 | cx_tree_link(&root, &b, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
873 | cx_tree_link(&root, &c, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
874 | cx_tree_link(&a, &aa, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
875 | cx_tree_link(&a, &ab, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
876 | cx_tree_link(&b, &ba, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
877 | cx_tree_link(&c, &ca, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
878 | cx_tree_link(&c, &cb, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
879 | cx_tree_link(&c, &cc, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
880 | cx_tree_link(&cb, &cba, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
881 | 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
|
882 | 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
|
883 | unsigned chk = 0; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
884 | cx_foreach(tree_node*, node, iter) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
885 | CX_TEST_ASSERT(node->data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
886 | node->data++; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
887 | actual_order[chk] = node; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
888 | chk++; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
889 | CX_TEST_ASSERT(node == iter.node); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
890 | if (node == &root) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
891 | CX_TEST_ASSERT(iter.depth == 1); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
892 | } else if (node == &a || node == &b || node == &c) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
893 | CX_TEST_ASSERT(iter.depth == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
894 | } else { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
895 | CX_TEST_ASSERT(iter.depth == 3); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
896 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
897 | if (node == &c) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
898 | cxTreeVisitorContinue(iter); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
899 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
900 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
901 | CX_TEST_ASSERT(iter.counter == 7); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
902 | CX_TEST_ASSERT(chk == 7); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
903 | for (unsigned i = 0 ; i < chk ; i++) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
904 | 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
|
905 | CX_TEST_ASSERT(actual_order[i]->data == 1); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
906 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
907 | CX_TEST_ASSERT(ca.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
908 | CX_TEST_ASSERT(cb.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
909 | CX_TEST_ASSERT(cc.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
910 | CX_TEST_ASSERT(cba.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
911 | CX_TEST_ASSERT(iter.queue_next == NULL); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
912 | CX_TEST_ASSERT(iter.queue_last == NULL); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
913 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
914 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
915 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
916 | CX_TEST(test_tree_iterator_continue) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
917 | tree_node root = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
918 | tree_node a = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
919 | tree_node b = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
920 | tree_node c = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
921 | tree_node aa = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
922 | tree_node ab = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
923 | tree_node ba = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
924 | tree_node ca = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
925 | tree_node cb = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
926 | tree_node cc = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
927 | tree_node cba = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
928 | |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
929 | tree_node *expected_order[] = { |
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
930 | &root, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
854
diff
changeset
|
931 | &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
|
932 | &b, &ba, |
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
933 | &c, |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
934 | }; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
935 | 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
|
936 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
937 | cx_tree_link(&root, &a, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
938 | cx_tree_link(&root, &b, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
939 | cx_tree_link(&root, &c, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
940 | cx_tree_link(&a, &aa, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
941 | cx_tree_link(&a, &ab, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
942 | cx_tree_link(&b, &ba, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
943 | cx_tree_link(&c, &ca, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
944 | cx_tree_link(&c, &cb, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
945 | cx_tree_link(&c, &cc, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
946 | cx_tree_link(&cb, &cba, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
947 | 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
|
948 | 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
|
949 | unsigned chk = 0; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
950 | cx_foreach(tree_node*, node, iter) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
951 | CX_TEST_ASSERT(node->data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
952 | node->data++; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
953 | actual_order[chk] = node; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
954 | chk++; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
955 | CX_TEST_ASSERT(node == iter.node); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
956 | CX_TEST_ASSERT(!iter.exiting); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
957 | if (node == &root) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
958 | CX_TEST_ASSERT(iter.depth == 1); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
959 | } else if (node == &a || node == &b || node == &c) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
960 | CX_TEST_ASSERT(iter.depth == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
961 | } else { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
962 | CX_TEST_ASSERT(iter.depth == 3); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
963 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
964 | if (node == &c) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
965 | cxTreeIteratorContinue(iter); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
966 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
967 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
968 | CX_TEST_ASSERT(iter.counter == 7); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
969 | CX_TEST_ASSERT(chk == 7); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
970 | for (unsigned i = 0 ; i < chk ; i++) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
971 | 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
|
972 | CX_TEST_ASSERT(actual_order[i]->data == 1); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
973 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
974 | CX_TEST_ASSERT(ca.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
975 | CX_TEST_ASSERT(cb.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
976 | CX_TEST_ASSERT(cc.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
977 | CX_TEST_ASSERT(cba.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
978 | CX_TEST_ASSERT(iter.stack == NULL); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
979 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
980 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
981 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
982 | CX_TEST(test_tree_iterator_continue_with_exit) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
983 | tree_node root = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
984 | tree_node a = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
985 | tree_node b = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
986 | tree_node c = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
987 | tree_node aa = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
988 | tree_node ab = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
989 | tree_node ba = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
990 | tree_node ca = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
991 | tree_node cb = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
992 | tree_node cc = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
993 | tree_node cba = {0}; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
994 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
995 | cx_tree_link(&root, &a, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
996 | cx_tree_link(&root, &b, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
997 | cx_tree_link(&root, &c, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
998 | cx_tree_link(&a, &aa, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
999 | cx_tree_link(&a, &ab, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1000 | cx_tree_link(&b, &ba, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1001 | cx_tree_link(&c, &ca, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1002 | cx_tree_link(&c, &cb, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1003 | cx_tree_link(&c, &cc, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1004 | cx_tree_link(&cb, &cba, tree_node_layout); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1005 | 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
|
1006 | 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
|
1007 | unsigned chk = 0; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1008 | cx_foreach(tree_node*, node, iter) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1009 | CX_TEST_ASSERT(iter.exiting || node->data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1010 | node->data++; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1011 | chk++; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1012 | CX_TEST_ASSERT(node == iter.node); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1013 | if (node == &root) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1014 | CX_TEST_ASSERT(iter.depth == 1); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1015 | } else if (node == &a || node == &b || node == &c) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1016 | CX_TEST_ASSERT(iter.depth == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1017 | } else { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1018 | CX_TEST_ASSERT(iter.depth == 3); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1019 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1020 | if (node == &c) { |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1021 | cxTreeIteratorContinue(iter); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1022 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1023 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1024 | CX_TEST_ASSERT(iter.counter == 7); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1025 | CX_TEST_ASSERT(chk == 14); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1026 | CX_TEST_ASSERT(iter.stack == NULL); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1027 | CX_TEST_ASSERT(root.data == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1028 | CX_TEST_ASSERT(a.data == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1029 | CX_TEST_ASSERT(b.data == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1030 | CX_TEST_ASSERT(c.data == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1031 | CX_TEST_ASSERT(aa.data == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1032 | CX_TEST_ASSERT(ab.data == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1033 | CX_TEST_ASSERT(ba.data == 2); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1034 | CX_TEST_ASSERT(ca.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1035 | CX_TEST_ASSERT(cb.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1036 | CX_TEST_ASSERT(cc.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1037 | CX_TEST_ASSERT(cba.data == 0); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1038 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1039 | } |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1040 | |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1041 | CX_TEST(test_tree_add_one) { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1042 | CxTestingAllocator talloc; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1043 | cx_testing_allocator_init(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1044 | CxAllocator *alloc = &talloc.base; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1045 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1046 | tree_node_file root = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1047 | root.path = "/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1048 | tree_node_file usr = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1049 | usr.path = "/usr/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1050 | 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
|
1051 | tree_node_file home = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1052 | home.path = "/home/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1053 | 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
|
1054 | tree_node_file lib = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1055 | lib.path = "/usr/lib/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1056 | 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
|
1057 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1058 | 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
|
1059 | 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
|
1060 | int result; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1061 | result = cx_tree_add( |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1062 | "/home/foo/", |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1063 | tree_node_file_search, |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1064 | create_tree_node_file, alloc, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1065 | (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
|
1066 | tree_node_file_layout |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1067 | ); |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1068 | 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
|
1069 | 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
|
1070 | 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
|
1071 | void *failed; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1072 | 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
|
1073 | bar_path, 1, sizeof(const char *), |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1074 | tree_node_file_search, |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1075 | create_tree_node_file, alloc, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1076 | &failed, &root, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1077 | tree_node_file_layout |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1078 | ); |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1079 | 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
|
1080 | 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
|
1081 | 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
|
1082 | CX_TEST_ASSERT(bar != NULL); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1083 | 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
|
1084 | CX_TEST_ASSERT(bar->path == bar_path); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1085 | CX_TEST_ASSERT(foo->parent == &home); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1086 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1087 | 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
|
1088 | 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
|
1089 | "newroot", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1090 | tree_node_file_search, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1091 | create_tree_node_file, alloc, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1092 | (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
|
1093 | 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
|
1094 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1095 | 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
|
1096 | 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
|
1097 | 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
|
1098 | CX_TEST_ASSERT(new_node->parent == NULL); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1099 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1100 | 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
|
1101 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1102 | 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
|
1103 | 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
|
1104 | cxFree(alloc, new_node); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1105 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1106 | CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1107 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1108 | cx_testing_allocator_destroy(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1109 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1110 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1111 | CX_TEST(test_tree_add_one_existing) { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1112 | CxTestingAllocator talloc; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1113 | cx_testing_allocator_init(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1114 | CxAllocator *alloc = &talloc.base; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1115 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1116 | tree_node_file root = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1117 | root.path = "/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1118 | tree_node_file usr = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1119 | usr.path = "/usr/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1120 | 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
|
1121 | tree_node_file home = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1122 | home.path = "/home/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1123 | 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
|
1124 | tree_node_file lib = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1125 | lib.path = "/usr/lib/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1126 | 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
|
1127 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1128 | CX_TEST_DO { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1129 | 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
|
1130 | int result = cx_tree_add( |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1131 | "/usr/lib/", |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1132 | tree_node_file_search, |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1133 | create_tree_node_file, alloc, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1134 | (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
|
1135 | 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
|
1136 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1137 | 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
|
1138 | 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
|
1139 | 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
|
1140 | 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
|
1141 | 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
|
1142 | 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
|
1143 | 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
|
1144 | 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
|
1145 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1146 | 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
|
1147 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1148 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1149 | 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
|
1150 | 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
|
1151 | 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
|
1152 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1153 | 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
|
1154 | 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
|
1155 | 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
|
1156 | "/usr/lib/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1157 | tree_node_file_search, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1158 | create_tree_node_file, NULL, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1159 | (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
|
1160 | tree_node_file_layout |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1161 | ); |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1162 | 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
|
1163 | 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
|
1164 | 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
|
1165 | 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
|
1166 | free(node); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1167 | node = NULL; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1168 | 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
|
1169 | "/", 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
|
1170 | tree_node_file_search, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1171 | create_tree_node_file, NULL, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1172 | (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
|
1173 | 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
|
1174 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1175 | 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
|
1176 | 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
|
1177 | 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
|
1178 | 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
|
1179 | free(node); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1180 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1181 | } |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1182 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1183 | 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
|
1184 | 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
|
1185 | root.path = "/"; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1186 | 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
|
1187 | 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
|
1188 | 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
|
1189 | "/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1190 | tree_node_file_search, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1191 | create_tree_node_file, NULL, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1192 | (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
|
1193 | 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
|
1194 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1195 | 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
|
1196 | 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
|
1197 | CX_TEST_ASSERT(node->parent == &root); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1198 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1199 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1200 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1201 | 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
|
1202 | CxTestingAllocator talloc; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1203 | 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
|
1204 | 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
|
1205 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1206 | 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
|
1207 | root.path = "/"; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1208 | 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
|
1209 | void *failed; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1210 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1211 | 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
|
1212 | (void *) 0xc0ffee, 0, sizeof(void *), |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1213 | tree_node_file_search, |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1214 | create_tree_node_file, 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 | &failed, &root, tree_node_file_layout |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1216 | ); |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1217 | 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
|
1218 | 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
|
1219 | CX_TEST_ASSERT(talloc.alloc_total == 0); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1220 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1221 | 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
|
1222 | 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
|
1223 | cxIteratorRef(iter), |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1224 | tree_node_file_search, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1225 | create_tree_node_file, alloc, |
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, 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
|
1227 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1228 | 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
|
1229 | CX_TEST_ASSERT(failed == NULL); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1230 | 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
|
1231 | |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1232 | CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1233 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1234 | cx_testing_allocator_destroy(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1235 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1236 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1237 | CX_TEST(test_tree_add_many) { |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1238 | // adds many elements to an existing tree |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1239 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1240 | CxTestingAllocator talloc; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1241 | cx_testing_allocator_init(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1242 | CxAllocator *alloc = &talloc.base; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1243 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1244 | tree_node_file root = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1245 | root.path = "/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1246 | tree_node_file usr = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1247 | usr.path = "/usr/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1248 | 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
|
1249 | tree_node_file home = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1250 | home.path = "/home/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1251 | 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
|
1252 | tree_node_file lib = {0}; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1253 | lib.path = "/usr/lib/"; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1254 | 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
|
1255 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1256 | 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
|
1257 | void *failed; |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1258 | |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
1259 | const char *paths[] = { |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1260 | "/home/foo/", |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1261 | "/home/foo/bar", |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1262 | "/usr/lib64/", |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1263 | "/usr/lib/foo.so" |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1264 | }; |
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 | 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
|
1267 | paths, 4, sizeof(const char *), |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1268 | tree_node_file_search, |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1269 | create_tree_node_file, alloc, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1270 | &failed, &root, tree_node_file_layout |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1271 | ); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1272 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1273 | CX_TEST_ASSERT(failed == NULL); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1274 | CX_TEST_ASSERT(processed == 4); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1275 | CX_TEST_ASSERT(talloc.alloc_total == 4); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1276 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1277 | CX_TEST_ASSERT(home.children == home.last_child); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1278 | tree_node_file *foo = home.children; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1279 | 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
|
1280 | CX_TEST_ASSERT(foo->children == foo->last_child); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1281 | tree_node_file *bar = foo->children; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1282 | 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
|
1283 | CX_TEST_ASSERT(usr.children != usr.last_child); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1284 | tree_node_file *lib64 = usr.last_child; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1285 | CX_TEST_ASSERT(lib64 != NULL); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1286 | CX_TEST_ASSERT(lib64->path == paths[2]); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1287 | CX_TEST_ASSERT(lib64->prev == &lib); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1288 | CX_TEST_ASSERT(lib64->parent == &usr); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1289 | CX_TEST_ASSERT(lib.children != NULL); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1290 | tree_node_file *libfoo = lib.children; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1291 | 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
|
1292 | |
871
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, foo); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1294 | 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
|
1295 | 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
|
1296 | 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
|
1297 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1298 | 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
|
1299 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1300 | 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
|
1301 | } |
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(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
|
1304 | CxTestingAllocator talloc; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1305 | 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
|
1306 | 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
|
1307 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1308 | 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
|
1309 | 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
|
1310 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1311 | 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
|
1312 | 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
|
1313 | |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
1314 | 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
|
1315 | "/mnt/sdcard/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1316 | "/mnt/foo/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1317 | "/mnt/sdcard/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1318 | "/home/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1319 | "/usr/" |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1320 | }; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1321 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1322 | 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
|
1323 | 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
|
1324 | tree_node_file_search, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1325 | create_tree_node_file, alloc, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1326 | (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
|
1327 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1328 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1329 | 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
|
1330 | 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
|
1331 | 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
|
1332 | 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
|
1333 | 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
|
1334 | 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
|
1335 | |
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_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
|
1337 | 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
|
1338 | 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
|
1339 | 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
|
1340 | 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
|
1341 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1342 | 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
|
1343 | &root, true, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1344 | 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
|
1345 | 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
|
1346 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1347 | 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
|
1348 | 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
|
1349 | 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
|
1350 | 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
|
1351 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1352 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1353 | } |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1354 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1355 | CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1356 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1357 | cx_testing_allocator_destroy(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1358 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1359 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1360 | 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
|
1361 | 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
|
1362 | 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
|
1363 | root.path = "/"; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1364 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1365 | void *failed; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1366 | 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
|
1367 | 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
|
1368 | tree_node_file_search, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1369 | create_tree_node_file, alloc, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1370 | &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
|
1371 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1372 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1373 | 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
|
1374 | 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
|
1375 | |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
1376 | 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
|
1377 | "/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1378 | "/usr/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1379 | "/usr/lib/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1380 | "/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
|
1381 | "/home/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1382 | "/home/foo/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1383 | "/var/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1384 | "/var/www/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1385 | "/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
|
1386 | "/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
|
1387 | "/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
|
1388 | }; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1389 | 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
|
1390 | 1, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1391 | 2, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1392 | 3, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1393 | 4, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1394 | 2, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1395 | 3, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1396 | 2, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1397 | 3, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1398 | 4, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1399 | 5, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1400 | 6 |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1401 | }; |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1402 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1403 | 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
|
1404 | &root, true, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1405 | 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
|
1406 | 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
|
1407 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1408 | 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
|
1409 | 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
|
1410 | 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
|
1411 | 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
|
1412 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1413 | } else { |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1414 | 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
|
1415 | 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
|
1416 | 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
|
1417 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1418 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1419 | } |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1420 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1421 | 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
|
1422 | // 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
|
1423 | |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1424 | CxTestingAllocator talloc; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1425 | cx_testing_allocator_init(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1426 | CxAllocator *alloc = &talloc.base; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1427 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1428 | CX_TEST_DO { |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
1429 | 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
|
1430 | "/usr/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1431 | "/home/", |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1432 | "/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
|
1433 | "/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
|
1434 | "/var/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1435 | "/var/www/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1436 | "/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
|
1437 | "/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
|
1438 | "/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
|
1439 | "/home/foo/" |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1440 | }; |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1441 | |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
1442 | 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
|
1443 | "/usr/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1444 | "/home/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1445 | "/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
|
1446 | "/usr/lib/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1447 | "/var/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1448 | "/var/www/", |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1449 | "/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
|
1450 | "/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
|
1451 | "/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
|
1452 | "/home/foo/" |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1453 | }; |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1454 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1455 | // 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
|
1456 | // 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
|
1457 | 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
|
1458 | paths); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1459 | 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
|
1460 | scrambled_paths); |
866
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1461 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1462 | CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1463 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1464 | cx_testing_allocator_destroy(&talloc); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1465 | } |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1466 | |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1467 | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1468 | 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
|
1469 | 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
|
1470 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1471 | 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
|
1472 | 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
|
1473 | 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
|
1474 | 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
|
1475 | 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
|
1476 | 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
|
1477 | 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
|
1478 | 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
|
1479 | cx_test_register(suite, test_tree_search); |
836
2672a2f79484
implement basic (enter only) tree iterator
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
1480 | cx_test_register(suite, test_tree_iterator_create_and_dispose); |
838
1ce90ab4fab9
add visit_on_exit to iterator implementation
Mike Becker <universe@uap-core.de>
parents:
837
diff
changeset
|
1481 | 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
|
1482 | 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
|
1483 | 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
|
1484 | cx_test_register(suite, test_tree_iterator_free_nodes); |
845 | 1485 | cx_test_register(suite, test_tree_visitor); |
1486 | cx_test_register(suite, test_tree_visitor_no_children); | |
1487 | 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
|
1488 | cx_test_register(suite, test_tree_visitor_continue); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1489 | cx_test_register(suite, test_tree_iterator_continue); |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
847
diff
changeset
|
1490 | 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
|
1491 | cx_test_register(suite, test_tree_add_one); |
1f636de4a63f
complete cx_tree_add() implementations
Mike Becker <universe@uap-core.de>
parents:
862
diff
changeset
|
1492 | 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
|
1493 | 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
|
1494 | 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
|
1495 | 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
|
1496 | cx_test_register(suite, test_tree_add_many); |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
866
diff
changeset
|
1497 | 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
|
1498 | 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
|
1499 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1500 | return suite; |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1501 | } |