diff mbox series

[uclibc-ng-devel] misc: add test for hasmntopt() option matching

Message ID 20201019061300.1377576-1-yann@sionneau.net
State New
Headers show
Series [uclibc-ng-devel] misc: add test for hasmntopt() option matching | expand

Commit Message

Yann Sionneau Oct. 19, 2020, 6:13 a.m. UTC
From: Yann Sionneau <yann@sionneau.net>

Signed-off-by: Yann Sionneau <yann@sionneau.net>
---
 test/misc/tst-hasmntopt.c | 47 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 test/misc/tst-hasmntopt.c

Comments

Waldemar Brodkorb Oct. 19, 2020, 8:08 a.m. UTC | #1
Hi Yann,
yann@sionneau.net wrote,

> From: Yann Sionneau <yann@sionneau.net>
> 
> Signed-off-by: Yann Sionneau <yann@sionneau.net>
> ---
>  test/misc/tst-hasmntopt.c | 47 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
>  create mode 100644 test/misc/tst-hasmntopt.c
> 
Applied and pushed,
 thx
  Waldemar
diff mbox series

Patch

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"