diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makemodule.am | 6 | ||||
-rw-r--r-- | tests/fstree_init.c | 47 |
2 files changed, 52 insertions, 1 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 14dacd0..17f36b2 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -28,11 +28,15 @@ test_fstree_sort_LDADD = libfstree.a libutil.a test_fstree_from_file_SOURCES = tests/fstree_from_file.c test_fstree_from_file_LDADD = libfstree.a libutil.a +test_fstree_init_SOURCES = tests/fstree_init.c +test_fstree_init_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 test_get_path test_fstree_sort -check_PROGRAMS += test_fstree_from_file +check_PROGRAMS += test_fstree_from_file test_fstree_init 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 test_get_path test_fstree_sort test_fstree_from_file +TESTS += test_fstree_init diff --git a/tests/fstree_init.c b/tests/fstree_init.c new file mode 100644 index 0000000..ea89633 --- /dev/null +++ b/tests/fstree_init.c @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "fstree.h" + +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <stdio.h> + +int main(void) +{ + fstree_t fs; + char *str; + + str = strdup("mtime=1337,uid=1000,gid=100,mode=0321"); + assert(str != NULL); + assert(fstree_init(&fs, 512, str) == 0); + free(str); + assert(fs.defaults.st_mtime == 1337); + assert(fs.defaults.st_atime == 1337); + assert(fs.defaults.st_ctime == 1337); + assert(fs.defaults.st_uid == 1000); + assert(fs.defaults.st_gid == 100); + assert(fs.defaults.st_mode == (S_IFDIR | 0321)); + fstree_cleanup(&fs); + + assert(fstree_init(&fs, 512, NULL) == 0); + assert(fs.defaults.st_mtime == 0); + assert(fs.defaults.st_atime == 0); + assert(fs.defaults.st_ctime == 0); + assert(fs.defaults.st_uid == 0); + assert(fs.defaults.st_gid == 0); + assert(fs.defaults.st_mode == (S_IFDIR | 0755)); + fstree_cleanup(&fs); + + str = strdup("mode=07777"); + assert(str != NULL); + assert(fstree_init(&fs, 512, str) == 0); + free(str); + fstree_cleanup(&fs); + + str = strdup("mode=017777"); + assert(str != NULL); + assert(fstree_init(&fs, 512, str) != 0); + free(str); + + return EXIT_SUCCESS; +} |