1770 CX_TEST_ASSERT(tree->loc_next == offsetof(tree_node_file, next)); |
1770 CX_TEST_ASSERT(tree->loc_next == offsetof(tree_node_file, next)); |
1771 |
1771 |
1772 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
1772 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
1773 CX_TEST_ASSERT(talloc.alloc_total == 1); |
1773 CX_TEST_ASSERT(talloc.alloc_total == 1); |
1774 |
1774 |
1775 cxTreeDestroy(tree); |
1775 cxTreeFree(tree); |
1776 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1776 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1777 } |
1777 } |
1778 cx_testing_allocator_destroy(&talloc); |
1778 cx_testing_allocator_destroy(&talloc); |
1779 } |
1779 } |
1780 |
1780 |
1799 CX_TEST_ASSERT(tree->loc_parent == offsetof(struct cx_tree_node_base_s, parent)); |
1799 CX_TEST_ASSERT(tree->loc_parent == offsetof(struct cx_tree_node_base_s, parent)); |
1800 CX_TEST_ASSERT(tree->loc_children == offsetof(struct cx_tree_node_base_s, children)); |
1800 CX_TEST_ASSERT(tree->loc_children == offsetof(struct cx_tree_node_base_s, children)); |
1801 CX_TEST_ASSERT(tree->loc_last_child == offsetof(struct cx_tree_node_base_s, last_child)); |
1801 CX_TEST_ASSERT(tree->loc_last_child == offsetof(struct cx_tree_node_base_s, last_child)); |
1802 CX_TEST_ASSERT(tree->loc_prev == offsetof(struct cx_tree_node_base_s, prev)); |
1802 CX_TEST_ASSERT(tree->loc_prev == offsetof(struct cx_tree_node_base_s, prev)); |
1803 CX_TEST_ASSERT(tree->loc_next == offsetof(struct cx_tree_node_base_s, next)); |
1803 CX_TEST_ASSERT(tree->loc_next == offsetof(struct cx_tree_node_base_s, next)); |
1804 cxTreeDestroy(tree); |
1804 cxTreeFree(tree); |
1805 } |
1805 } |
1806 } |
1806 } |
1807 |
1807 |
1808 CX_TEST(test_tree_high_create_wrapped) { |
1808 CX_TEST(test_tree_high_create_wrapped) { |
1809 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0}; |
1809 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0}; |
1825 CX_TEST_ASSERT(tree->loc_parent == offsetof(tree_node, parent)); |
1825 CX_TEST_ASSERT(tree->loc_parent == offsetof(tree_node, parent)); |
1826 CX_TEST_ASSERT(tree->loc_children == offsetof(tree_node, children)); |
1826 CX_TEST_ASSERT(tree->loc_children == offsetof(tree_node, children)); |
1827 CX_TEST_ASSERT(tree->loc_last_child == -1); |
1827 CX_TEST_ASSERT(tree->loc_last_child == -1); |
1828 CX_TEST_ASSERT(tree->loc_prev == offsetof(tree_node, prev)); |
1828 CX_TEST_ASSERT(tree->loc_prev == offsetof(tree_node, prev)); |
1829 CX_TEST_ASSERT(tree->loc_next == offsetof(tree_node, next)); |
1829 CX_TEST_ASSERT(tree->loc_next == offsetof(tree_node, next)); |
1830 cxTreeDestroy(tree); |
1830 cxTreeFree(tree); |
1831 } |
1831 } |
1832 } |
1832 } |
1833 |
1833 |
1834 CX_TEST(test_tree_high_tree_depth) { |
1834 CX_TEST(test_tree_high_tree_depth) { |
1835 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0}; |
1835 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0}; |
1850 tree_node_file_search, |
1850 tree_node_file_search, |
1851 tree_node_file_search_data, |
1851 tree_node_file_search_data, |
1852 tree_node_file_layout |
1852 tree_node_file_layout |
1853 ); |
1853 ); |
1854 CX_TEST_ASSERT(cxTreeDepth(empty) == 0); |
1854 CX_TEST_ASSERT(cxTreeDepth(empty) == 0); |
1855 cxTreeDestroy(empty); |
1855 cxTreeFree(empty); |
1856 } |
1856 } |
1857 cxTreeDestroy(tree); |
1857 cxTreeFree(tree); |
1858 } |
1858 } |
1859 |
1859 |
1860 CX_TEST(test_tree_high_set_parent) { |
1860 CX_TEST(test_tree_high_set_parent) { |
1861 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0}; |
1861 tree_node root = {0}, child1 = {0}, child2 = {0}, child3 = {0}; |
1862 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout); |
1862 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout); |
1882 tree_node_file_search, |
1882 tree_node_file_search, |
1883 tree_node_file_search_data, |
1883 tree_node_file_search_data, |
1884 tree_node_file_layout |
1884 tree_node_file_layout |
1885 ); |
1885 ); |
1886 CX_TEST_ASSERT(cxTreeDepth(empty) == 0); |
1886 CX_TEST_ASSERT(cxTreeDepth(empty) == 0); |
1887 cxTreeDestroy(empty); |
1887 cxTreeFree(empty); |
1888 } |
1888 } |
1889 cxTreeDestroy(tree); |
1889 cxTreeFree(tree); |
1890 } |
1890 } |
1891 |
1891 |
1892 CX_TEST(test_tree_high_insert_one) { |
1892 CX_TEST(test_tree_high_insert_one) { |
1893 CxTestingAllocator talloc; |
1893 CxTestingAllocator talloc; |
1894 cx_testing_allocator_init(&talloc); |
1894 cx_testing_allocator_init(&talloc); |
1914 CX_TEST_ASSERT(tree->size == 6); |
1914 CX_TEST_ASSERT(tree->size == 6); |
1915 |
1915 |
1916 CX_TEST_ASSERT(talloc.alloc_total == 8); |
1916 CX_TEST_ASSERT(talloc.alloc_total == 8); |
1917 CX_TEST_ASSERT(talloc.free_total == 1); // the one that could not be added |
1917 CX_TEST_ASSERT(talloc.free_total == 1); // the one that could not be added |
1918 |
1918 |
1919 cxTreeDestroy(tree); |
1919 cxTreeFree(tree); |
1920 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1920 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1921 } |
1921 } |
1922 cx_testing_allocator_destroy(&talloc); |
1922 cx_testing_allocator_destroy(&talloc); |
1923 } |
1923 } |
1924 |
1924 |
1947 CX_TEST_ASSERT(tree->size == 6); |
1947 CX_TEST_ASSERT(tree->size == 6); |
1948 |
1948 |
1949 CX_TEST_ASSERT(talloc.alloc_total == 8); |
1949 CX_TEST_ASSERT(talloc.alloc_total == 8); |
1950 CX_TEST_ASSERT(talloc.free_total == 1); // the one that could not be added |
1950 CX_TEST_ASSERT(talloc.free_total == 1); // the one that could not be added |
1951 |
1951 |
1952 cxTreeDestroy(tree); |
1952 cxTreeFree(tree); |
1953 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1953 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
1954 } |
1954 } |
1955 cx_testing_allocator_destroy(&talloc); |
1955 cx_testing_allocator_destroy(&talloc); |
1956 } |
1956 } |
1957 |
1957 |
2042 CX_TEST_ASSERT(relinked_lib != NULL); |
2042 CX_TEST_ASSERT(relinked_lib != NULL); |
2043 CX_TEST_ASSERT(relinked_lib->parent == tree->root); |
2043 CX_TEST_ASSERT(relinked_lib->parent == tree->root); |
2044 CX_TEST_ASSERT(NULL != cxTreeFind(tree, "/home/")); |
2044 CX_TEST_ASSERT(NULL != cxTreeFind(tree, "/home/")); |
2045 |
2045 |
2046 |
2046 |
2047 cxTreeDestroy(tree); |
2047 cxTreeFree(tree); |
2048 // we are not done yet, because we need to free the removed stuff |
2048 // we are not done yet, because we need to free the removed stuff |
2049 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
2049 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
2050 |
2050 |
2051 cxFree(alloc, usr); |
2051 cxFree(alloc, usr); |
2052 // for the subtree, we use a little trick and wrap it in a new tree |
2052 // for the subtree, we use a little trick and wrap it in a new tree |
2053 CxTree *foo_tree = cxTreeCreateWrapped(alloc, foo, tree_node_file_layout); |
2053 CxTree *foo_tree = cxTreeCreateWrapped(alloc, foo, tree_node_file_layout); |
2054 foo_tree->allocator = alloc; |
2054 foo_tree->allocator = alloc; |
2055 foo_tree->advanced_destructor = (cx_destructor_func2 ) cxFree; |
2055 foo_tree->advanced_destructor = (cx_destructor_func2 ) cxFree; |
2056 foo_tree->destructor_data = alloc; |
2056 foo_tree->destructor_data = alloc; |
2057 cxTreeDestroy(foo_tree); |
2057 cxTreeFree(foo_tree); |
2058 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
2058 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
2059 } |
2059 } |
2060 cx_testing_allocator_destroy(&talloc); |
2060 cx_testing_allocator_destroy(&talloc); |
2061 } |
2061 } |
2062 |
2062 |
2127 CX_TEST_ASSERT(relinked_share->parent == tree->root); |
2127 CX_TEST_ASSERT(relinked_share->parent == tree->root); |
2128 CX_TEST_ASSERT(relinked_lib != NULL); |
2128 CX_TEST_ASSERT(relinked_lib != NULL); |
2129 CX_TEST_ASSERT(relinked_lib->parent == tree->root); |
2129 CX_TEST_ASSERT(relinked_lib->parent == tree->root); |
2130 CX_TEST_ASSERT(NULL != cxTreeFind(tree, "/home/")); |
2130 CX_TEST_ASSERT(NULL != cxTreeFind(tree, "/home/")); |
2131 |
2131 |
2132 cxTreeDestroy(tree); |
2132 cxTreeFree(tree); |
2133 // all memory should be free when using destroy instead of remove |
2133 // all memory should be free when using destroy instead of remove |
2134 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
2134 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
2135 } |
2135 } |
2136 cx_testing_allocator_destroy(&talloc); |
2136 cx_testing_allocator_destroy(&talloc); |
2137 } |
2137 } |
2166 CX_TEST_ASSERT(tree->size == 6); |
2166 CX_TEST_ASSERT(tree->size == 6); |
2167 cxTreeRemoveSubtree(tree, root); |
2167 cxTreeRemoveSubtree(tree, root); |
2168 CX_TEST_ASSERT(tree->size == 0); |
2168 CX_TEST_ASSERT(tree->size == 0); |
2169 CX_TEST_ASSERT(tree->root == NULL); |
2169 CX_TEST_ASSERT(tree->root == NULL); |
2170 CX_TEST_ASSERT(cxTreeDepth(tree) == 0); |
2170 CX_TEST_ASSERT(cxTreeDepth(tree) == 0); |
2171 cxTreeDestroy(tree); |
2171 cxTreeFree(tree); |
2172 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
2172 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
2173 CxTree *w = cxTreeCreateWrapped(alloc, root, tree_node_file_layout); |
2173 CxTree *w = cxTreeCreateWrapped(alloc, root, tree_node_file_layout); |
2174 w->advanced_destructor = (cx_destructor_func2) cxFree; |
2174 w->advanced_destructor = (cx_destructor_func2) cxFree; |
2175 w->destructor_data = alloc; |
2175 w->destructor_data = alloc; |
2176 cxTreeDestroySubtree(w, w->root); |
2176 cxTreeDestroySubtree(w, w->root); |
2177 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
2177 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); |
2178 cxTreeDestroy(w); |
2178 cxTreeFree(w); |
2179 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
2179 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
2180 } |
2180 } |
2181 cx_testing_allocator_destroy(&talloc); |
2181 cx_testing_allocator_destroy(&talloc); |
2182 } |
2182 } |
2183 |
2183 |
2192 cx_tree_link(&child1, &child3, tree_node_layout); |
2192 cx_tree_link(&child1, &child3, tree_node_layout); |
2193 CX_TEST_DO { |
2193 CX_TEST_DO { |
2194 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout); |
2194 CxTree *tree = cxTreeCreateWrapped(cxDefaultAllocator, &root, tree_node_layout); |
2195 tree->simple_destructor = test_tree_high_simple_destructor_func; |
2195 tree->simple_destructor = test_tree_high_simple_destructor_func; |
2196 cxTreeDestroyNode(tree, &child1, NULL); |
2196 cxTreeDestroyNode(tree, &child1, NULL); |
2197 cxTreeDestroy(tree); |
2197 cxTreeFree(tree); |
2198 CX_TEST_ASSERT(root.data == 1); |
2198 CX_TEST_ASSERT(root.data == 1); |
2199 CX_TEST_ASSERT(child1.data == 1); |
2199 CX_TEST_ASSERT(child1.data == 1); |
2200 CX_TEST_ASSERT(child2.data == 1); |
2200 CX_TEST_ASSERT(child2.data == 1); |
2201 CX_TEST_ASSERT(child3.data == 1); |
2201 CX_TEST_ASSERT(child3.data == 1); |
2202 } |
2202 } |