aboutsummaryrefslogtreecommitdiff
path: root/tests/libfstree/get_path.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/get_path.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/get_path.c')
-rw-r--r--tests/libfstree/get_path.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/libfstree/get_path.c b/tests/libfstree/get_path.c
new file mode 100644
index 0000000..9bf618b
--- /dev/null
+++ b/tests/libfstree/get_path.c
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * get_path.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "fstree.h"
+#include "../test.h"
+
+int main(void)
+{
+ tree_node_t *a, *b, *c, *d;
+ struct stat sb;
+ fstree_t fs;
+ char *str;
+
+ TEST_ASSERT(fstree_init(&fs, NULL) == 0);
+
+ memset(&sb, 0, sizeof(sb));
+ sb.st_mode = S_IFDIR | 0750;
+ sb.st_uid = 1000;
+ sb.st_gid = 100;
+
+ a = fstree_add_generic(&fs, "foo", &sb, NULL);
+ b = fstree_add_generic(&fs, "foo/bar", &sb, NULL);
+ c = fstree_add_generic(&fs, "foo/bar/baz", &sb, NULL);
+ d = fstree_add_generic(&fs, "foo/bar/baz/dir", &sb, NULL);
+
+ str = fstree_get_path(fs.root);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/");
+ free(str);
+
+ str = fstree_get_path(a);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo");
+ free(str);
+
+ str = fstree_get_path(b);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo/bar");
+ free(str);
+
+ str = fstree_get_path(c);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo/bar/baz");
+ free(str);
+
+ str = fstree_get_path(d);
+ TEST_NOT_NULL(str);
+ TEST_STR_EQUAL(str, "/foo/bar/baz/dir");
+ free(str);
+
+ fstree_cleanup(&fs);
+ return EXIT_SUCCESS;
+}