summaryrefslogtreecommitdiff
path: root/tests/libfstree/gen_inode_numbers.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-05 15:53:21 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-06 22:08:36 +0100
commitb950412ca3a91aa37349cf51ebe98cc84767d448 (patch)
treee3bb062114d019984321a5a21b29818c88c36795 /tests/libfstree/gen_inode_numbers.c
parent3fc6bf24b5cc071fc323f08ece541e37578f6369 (diff)
Cleanup: add some structure to the test directory
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libfstree/gen_inode_numbers.c')
-rw-r--r--tests/libfstree/gen_inode_numbers.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/libfstree/gen_inode_numbers.c b/tests/libfstree/gen_inode_numbers.c
new file mode 100644
index 0000000..8ee2315
--- /dev/null
+++ b/tests/libfstree/gen_inode_numbers.c
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * gen_inode_table.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "../test.h"
+
+static tree_node_t *gen_node(tree_node_t *parent, const char *name)
+{
+ struct stat sb;
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFDIR | 0755;
+
+ return fstree_mknode(parent, name, strlen(name), NULL, &sb);
+}
+
+static void check_children_before_root(tree_node_t *root)
+{
+ tree_node_t *n;
+
+ for (n = root->data.dir.children; n != NULL; n = n->next)
+ TEST_LESS_THAN_UI(n->inode_num, root->inode_num);
+
+ for (n = root->data.dir.children; n != NULL; n = n->next)
+ check_children_before_root(n);
+}
+
+static void check_children_continuous(tree_node_t *root)
+{
+ tree_node_t *n;
+
+ for (n = root->data.dir.children; n != NULL; n = n->next) {
+ if (n->next != NULL) {
+ TEST_EQUAL_UI(n->next->inode_num, (n->inode_num + 1));
+ }
+ }
+
+ for (n = root->data.dir.children; n != NULL; n = n->next)
+ check_children_continuous(n);
+}
+
+int main(void)
+{
+ tree_node_t *a, *b, *c;
+ fstree_t fs;
+
+ // inode table for the empty tree
+ TEST_ASSERT(fstree_init(&fs, NULL) == 0);
+ fstree_post_process(&fs);
+ TEST_EQUAL_UI(fs.unique_inode_count, 1);
+ TEST_EQUAL_UI(fs.root->inode_num, 1);
+ fstree_cleanup(&fs);
+
+ // tree with 2 levels under root, fan out 3
+ TEST_ASSERT(fstree_init(&fs, NULL) == 0);
+
+ a = gen_node(fs.root, "a");
+ b = gen_node(fs.root, "b");
+ c = gen_node(fs.root, "c");
+ TEST_NOT_NULL(a);
+ TEST_NOT_NULL(b);
+ TEST_NOT_NULL(c);
+
+ TEST_NOT_NULL(gen_node(a, "a_a"));
+ TEST_NOT_NULL(gen_node(a, "a_b"));
+ TEST_NOT_NULL(gen_node(a, "a_c"));
+
+ TEST_NOT_NULL(gen_node(b, "b_a"));
+ TEST_NOT_NULL(gen_node(b, "b_b"));
+ TEST_NOT_NULL(gen_node(b, "b_c"));
+
+ TEST_NOT_NULL(gen_node(c, "c_a"));
+ TEST_NOT_NULL(gen_node(c, "c_b"));
+ TEST_NOT_NULL(gen_node(c, "c_c"));
+
+ fstree_post_process(&fs);
+ TEST_EQUAL_UI(fs.unique_inode_count, 13);
+
+ check_children_before_root(fs.root);
+ check_children_continuous(fs.root);
+
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}