add test for simple destructor in trees - fixes #436

Sat, 05 Oct 2024 14:16:01 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 05 Oct 2024 14:16:01 +0200
changeset 906
b51e5268bd9b
parent 905
39aa4f106a71
child 907
1f72fb9af87e

add test for simple destructor in trees - fixes #436

tests/test_tree.c file | annotate | diff | comparison | revisions
--- a/tests/test_tree.c	Thu Oct 03 17:39:21 2024 +0200
+++ b/tests/test_tree.c	Sat Oct 05 14:16:01 2024 +0200
@@ -1789,6 +1789,26 @@
     cx_testing_allocator_destroy(&talloc);
 }
 
+static void test_tree_high_simple_destructor_func(void *node) {
+    ((tree_node *)node)->data++;
+}
+
+CX_TEST(test_tree_high_simple_destructor) {
+    tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0};
+    cx_tree_link(&root, &child1, tree_node_layout);
+    cx_tree_link(&root, &child2, tree_node_layout);
+    cx_tree_link(&child1, &child3, tree_node_layout);
+    CX_TEST_DO {
+        CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout);
+        tree->simple_destructor = test_tree_high_simple_destructor_func;
+        cxTreeDestroy(tree);
+        CX_TEST_ASSERT(root.data == 1);
+        CX_TEST_ASSERT(child1.data == 1);
+        CX_TEST_ASSERT(child2.data == 1);
+        CX_TEST_ASSERT(child3.data == 1);
+    }
+}
+
 CxTestSuite *cx_test_suite_tree_low_level(void) {
     CxTestSuite *suite = cx_test_suite_new("tree (low level)");
 
@@ -1835,6 +1855,7 @@
     cx_test_register(suite, test_tree_high_insert_one);
     cx_test_register(suite, test_tree_high_insert_many);
     cx_test_register(suite, test_tree_high_add_find_remove_nodes);
+    cx_test_register(suite, test_tree_high_simple_destructor);
 
     return suite;
 }

mercurial