aboutsummaryrefslogtreecommitdiff
path: root/bin/gensquashfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-01 14:29:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-01 14:29:28 +0200
commitcdf61c556f95b0fc8a8ecf187d9f61e60bf99c53 (patch)
tree2d62d821b8fe75282720ffe28645d711ed3b7ebb /bin/gensquashfs
parent610063cb0934e2aaf4e1690b73b87b15691d10d0 (diff)
gensquashfs: add a test for fstree_from_dir file source path
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/gensquashfs')
-rw-r--r--bin/gensquashfs/Makemodule.am12
-rw-r--r--bin/gensquashfs/test/fstree_from_file2.c96
2 files changed, 107 insertions, 1 deletions
diff --git a/bin/gensquashfs/Makemodule.am b/bin/gensquashfs/Makemodule.am
index dd32d5a..5246abf 100644
--- a/bin/gensquashfs/Makemodule.am
+++ b/bin/gensquashfs/Makemodule.am
@@ -38,6 +38,16 @@ test_fstree_from_file_CPPFLAGS += -I$(top_srcdir)/bin/gensquashfs/src
test_fstree_from_file_LDADD = libio.a libsquashfs.la libcommon.a libfstree.a \
libutil.a libcompat.a
+test_fstree_from_file2_SOURCES = bin/gensquashfs/test/fstree_from_file2.c \
+ bin/gensquashfs/src/fstree_from_file.c \
+ bin/gensquashfs/src/fstree_from_dir.c \
+ bin/gensquashfs/src/glob.c \
+ bin/gensquashfs/src/mkfs.h
+test_fstree_from_file2_CPPFLAGS = $(AM_CPPFLAGS)
+test_fstree_from_file2_CPPFLAGS += -I$(top_srcdir)/bin/gensquashfs/src
+test_fstree_from_file2_LDADD = libio.a libsquashfs.la libcommon.a libfstree.a \
+ libutil.a libcompat.a
+
test_fstree_glob1_SOURCES = bin/gensquashfs/test/fstree_glob1.c \
bin/gensquashfs/src/fstree_from_file.c \
bin/gensquashfs/src/fstree_from_dir.c \
@@ -68,7 +78,7 @@ fstree_fuzz_LDADD = libio.a libsquashfs.la libcommon.a libfstree.a \
libutil.a libcompat.a
GENSQUASHFS_TESTS = \
- test_filemap_xattr test_fstree_from_file \
+ test_filemap_xattr test_fstree_from_file test_fstree_from_file2 \
test_fstree_glob1 test_sort_file
noinst_PROGRAMS += fstree_fuzz
diff --git a/bin/gensquashfs/test/fstree_from_file2.c b/bin/gensquashfs/test/fstree_from_file2.c
new file mode 100644
index 0000000..ab372c9
--- /dev/null
+++ b/bin/gensquashfs/test/fstree_from_file2.c
@@ -0,0 +1,96 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_from_file2.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "util/test.h"
+#include "io/mem.h"
+#include "mkfs.h"
+
+const char *listing =
+"dir /test 0755 0 0\n"
+"file /test/file1 0644 0 0\n"
+"file /test/file2 0644 0 0 completely/different/path\n"
+"file /test/file3 0644 0 0 /absolute/path\n"
+"file /test/file4 0644 0 0 \"/ \x21 \"\n";
+
+int main(int argc, char **argv)
+{
+ fstree_defaults_t fsd;
+ sqfs_istream_t *file;
+ tree_node_t *n;
+ fstree_t fs;
+ (void)argc; (void)argv;
+
+ file = istream_memory_create("memfile", 7, listing, strlen(listing));
+ TEST_NOT_NULL(file);
+
+ TEST_ASSERT(parse_fstree_defaults(&fsd, NULL) == 0);
+ TEST_ASSERT(fstree_init(&fs, &fsd) == 0);
+ TEST_ASSERT(fstree_from_file_stream(&fs, file, NULL) == 0);
+ sqfs_drop(file);
+
+ fstree_post_process(&fs);
+ TEST_EQUAL_UI(fs.root->link_count, 3);
+ TEST_EQUAL_UI(fs.root->mode, S_IFDIR | 0755);
+ TEST_EQUAL_UI(fs.root->uid, 0);
+ TEST_EQUAL_UI(fs.root->gid, 0);
+
+ n = fs.root->data.children;
+ TEST_NOT_NULL(n);
+
+ TEST_EQUAL_UI(n->mode, S_IFDIR | 0755);
+ TEST_EQUAL_UI(n->uid, 0);
+ TEST_EQUAL_UI(n->gid, 0);
+ TEST_EQUAL_UI(n->link_count, 6);
+ TEST_STR_EQUAL(n->name, "test");
+ TEST_NULL(n->next);
+
+ n = n->data.children;
+ TEST_NOT_NULL(n);
+
+ TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(n->uid, 0);
+ TEST_EQUAL_UI(n->gid, 0);
+ TEST_EQUAL_UI(n->link_count, 1);
+ TEST_STR_EQUAL(n->name, "file1");
+ TEST_NOT_NULL(n->data.file.input_file);
+ TEST_STR_EQUAL(n->data.file.input_file, "test/file1");
+ TEST_NOT_NULL(n->next);
+ n = n->next;
+
+ TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(n->uid, 0);
+ TEST_EQUAL_UI(n->gid, 0);
+ TEST_EQUAL_UI(n->link_count, 1);
+ TEST_STR_EQUAL(n->name, "file2");
+ TEST_NOT_NULL(n->data.file.input_file);
+ TEST_STR_EQUAL(n->data.file.input_file, "completely/different/path");
+ TEST_NOT_NULL(n->next);
+ n = n->next;
+
+ TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(n->uid, 0);
+ TEST_EQUAL_UI(n->gid, 0);
+ TEST_EQUAL_UI(n->link_count, 1);
+ TEST_STR_EQUAL(n->name, "file3");
+ TEST_NOT_NULL(n->data.file.input_file);
+ TEST_STR_EQUAL(n->data.file.input_file, "/absolute/path");
+ TEST_NOT_NULL(n->next);
+ n = n->next;
+
+ TEST_EQUAL_UI(n->mode, S_IFREG | 0644);
+ TEST_EQUAL_UI(n->uid, 0);
+ TEST_EQUAL_UI(n->gid, 0);
+ TEST_EQUAL_UI(n->link_count, 1);
+ TEST_STR_EQUAL(n->name, "file4");
+ TEST_NOT_NULL(n->data.file.input_file);
+ TEST_STR_EQUAL(n->data.file.input_file, "/ ! ");
+ TEST_NULL(n->next);
+
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}