summaryrefslogtreecommitdiff
path: root/tests/fstree_init.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-23 02:27:36 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-23 02:39:57 +0200
commitf7dee65fd3b3d7e591f3be246b481f337681aba9 (patch)
treee07cfe6a5944a3a95092b0176f2a6284bfc6b910 /tests/fstree_init.c
parent73dec828ad61d046d10648ddca5c89ce70352a7a (diff)
Add test case for fstree_init options parsing
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/fstree_init.c')
-rw-r--r--tests/fstree_init.c47
1 files changed, 47 insertions, 0 deletions
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;
+}