gettimeofday: port recent C++ fix to Emacs
[gnulib.git] / tests / test-symlink.h
index d009a80..56cdc84 100644 (file)
@@ -1,5 +1,5 @@
 /* Tests of symlink.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009-2013 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
@@ -35,11 +35,18 @@ test_symlink (int (*func) (char const *, char const *), bool print)
 
   /* Some systems allow the creation of 0-length symlinks as a synonym
      for "."; but most reject it.  */
-  errno = 0;
-  if (func ("", BASE "link2") == -1)
-    ASSERT (errno == ENOENT || errno == EINVAL);
-  else
-    ASSERT (unlink (BASE "link2") == 0);
+  {
+    int status;
+    errno = 0;
+    status = func ("", BASE "link2");
+    if (status == -1)
+      ASSERT (errno == ENOENT || errno == EINVAL);
+    else
+      {
+        ASSERT (status == 0);
+        ASSERT (unlink (BASE "link2") == 0);
+      }
+  }
 
   /* Sanity checks of failures.  */
   errno = 0;
@@ -69,6 +76,17 @@ test_symlink (int (*func) (char const *, char const *), bool print)
   ASSERT (func ("nowhere", BASE "file/") == -1);
   ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
 
+  /* Trailing slash must always be rejected.  */
+  ASSERT (unlink (BASE "link1") == 0);
+  ASSERT (func (BASE "link2", BASE "link1") == 0);
+  errno = 0;
+  ASSERT (func (BASE "nowhere", BASE "link1/") == -1);
+  ASSERT (errno == EEXIST || errno == ENOTDIR || errno == ENOENT);
+  errno = 0;
+  ASSERT (unlink (BASE "link2") == -1);
+  ASSERT (errno == ENOENT);
+
+  /* Cleanup.  */
   ASSERT (rmdir (BASE "dir") == 0);
   ASSERT (unlink (BASE "file") == 0);
   ASSERT (unlink (BASE "link1") == 0);