]> Savannah Git Hosting - gnulib.git/commitdiff
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 29048f53c96b0a5952299b051613417e2682b3c8..04668ed25a3dd9e597612e10d6280803feea54b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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.
index b83fb721d293ce71089f2b233ddbd8b619e47b2d..da00b983f0eac7f9a829fac1368b50f22a1bfd9e 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 060013e1ed8c2f72929408efb16ed4a15e5f08ca..dda6c0fd6975e1df86017b2ce7cf4fd8f27c8fed 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 aef113655204e3ba3fcd12797202e1c647034f2c..297eb798f647ba20baa2e7364bb58fb5d098f8bd 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 0eb5e2d491e5ba984869ba657f0d90e649a9506c..cd0c6cdf4cd9690fa8a776efcc756329404fbe82 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 6e6ba5b9b0977b02d5b4c2e77b4b9fb46be23d39..f36145a3a775f0dc6cb6655ea500cb3e1258e7e7 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 30af671a398b2c2f6797c03e35e79ad06578648c..7d25b6edecc3e77f3070534e782f539f8156d778 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);