test/test_tree.c

Sun, 03 Oct 2021 12:02:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 03 Oct 2021 12:02:57 +0200
changeset 450
7960298039cf
parent 449
68ad5750ba6b
child 453
bb144d08cd44
permissions
-rw-r--r--

improves usage of attributes

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

mercurial