diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-22 16:30:24 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-06-22 16:31:46 +0200 |
commit | 8edee9c4967ed9f3ce53cdc752cd2c02ca585bfe (patch) | |
tree | 8d34566ef221e0185ac405f0113c59317012760c /tests | |
parent | 64484ae0ff4d1bf52f618093bf3fc43a86745573 (diff) |
Add test case for fstree_get_path
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makemodule.am | 7 | ||||
-rw-r--r-- | tests/get_path.c | 54 |
2 files changed, 59 insertions, 2 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 8706bca..860cc49 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -19,10 +19,13 @@ test_gen_inode_table_LDADD = libfstree.a libutil.a test_add_by_path_SOURCES = tests/add_by_path.c test_add_by_path_LDADD = libfstree.a libutil.a +test_get_path_SOURCES = tests/get_path.c +test_get_path_LDADD = libfstree.a libutil.a + check_PROGRAMS += test_canonicalize_name test_mknode_simple test_mknode_slink check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table -check_PROGRAMS += test_add_by_path +check_PROGRAMS += test_add_by_path test_get_path TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink TESTS += test_mknode_reg test_mknode_dir test_gen_inode_table -TESTS += test_add_by_path +TESTS += test_add_by_path test_get_path 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 <stdlib.h> +#include <string.h> +#include <assert.h> + +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; +} |