From 8edee9c4967ed9f3ce53cdc752cd2c02ca585bfe Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 22 Jun 2019 16:30:24 +0200 Subject: Add test case for fstree_get_path Signed-off-by: David Oberhollenzer --- tests/get_path.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/get_path.c (limited to 'tests/get_path.c') diff --git a/tests/get_path.c b/tests/get_path.c new file mode 100644 index 0000000..39d3431 --- /dev/null +++ b/tests/get_path.c @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "fstree.h" + +#include +#include +#include + +int main(void) +{ + tree_node_t *a, *b, *c, *d; + struct stat sb; + fstree_t fs; + char *str; + + assert(fstree_init(&fs, 512, 1337, 0755, 21, 42) == 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); + assert(str != NULL); + assert(strcmp(str, "/") == 0); + free(str); + + str = fstree_get_path(a); + assert(str != NULL); + assert(strcmp(str, "/foo") == 0); + free(str); + + str = fstree_get_path(b); + assert(str != NULL); + assert(strcmp(str, "/foo/bar") == 0); + free(str); + + str = fstree_get_path(c); + assert(str != NULL); + assert(strcmp(str, "/foo/bar/baz") == 0); + free(str); + + str = fstree_get_path(d); + assert(str != NULL); + assert(strcmp(str, "/foo/bar/baz/dir") == 0); + free(str); + + fstree_cleanup(&fs); + return EXIT_SUCCESS; +} -- cgit v1.2.3