aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-02-19 17:26:06 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-02-19 17:40:48 +0100
commit6424676d6332cf00e4146d4b45d00cd2eb25d359 (patch)
treeec9051eb4503449857a37d4b3570404ab0e0f220
parent5b32051eb638ba0560146576c4e8d2d0ec75553d (diff)
Add simple test cases for fstree globbing
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--tests/Makemodule.am10
-rw-r--r--tests/fstree_glob1.c224
-rw-r--r--tests/fstree_glob1.txt2
-rw-r--r--tests/fstree_glob2.txt3
4 files changed, 237 insertions, 2 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index cf09f2a..dd49ccd 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -51,6 +51,10 @@ test_fstree_from_file_SOURCES = tests/fstree_from_file.c tests/test.h
test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/fstree1.txt
test_fstree_from_file_LDADD = libfstree.a libfstream.a libcompat.a
+test_fstree_glob1_SOURCES = tests/fstree_glob1.c tests/test.h
+test_fstree_glob1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests
+test_fstree_glob1_LDADD = libfstree.a libfstream.a libcompat.a
+
test_fstree_from_dir_SOURCES = tests/fstree_from_dir.c tests/test.h
test_fstree_from_dir_CPPFLAGS = $(AM_CPPFLAGS)
test_fstree_from_dir_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
@@ -241,7 +245,7 @@ check_PROGRAMS += test_mknode_simple test_mknode_slink test_mknode_reg
check_PROGRAMS += test_mknode_dir test_gen_inode_numbers test_add_by_path
check_PROGRAMS += test_get_path test_fstree_sort test_fstree_from_file
check_PROGRAMS += test_fstree_init test_filename_sane test_filename_sane_w32
-check_PROGRAMS += test_fstree_from_dir
+check_PROGRAMS += test_fstree_from_dir test_fstree_glob1
check_PROGRAMS += test_tar_ustar0 test_tar_ustar1 test_tar_ustar2
check_PROGRAMS += test_tar_ustar3 test_tar_ustar4 test_tar_ustar5
check_PROGRAMS += test_tar_ustar6
@@ -261,7 +265,7 @@ TESTS += test_mknode_simple test_mknode_slink
TESTS += test_mknode_reg test_mknode_dir test_gen_inode_numbers
TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file
TESTS += test_fstree_init test_filename_sane test_filename_sane_w32
-TESTS += test_fstree_from_dir
+TESTS += test_fstree_from_dir test_fstree_glob1
TESTS += test_tar_ustar0 test_tar_ustar1 test_tar_ustar2 test_tar_ustar3
TESTS += test_tar_ustar4 test_tar_ustar5 test_tar_ustar6
TESTS += test_tar_gnu0 test_tar_gnu1 test_tar_gnu2 test_tar_gnu3 test_tar_gnu4
@@ -282,6 +286,8 @@ endif
EXTRA_DIST += $(top_srcdir)/tests/tar $(top_srcdir)/tests/words.txt
EXTRA_DIST += $(top_srcdir)/tests/tar2sqfs
EXTRA_DIST += $(top_srcdir)/tests/fstree1.txt
+EXTRA_DIST += $(top_srcdir)/tests/fstree_glob1.txt
+EXTRA_DIST += $(top_srcdir)/tests/fstree_glob2.txt
EXTRA_DIST += $(top_srcdir)/tests/corpus/cantrbry.tar.xz
EXTRA_DIST += $(top_srcdir)/tests/corpus/cantrbry.sha512
EXTRA_DIST += $(top_srcdir)/tests/pack_dir_root.txt.ref
diff --git a/tests/fstree_glob1.c b/tests/fstree_glob1.c
new file mode 100644
index 0000000..a3a5074
--- /dev/null
+++ b/tests/fstree_glob1.c
@@ -0,0 +1,224 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * fstree_glob1.c
+ *
+ * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "test.h"
+
+static void check_hierarchy(tree_node_t *root, bool recursive)
+{
+ tree_node_t *n, *m;
+
+ n = root->data.dir.children;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "tarcorpus");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root);
+ TEST_NULL(n->next);
+
+ n = n->data.dir.children;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "file-size");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+
+ if (recursive) {
+ m = n->data.dir.children;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NULL(m);
+ } else {
+ TEST_NULL(n->data.dir.children);
+ }
+
+ n = n->next;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "format-acceptance");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+
+ if (recursive) {
+ m = n->data.dir.children;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu-g.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NULL(m);
+ } else {
+ TEST_NULL(n->data.dir.children);
+ }
+
+ n = n->next;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "large-mtime");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+
+ if (recursive) {
+ m = n->data.dir.children;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NULL(m);
+ } else {
+ TEST_NULL(n->data.dir.children);
+ }
+
+ n = n->next;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "long-paths");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+
+ if (recursive) {
+ m = n->data.dir.children;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NULL(m);
+ } else {
+ TEST_NULL(n->data.dir.children);
+ }
+
+ n = n->next;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "negative-mtime");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+
+ if (recursive) {
+ m = n->data.dir.children;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NULL(m);
+ } else {
+ TEST_NULL(n->data.dir.children);
+ }
+
+ n = n->next;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "sparse-files");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+
+ if (recursive) {
+ m = n->data.dir.children;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu-small.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "pax-gnu0-0.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "pax-gnu0-1.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "pax-gnu1-0.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NULL(m);
+ } else {
+ TEST_NULL(n->data.dir.children);
+ }
+
+ n = n->next;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "user-group-largenum");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+
+ if (recursive) {
+ m = n->data.dir.children;
+ TEST_NOT_NULL(m);
+ TEST_STR_EQUAL(m->name, "gnu.tar");
+ TEST_ASSERT(S_ISREG(m->mode));
+ TEST_ASSERT(m->parent == n);
+
+ m = m->next;
+ TEST_NULL(m);
+ } else {
+ TEST_NULL(n->data.dir.children);
+ }
+
+ n = n->next;
+ TEST_NOT_NULL(n);
+ TEST_STR_EQUAL(n->name, "xattr");
+ TEST_ASSERT(S_ISDIR(n->mode));
+ TEST_ASSERT(n->parent == root->data.dir.children);
+ TEST_NULL(n->data.dir.children);
+
+ n = n->next;
+ TEST_NULL(n);
+}
+
+int main(void)
+{
+ fstree_t fs;
+ int ret;
+
+ /* first test case, directory tree only */
+ ret = fstree_init(&fs, NULL);
+ TEST_EQUAL_I(ret, 0);
+
+ ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob1.txt", TEST_PATH);
+ TEST_EQUAL_I(ret, 0);
+
+ fstree_post_process(&fs);
+ check_hierarchy(fs.root, false);
+ fstree_cleanup(&fs);
+
+ /* first test case, directory tree plus fnmatch()ed files */
+ ret = fstree_init(&fs, NULL);
+ TEST_EQUAL_I(ret, 0);
+
+ ret = fstree_from_file(&fs, TEST_PATH "/fstree_glob2.txt", TEST_PATH);
+ TEST_EQUAL_I(ret, 0);
+
+ fstree_post_process(&fs);
+ check_hierarchy(fs.root, true);
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}
diff --git a/tests/fstree_glob1.txt b/tests/fstree_glob1.txt
new file mode 100644
index 0000000..28dbecb
--- /dev/null
+++ b/tests/fstree_glob1.txt
@@ -0,0 +1,2 @@
+dir /tarcorpus 0755 0 0
+glob /tarcorpus 0755 0 0 -type d tar
diff --git a/tests/fstree_glob2.txt b/tests/fstree_glob2.txt
new file mode 100644
index 0000000..be30fcc
--- /dev/null
+++ b/tests/fstree_glob2.txt
@@ -0,0 +1,3 @@
+dir /tarcorpus 0755 0 0
+glob /tarcorpus 0755 0 0 -type d tar
+glob /tarcorpus 0644 0 0 -type f -name "*gnu*.tar" tar