]> Savannah Git Hosting - gnulib.git/commitdiff
getumask: Add tests.
authorBruno Haible <bruno@clisp.org>
Sat, 4 Jul 2020 16:16:06 +0000 (18:16 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 4 Jul 2020 16:16:06 +0000 (18:16 +0200)
* tests/test-getumask.c: New file.
* modules/getumask-tests: New file.

ChangeLog
modules/getumask-tests [new file with mode: 0644]
tests/test-getumask.c [new file with mode: 0644]

index fb1b853cae677c1794fd43c5f882675dc9503a27..cbf1ccc4654b1000a3f76971f71fa15c5a519993 100644 (file)
--- 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 (file)
index 0000000..2968f37
--- /dev/null
@@ -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 (file)
index 0000000..b18afa2
--- /dev/null
@@ -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;
+}