aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree/test
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 11:30:46 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-31 18:04:25 +0100
commit72c8155d9fc0eaeac72c053f46ebb7b231d4596a (patch)
tree5758865289c52fa93f56e3fe743bb40c283c5233 /lib/fstree/test
parentcdccc69c62579b0c13b35fad0728079652b8f3c9 (diff)
Reintegrate test code with library code
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/test')
-rw-r--r--lib/fstree/test/add_by_path.c134
-rw-r--r--lib/fstree/test/fstree_init.c50
-rw-r--r--lib/fstree/test/fstree_sort.c88
-rw-r--r--lib/fstree/test/gen_inode_numbers.c90
-rw-r--r--lib/fstree/test/get_path.c59
-rw-r--r--lib/fstree/test/mknode_dir.c63
-rw-r--r--lib/fstree/test/mknode_reg.c42
-rw-r--r--lib/fstree/test/mknode_simple.c98
-rw-r--r--lib/fstree/test/mknode_slink.c54
9 files changed, 678 insertions, 0 deletions
diff --git a/lib/fstree/test/add_by_path.c b/lib/fstree/test/add_by_path.c
new file mode 100644
index 0000000..97e5a60
--- /dev/null
+++ b/lib/fstree/test/add_by_path.c
@@ -0,0 +1,134 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * add_by_path.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+
+int main(int argc, char **argv)
+{
+ tree_node_t *a, *b;
+ struct stat sb;
+ fstree_t fs;
+ char *opts;
+ (void)argc; (void)argv;
+
+ opts = strdup("mode=0755,uid=21,gid=42");
+ TEST_ASSERT(fstree_init(&fs, opts) == 0);
+ free(opts);
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFDIR | 0750;
+ sb.st_uid = 1000;
+ sb.st_gid = 100;
+
+ TEST_EQUAL_UI(fs.root->link_count, 2);
+
+ a = fstree_add_generic(&fs, "dir", &sb, NULL);
+ TEST_NOT_NULL(a);
+ TEST_STR_EQUAL(a->name, "dir");
+ TEST_EQUAL_UI(a->mode, sb.st_mode);
+ TEST_EQUAL_UI(a->uid, sb.st_uid);
+ TEST_EQUAL_UI(a->gid, sb.st_gid);
+ TEST_ASSERT(a->parent == fs.root);
+ TEST_EQUAL_UI(a->link_count, 2);
+ TEST_NULL(a->next);
+ TEST_ASSERT(fs.root->data.dir.children == a);
+ TEST_EQUAL_UI(fs.root->link_count, 3);
+ TEST_ASSERT(!a->data.dir.created_implicitly);
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFBLK | 0640;
+ sb.st_rdev = 1234;
+
+ b = fstree_add_generic(&fs, "blkdev", &sb, NULL);
+ TEST_NOT_NULL(b);
+ TEST_ASSERT(b != a);
+ TEST_STR_EQUAL(b->name, "blkdev");
+ TEST_EQUAL_UI(b->mode, sb.st_mode);
+ TEST_EQUAL_UI(b->uid, sb.st_uid);
+ TEST_EQUAL_UI(b->gid, sb.st_gid);
+ TEST_ASSERT(b->parent == fs.root);
+ TEST_EQUAL_UI(b->link_count, 1);
+ TEST_EQUAL_UI(b->data.devno, sb.st_rdev);
+ TEST_ASSERT(b->next == a);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
+ TEST_ASSERT(fs.root->data.dir.children == b);
+
+ TEST_NULL(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL));
+ TEST_EQUAL_UI(errno, ENOTDIR);
+
+ TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL));
+ TEST_EQUAL_UI(errno, EEXIST);
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFDIR | 0755;
+ TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL));
+ TEST_EQUAL_UI(errno, EEXIST);
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFCHR | 0444;
+ b = fstree_add_generic(&fs, "dir/chrdev", &sb, NULL);
+ TEST_NOT_NULL(b);
+ TEST_EQUAL_UI(b->mode, sb.st_mode);
+ TEST_EQUAL_UI(b->uid, sb.st_uid);
+ TEST_EQUAL_UI(b->gid, sb.st_gid);
+ TEST_EQUAL_UI(b->link_count, 1);
+ TEST_ASSERT(b->parent == a);
+ TEST_EQUAL_UI(b->data.devno, sb.st_rdev);
+ TEST_NULL(b->next);
+ TEST_ASSERT(a->data.dir.children == b);
+
+ TEST_EQUAL_UI(a->link_count, 3);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
+
+ b = fstree_add_generic(&fs, "dir/foo/chrdev", &sb, NULL);
+ TEST_NOT_NULL(b);
+ TEST_NULL(b->next);
+ TEST_EQUAL_UI(b->mode, sb.st_mode);
+ TEST_EQUAL_UI(b->uid, sb.st_uid);
+ TEST_EQUAL_UI(b->gid, sb.st_gid);
+ TEST_EQUAL_UI(b->link_count, 1);
+ TEST_ASSERT(b->parent != a);
+ TEST_ASSERT(b->parent->parent == a);
+ TEST_EQUAL_UI(b->data.devno, sb.st_rdev);
+ TEST_NULL(b->next);
+
+ TEST_EQUAL_UI(a->link_count, 4);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
+ TEST_ASSERT(a->data.dir.children != b);
+
+ b = b->parent;
+ TEST_ASSERT(b->data.dir.created_implicitly);
+ TEST_EQUAL_UI(b->mode, S_IFDIR | 0755);
+ TEST_EQUAL_UI(b->uid, 21);
+ TEST_EQUAL_UI(b->gid, 42);
+ TEST_EQUAL_UI(b->link_count, 3);
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFDIR | 0750;
+ sb.st_uid = 1000;
+ sb.st_gid = 100;
+
+ a = fstree_add_generic(&fs, "dir/foo", &sb, NULL);
+ TEST_NOT_NULL(a);
+ TEST_ASSERT(a == b);
+ TEST_ASSERT(!a->data.dir.created_implicitly);
+ TEST_EQUAL_UI(a->mode, sb.st_mode);
+ TEST_EQUAL_UI(a->uid, sb.st_uid);
+ TEST_EQUAL_UI(a->gid, sb.st_gid);
+ TEST_EQUAL_UI(a->link_count, 3);
+
+ TEST_EQUAL_UI(a->parent->link_count, 4);
+ TEST_EQUAL_UI(fs.root->link_count, 4);
+
+ TEST_NULL(fstree_add_generic(&fs, "dir/foo", &sb, NULL));
+ TEST_EQUAL_UI(errno, EEXIST);
+
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}
diff --git a/lib/fstree/test/fstree_init.c b/lib/fstree/test/fstree_init.c
new file mode 100644
index 0000000..186f25b
--- /dev/null
+++ b/lib/fstree/test/fstree_init.c
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_init.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+#include "util/util.h"
+
+int main(int argc, char **argv)
+{
+ fstree_t fs;
+ char *str;
+ (void)argc; (void)argv;
+
+ str = strdup("mtime=1337,uid=1000,gid=100,mode=0321");
+ TEST_NOT_NULL(str);
+ TEST_ASSERT(fstree_init(&fs, str) == 0);
+ free(str);
+ TEST_EQUAL_UI(fs.defaults.st_mtime, 1337);
+ TEST_EQUAL_UI(fs.defaults.st_uid, 1000);
+ TEST_EQUAL_UI(fs.defaults.st_gid, 100);
+ TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0321);
+ fstree_cleanup(&fs);
+
+ TEST_ASSERT(fstree_init(&fs, NULL) == 0);
+ if (fs.defaults.st_mtime != 0) {
+ TEST_EQUAL_UI(fs.defaults.st_mtime, get_source_date_epoch());
+ }
+ TEST_EQUAL_UI(fs.defaults.st_uid, 0);
+ TEST_EQUAL_UI(fs.defaults.st_gid, 0);
+ TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0755);
+ fstree_cleanup(&fs);
+
+ str = strdup("mode=07777");
+ TEST_NOT_NULL(str);
+ TEST_ASSERT(fstree_init(&fs, str) == 0);
+ free(str);
+ fstree_cleanup(&fs);
+
+ str = strdup("mode=017777");
+ TEST_NOT_NULL(str);
+ TEST_ASSERT(fstree_init(&fs, str) != 0);
+ free(str);
+
+ return EXIT_SUCCESS;
+}
diff --git a/lib/fstree/test/fstree_sort.c b/lib/fstree/test/fstree_sort.c
new file mode 100644
index 0000000..7df85f5
--- /dev/null
+++ b/lib/fstree/test/fstree_sort.c
@@ -0,0 +1,88 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_sort.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+
+int main(int argc, char **argv)
+{
+ tree_node_t *a, *b, *c, *d;
+ struct stat sb;
+ fstree_t fs;
+ int ret;
+ (void)argc; (void)argv;
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFBLK | 0600;
+ sb.st_rdev = 1337;
+
+ /* in order */
+ ret = fstree_init(&fs, NULL);
+ TEST_EQUAL_I(ret, 0);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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_ASSERT(c->next == d);
+ TEST_NULL(d->next);
+
+ fstree_cleanup(&fs);
+
+ /* 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);
+
+ 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);
+
+ 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);
+
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}
diff --git a/lib/fstree/test/gen_inode_numbers.c b/lib/fstree/test/gen_inode_numbers.c
new file mode 100644
index 0000000..5403580
--- /dev/null
+++ b/lib/fstree/test/gen_inode_numbers.c
@@ -0,0 +1,90 @@
+/* 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 "util/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(int argc, char **argv)
+{
+ tree_node_t *a, *b, *c;
+ fstree_t fs;
+ (void)argc; (void)argv;
+
+ // 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;
+}
diff --git a/lib/fstree/test/get_path.c b/lib/fstree/test/get_path.c
new file mode 100644
index 0000000..61001e9
--- /dev/null
+++ b/lib/fstree/test/get_path.c
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * get_path.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+
+int main(int argc, char **argv)
+{
+ tree_node_t *a, *b, *c, *d;
+ struct stat sb;
+ fstree_t fs;
+ char *str;
+ (void)argc; (void)argv;
+
+ TEST_ASSERT(fstree_init(&fs, NULL) == 0);
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFDIR | 0750;
+ sb.st_uid = 1000;
+ sb.st_gid = 100;
+
+ a = fstree_add_generic(&fs, "foo", &sb, NULL);
+ b = fstree_add_generic(&fs, "foo/bar", &sb, NULL);
+ c = fstree_add_generic(&fs, "foo/bar/baz", &sb, NULL);
+ d = fstree_add_generic(&fs, "foo/bar/baz/dir", &sb, NULL);
+
+ str = fstree_get_path(fs.root);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/");
+ free(str);
+
+ str = fstree_get_path(a);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo");
+ free(str);
+
+ str = fstree_get_path(b);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo/bar");
+ free(str);
+
+ str = fstree_get_path(c);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo/bar/baz");
+ free(str);
+
+ str = fstree_get_path(d);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo/bar/baz/dir");
+ free(str);
+
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}
diff --git a/lib/fstree/test/mknode_dir.c b/lib/fstree/test/mknode_dir.c
new file mode 100644
index 0000000..dd7eba7
--- /dev/null
+++ b/lib/fstree/test/mknode_dir.c
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * mknode_dir.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+
+int main(int argc, char **argv)
+{
+ tree_node_t *root, *a, *b;
+ struct stat sb;
+ fstree_t fs;
+ (void)argc; (void)argv;
+
+ memset(&fs, 0, sizeof(fs));
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFDIR | 0654;
+ sb.st_uid = 123;
+ sb.st_gid = 456;
+ sb.st_rdev = 789;
+ sb.st_size = 4096;
+
+ root = fstree_mknode(NULL, "rootdir", 7, NULL, &sb);
+ TEST_EQUAL_UI(root->uid, sb.st_uid);
+ TEST_EQUAL_UI(root->gid, sb.st_gid);
+ TEST_EQUAL_UI(root->mode, sb.st_mode);
+ TEST_EQUAL_UI(root->link_count, 2);
+ TEST_ASSERT(root->name >= (char *)root->payload);
+ TEST_STR_EQUAL(root->name, "rootdir");
+ TEST_NULL(root->data.dir.children);
+ TEST_NULL(root->parent);
+ TEST_NULL(root->next);
+
+ a = fstree_mknode(root, "adir", 4, NULL, &sb);
+ TEST_ASSERT(a->parent == root);
+ TEST_NULL(a->next);
+ TEST_EQUAL_UI(a->link_count, 2);
+ TEST_EQUAL_UI(root->link_count, 3);
+ TEST_ASSERT(root->data.dir.children == a);
+ TEST_NULL(root->parent);
+ TEST_NULL(root->next);
+
+ b = fstree_mknode(root, "bdir", 4, NULL, &sb);
+ TEST_ASSERT(a->parent == root);
+ TEST_ASSERT(b->parent == root);
+ TEST_EQUAL_UI(b->link_count, 2);
+ TEST_ASSERT(root->data.dir.children == a);
+ TEST_ASSERT(a->next == b);
+ TEST_EQUAL_UI(root->link_count, 4);
+ TEST_NULL(b->next);
+ TEST_NULL(root->parent);
+ TEST_NULL(root->next);
+
+ free(root);
+ free(a);
+ free(b);
+
+ return EXIT_SUCCESS;
+}
diff --git a/lib/fstree/test/mknode_reg.c b/lib/fstree/test/mknode_reg.c
new file mode 100644
index 0000000..368720f
--- /dev/null
+++ b/lib/fstree/test/mknode_reg.c
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * mknode_reg.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+
+int main(int argc, char **argv)
+{
+ tree_node_t *node;
+ struct stat sb;
+ fstree_t fs;
+ (void)argc; (void)argv;
+
+ memset(&fs, 0, sizeof(fs));
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFREG | 0654;
+ sb.st_uid = 123;
+ sb.st_gid = 456;
+ sb.st_rdev = 789;
+ sb.st_size = 4096;
+
+ node = fstree_mknode(NULL, "filename", 8, "input", &sb);
+ TEST_EQUAL_UI(node->uid, sb.st_uid);
+ TEST_EQUAL_UI(node->gid, sb.st_gid);
+ TEST_EQUAL_UI(node->mode, sb.st_mode);
+ TEST_NULL(node->parent);
+ TEST_EQUAL_UI(node->link_count, 1);
+ TEST_ASSERT((char *)node->name >= (char *)node->payload);
+ TEST_ASSERT(node->data.file.input_file >= (char *)node->payload);
+ TEST_ASSERT(node->data.file.input_file >= node->name + 8);
+ TEST_STR_EQUAL(node->name, "filename");
+ TEST_STR_EQUAL(node->data.file.input_file, "input");
+ free(node);
+
+ return EXIT_SUCCESS;
+}
diff --git a/lib/fstree/test/mknode_simple.c b/lib/fstree/test/mknode_simple.c
new file mode 100644
index 0000000..c7efb49
--- /dev/null
+++ b/lib/fstree/test/mknode_simple.c
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * mknode_simple.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+
+int main(int argc, char **argv)
+{
+ tree_node_t *node;
+ struct stat sb;
+ fstree_t fs;
+ (void)argc; (void)argv;
+
+ memset(&fs, 0, sizeof(fs));
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFSOCK | 0654;
+ sb.st_uid = 123;
+ sb.st_gid = 456;
+ sb.st_rdev = 789;
+ sb.st_size = 1337;
+
+ node = fstree_mknode(NULL, "sockfile", 8, NULL, &sb);
+ TEST_ASSERT((char *)node->name >= (char *)node->payload);
+ TEST_STR_EQUAL(node->name, "sockfile");
+ TEST_EQUAL_UI(node->uid, sb.st_uid);
+ TEST_EQUAL_UI(node->gid, sb.st_gid);
+ TEST_EQUAL_UI(node->mode, sb.st_mode);
+ TEST_EQUAL_UI(node->link_count, 1);
+ TEST_NULL(node->parent);
+ TEST_NULL(node->data.target);
+ TEST_EQUAL_UI(node->data.devno, 0);
+ free(node);
+
+ memset(&fs, 0, sizeof(fs));
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFIFO | 0654;
+ sb.st_uid = 123;
+ sb.st_gid = 456;
+ sb.st_rdev = 789;
+ sb.st_size = 1337;
+
+ node = fstree_mknode(NULL, "fifo", 4, NULL, &sb);
+ TEST_ASSERT((char *)node->name >= (char *)node->payload);
+ TEST_STR_EQUAL(node->name, "fifo");
+ TEST_EQUAL_UI(node->uid, sb.st_uid);
+ TEST_EQUAL_UI(node->gid, sb.st_gid);
+ TEST_EQUAL_UI(node->mode, sb.st_mode);
+ TEST_EQUAL_UI(node->link_count, 1);
+ TEST_NULL(node->parent);
+ TEST_NULL(node->data.target);
+ TEST_EQUAL_UI(node->data.devno, 0);
+ free(node);
+
+ memset(&fs, 0, sizeof(fs));
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFBLK | 0654;
+ sb.st_uid = 123;
+ sb.st_gid = 456;
+ sb.st_rdev = 789;
+ sb.st_size = 1337;
+
+ node = fstree_mknode(NULL, "blkdev", 6, NULL, &sb);
+ TEST_ASSERT((char *)node->name >= (char *)node->payload);
+ TEST_STR_EQUAL(node->name, "blkdev");
+ TEST_EQUAL_UI(node->uid, sb.st_uid);
+ TEST_EQUAL_UI(node->gid, sb.st_gid);
+ TEST_EQUAL_UI(node->mode, sb.st_mode);
+ TEST_EQUAL_UI(node->link_count, 1);
+ TEST_EQUAL_UI(node->data.devno, sb.st_rdev);
+ TEST_NULL(node->parent);
+ free(node);
+
+ memset(&fs, 0, sizeof(fs));
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFCHR | 0654;
+ sb.st_uid = 123;
+ sb.st_gid = 456;
+ sb.st_rdev = 789;
+ sb.st_size = 1337;
+
+ node = fstree_mknode(NULL, "chardev", 7, NULL, &sb);
+ TEST_ASSERT((char *)node->name >= (char *)node->payload);
+ TEST_STR_EQUAL(node->name, "chardev");
+ TEST_EQUAL_UI(node->uid, sb.st_uid);
+ TEST_EQUAL_UI(node->gid, sb.st_gid);
+ TEST_EQUAL_UI(node->mode, sb.st_mode);
+ TEST_EQUAL_UI(node->link_count, 1);
+ TEST_EQUAL_UI(node->data.devno, sb.st_rdev);
+ TEST_NULL(node->parent);
+ free(node);
+
+ return EXIT_SUCCESS;
+}
diff --git a/lib/fstree/test/mknode_slink.c b/lib/fstree/test/mknode_slink.c
new file mode 100644
index 0000000..c50a0ba
--- /dev/null
+++ b/lib/fstree/test/mknode_slink.c
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * mknode_slink.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "util/test.h"
+
+int main(int argc, char **argv)
+{
+ tree_node_t *node;
+ struct stat sb;
+ fstree_t fs;
+ (void)argc; (void)argv;
+
+ memset(&fs, 0, sizeof(fs));
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFLNK | 0654;
+ sb.st_uid = 123;
+ sb.st_gid = 456;
+ sb.st_rdev = 789;
+ sb.st_size = 1337;
+
+ node = fstree_mknode(NULL, "symlink", 7, "target", &sb);
+ TEST_EQUAL_UI(node->uid, sb.st_uid);
+ TEST_EQUAL_UI(node->gid, sb.st_gid);
+ TEST_EQUAL_UI(node->mode, S_IFLNK | 0777);
+ TEST_EQUAL_UI(node->link_count, 1);
+ TEST_NULL(node->parent);
+ TEST_ASSERT((char *)node->name >= (char *)node->payload);
+ TEST_ASSERT(node->data.target >= (char *)node->payload);
+ TEST_ASSERT(node->data.target >= node->name + 8);
+ TEST_STR_EQUAL(node->name, "symlink");
+ TEST_STR_EQUAL(node->data.target, "target");
+ free(node);
+
+ node = fstree_mknode(NULL, "symlink", 7, "", &sb);
+ TEST_EQUAL_UI(node->uid, sb.st_uid);
+ TEST_EQUAL_UI(node->gid, sb.st_gid);
+ TEST_EQUAL_UI(node->mode, S_IFLNK | 0777);
+ TEST_EQUAL_UI(node->link_count, 1);
+ TEST_NULL(node->parent);
+ TEST_ASSERT((char *)node->name >= (char *)node->payload);
+ TEST_ASSERT(node->data.target >= (char *)node->payload);
+ TEST_ASSERT(node->data.target >= node->name + 8);
+ TEST_STR_EQUAL(node->name, "symlink");
+ TEST_STR_EQUAL(node->data.target, "");
+ free(node);
+
+ return EXIT_SUCCESS;
+}