maint: update all copyright year number ranges
[gnulib.git] / tests / test-getcwd.c
index 14a526f..4b951e0 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of getcwd() function.
-   Copyright (C) 2009-2011 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
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <sys/stat.h>
 
+#include "pathmax.h"
 #include "macros.h"
 
 #if ! HAVE_GETPAGESIZE
@@ -48,10 +49,12 @@ test_abort_bug (void)
   size_t desired_depth;
   size_t d;
 
+#ifdef PATH_MAX
   /* The bug is triggered when PATH_MAX < getpagesize (), so skip
      this relatively expensive and invasive test if that's not true.  */
   if (getpagesize () <= PATH_MAX)
     return 0;
+#endif
 
   cwd = getcwd (NULL, 0);
   if (cwd == NULL)
@@ -65,7 +68,8 @@ test_abort_bug (void)
     {
       if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0)
         {
-          fail = 3; /* Unable to construct deep hierarchy.  */
+          if (! (errno == ERANGE || errno == ENAMETOOLONG || errno == ENOENT))
+            fail = 3; /* Unable to construct deep hierarchy.  */
           break;
         }
     }
@@ -74,7 +78,8 @@ test_abort_bug (void)
      results in a failed assertion.  */
   cwd = getcwd (NULL, 0);
   if (cwd == NULL)
-    fail = 4; /* getcwd failed.  This is ok, and expected.  */
+    fail = 4; /* getcwd didn't assert, but it failed for a long name
+                 where the answer could have been learned.  */
   free (cwd);
 
   /* Call rmdir first, in case the above chdir failed.  */
@@ -129,7 +134,7 @@ test_long_name (void)
   size_t n_chdirs = 0;
 
   if (cwd == NULL)
-    return 10;
+    return 1;
 
   cwd_len = initial_cwd_len = strlen (cwd);
 
@@ -146,8 +151,8 @@ test_long_name (void)
          errors, be pessimistic and consider that as a failure, too.  */
       if (mkdir (DIR_NAME, S_IRWXU) < 0 || chdir (DIR_NAME) < 0)
         {
-          if (! (errno == ERANGE || errno == ENAMETOOLONG))
-            fail = 20;
+          if (! (errno == ERANGE || errno == ENAMETOOLONG || errno == ENOENT))
+            fail = 2;
           break;
         }
 
@@ -156,12 +161,17 @@ test_long_name (void)
           c = getcwd (buf, PATH_MAX);
           if (!c && errno == ENOENT)
             {
-              fail = 11;
+              fail = 3;
+              break;
+            }
+          if (c)
+            {
+              fail = 4;
               break;
             }
-          if (c || ! (errno == ERANGE || errno == ENAMETOOLONG))
+          if (! (errno == ERANGE || errno == ENAMETOOLONG))
             {
-              fail = 21;
+              fail = 5;
               break;
             }
         }
@@ -176,12 +186,12 @@ test_long_name (void)
               if (! (errno == ERANGE || errno == ENOENT
                      || errno == ENAMETOOLONG))
                 {
-                  fail = 22;
+                  fail = 6;
                   break;
                 }
               if (AT_FDCWD || errno == ERANGE || errno == ENOENT)
                 {
-                  fail = 12;
+                  fail = 7;
                   break;
                 }
             }
@@ -189,7 +199,7 @@ test_long_name (void)
 
       if (c && strlen (c) != cwd_len)
         {
-          fail = 23;
+          fail = 8;
           break;
         }
       ++n_chdirs;
@@ -219,5 +229,5 @@ test_long_name (void)
 int
 main (int argc, char **argv)
 {
-  return test_abort_bug () + test_long_name ();
+  return test_abort_bug () * 10 + test_long_name ();
 }