1.1 --- a/test/test_tree.c Tue Sep 28 18:49:12 2021 +0200 1.2 +++ b/test/test_tree.c Sun Oct 03 10:43:31 2021 +0200 1.3 @@ -40,11 +40,9 @@ 1.4 1.5 TestNode *children_begin; 1.6 TestNode *children_end; 1.7 - 1.8 - int content; 1.9 }; 1.10 1.11 -void test_cx_tree_add_node() { 1.12 +void test_cx_tree_add_node(void) { 1.13 // prepare test tree 1.14 TestNode root; 1.15 memset(&root, 0, sizeof(TestNode)); 1.16 @@ -54,8 +52,7 @@ 1.17 root.children_begin = &a; 1.18 root.children_end = &a; 1.19 a.parent = &root; 1.20 - a.content = 1; 1.21 - 1.22 + 1.23 // new test nodes 1.24 TestNode b; 1.25 memset(&b, 0, sizeof(TestNode)); 1.26 @@ -63,24 +60,22 @@ 1.27 memset(&c, 0, sizeof(TestNode)); 1.28 1.29 // test 1.30 - b.content = 2; 1.31 int ret = cx_tree_add_node(&a, offsetof(TestNode, parent), offsetof(TestNode, prev), offsetof(TestNode, next), &b); 1.32 - CU_ASSERT_EQUAL(ret, 0); 1.33 - CU_ASSERT_PTR_EQUAL(b.parent, &root); 1.34 - CU_ASSERT_PTR_EQUAL(b.prev, &a); 1.35 - CU_ASSERT_PTR_EQUAL(b.next, NULL); 1.36 - CU_ASSERT_PTR_EQUAL(a.next, &b); 1.37 + CU_ASSERT_EQUAL(ret, 0) 1.38 + CU_ASSERT_PTR_EQUAL(b.parent, &root) 1.39 + CU_ASSERT_PTR_EQUAL(b.prev, &a) 1.40 + CU_ASSERT_PTR_NULL(b.next) 1.41 + CU_ASSERT_PTR_EQUAL(a.next, &b) 1.42 1.43 - c.content = 3; 1.44 ret = cx_tree_add_node(&a, -1, -1, offsetof(TestNode, next), &c); 1.45 - CU_ASSERT_EQUAL(ret, 0); 1.46 - CU_ASSERT_PTR_EQUAL(c.parent, NULL); 1.47 - CU_ASSERT_PTR_EQUAL(c.prev, NULL); 1.48 - CU_ASSERT_PTR_EQUAL(c.next, NULL); 1.49 - CU_ASSERT_PTR_EQUAL(b.next, &c); 1.50 + CU_ASSERT_EQUAL(ret, 0) 1.51 + CU_ASSERT_PTR_NULL(c.parent) 1.52 + CU_ASSERT_PTR_NULL(c.prev) 1.53 + CU_ASSERT_PTR_NULL(c.next) 1.54 + CU_ASSERT_PTR_EQUAL(b.next, &c) 1.55 } 1.56 1.57 -void test_cx_tree_add_child_node() { 1.58 +void test_cx_tree_add_child_node(void) { 1.59 // prepare test tree 1.60 TestNode root; 1.61 memset(&root, 0, sizeof(TestNode)); 1.62 @@ -97,7 +92,6 @@ 1.63 int ret; 1.64 1.65 // test 1.66 - a.content = 1; 1.67 ret = cx_tree_add_child_node( 1.68 &root, 1.69 offsetof(TestNode, parent), 1.70 @@ -106,14 +100,13 @@ 1.71 (void**)&root.children_begin, 1.72 (void**)&root.children_end, 1.73 &a); 1.74 - CU_ASSERT_EQUAL(ret, 0); 1.75 - CU_ASSERT_PTR_EQUAL(root.children_begin, &a); 1.76 - CU_ASSERT_PTR_EQUAL(root.children_end, &a); 1.77 - CU_ASSERT_PTR_EQUAL(a.parent, &root); 1.78 - CU_ASSERT_PTR_EQUAL(a.prev, NULL); 1.79 - CU_ASSERT_PTR_EQUAL(a.next, NULL); 1.80 - 1.81 - b.content = 2; 1.82 + CU_ASSERT_EQUAL(ret, 0) 1.83 + CU_ASSERT_PTR_EQUAL(root.children_begin, &a) 1.84 + CU_ASSERT_PTR_EQUAL(root.children_end, &a) 1.85 + CU_ASSERT_PTR_EQUAL(a.parent, &root) 1.86 + CU_ASSERT_PTR_NULL(a.prev) 1.87 + CU_ASSERT_PTR_NULL(a.next) 1.88 + 1.89 ret = cx_tree_add_child_node( 1.90 &root, 1.91 offsetof(TestNode, parent), 1.92 @@ -122,13 +115,13 @@ 1.93 (void**)&root.children_begin, 1.94 (void**)&root.children_end, 1.95 &b); 1.96 - CU_ASSERT_EQUAL(ret, 0); 1.97 - CU_ASSERT_TRUE(root.children_begin ? root.children_begin->next == &b : 0); 1.98 - CU_ASSERT_PTR_EQUAL(root.children_end, &b); 1.99 - CU_ASSERT_PTR_EQUAL(b.parent, &root); 1.100 - CU_ASSERT_PTR_EQUAL(b.prev, &a); 1.101 + CU_ASSERT_EQUAL(ret, 0) 1.102 + CU_ASSERT_PTR_NOT_NULL(root.children_begin) 1.103 + CU_ASSERT_PTR_EQUAL(root.children_begin->next, &b) 1.104 + CU_ASSERT_PTR_EQUAL(root.children_end, &b) 1.105 + CU_ASSERT_PTR_EQUAL(b.parent, &root) 1.106 + CU_ASSERT_PTR_EQUAL(b.prev, &a) 1.107 1.108 - c.content = 3; 1.109 ret = cx_tree_add_child_node( 1.110 &root, 1.111 -1, 1.112 @@ -137,14 +130,13 @@ 1.113 (void**)&root.children_begin, 1.114 NULL, 1.115 &c); 1.116 - CU_ASSERT_EQUAL(ret, 0); 1.117 - CU_ASSERT_PTR_EQUAL(root.children_end, &b); // children_end unchanged 1.118 - CU_ASSERT_PTR_EQUAL(b.next, &c); 1.119 - CU_ASSERT_PTR_EQUAL(c.prev, NULL); 1.120 - CU_ASSERT_PTR_EQUAL(c.next, NULL); 1.121 - CU_ASSERT_PTR_EQUAL(c.parent, NULL); 1.122 + CU_ASSERT_EQUAL(ret, 0) 1.123 + CU_ASSERT_PTR_EQUAL(root.children_end, &b) // children_end unchanged 1.124 + CU_ASSERT_PTR_EQUAL(b.next, &c) 1.125 + CU_ASSERT_PTR_NULL(c.prev) 1.126 + CU_ASSERT_PTR_NULL(c.next) 1.127 + CU_ASSERT_PTR_NULL(c.parent) 1.128 1.129 - a1.content = 11; 1.130 ret = cx_tree_add_child_node( 1.131 &a, 1.132 offsetof(TestNode, parent), 1.133 @@ -156,7 +148,8 @@ 1.134 CU_ASSERT_EQUAL(ret, 0); 1.135 CU_ASSERT_PTR_EQUAL(a.children_begin, &a1); 1.136 CU_ASSERT_PTR_EQUAL(a1.parent, &a); 1.137 - CU_ASSERT_TRUE(root.children_begin ? root.children_begin->children_begin == &a1 : 0); 1.138 + CU_ASSERT_PTR_NOT_NULL(root.children_begin) 1.139 + CU_ASSERT_PTR_EQUAL(root.children_begin->children_begin, &a1) 1.140 } 1.141 1.142 int main() {