]> Savannah Git Hosting - gnulib.git/commitdiff
fchmodat: Strengthen tests.
authorBruno Haible <bruno@clisp.org>
Sat, 8 Feb 2020 19:47:58 +0000 (20:47 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 8 Feb 2020 19:47:58 +0000 (20:47 +0100)
* tests/test-fchmodat.c (BASE): New macro.
(main): Use it, to avoid conflicts with other unit tests. Verify that
fchmodat changed the file permission bits.

ChangeLog
tests/test-fchmodat.c

index a5ca210e0eef739822baf3f7d3dd26ce9c6f5d07..fc07914b210aa455319e4e913aef0455812c8897 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-02-08  Bruno Haible  <bruno@clisp.org>
+
+       fchmodat: Strengthen tests.
+       * tests/test-fchmodat.c (BASE): New macro.
+       (main): Use it, to avoid conflicts with other unit tests. Verify that
+       fchmodat changed the file permission bits.
+
 2020-02-08  Bruno Haible  <bruno@clisp.org>
 
        fchmodat: Fix endless recursion on Cygwin (regression from 2020-02-07).
index df0f604d83c13bf05bab57b55acb624d6b57e617..f6b695bb85dd760d492fb095251f00ce2801e7ea 100644 (file)
@@ -28,6 +28,8 @@ SIGNATURE_CHECK (fchmodat, int, (int, const char *, mode_t, int));
 
 #include "macros.h"
 
+#define BASE "test-fchmodat."
+
 int
 main (void)
 {
@@ -47,9 +49,15 @@ main (void)
   /* Test that fchmodat works on non-symlinks, when given
      the AT_SYMLINK_NOFOLLOW flag.  */
   {
-    ASSERT (close (creat ("file", 0600)) == 0);
-    ASSERT (fchmodat (AT_FDCWD, "file", 0700, AT_SYMLINK_NOFOLLOW) == 0);
-    ASSERT (unlink ("file") == 0);
+    struct stat statbuf;
+    unlink (BASE "file");
+    ASSERT (close (creat (BASE "file", 0600)) == 0);
+    ASSERT (fchmodat (AT_FDCWD, BASE "file", 0400, AT_SYMLINK_NOFOLLOW) == 0);
+    ASSERT (stat (BASE "file", &statbuf) >= 0);
+    ASSERT ((statbuf.st_mode & 0700) == 0400);
+    /* Clean up.  */
+    ASSERT (chmod (BASE "file", 0600) == 0);
+    ASSERT (unlink (BASE "file") == 0);
   }
 
   return 0;