test/test_tree.c

changeset 453
bb144d08cd44
parent 449
68ad5750ba6b
child 455
8168e16cd1e9
equal deleted inserted replaced
452:a10c3e127050 453:bb144d08cd44
58 memset(&b, 0, sizeof(TestNode)); 58 memset(&b, 0, sizeof(TestNode));
59 TestNode c; 59 TestNode c;
60 memset(&c, 0, sizeof(TestNode)); 60 memset(&c, 0, sizeof(TestNode));
61 61
62 // test 62 // test
63 int ret = cx_tree_add_node(&a, offsetof(TestNode, parent), offsetof(TestNode, prev), offsetof(TestNode, next), &b); 63 cx_tree_add_sibling(&a, offsetof(TestNode, prev), offsetof(TestNode, next), offsetof(TestNode, parent), &b);
64 CU_ASSERT_EQUAL(ret, 0)
65 CU_ASSERT_PTR_EQUAL(b.parent, &root) 64 CU_ASSERT_PTR_EQUAL(b.parent, &root)
66 CU_ASSERT_PTR_EQUAL(b.prev, &a) 65 CU_ASSERT_PTR_EQUAL(b.prev, &a)
67 CU_ASSERT_PTR_NULL(b.next) 66 CU_ASSERT_PTR_NULL(b.next)
68 CU_ASSERT_PTR_EQUAL(a.next, &b) 67 CU_ASSERT_PTR_EQUAL(a.next, &b)
69 68
70 ret = cx_tree_add_node(&a, -1, -1, offsetof(TestNode, next), &c); 69 cx_tree_add_sibling(&a, -1, offsetof(TestNode, next), -1, &c);
71 CU_ASSERT_EQUAL(ret, 0)
72 CU_ASSERT_PTR_NULL(c.parent) 70 CU_ASSERT_PTR_NULL(c.parent)
73 CU_ASSERT_PTR_NULL(c.prev) 71 CU_ASSERT_PTR_NULL(c.prev)
74 CU_ASSERT_PTR_NULL(c.next) 72 CU_ASSERT_PTR_NULL(c.next)
75 CU_ASSERT_PTR_EQUAL(b.next, &c) 73 CU_ASSERT_PTR_EQUAL(b.next, &c)
76 } 74 }
87 TestNode c; 85 TestNode c;
88 memset(&c, 0, sizeof(TestNode)); 86 memset(&c, 0, sizeof(TestNode));
89 TestNode a1; 87 TestNode a1;
90 memset(&a1, 0, sizeof(TestNode)); 88 memset(&a1, 0, sizeof(TestNode));
91 89
92 int ret;
93
94 // test 90 // test
95 ret = cx_tree_add_child_node( 91 cx_tree_add_child(
96 &root, 92 (void **) &root.children_begin,
97 offsetof(TestNode, parent), 93 (void **) &root.children_end,
98 offsetof(TestNode, prev), 94 offsetof(TestNode, prev),
99 offsetof(TestNode, next), 95 offsetof(TestNode, next),
100 (void**)&root.children_begin, 96 &a,
101 (void**)&root.children_end, 97 offsetof(TestNode, parent),
102 &a); 98 &root);
103 CU_ASSERT_EQUAL(ret, 0)
104 CU_ASSERT_PTR_EQUAL(root.children_begin, &a) 99 CU_ASSERT_PTR_EQUAL(root.children_begin, &a)
105 CU_ASSERT_PTR_EQUAL(root.children_end, &a) 100 CU_ASSERT_PTR_EQUAL(root.children_end, &a)
106 CU_ASSERT_PTR_EQUAL(a.parent, &root) 101 CU_ASSERT_PTR_EQUAL(a.parent, &root)
107 CU_ASSERT_PTR_NULL(a.prev) 102 CU_ASSERT_PTR_NULL(a.prev)
108 CU_ASSERT_PTR_NULL(a.next) 103 CU_ASSERT_PTR_NULL(a.next)
109 104
110 ret = cx_tree_add_child_node( 105 cx_tree_add_child(
111 &root, 106 (void **) &root.children_begin,
112 offsetof(TestNode, parent), 107 (void **) &root.children_end,
113 offsetof(TestNode, prev), 108 offsetof(TestNode, prev),
114 offsetof(TestNode, next), 109 offsetof(TestNode, next),
115 (void**)&root.children_begin, 110 &b,
116 (void**)&root.children_end, 111 offsetof(TestNode, parent),
117 &b); 112 &root);
118 CU_ASSERT_EQUAL(ret, 0)
119 CU_ASSERT_PTR_NOT_NULL(root.children_begin) 113 CU_ASSERT_PTR_NOT_NULL(root.children_begin)
120 CU_ASSERT_PTR_EQUAL(root.children_begin->next, &b) 114 CU_ASSERT_PTR_EQUAL(root.children_begin->next, &b)
121 CU_ASSERT_PTR_EQUAL(root.children_end, &b) 115 CU_ASSERT_PTR_EQUAL(root.children_end, &b)
122 CU_ASSERT_PTR_EQUAL(b.parent, &root) 116 CU_ASSERT_PTR_EQUAL(b.parent, &root)
123 CU_ASSERT_PTR_EQUAL(b.prev, &a) 117 CU_ASSERT_PTR_EQUAL(b.prev, &a)
124 118
125 ret = cx_tree_add_child_node( 119 cx_tree_add_child(
126 &root, 120 (void **) &root.children_begin,
127 -1, 121 NULL,
128 -1, 122 -1,
129 offsetof(TestNode, next), 123 offsetof(TestNode, next),
130 (void**)&root.children_begin, 124 &c,
131 NULL, 125 -1,
132 &c); 126 &root);
133 CU_ASSERT_EQUAL(ret, 0)
134 CU_ASSERT_PTR_EQUAL(root.children_end, &b) // children_end unchanged 127 CU_ASSERT_PTR_EQUAL(root.children_end, &b) // children_end unchanged
135 CU_ASSERT_PTR_EQUAL(b.next, &c) 128 CU_ASSERT_PTR_EQUAL(b.next, &c)
136 CU_ASSERT_PTR_NULL(c.prev) 129 CU_ASSERT_PTR_NULL(c.prev)
137 CU_ASSERT_PTR_NULL(c.next) 130 CU_ASSERT_PTR_NULL(c.next)
138 CU_ASSERT_PTR_NULL(c.parent) 131 CU_ASSERT_PTR_NULL(c.parent)
139 132
140 ret = cx_tree_add_child_node( 133 cx_tree_add_child(
141 &a, 134 (void **) &a.children_begin,
142 offsetof(TestNode, parent), 135 (void **) &a.children_end,
143 offsetof(TestNode, prev), 136 offsetof(TestNode, prev),
144 offsetof(TestNode, next), 137 offsetof(TestNode, next),
145 (void**)&a.children_begin, 138 &a1,
146 (void**)&a.children_end, 139 offsetof(TestNode, parent),
147 &a1); 140 &a);
148 CU_ASSERT_EQUAL(ret, 0);
149 CU_ASSERT_PTR_EQUAL(a.children_begin, &a1); 141 CU_ASSERT_PTR_EQUAL(a.children_begin, &a1);
150 CU_ASSERT_PTR_EQUAL(a1.parent, &a); 142 CU_ASSERT_PTR_EQUAL(a1.parent, &a);
151 CU_ASSERT_PTR_NOT_NULL(root.children_begin) 143 CU_ASSERT_PTR_NOT_NULL(root.children_begin)
152 CU_ASSERT_PTR_EQUAL(root.children_begin->children_begin, &a1) 144 CU_ASSERT_PTR_EQUAL(root.children_begin->children_begin, &a1)
153 } 145 }

mercurial