static void manual_cleanup(MBIt_AVLnode *node) { if (node == NULL) return; if (node->data != NULL) free(node->data); manual_cleanup(node->child[AVL_LEFT]); manual_cleanup(node->child[AVL_RIGHT]); }
void test_avl_walk(void) { int i, rc; MBIt_AVLtree *tree = NULL; /* test NULL tree */ rc = MBI_AVLtree_walk(tree, &walkfunc); CU_ASSERT_EQUAL(rc, AVL_ERR_INVALID); /* create tree */ tree = MBI_AVLtree_create(); CU_ASSERT_PTR_NOT_NULL_FATAL(tree); CU_ASSERT_EQUAL(tree->count, 0); CU_ASSERT_PTR_NULL(tree->root); /* test empty tree */ rc = MBI_AVLtree_walk(tree, &walkfunc); CU_ASSERT_EQUAL(rc, AVL_SUCCESS); /* add nodes */ for (i = 0; i < TEST_AVL_TREESIZE; i++) { MBI_AVLtree_insert(tree, i, malloc(10)); } /* walk the tree */ rc = MBI_AVLtree_walk(tree, &walkfunc); CU_ASSERT_EQUAL(rc, AVL_SUCCESS); /* check results manually */ manual_walk(tree->root); /* clean up */ manual_cleanup(tree->root); /* destroy tree */ MBI_AVLtree_destroy(&tree); CU_ASSERT_PTR_NULL(tree); }
~manual() { manual_cleanup(data_); }