From b63008c3f1199f3abeb271338cc690a96b51dff3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 19 Aug 2024 16:21:27 +0200 Subject: [PATCH] hasmntopt: Add tests. * tests/test-hasmntopt.c: New file. * modules/hasmntopt-tests: New file. --- ChangeLog | 4 +++ modules/hasmntopt-tests | 11 ++++++++ tests/test-hasmntopt.c | 60 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 modules/hasmntopt-tests create mode 100644 tests/test-hasmntopt.c diff --git a/ChangeLog b/ChangeLog index 8cbd4b8a80..5b3996e920 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2024-08-19 Bruno Haible + hasmntopt: Add tests. + * tests/test-hasmntopt.c: New file. + * modules/hasmntopt-tests: New file. + hasmntopt: New module. * lib/mntent.in.h: Add config.h check. (hasmntopt): New declaration. diff --git a/modules/hasmntopt-tests b/modules/hasmntopt-tests new file mode 100644 index 0000000000..a15dd29420 --- /dev/null +++ b/modules/hasmntopt-tests @@ -0,0 +1,11 @@ +Files: +tests/test-hasmntopt.c +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-hasmntopt +check_PROGRAMS += test-hasmntopt diff --git a/tests/test-hasmntopt.c b/tests/test-hasmntopt.c new file mode 100644 index 0000000000..e4f0b380fe --- /dev/null +++ b/tests/test-hasmntopt.c @@ -0,0 +1,60 @@ +/* Test of hasmntopt() function. + Copyright (C) 2024 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2024. */ + +#include + +#if HAVE_SETMNTENT + +/* Specification. */ +# include + +# include "macros.h" + +int +main () +{ + char options[] = "rw,nosuid,nodev,noexec,relatime,size=5120k,inode64"; + struct mntent me; + me.mnt_opts = options; + + ASSERT (hasmntopt (&me, "ro") == NULL); + ASSERT (hasmntopt (&me, "rw") == options + 0); + ASSERT (hasmntopt (&me, "atime") == NULL); + ASSERT (hasmntopt (&me, "rela") == NULL); + ASSERT (hasmntopt (&me, "relatime") == options + 23); + ASSERT (hasmntopt (&me, "size") == options + 32); + ASSERT (hasmntopt (&me, "size=512") == NULL); + ASSERT (hasmntopt (&me, "size=5120k") == options + 32); + ASSERT (hasmntopt (&me, "inode64") == options + 43); + + return test_exit_status; +} + +#else + +# include + +int +main () +{ + fputs ("Skipping test: no setmntent, getmntent, endmntent functions\n", + stderr); + return 77; +} + +#endif -- 2.39.5