summaryrefslogtreecommitdiff
path: root/tests/libfstree/fstree_glob1.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-05 15:53:21 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-06 22:08:36 +0100
commitb950412ca3a91aa37349cf51ebe98cc84767d448 (patch)
treee3bb062114d019984321a5a21b29818c88c36795 /tests/libfstree/fstree_glob1.c
parent3fc6bf24b5cc071fc323f08ece541e37578f6369 (diff)
Cleanup: add some structure to the test directory
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libfstree/fstree_glob1.c')
-rw-r--r--tests/libfstree/fstree_glob1.c224
1 files changed, 224 insertions, 0 deletions
diff --git a/tests/libfstree/fstree_glob1.c b/tests/libfstree/fstree_glob1.c
new file mode 100644
index 0000000..592180b
--- /dev/null
+++ b/tests/libfstree/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;
+}