summaryrefslogtreecommitdiff
path: root/tests/libfstree
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-10-16 21:50:40 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-03-30 22:31:30 +0200
commite5fa9d585ed090602bcc045689046702199def86 (patch)
tree2b391a68d67972686db86f5d44a90a416695c058 /tests/libfstree
parent5e54880a2db2aeb7a6c301a69ee2bef9a09a237f (diff)
Cleanup: remove node sorting from libfstree
Always insert the tree nodes in the correct oder and remove the post-process sorting step. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libfstree')
-rw-r--r--tests/libfstree/fstree_sort.c89
-rw-r--r--tests/libfstree/mknode_dir.c6
2 files changed, 40 insertions, 55 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;
}
diff --git a/tests/libfstree/mknode_dir.c b/tests/libfstree/mknode_dir.c
index 900edaa..63e01c1 100644
--- a/tests/libfstree/mknode_dir.c
+++ b/tests/libfstree/mknode_dir.c
@@ -48,10 +48,10 @@ int main(int argc, char **argv)
TEST_ASSERT(a->parent == root);
TEST_ASSERT(b->parent == root);
TEST_EQUAL_UI(b->link_count, 2);
- TEST_ASSERT(root->data.dir.children == b);
+ TEST_ASSERT(root->data.dir.children == a);
+ TEST_ASSERT(a->next == b);
TEST_EQUAL_UI(root->link_count, 4);
- TEST_ASSERT(b->next == a);
- TEST_NULL(a->next);
+ TEST_NULL(b->next);
TEST_NULL(root->parent);
TEST_NULL(root->next);