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/get_path.c | |
parent | 64484ae0ff4d1bf52f618093bf3fc43a86745573 (diff) |
Add test case for fstree_get_path
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/get_path.c')
-rw-r--r-- | tests/get_path.c | 54 |
1 files changed, 54 insertions, 0 deletions
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; +} |