summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-07-04 18:16:06 +0200
committerBruno Haible <bruno@clisp.org>2020-07-04 18:16:06 +0200
commitdaa03df900fa6c24a5a331b570ae65ab632c529c (patch)
treeab09ce8db513ba33c7cfdbab3bb85c8685f3051f
parent6aa22a864222eb7199a71dabb85906088ee988cc (diff)
downloadgnulib-daa03df900fa6c24a5a331b570ae65ab632c529c.tar.gz
gnulib-daa03df900fa6c24a5a331b570ae65ab632c529c.tar.bz2
getumask: Add tests.
* tests/test-getumask.c: New file. * modules/getumask-tests: New file.
-rw-r--r--ChangeLog4
-rw-r--r--modules/getumask-tests13
-rw-r--r--tests/test-getumask.c52
3 files changed, 69 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index fb1b853cae..cbf1ccc465 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2020-07-04 Bruno Haible <bruno@clisp.org>
+ getumask: Add tests.
+ * tests/test-getumask.c: New file.
+ * modules/getumask-tests: New file.
+
getumask: New module.
* lib/sys_stat.in.h (getumask): New declaration.
* lib/getumask.c: New file.
diff --git a/modules/getumask-tests b/modules/getumask-tests
new file mode 100644
index 0000000000..2968f37c51
--- /dev/null
+++ b/modules/getumask-tests
@@ -0,0 +1,13 @@
+Files:
+tests/test-getumask.c
+tests/signature.h
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-getumask
+check_PROGRAMS += test-getumask
+test_getumask_LDADD = $(LDADD) $(LIB_GETRANDOM)
diff --git a/tests/test-getumask.c b/tests/test-getumask.c
new file mode 100644
index 0000000000..b18afa2824
--- /dev/null
+++ b/tests/test-getumask.c
@@ -0,0 +1,52 @@
+/* Test of retrieving the umask of the process.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This program 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 program 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 <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible. */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (getumask, mode_t, (void));
+
+#include "macros.h"
+
+int
+main (void)
+{
+ int mask;
+
+ mask = getumask ();
+ ASSERT (mask >= 0);
+
+#if !ASSUME_UMASK_CONSTANT
+ /* These tests fail if the umask is required to not change. */
+
+ umask (002);
+
+ mask = getumask ();
+ ASSERT (mask == 002);
+
+ umask (077);
+
+ mask = getumask ();
+ ASSERT (mask == 077);
+
+#endif
+
+ return 0;
+}

Return to:

Send suggestions and report system problems to the System administrator.