tests/test_tree.c

changeset 1295
b00c6ae1441a
parent 1183
86d386c0cf75
equal deleted inserted replaced
1294:30d7ae76c76a 1295:b00c6ae1441a
1907 result |= cxTreeInsert(tree, "/home/"); 1907 result |= cxTreeInsert(tree, "/home/");
1908 result |= cxTreeInsert(tree, "/usr/lib/"); 1908 result |= cxTreeInsert(tree, "/usr/lib/");
1909 result |= cxTreeInsert(tree, "/home/foo/"); 1909 result |= cxTreeInsert(tree, "/home/foo/");
1910 CX_TEST_ASSERT(result == 0); 1910 CX_TEST_ASSERT(result == 0);
1911 CX_TEST_ASSERT(1 == cxTreeInsertArray(tree, "/home/foo/bar/", sizeof(const char*), 1)); 1911 CX_TEST_ASSERT(1 == cxTreeInsertArray(tree, "/home/foo/bar/", sizeof(const char*), 1));
1912 CX_TEST_ASSERT(tree->size == 6); 1912 CX_TEST_ASSERT(cxTreeSize(tree) == 6);
1913 CX_TEST_ASSERT(0 != cxTreeInsert(tree, "newroot")); 1913 CX_TEST_ASSERT(0 != cxTreeInsert(tree, "newroot"));
1914 CX_TEST_ASSERT(tree->size == 6); 1914 CX_TEST_ASSERT(cxTreeSize(tree) == 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 cxTreeFree(tree); 1919 cxTreeFree(tree);
1942 "/home/foo/", 1942 "/home/foo/",
1943 "/home/foo/bar/", 1943 "/home/foo/bar/",
1944 "newroot" 1944 "newroot"
1945 }; 1945 };
1946 CX_TEST_ASSERT(6 == cxTreeInsertArray(tree, paths, sizeof(const char*), 7)); 1946 CX_TEST_ASSERT(6 == cxTreeInsertArray(tree, paths, sizeof(const char*), 7));
1947 CX_TEST_ASSERT(tree->size == 6); 1947 CX_TEST_ASSERT(cxTreeSize(tree) == 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 cxTreeFree(tree); 1952 cxTreeFree(tree);
1994 tree_node_file *foo = cxTreeFind(tree, "/home/foo/"); 1994 tree_node_file *foo = cxTreeFind(tree, "/home/foo/");
1995 CX_TEST_ASSERT(NULL != foo); 1995 CX_TEST_ASSERT(NULL != foo);
1996 CX_TEST_ASSERT(0 == strcmp("/home/foo/", foo->path)); 1996 CX_TEST_ASSERT(0 == strcmp("/home/foo/", foo->path));
1997 CX_TEST_ASSERT(NULL != foo->parent); 1997 CX_TEST_ASSERT(NULL != foo->parent);
1998 CX_TEST_ASSERT(0 == strcmp("/home/", foo->parent->path)); 1998 CX_TEST_ASSERT(0 == strcmp("/home/", foo->parent->path));
1999 CX_TEST_ASSERT(tree->size == 6); 1999 CX_TEST_ASSERT(cxTreeSize(tree) == 6);
2000 2000
2001 CX_TEST_ASSERT(0 == cxTreeAddChild(tree, foo->parent, "/home/baz/")); 2001 CX_TEST_ASSERT(0 == cxTreeAddChild(tree, foo->parent, "/home/baz/"));
2002 tree_node_file *baz = cxTreeFind(tree, "/home/baz/"); 2002 tree_node_file *baz = cxTreeFind(tree, "/home/baz/");
2003 CX_TEST_ASSERT(NULL != baz); 2003 CX_TEST_ASSERT(NULL != baz);
2004 CX_TEST_ASSERT(0 == strcmp("/home/baz/", baz->path)); 2004 CX_TEST_ASSERT(0 == strcmp("/home/baz/", baz->path));
2005 CX_TEST_ASSERT(NULL != baz->parent); 2005 CX_TEST_ASSERT(NULL != baz->parent);
2006 CX_TEST_ASSERT(0 == strcmp("/home/", baz->parent->path)); 2006 CX_TEST_ASSERT(0 == strcmp("/home/", baz->parent->path));
2007 CX_TEST_ASSERT(tree->size == 7); 2007 CX_TEST_ASSERT(cxTreeSize(tree) == 7);
2008 2008
2009 tree_node_file *home = cxTreeFind(tree, "/home/"); 2009 tree_node_file *home = cxTreeFind(tree, "/home/");
2010 CX_TEST_ASSERT(NULL == cxTreeFindInSubtree(tree, "/usr/", foo, 0)); 2010 CX_TEST_ASSERT(NULL == cxTreeFindInSubtree(tree, "/usr/", foo, 0));
2011 tree_node_file *bar = cxTreeFindInSubtree(tree, "/home/foo/bar/", home, 0); 2011 tree_node_file *bar = cxTreeFindInSubtree(tree, "/home/foo/bar/", home, 0);
2012 CX_TEST_ASSERT(NULL != bar); 2012 CX_TEST_ASSERT(NULL != bar);
2015 2015
2016 tree_node_file *share = cxCalloc(alloc, 1, sizeof(tree_node_file)); 2016 tree_node_file *share = cxCalloc(alloc, 1, sizeof(tree_node_file));
2017 share->path = "/usr/share/"; 2017 share->path = "/usr/share/";
2018 tree_node_file *usr = cxTreeFind(tree, "/usr/"); 2018 tree_node_file *usr = cxTreeFind(tree, "/usr/");
2019 cxTreeAddChildNode(tree, usr, share); 2019 cxTreeAddChildNode(tree, usr, share);
2020 CX_TEST_ASSERT(tree->size == 8); 2020 CX_TEST_ASSERT(cxTreeSize(tree) == 8);
2021 2021
2022 cxTreeRemoveSubtree(tree, foo); 2022 cxTreeRemoveSubtree(tree, foo);
2023 CX_TEST_ASSERT(tree->size == 6); 2023 CX_TEST_ASSERT(cxTreeSize(tree) == 6);
2024 CX_TEST_ASSERT(foo->children == bar); 2024 CX_TEST_ASSERT(foo->children == bar);
2025 CX_TEST_ASSERT(foo->last_child == bar); 2025 CX_TEST_ASSERT(foo->last_child == bar);
2026 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/")); 2026 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/"));
2027 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/bar/")); 2027 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/bar/"));
2028 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/bar/")); 2028 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/bar/"));
2029 2029
2030 CX_TEST_ASSERT(0 == cxTreeRemoveNode(tree, usr, test_tree_remove_node_relink_mock)); 2030 CX_TEST_ASSERT(0 == cxTreeRemoveNode(tree, usr, test_tree_remove_node_relink_mock));
2031 CX_TEST_ASSERT(tree->size == 5); 2031 CX_TEST_ASSERT(cxTreeSize(tree) == 5);
2032 CX_TEST_ASSERT(usr->parent == NULL); 2032 CX_TEST_ASSERT(usr->parent == NULL);
2033 CX_TEST_ASSERT(usr->children == NULL); 2033 CX_TEST_ASSERT(usr->children == NULL);
2034 CX_TEST_ASSERT(usr->last_child == NULL); 2034 CX_TEST_ASSERT(usr->last_child == NULL);
2035 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/")); 2035 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/"));
2036 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/lib/")); 2036 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/lib/"));
2085 tree_node_file *foo = cxTreeFind(tree, "/home/foo/"); 2085 tree_node_file *foo = cxTreeFind(tree, "/home/foo/");
2086 CX_TEST_ASSERT(NULL != foo); 2086 CX_TEST_ASSERT(NULL != foo);
2087 CX_TEST_ASSERT(0 == strcmp("/home/foo/", foo->path)); 2087 CX_TEST_ASSERT(0 == strcmp("/home/foo/", foo->path));
2088 CX_TEST_ASSERT(NULL != foo->parent); 2088 CX_TEST_ASSERT(NULL != foo->parent);
2089 CX_TEST_ASSERT(0 == strcmp("/home/", foo->parent->path)); 2089 CX_TEST_ASSERT(0 == strcmp("/home/", foo->parent->path));
2090 CX_TEST_ASSERT(tree->size == 6); 2090 CX_TEST_ASSERT(cxTreeSize(tree) == 6);
2091 2091
2092 CX_TEST_ASSERT(0 == cxTreeAddChild(tree, foo->parent, "/home/baz/")); 2092 CX_TEST_ASSERT(0 == cxTreeAddChild(tree, foo->parent, "/home/baz/"));
2093 tree_node_file *baz = cxTreeFind(tree, "/home/baz/"); 2093 tree_node_file *baz = cxTreeFind(tree, "/home/baz/");
2094 CX_TEST_ASSERT(NULL != baz); 2094 CX_TEST_ASSERT(NULL != baz);
2095 CX_TEST_ASSERT(0 == strcmp("/home/baz/", baz->path)); 2095 CX_TEST_ASSERT(0 == strcmp("/home/baz/", baz->path));
2096 CX_TEST_ASSERT(NULL != baz->parent); 2096 CX_TEST_ASSERT(NULL != baz->parent);
2097 CX_TEST_ASSERT(0 == strcmp("/home/", baz->parent->path)); 2097 CX_TEST_ASSERT(0 == strcmp("/home/", baz->parent->path));
2098 CX_TEST_ASSERT(tree->size == 7); 2098 CX_TEST_ASSERT(cxTreeSize(tree) == 7);
2099 2099
2100 tree_node_file *home = cxTreeFind(tree, "/home/"); 2100 tree_node_file *home = cxTreeFind(tree, "/home/");
2101 CX_TEST_ASSERT(NULL == cxTreeFindInSubtree(tree, "/usr/", foo, 0)); 2101 CX_TEST_ASSERT(NULL == cxTreeFindInSubtree(tree, "/usr/", foo, 0));
2102 tree_node_file *bar = cxTreeFindInSubtree(tree, "/home/foo/bar/", home, 0); 2102 tree_node_file *bar = cxTreeFindInSubtree(tree, "/home/foo/bar/", home, 0);
2103 CX_TEST_ASSERT(NULL != bar); 2103 CX_TEST_ASSERT(NULL != bar);
2106 2106
2107 tree_node_file *share = cxCalloc(alloc, 1, sizeof(tree_node_file)); 2107 tree_node_file *share = cxCalloc(alloc, 1, sizeof(tree_node_file));
2108 share->path = "/usr/share/"; 2108 share->path = "/usr/share/";
2109 tree_node_file *usr = cxTreeFind(tree, "/usr/"); 2109 tree_node_file *usr = cxTreeFind(tree, "/usr/");
2110 cxTreeAddChildNode(tree, usr, share); 2110 cxTreeAddChildNode(tree, usr, share);
2111 CX_TEST_ASSERT(tree->size == 8); 2111 CX_TEST_ASSERT(cxTreeSize(tree) == 8);
2112 2112
2113 cxTreeDestroySubtree(tree, foo); 2113 cxTreeDestroySubtree(tree, foo);
2114 CX_TEST_ASSERT(tree->size == 6); 2114 CX_TEST_ASSERT(cxTreeSize(tree) == 6);
2115 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/")); 2115 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/"));
2116 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/bar/")); 2116 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/foo/bar/"));
2117 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/bar/")); 2117 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/home/bar/"));
2118 2118
2119 CX_TEST_ASSERT(0 == cxTreeDestroyNode(tree, usr, test_tree_remove_node_relink_mock)); 2119 CX_TEST_ASSERT(0 == cxTreeDestroyNode(tree, usr, test_tree_remove_node_relink_mock));
2120 CX_TEST_ASSERT(tree->size == 5); 2120 CX_TEST_ASSERT(cxTreeSize(tree) == 5);
2121 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/")); 2121 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/"));
2122 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/lib/")); 2122 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/lib/"));
2123 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/share/")); 2123 CX_TEST_ASSERT(NULL == cxTreeFind(tree, "/usr/share/"));
2124 tree_node_file *relinked_share = cxTreeFind(tree, "/share/"); 2124 tree_node_file *relinked_share = cxTreeFind(tree, "/share/");
2125 tree_node_file *relinked_lib = cxTreeFind(tree, "/lib/"); 2125 tree_node_file *relinked_lib = cxTreeFind(tree, "/lib/");
2158 }; 2158 };
2159 cxTreeInsertArray(tree, paths, sizeof(const char*), 6); 2159 cxTreeInsertArray(tree, paths, sizeof(const char*), 6);
2160 void *root = tree->root; 2160 void *root = tree->root;
2161 CX_TEST_ASSERT(0 != cxTreeRemoveNode(tree, root, NULL)); 2161 CX_TEST_ASSERT(0 != cxTreeRemoveNode(tree, root, NULL));
2162 CX_TEST_ASSERT(tree->root == root); 2162 CX_TEST_ASSERT(tree->root == root);
2163 CX_TEST_ASSERT(tree->size == 6); 2163 CX_TEST_ASSERT(cxTreeSize(tree) == 6);
2164 CX_TEST_ASSERT(0 != cxTreeDestroyNode(tree, root, NULL)); 2164 CX_TEST_ASSERT(0 != cxTreeDestroyNode(tree, root, NULL));
2165 CX_TEST_ASSERT(tree->root == root); 2165 CX_TEST_ASSERT(tree->root == root);
2166 CX_TEST_ASSERT(tree->size == 6); 2166 CX_TEST_ASSERT(cxTreeSize(tree) == 6);
2167 cxTreeRemoveSubtree(tree, root); 2167 cxTreeRemoveSubtree(tree, root);
2168 CX_TEST_ASSERT(tree->size == 0); 2168 CX_TEST_ASSERT(cxTreeSize(tree) == 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 cxTreeFree(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);

mercurial