aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makemodule.am6
-rw-r--r--tests/fstree_from_file.c81
2 files changed, 86 insertions, 1 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 4e8314a..14dacd0 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -25,10 +25,14 @@ test_get_path_LDADD = libfstree.a libutil.a
test_fstree_sort_SOURCES = tests/fstree_sort.c
test_fstree_sort_LDADD = libfstree.a libutil.a
+test_fstree_from_file_SOURCES = tests/fstree_from_file.c
+test_fstree_from_file_LDADD = libfstree.a libutil.a
+
check_PROGRAMS += test_canonicalize_name test_mknode_simple test_mknode_slink
check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table
check_PROGRAMS += test_add_by_path test_get_path test_fstree_sort
+check_PROGRAMS += test_fstree_from_file
TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink
TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table
-TESTS += test_add_by_path test_get_path test_fstree_sort
+TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file
diff --git a/tests/fstree_from_file.c b/tests/fstree_from_file.c
new file mode 100644
index 0000000..f9a9e28
--- /dev/null
+++ b/tests/fstree_from_file.c
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "fstree.h"
+
+#include <sys/sysmacros.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdio.h>
+
+static const char *testdesc =
+"# comment line\n"
+"slink /slink 0644 2 3 slinktarget\n"
+"dir /dir 0755 4 5\n"
+"nod /chardev 0600 6 7 c 13:37\n"
+"nod /blkdev 0600 8 9 b 42:21\n"
+"pipe /pipe 0644 10 11\n"
+" sock /sock 0555 12 13 ";
+
+int main(void)
+{
+ tree_node_t *n;
+ fstree_t fs;
+ char *ptr;
+ FILE *fp;
+
+ ptr = strdup(testdesc);
+ assert(ptr != NULL);
+
+ fp = fmemopen(ptr, strlen(ptr), "r");
+ assert(fp != NULL);
+
+ assert(fstree_init(&fs, 512, 0, 0755, 0, 0) == 0);
+ assert(fstree_from_file(&fs, "testfile", fp) == 0);
+
+ tree_node_sort_recursive(fs.root);
+ n = fs.root->data.dir->children;
+
+ assert(n->mode == (S_IFBLK | 0600));
+ assert(n->uid == 8);
+ assert(n->gid == 9);
+ assert(strcmp(n->name, "blkdev") == 0);
+ assert(n->data.devno == makedev(42, 21));
+
+ n = n->next;
+ assert(n->mode == (S_IFCHR | 0600));
+ assert(n->uid == 6);
+ assert(n->gid == 7);
+ assert(strcmp(n->name, "chardev") == 0);
+ assert(n->data.devno == makedev(13, 37));
+
+ n = n->next;
+ assert(n->mode == (S_IFDIR | 0755));
+ assert(n->uid == 4);
+ assert(n->gid == 5);
+ assert(strcmp(n->name, "dir") == 0);
+ assert(n->data.dir->children == NULL);
+
+ n = n->next;
+ assert(n->mode == (S_IFIFO | 0644));
+ assert(n->uid == 10);
+ assert(n->gid == 11);
+ assert(strcmp(n->name, "pipe") == 0);
+
+ n = n->next;
+ assert(n->mode == (S_IFLNK | 0777));
+ assert(n->uid == 2);
+ assert(n->gid == 3);
+ assert(strcmp(n->name, "slink") == 0);
+ assert(strcmp(n->data.slink_target, "slinktarget") == 0);
+
+ n = n->next;
+ assert(n->mode == (S_IFSOCK | 0555));
+ assert(n->uid == 12);
+ assert(n->gid == 13);
+ assert(strcmp(n->name, "sock") == 0);
+ assert(n->next == NULL);
+
+ fclose(fp);
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}