Sun, 06 Oct 2024 13:44:26 +0200
add test for creating an iterator over an empty tree
tests/test_tree.c | file | annotate | diff | comparison | revisions |
--- a/tests/test_tree.c Sun Oct 06 13:41:26 2024 +0200 +++ b/tests/test_tree.c Sun Oct 06 13:44:26 2024 +0200 @@ -488,6 +488,27 @@ } } +CX_TEST(test_tree_iterator_create_for_empty_tree) { + CX_TEST_DO { + CxTreeIterator iter = cx_tree_iterator(NULL, false, tree_children(tree_node)); + CX_TEST_ASSERT(!iter.visit_on_exit); + CX_TEST_ASSERT(!iter.exiting); + CX_TEST_ASSERT(iter.counter == 0); + CX_TEST_ASSERT(iter.node == NULL); + CX_TEST_ASSERT(!iter.base.mutating); + CX_TEST_ASSERT(!iter.base.remove); + CX_TEST_ASSERT(iter.stack == NULL); + CX_TEST_ASSERT(iter.stack_capacity == 0); + CX_TEST_ASSERT(iter.stack_size == 0); + CX_TEST_ASSERT(iter.depth == 0); + CX_TEST_ASSERT(iter.loc_next == offsetof(tree_node, next)); + CX_TEST_ASSERT(iter.loc_children == offsetof(tree_node, children)); + CX_TEST_ASSERT(!cxIteratorValid(iter)); + // disposing this iterator should also be harmless + cxTreeIteratorDispose(&iter); + } +} + CX_TEST(test_tree_iterator_basic_only_enter) { tree_node root = {0}; tree_node a = {0}; @@ -1894,7 +1915,6 @@ CX_TEST_ASSERT(relinked_lib->parent == tree->root); CX_TEST_ASSERT(NULL != cxTreeFind(tree, "/home/")); - cxTreeDestroy(tree); // all memory should be free when using destroy instead of remove CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); @@ -1975,6 +1995,7 @@ cx_test_register(suite, test_tree2_unlink); cx_test_register(suite, test_tree_search); cx_test_register(suite, test_tree_iterator_create_and_dispose); + cx_test_register(suite, test_tree_iterator_create_for_empty_tree); cx_test_register(suite, test_tree_iterator_basic_only_enter); cx_test_register(suite, test_tree_iterator_basic_enter_and_exit); cx_test_register(suite, test_tree_iterator_xml);