summaryrefslogtreecommitdiff
path: root/tests/libfstree
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-07-05 15:34:08 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-07-08 19:17:35 +0200
commitd6e2106e96b6969e045251d972e1adcceb9728df (patch)
tree6435792bf334cdd1980c071348348f697cf027cb /tests/libfstree
parent4a607edbdfc12f97da0810563fd2e699dcecaa71 (diff)
Cleanup: move filename_sane & canonicalize_path functions to libutil
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libfstree')
-rw-r--r--tests/libfstree/Makemodule.am28
-rw-r--r--tests/libfstree/canonicalize_name.c78
-rw-r--r--tests/libfstree/filename_sane.c94
-rw-r--r--tests/libfstree/sort_file.c1
4 files changed, 9 insertions, 192 deletions
diff --git a/tests/libfstree/Makemodule.am b/tests/libfstree/Makemodule.am
index a79d670..107a66c 100644
--- a/tests/libfstree/Makemodule.am
+++ b/tests/libfstree/Makemodule.am
@@ -1,8 +1,5 @@
FSTDATADIR=$(top_srcdir)/tests/libfstree
-test_canonicalize_name_SOURCES = tests/libfstree/canonicalize_name.c
-test_canonicalize_name_LDADD = libfstree.a libcompat.a
-
test_mknode_simple_SOURCES = tests/libfstree/mknode_simple.c
test_mknode_simple_LDADD = libfstree.a libcompat.a
@@ -16,7 +13,7 @@ test_mknode_dir_SOURCES = tests/libfstree/mknode_dir.c
test_mknode_dir_LDADD = libfstree.a libcompat.a
test_gen_inode_numbers_SOURCES = tests/libfstree/gen_inode_numbers.c
-test_gen_inode_numbers_LDADD = libfstree.a libcompat.a
+test_gen_inode_numbers_LDADD = libfstree.a libutil.a libcompat.a
test_add_by_path_SOURCES = tests/libfstree/add_by_path.c
test_add_by_path_LDADD = libfstree.a libcompat.a
@@ -31,46 +28,37 @@ test_fstree_sort_LDADD = libfstree.a libio.a libcompat.a
test_fstree_from_file_SOURCES = tests/libfstree/fstree_from_file.c
test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS)
test_fstree_from_file_CPPFLAGS += -DTESTPATH=$(FSTDATADIR)/fstree1.txt
-test_fstree_from_file_LDADD = libfstree.a libio.a libcompat.a
+test_fstree_from_file_LDADD = libfstree.a libio.a libutil.a libcompat.a
test_fstree_glob1_SOURCES = tests/libfstree/fstree_glob1.c
test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(FSTDATADIR)
-test_fstree_glob1_LDADD = libfstree.a libio.a libcompat.a
+test_fstree_glob1_LDADD = libfstree.a libio.a libutil.a libcompat.a
test_fstree_from_dir_SOURCES = tests/libfstree/fstree_from_dir.c
test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS)
test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/libtar/data
-test_fstree_from_dir_LDADD = libfstree.a libcompat.a
+test_fstree_from_dir_LDADD = libfstree.a libutil.a libcompat.a
test_fstree_init_SOURCES = tests/libfstree/fstree_init.c
test_fstree_init_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree
test_fstree_init_LDADD = libfstree.a libio.a libcompat.a
-test_filename_sane_SOURCES = tests/libfstree/filename_sane.c
-test_filename_sane_SOURCES += lib/fstree/filename_sane.c
-test_filename_sane_LDADD = libcompat.a
-
-test_filename_sane_w32_SOURCES = tests/libfstree/filename_sane.c
-test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c
-test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1
-test_filename_sane_w32_LDADD = libcompat.a
-
test_fstree_epoch_SOURCES = tests/libfstree/epoch.c
test_fstree_epoch_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree
test_fstree_epoch_SOURCES += lib/fstree/source_date_epoch.c
test_fstree_epoch_LDADD = libcompat.a
test_sort_file_SOURCES = tests/libfstree/sort_file.c
-test_sort_file_LDADD = libfstree.a libio.a libcompat.a
+test_sort_file_LDADD = libfstree.a libio.a libutil.a libcompat.a
fstree_fuzz_SOURCES = tests/libfstree/fstree_fuzz.c
-fstree_fuzz_LDADD = libfstree.a libio.a libcompat.a
+fstree_fuzz_LDADD = libfstree.a libio.a libutil.a libcompat.a
FSTREE_TESTS = \
- test_canonicalize_name test_mknode_simple test_mknode_slink \
+ test_mknode_simple test_mknode_slink \
test_mknode_reg test_mknode_dir test_gen_inode_numbers \
test_add_by_path test_get_path test_fstree_sort test_fstree_from_file \
- test_fstree_init test_filename_sane test_filename_sane_w32 \
+ test_fstree_init \
test_fstree_from_dir test_fstree_glob1 test_fstree_epoch \
test_sort_file
diff --git a/tests/libfstree/canonicalize_name.c b/tests/libfstree/canonicalize_name.c
deleted file mode 100644
index f117a0d..0000000
--- a/tests/libfstree/canonicalize_name.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * canonicalize_name.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-#include "fstree.h"
-#include "util/test.h"
-
-static const struct {
- const char *in;
- const char *out;
-} must_work[] = {
- { "", "" },
- { "/", "" },
- { "\\", "\\" },
- { "///", "" },
- { "\\\\\\", "\\\\\\" },
- { "/\\//\\\\/", "\\/\\\\" },
- { "foo/bar/test", "foo/bar/test" },
- { "foo\\bar\\test", "foo\\bar\\test" },
- { "/foo/bar/test/", "foo/bar/test" },
- { "\\foo\\bar\\test\\", "\\foo\\bar\\test\\" },
- { "///foo//bar//test///", "foo/bar/test" },
- { "./foo/././bar/test/./.", "foo/bar/test" },
- { "./foo/././", "foo" },
- { ".", "" },
- { "./", "" },
- { "./.", "" },
- { "foo/.../bar", "foo/.../bar" },
- { "foo/.test/bar", "foo/.test/bar" },
-};
-
-static const char *must_not_work[] = {
- "..",
- "foo/../bar",
- "../foo/bar",
- "foo/bar/..",
- "foo/bar/../",
-};
-
-int main(int argc, char **argv)
-{
- char buffer[512];
- size_t i;
- (void)argc; (void)argv;
-
- for (i = 0; i < sizeof(must_work) / sizeof(must_work[0]); ++i) {
- strcpy(buffer, must_work[i].in);
-
- if (canonicalize_name(buffer)) {
- fprintf(stderr, "Test case rejected: '%s'\n",
- must_work[i].in);
- return EXIT_FAILURE;
- }
-
- if (strcmp(buffer, must_work[i].out) != 0) {
- fprintf(stderr, "Expected result: %s\n",
- must_work[i].out);
- fprintf(stderr, "Actual result: %s\n", buffer);
- return EXIT_FAILURE;
- }
- }
-
- for (i = 0; i < sizeof(must_not_work) / sizeof(must_not_work[0]); ++i) {
- strcpy(buffer, must_not_work[i]);
-
- if (canonicalize_name(buffer) == 0) {
- fprintf(stderr, "Test case accepted: '%s'\n",
- must_not_work[i]);
- fprintf(stderr, "Transformed into: '%s'\n", buffer);
- return EXIT_FAILURE;
- }
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/tests/libfstree/filename_sane.c b/tests/libfstree/filename_sane.c
deleted file mode 100644
index a1dc79c..0000000
--- a/tests/libfstree/filename_sane.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * filename_sane.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-#include "fstree.h"
-#include "util/test.h"
-
-static const char *must_work[] = {
- "foobar",
- "test.txt",
-#if !defined(_WIN32) && !defined(__WINDOWS__) && !defined(TEST_WIN32)
- "\\foo", "foo\\", "foo\\bar",
-#endif
- NULL,
-};
-
-static const char *must_not_work[] = {
- ".",
- "..",
- "/foo",
- "foo/",
- "foo/bar",
- NULL,
-};
-
-static const char *must_not_work_here[] = {
-#if defined(_WIN32) || defined(__WINDOWS__) || defined(TEST_WIN32)
- "\\foo", "foo\\", "foo\\bar",
- "fo<o", "fo>o", "fo:o", "fo\"o",
- "fo|o", "fo?o", "fo*o", "fo\ro",
- "CON", "PRN", "AUX", "NUL",
- "COM1", "COM2", "LPT1", "LPT2",
- "con", "prn", "aux", "nul",
- "com1", "com2", "lpt1", "lpt2",
- "AUX.txt", "aux.txt", "NUL.txt", "nul.txt",
-#endif
- NULL,
-};
-
-int main(int argc, char **argv)
-{
- size_t i;
- (void)argc; (void)argv;
-
- for (i = 0; must_work[i] != NULL; ++i) {
- if (!is_filename_sane(must_work[i], false)) {
- fprintf(stderr, "%s was rejected!\n", must_work[i]);
- return EXIT_FAILURE;
- }
-
- if (!is_filename_sane(must_work[i], true)) {
- fprintf(stderr,
- "%s was rejected when testing for "
- "OS specific stuff!\n", must_work[i]);
- return EXIT_FAILURE;
- }
- }
-
- for (i = 0; must_not_work[i] != NULL; ++i) {
- if (is_filename_sane(must_not_work[i], false)) {
- fprintf(stderr, "%s was accepted!\n",
- must_not_work[i]);
- return EXIT_FAILURE;
- }
-
- if (is_filename_sane(must_not_work[i], true)) {
- fprintf(stderr,
- "%s was accepted when testing for "
- "OS specific stuff!\n", must_not_work[i]);
- return EXIT_FAILURE;
- }
- }
-
- for (i = 0; must_not_work_here[i] != NULL; ++i) {
- if (!is_filename_sane(must_not_work_here[i], false)) {
- fprintf(stderr,
- "%s was rejected in the generic test!\n",
- must_not_work_here[i]);
- return EXIT_FAILURE;
- }
-
- if (is_filename_sane(must_not_work_here[i], true)) {
- fprintf(stderr,
- "%s was accepted when testing for "
- "OS specific stuff!\n", must_not_work_here[i]);
- return EXIT_FAILURE;
- }
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/tests/libfstree/sort_file.c b/tests/libfstree/sort_file.c
index 93d60e0..78d1606 100644
--- a/tests/libfstree/sort_file.c
+++ b/tests/libfstree/sort_file.c
@@ -9,6 +9,7 @@
#include "sqfs/block.h"
#include "fstree.h"
#include "util/test.h"
+#include "util/util.h"
static const char *listing =
"dir /bin 0755 0 0\n"