summaryrefslogtreecommitdiff
path: root/tests/libfstree/fstree_sort.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libfstree/fstree_sort.c')
-rw-r--r--tests/libfstree/fstree_sort.c89
1 files changed, 37 insertions, 52 deletions
diff --git a/tests/libfstree/fstree_sort.c b/tests/libfstree/fstree_sort.c
index 618ae9f..6db607d 100644
--- a/tests/libfstree/fstree_sort.c
+++ b/tests/libfstree/fstree_sort.c
@@ -7,7 +7,6 @@
#include "config.h"
#include "fstree.h"
-#include "internal.h"
#include "../test.h"
int main(int argc, char **argv)
@@ -18,86 +17,72 @@ int main(int argc, char **argv)
int ret;
(void)argc; (void)argv;
- memset(&fs, 0, sizeof(fs));
memset(&sb, 0, sizeof(sb));
sb.st_mode = S_IFBLK | 0600;
sb.st_rdev = 1337;
- a = fstree_mknode(NULL, "a", 1, NULL, &sb);
- b = fstree_mknode(NULL, "b", 1, NULL, &sb);
- c = fstree_mknode(NULL, "c", 1, NULL, &sb);
- d = fstree_mknode(NULL, "d", 1, NULL, &sb);
- TEST_ASSERT(a != NULL && b != NULL && c != NULL && d != NULL);
+ /* in order */
+ ret = fstree_init(&fs, NULL);
+ TEST_EQUAL_I(ret, 0);
- /* empty list */
- TEST_NULL(tree_node_list_sort(NULL));
-
- /* single element */
- TEST_ASSERT(tree_node_list_sort(a) == a);
+ a = fstree_mknode(fs.root, "a", 1, NULL, &sb);
+ TEST_NOT_NULL(a);
+ TEST_ASSERT(fs.root->data.dir.children == a);
TEST_NULL(a->next);
- /* two elements, reverse order */
- b->next = a;
- TEST_ASSERT(tree_node_list_sort(b) == a);
- TEST_ASSERT(a->next == b);
- TEST_NULL(b->next);
-
- /* two elements, sorted order */
- TEST_ASSERT(tree_node_list_sort(a) == a);
+ b = fstree_mknode(fs.root, "b", 1, NULL, &sb);
+ TEST_NOT_NULL(a);
+ TEST_ASSERT(fs.root->data.dir.children == a);
TEST_ASSERT(a->next == b);
TEST_NULL(b->next);
- /* three elements, reverse order */
- c->next = b;
- b->next = a;
- a->next = NULL;
-
- TEST_ASSERT(tree_node_list_sort(c) == a);
+ c = fstree_mknode(fs.root, "c", 1, NULL, &sb);
+ TEST_NOT_NULL(c);
+ TEST_ASSERT(fs.root->data.dir.children == a);
TEST_ASSERT(a->next == b);
TEST_ASSERT(b->next == c);
TEST_NULL(c->next);
- /* three elements, ordered */
- TEST_ASSERT(tree_node_list_sort(a) == a);
+ d = fstree_mknode(fs.root, "d", 1, NULL, &sb);
+ TEST_NOT_NULL(d);
+ TEST_ASSERT(fs.root->data.dir.children == a);
TEST_ASSERT(a->next == b);
TEST_ASSERT(b->next == c);
- TEST_NULL(c->next);
+ TEST_ASSERT(c->next == d);
+ TEST_NULL(d->next);
- /* four elements, reverse order */
- d->next = c;
- c->next = b;
- b->next = a;
- a->next = NULL;
+ fstree_cleanup(&fs);
- TEST_ASSERT(tree_node_list_sort(d) == a);
- TEST_ASSERT(a->next == b);
- TEST_ASSERT(b->next == c);
+ /* out-of-order */
+ ret = fstree_init(&fs, NULL);
+ TEST_EQUAL_I(ret, 0);
+
+ d = fstree_mknode(fs.root, "d", 1, NULL, &sb);
+ TEST_NOT_NULL(d);
+ TEST_ASSERT(fs.root->data.dir.children == d);
+ TEST_NULL(d->next);
+
+ c = fstree_mknode(fs.root, "c", 1, NULL, &sb);
+ TEST_NOT_NULL(c);
+ TEST_ASSERT(fs.root->data.dir.children == c);
TEST_ASSERT(c->next == d);
TEST_NULL(d->next);
- /* four elements, sorted order */
- TEST_ASSERT(tree_node_list_sort(a) == a);
- TEST_ASSERT(a->next == b);
+ b = fstree_mknode(fs.root, "b", 1, NULL, &sb);
+ TEST_NOT_NULL(b);
+ TEST_ASSERT(fs.root->data.dir.children == b);
TEST_ASSERT(b->next == c);
TEST_ASSERT(c->next == d);
TEST_NULL(d->next);
- /* force merge sort to go through LRLR pattern */
- b->next = a;
- a->next = d;
- d->next = c;
- c->next = NULL;
-
- TEST_ASSERT(tree_node_list_sort(b) == a);
+ a = fstree_mknode(fs.root, "a", 1, NULL, &sb);
+ TEST_NOT_NULL(a);
+ TEST_ASSERT(fs.root->data.dir.children == a);
TEST_ASSERT(a->next == b);
TEST_ASSERT(b->next == c);
TEST_ASSERT(c->next == d);
TEST_NULL(d->next);
- /* cleanup and done */
- free(a);
- free(b);
- free(c);
- free(d);
+ fstree_cleanup(&fs);
return EXIT_SUCCESS;
}