openat tests: EBADF tests.
authorBruno Haible <bruno@clisp.org>
Tue, 20 Sep 2011 20:36:37 +0000 (22:36 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 20 Sep 2011 21:27:58 +0000 (23:27 +0200)
* tests/test-fchownat.c (main): Add tests for EBADF.
* tests/test-fstatat.c (main): Likewise.
* tests/test-mkdirat.c (main): Likewise.
* tests/test-openat.c (main): Likewise.
* tests/test-unlinkat.c (main): Likewise.
* tests/test-fchmodat.c: New file.
* modules/openat-tests (Files): Add tests/test-fchmodat.c.
(Makefile.am): Also run 'test-fchmodat'.

ChangeLog
modules/openat-tests
tests/test-fchmodat.c [new file with mode: 0644]
tests/test-fchownat.c
tests/test-fstatat.c
tests/test-mkdirat.c
tests/test-openat.c
tests/test-unlinkat.c

index 29048f5..04668ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2011-09-20  Bruno Haible  <bruno@clisp.org>
 
+       openat tests: EBADF tests.
+       * tests/test-fchownat.c (main): Add tests for EBADF.
+       * tests/test-fstatat.c (main): Likewise.
+       * tests/test-mkdirat.c (main): Likewise.
+       * tests/test-openat.c (main): Likewise.
+       * tests/test-unlinkat.c (main): Likewise.
+       * tests/test-fchmodat.c: New file.
+       * modules/openat-tests (Files): Add tests/test-fchmodat.c.
+       (Makefile.am): Also run 'test-fchmodat'.
+
+2011-09-20  Bruno Haible  <bruno@clisp.org>
+
        utimens, futimens, fdutimensat tests: EBADF tests.
        * tests/test-futimens.h (test_futimens): Add more tests for EBADF.
 
index b83fb72..da00b98 100644 (file)
@@ -12,6 +12,7 @@ tests/test-fstatat.c
 tests/test-mkdirat.c
 tests/test-openat.c
 tests/test-unlinkat.c
+tests/test-fchmodat.c
 tests/signature.h
 tests/macros.h
 
@@ -29,8 +30,11 @@ configure.ac:
 AC_CHECK_FUNCS_ONCE([getegid])
 
 Makefile.am:
-TESTS += test-fchownat test-fstatat test-mkdirat test-openat test-unlinkat
-check_PROGRAMS += test-fchownat test-fstatat test-mkdirat test-openat \
+TESTS += \
+  test-fchmodat test-fchownat test-fstatat test-mkdirat test-openat \
+  test-unlinkat
+check_PROGRAMS += \
+  test-fchmodat test-fchownat test-fstatat test-mkdirat test-openat \
   test-unlinkat
 test_fchownat_LDADD = $(LDADD) @LIBINTL@
 test_fstatat_LDADD = $(LDADD) @LIBINTL@
diff --git a/tests/test-fchmodat.c b/tests/test-fchmodat.c
new file mode 100644 (file)
index 0000000..d52f5c3
--- /dev/null
@@ -0,0 +1,44 @@
+/* Test changing the protections of a file relative to an open directory.
+   Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fchmodat, int, (int, const char *, mode_t, int));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (fchmodat (-1, "foo", 0600, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (fchmodat (99, "foo", 0600, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
index 060013e..dda6c0f 100644 (file)
@@ -69,6 +69,18 @@ main (int argc _GL_UNUSED, char *argv[])
   /* Clean up any trash from prior testsuite runs.  */
   ignore_value (system ("rm -rf " BASE "*"));
 
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (fchownat (-1, "foo", getuid (), getgid (), 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (fchownat (99, "foo", getuid (), getgid (), 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
   /* Basic tests.  */
   result1 = test_chown (do_chown, true);
   result2 = test_lchown (do_lchown, result1 == 0);
index aef1136..297eb79 100644 (file)
@@ -67,6 +67,22 @@ main (int argc _GL_UNUSED, char *argv[])
   /* Remove any leftovers from a previous partial run.  */
   ignore_value (system ("rm -rf " BASE "*"));
 
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstatat (-1, "foo", &statbuf, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    struct stat statbuf;
+
+    errno = 0;
+    ASSERT (fstatat (99, "foo", &statbuf, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
   result = test_stat_func (do_stat, false);
   ASSERT (test_lstat_func (do_lstat, false) == result);
   dfd = open (".", O_RDONLY);
index 0eb5e2d..cd0c6cd 100644 (file)
@@ -57,6 +57,18 @@ main (int argc _GL_UNUSED, char *argv[])
   /* Clean up any trash from prior testsuite runs.  */
   ignore_value (system ("rm -rf " BASE "*"));
 
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (mkdirat (-1, "foo", 0700) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (mkdirat (99, "foo", 0700) == -1);
+    ASSERT (errno == EBADF);
+  }
+
   /* Test basic mkdir functionality.  */
   result = test_mkdir (do_mkdir, false);
   dfd = open (".", O_RDONLY);
index 6e6ba5b..f36145a 100644 (file)
@@ -65,6 +65,18 @@ main (int argc _GL_UNUSED, char *argv[])
 
   set_program_name (argv[0]);
 
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (openat (-1, "foo", O_RDONLY) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (openat (99, "foo", O_RDONLY) == -1);
+    ASSERT (errno == EBADF);
+  }
+
   /* Basic checks.  */
   result = test_open (do_open, false);
   dfd = open (".", O_RDONLY);
index 30af671..7d25b6e 100644 (file)
@@ -68,6 +68,18 @@ main (int argc _GL_UNUSED, char *argv[])
   /* Remove any leftovers from a previous partial run.  */
   ignore_value (system ("rm -rf " BASE "*"));
 
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (unlinkat (-1, "foo", 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (unlinkat (99, "foo", 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
   result1 = test_rmdir_func (rmdirat, false);
   result2 = test_unlink_func (unlinker, false);
   ASSERT (result1 == result2);