>From daa03df900fa6c24a5a331b570ae65ab632c529c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 4 Jul 2020 18:16:06 +0200 Subject: [PATCH 2/2] getumask: Add tests. * tests/test-getumask.c: New file. * modules/getumask-tests: New file. --- ChangeLog | 4 ++++ modules/getumask-tests | 13 +++++++++++++ tests/test-getumask.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 modules/getumask-tests create mode 100644 tests/test-getumask.c diff --git a/ChangeLog b/ChangeLog index fb1b853..cbf1ccc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-07-04 Bruno Haible + 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 0000000..2968f37 --- /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 0000000..b18afa2 --- /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 . */ + +/* Written by Bruno Haible. */ + +#include + +#include + +#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; +} -- 2.7.4