78 CU_ASSERT_PTR_EQUAL(c.prev, NULL); |
78 CU_ASSERT_PTR_EQUAL(c.prev, NULL); |
79 CU_ASSERT_PTR_EQUAL(c.next, NULL); |
79 CU_ASSERT_PTR_EQUAL(c.next, NULL); |
80 CU_ASSERT_PTR_EQUAL(b.next, &c); |
80 CU_ASSERT_PTR_EQUAL(b.next, &c); |
81 } |
81 } |
82 |
82 |
|
83 void test_cx_tree_add_child_node() { |
|
84 // prepare test tree |
|
85 TestNode root; |
|
86 memset(&root, 0, sizeof(TestNode)); |
|
87 |
|
88 TestNode a; |
|
89 memset(&a, 0, sizeof(TestNode)); |
|
90 TestNode b; |
|
91 memset(&b, 0, sizeof(TestNode)); |
|
92 TestNode c; |
|
93 memset(&c, 0, sizeof(TestNode)); |
|
94 TestNode a1; |
|
95 memset(&a1, 0, sizeof(TestNode)); |
|
96 |
|
97 int ret; |
|
98 |
|
99 // test |
|
100 a.content = 1; |
|
101 ret = cx_tree_add_child_node( |
|
102 &root, |
|
103 offsetof(TestNode, parent), |
|
104 offsetof(TestNode, prev), |
|
105 offsetof(TestNode, next), |
|
106 (void**)&root.children_begin, |
|
107 (void**)&root.children_end, |
|
108 &a); |
|
109 CU_ASSERT_EQUAL(ret, 0); |
|
110 CU_ASSERT_PTR_EQUAL(root.children_begin, &a); |
|
111 CU_ASSERT_PTR_EQUAL(root.children_end, &a); |
|
112 CU_ASSERT_PTR_EQUAL(a.parent, &root); |
|
113 CU_ASSERT_PTR_EQUAL(a.prev, NULL); |
|
114 CU_ASSERT_PTR_EQUAL(a.next, NULL); |
|
115 |
|
116 b.content = 2; |
|
117 ret = cx_tree_add_child_node( |
|
118 &root, |
|
119 offsetof(TestNode, parent), |
|
120 offsetof(TestNode, prev), |
|
121 offsetof(TestNode, next), |
|
122 (void**)&root.children_begin, |
|
123 (void**)&root.children_end, |
|
124 &b); |
|
125 CU_ASSERT_EQUAL(ret, 0); |
|
126 CU_ASSERT_TRUE(root.children_begin ? root.children_begin->next == &b : 0); |
|
127 CU_ASSERT_PTR_EQUAL(root.children_end, &b); |
|
128 CU_ASSERT_PTR_EQUAL(b.parent, &root); |
|
129 CU_ASSERT_PTR_EQUAL(b.prev, &a); |
|
130 |
|
131 c.content = 3; |
|
132 ret = cx_tree_add_child_node( |
|
133 &root, |
|
134 -1, |
|
135 -1, |
|
136 offsetof(TestNode, next), |
|
137 (void**)&root.children_begin, |
|
138 NULL, |
|
139 &c); |
|
140 CU_ASSERT_EQUAL(ret, 0); |
|
141 CU_ASSERT_PTR_EQUAL(root.children_end, &b); // children_end unchanged |
|
142 CU_ASSERT_PTR_EQUAL(b.next, &c); |
|
143 CU_ASSERT_PTR_EQUAL(c.prev, NULL); |
|
144 CU_ASSERT_PTR_EQUAL(c.next, NULL); |
|
145 CU_ASSERT_PTR_EQUAL(c.parent, NULL); |
|
146 |
|
147 a1.content = 11; |
|
148 ret = cx_tree_add_child_node( |
|
149 &a, |
|
150 offsetof(TestNode, parent), |
|
151 offsetof(TestNode, prev), |
|
152 offsetof(TestNode, next), |
|
153 (void**)&a.children_begin, |
|
154 (void**)&a.children_end, |
|
155 &a1); |
|
156 CU_ASSERT_EQUAL(ret, 0); |
|
157 CU_ASSERT_PTR_EQUAL(a.children_begin, &a1); |
|
158 CU_ASSERT_PTR_EQUAL(a1.parent, &a); |
|
159 CU_ASSERT_TRUE(root.children_begin ? root.children_begin->children_begin == &a1 : 0); |
|
160 } |
|
161 |
83 int main() { |
162 int main() { |
84 CU_pSuite suite = NULL; |
163 CU_pSuite suite = NULL; |
85 |
164 |
86 if (CUE_SUCCESS != CU_initialize_registry()) { |
165 if (CUE_SUCCESS != CU_initialize_registry()) { |
87 return CU_get_error(); |
166 return CU_get_error(); |