diff -r 37c5d2fdb36b -r 68ad5750ba6b test/test_tree.c --- a/test/test_tree.c Tue Sep 28 18:49:12 2021 +0200 +++ b/test/test_tree.c Sun Oct 03 10:43:31 2021 +0200 @@ -40,11 +40,9 @@ TestNode *children_begin; TestNode *children_end; - - int content; }; -void test_cx_tree_add_node() { +void test_cx_tree_add_node(void) { // prepare test tree TestNode root; memset(&root, 0, sizeof(TestNode)); @@ -54,8 +52,7 @@ root.children_begin = &a; root.children_end = &a; a.parent = &root; - a.content = 1; - + // new test nodes TestNode b; memset(&b, 0, sizeof(TestNode)); @@ -63,24 +60,22 @@ memset(&c, 0, sizeof(TestNode)); // test - b.content = 2; int ret = cx_tree_add_node(&a, offsetof(TestNode, parent), offsetof(TestNode, prev), offsetof(TestNode, next), &b); - CU_ASSERT_EQUAL(ret, 0); - CU_ASSERT_PTR_EQUAL(b.parent, &root); - CU_ASSERT_PTR_EQUAL(b.prev, &a); - CU_ASSERT_PTR_EQUAL(b.next, NULL); - CU_ASSERT_PTR_EQUAL(a.next, &b); + CU_ASSERT_EQUAL(ret, 0) + CU_ASSERT_PTR_EQUAL(b.parent, &root) + CU_ASSERT_PTR_EQUAL(b.prev, &a) + CU_ASSERT_PTR_NULL(b.next) + CU_ASSERT_PTR_EQUAL(a.next, &b) - c.content = 3; ret = cx_tree_add_node(&a, -1, -1, offsetof(TestNode, next), &c); - CU_ASSERT_EQUAL(ret, 0); - CU_ASSERT_PTR_EQUAL(c.parent, NULL); - CU_ASSERT_PTR_EQUAL(c.prev, NULL); - CU_ASSERT_PTR_EQUAL(c.next, NULL); - CU_ASSERT_PTR_EQUAL(b.next, &c); + CU_ASSERT_EQUAL(ret, 0) + CU_ASSERT_PTR_NULL(c.parent) + CU_ASSERT_PTR_NULL(c.prev) + CU_ASSERT_PTR_NULL(c.next) + CU_ASSERT_PTR_EQUAL(b.next, &c) } -void test_cx_tree_add_child_node() { +void test_cx_tree_add_child_node(void) { // prepare test tree TestNode root; memset(&root, 0, sizeof(TestNode)); @@ -97,7 +92,6 @@ int ret; // test - a.content = 1; ret = cx_tree_add_child_node( &root, offsetof(TestNode, parent), @@ -106,14 +100,13 @@ (void**)&root.children_begin, (void**)&root.children_end, &a); - CU_ASSERT_EQUAL(ret, 0); - CU_ASSERT_PTR_EQUAL(root.children_begin, &a); - CU_ASSERT_PTR_EQUAL(root.children_end, &a); - CU_ASSERT_PTR_EQUAL(a.parent, &root); - CU_ASSERT_PTR_EQUAL(a.prev, NULL); - CU_ASSERT_PTR_EQUAL(a.next, NULL); - - b.content = 2; + CU_ASSERT_EQUAL(ret, 0) + CU_ASSERT_PTR_EQUAL(root.children_begin, &a) + CU_ASSERT_PTR_EQUAL(root.children_end, &a) + CU_ASSERT_PTR_EQUAL(a.parent, &root) + CU_ASSERT_PTR_NULL(a.prev) + CU_ASSERT_PTR_NULL(a.next) + ret = cx_tree_add_child_node( &root, offsetof(TestNode, parent), @@ -122,13 +115,13 @@ (void**)&root.children_begin, (void**)&root.children_end, &b); - CU_ASSERT_EQUAL(ret, 0); - CU_ASSERT_TRUE(root.children_begin ? root.children_begin->next == &b : 0); - CU_ASSERT_PTR_EQUAL(root.children_end, &b); - CU_ASSERT_PTR_EQUAL(b.parent, &root); - CU_ASSERT_PTR_EQUAL(b.prev, &a); + CU_ASSERT_EQUAL(ret, 0) + CU_ASSERT_PTR_NOT_NULL(root.children_begin) + CU_ASSERT_PTR_EQUAL(root.children_begin->next, &b) + CU_ASSERT_PTR_EQUAL(root.children_end, &b) + CU_ASSERT_PTR_EQUAL(b.parent, &root) + CU_ASSERT_PTR_EQUAL(b.prev, &a) - c.content = 3; ret = cx_tree_add_child_node( &root, -1, @@ -137,14 +130,13 @@ (void**)&root.children_begin, NULL, &c); - CU_ASSERT_EQUAL(ret, 0); - CU_ASSERT_PTR_EQUAL(root.children_end, &b); // children_end unchanged - CU_ASSERT_PTR_EQUAL(b.next, &c); - CU_ASSERT_PTR_EQUAL(c.prev, NULL); - CU_ASSERT_PTR_EQUAL(c.next, NULL); - CU_ASSERT_PTR_EQUAL(c.parent, NULL); + CU_ASSERT_EQUAL(ret, 0) + CU_ASSERT_PTR_EQUAL(root.children_end, &b) // children_end unchanged + CU_ASSERT_PTR_EQUAL(b.next, &c) + CU_ASSERT_PTR_NULL(c.prev) + CU_ASSERT_PTR_NULL(c.next) + CU_ASSERT_PTR_NULL(c.parent) - a1.content = 11; ret = cx_tree_add_child_node( &a, offsetof(TestNode, parent), @@ -156,7 +148,8 @@ CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_PTR_EQUAL(a.children_begin, &a1); CU_ASSERT_PTR_EQUAL(a1.parent, &a); - CU_ASSERT_TRUE(root.children_begin ? root.children_begin->children_begin == &a1 : 0); + CU_ASSERT_PTR_NOT_NULL(root.children_begin) + CU_ASSERT_PTR_EQUAL(root.children_begin->children_begin, &a1) } int main() {