diff options
author | Bruno Haible <bruno@clisp.org> | 2019-09-15 18:58:42 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-09-15 18:58:42 +0200 |
commit | 213cd443c2fdae0471e30546755e3cd15fcf7d9d (patch) | |
tree | d0d144a0570be0c48f3d703cf9d5a41a0f37c80f | |
parent | 265886a27c8bc637b1e1f3e85e68d594bbe5fa2c (diff) | |
download | gnulib-213cd443c2fdae0471e30546755e3cd15fcf7d9d.tar.gz gnulib-213cd443c2fdae0471e30546755e3cd15fcf7d9d.tar.bz2 |
access: Add tests.
* tests/test-access.c: New file.
* modules/access-tests: New file.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | modules/access-tests | 13 | ||||
-rw-r--r-- | tests/test-access.c | 80 |
3 files changed, 97 insertions, 0 deletions
@@ -1,5 +1,9 @@ 2019-09-15 Bruno Haible <bruno@clisp.org> + access: Add tests. + * tests/test-access.c: New file. + * modules/access-tests: New file. + access: New module. * lib/unistd.in.h (access): New declaration. * lib/access.c: New file. diff --git a/modules/access-tests b/modules/access-tests new file mode 100644 index 0000000000..082aeb58b1 --- /dev/null +++ b/modules/access-tests @@ -0,0 +1,13 @@ +Files: +tests/test-access.c +tests/signature.h +tests/macros.h + +Depends-on: +creat + +configure.ac: + +Makefile.am: +TESTS += test-access +check_PROGRAMS += test-access diff --git a/tests/test-access.c b/tests/test-access.c new file mode 100644 index 0000000000..7af7f9a239 --- /dev/null +++ b/tests/test-access.c @@ -0,0 +1,80 @@ +/* Tests of access. + Copyright (C) 2019 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/>. */ + +#include <config.h> + +#include <unistd.h> + +#include "signature.h" +SIGNATURE_CHECK (access, int, (const char *, int)); + +#include <errno.h> +#include <fcntl.h> +#include <sys/stat.h> +#include "macros.h" + +#define BASE "test-access.t" + +int +main () +{ + /* Remove anything from prior partial run. */ + unlink (BASE "f"); + unlink (BASE "f1"); + unlink (BASE "f2"); + + { + errno = 0; + ASSERT (access (BASE "f", R_OK) == -1); + ASSERT (errno == ENOENT); + + errno = 0; + ASSERT (access (BASE "f", W_OK) == -1); + ASSERT (errno == ENOENT); + + errno = 0; + ASSERT (access (BASE "f", X_OK) == -1); + ASSERT (errno == ENOENT); + } + { + ASSERT (close (creat (BASE "f1", 0700)) == 0); + + ASSERT (access (BASE "f1", R_OK) == 0); + ASSERT (access (BASE "f1", W_OK) == 0); + ASSERT (access (BASE "f1", X_OK) == 0); + } + { + ASSERT (close (creat (BASE "f2", 0600)) == 0); + ASSERT (chmod (BASE "f2", 0400) == 0); + + ASSERT (access (BASE "f2", R_OK) == 0); + + errno = 0; + ASSERT (access (BASE "f2", W_OK) == -1); + ASSERT (errno == EACCES); + +#if defined _WIN32 && !defined __CYGWIN__ + /* X_OK works like R_OK. */ + ASSERT (access (BASE "f2", X_OK) == 0); +#else + errno = 0; + ASSERT (access (BASE "f2", X_OK) == -1); + ASSERT (errno == EACCES); +#endif + } + + return 0; +} |