tests/test_tree.c

changeset 906
b51e5268bd9b
parent 905
39aa4f106a71
child 907
1f72fb9af87e
equal deleted inserted replaced
905:39aa4f106a71 906:b51e5268bd9b
1787 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 1787 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
1788 } 1788 }
1789 cx_testing_allocator_destroy(&talloc); 1789 cx_testing_allocator_destroy(&talloc);
1790 } 1790 }
1791 1791
1792 static void test_tree_high_simple_destructor_func(void *node) {
1793 ((tree_node *)node)->data++;
1794 }
1795
1796 CX_TEST(test_tree_high_simple_destructor) {
1797 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0};
1798 cx_tree_link(&root, &child1, tree_node_layout);
1799 cx_tree_link(&root, &child2, tree_node_layout);
1800 cx_tree_link(&child1, &child3, tree_node_layout);
1801 CX_TEST_DO {
1802 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout);
1803 tree->simple_destructor = test_tree_high_simple_destructor_func;
1804 cxTreeDestroy(tree);
1805 CX_TEST_ASSERT(root.data == 1);
1806 CX_TEST_ASSERT(child1.data == 1);
1807 CX_TEST_ASSERT(child2.data == 1);
1808 CX_TEST_ASSERT(child3.data == 1);
1809 }
1810 }
1811
1792 CxTestSuite *cx_test_suite_tree_low_level(void) { 1812 CxTestSuite *cx_test_suite_tree_low_level(void) {
1793 CxTestSuite *suite = cx_test_suite_new("tree (low level)"); 1813 CxTestSuite *suite = cx_test_suite_new("tree (low level)");
1794 1814
1795 cx_test_register(suite, test_tree_link_new_child); 1815 cx_test_register(suite, test_tree_link_new_child);
1796 cx_test_register(suite, test_tree_link_add_child); 1816 cx_test_register(suite, test_tree_link_add_child);
1833 cx_test_register(suite, test_tree_high_create_wrapped); 1853 cx_test_register(suite, test_tree_high_create_wrapped);
1834 cx_test_register(suite, test_tree_high_tree_depth); 1854 cx_test_register(suite, test_tree_high_tree_depth);
1835 cx_test_register(suite, test_tree_high_insert_one); 1855 cx_test_register(suite, test_tree_high_insert_one);
1836 cx_test_register(suite, test_tree_high_insert_many); 1856 cx_test_register(suite, test_tree_high_insert_many);
1837 cx_test_register(suite, test_tree_high_add_find_remove_nodes); 1857 cx_test_register(suite, test_tree_high_add_find_remove_nodes);
1858 cx_test_register(suite, test_tree_high_simple_destructor);
1838 1859
1839 return suite; 1860 return suite;
1840 } 1861 }

mercurial