summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Sionneau <yann@sionneau.net>2020-10-19 06:13:00 (GMT)
committerWaldemar Brodkorb <wbx@openadk.org>2020-10-19 07:55:54 (GMT)
commit653ffbcd4d8aaf97cacbd4d4455ca319a157f34e (patch)
treec2a98a3d2ec56d4bafd1e6c722032c9479b4a45a
parentc64d6ac77f0e745c70e76024212c72e4bbe2091a (diff)
misc: add test for hasmntopt() option matchingHEADmaster
Signed-off-by: Yann Sionneau <yann@sionneau.net>
-rw-r--r--test/misc/tst-hasmntopt.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/misc/tst-hasmntopt.c b/test/misc/tst-hasmntopt.c
new file mode 100644
index 0000000..17655bd
--- /dev/null
+++ b/test/misc/tst-hasmntopt.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2020 by Yann Sionneau <yann@sionneau.net> */
+
+#include <stdio.h>
+#include <mntent.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int
+do_test (void)
+{
+ char *res;
+ struct mntent m;
+
+ /* check that "ro" does not match "erROr" */
+ m.mnt_opts = "error";
+ res = hasmntopt (&m, MNTOPT_RO);
+ if (res != NULL) {
+ puts ("error: hasmntopt() picked up non existing option");
+ exit (1);
+ }
+
+ /* check that "ro" does not match "remount-ro" */
+ m.mnt_opts = "rw,relatime,errors=remount-ro";
+ res = hasmntopt (&m, MNTOPT_RO);
+ if (res != NULL) {
+ puts ("error: hasmntopt() picked up non existing option");
+ exit (1);
+ }
+
+ /* check that "ro" does match "ro" */
+ m.mnt_opts = "noatime,ro";
+ res = hasmntopt (&m, MNTOPT_RO);
+ if (res == NULL) {
+ puts ("error: hasmntopt() did not pick up an existing option");
+ exit (1);
+ }
+
+ if (strncmp(res, "ro", 2) != 0) {
+ puts ("error: hasmntopt() did not return a pointer to corresponding option");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"