X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-canonicalize-lgpl.c;h=05700530f67e74bf008188e2717fd5e0938a18e9;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=704c0ecc5af27cfbe2dd60bb9e774f21839324de;hpb=99ad8ac789556142ef090fcaefae36aabef00ca4;p=gnulib.git diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index 704c0ecc5..05700530f 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -1,5 +1,5 @@ /* Test of execution of program termination handlers. - Copyright (C) 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2007-2014 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 @@ -20,6 +20,10 @@ #include +#include "signature.h" +SIGNATURE_CHECK (realpath, char *, (const char *, char *)); +SIGNATURE_CHECK (canonicalize_file_name, char *, (const char *)); + #include #include #include @@ -27,28 +31,22 @@ #include #include -#if !HAVE_SYMLINK -# define symlink(a,b) (-1) -#endif /* !HAVE_SYMLINK */ - -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "same-inode.h" +#include "ignore-value.h" +#include "macros.h" #define BASE "t-can-lgpl.tmp" +static void * +null_ptr (void) +{ + return NULL; +} + int -main () +main (void) { -#ifdef GNULIB_CANONICALIZE +#if GNULIB_TEST_CANONICALIZE /* No need to test canonicalize-lgpl module if canonicalize is also in use. */ return 0; @@ -58,7 +56,7 @@ main () any leftovers from a previous partial run. */ { int fd; - ASSERT (system ("rm -rf " BASE " ise") == 0); + ignore_value (system ("rm -rf " BASE " ise")); ASSERT (mkdir (BASE, 0700) == 0); fd = creat (BASE "/tra", 0600); ASSERT (0 <= fd); @@ -70,25 +68,43 @@ main () char *result = canonicalize_file_name (BASE "//./..//" BASE "/tra"); ASSERT (result != NULL); ASSERT (strstr (result, "/" BASE "/tra") - == result + strlen (result) - strlen ("/" BASE "/tra")); + == result + strlen (result) - strlen ("/" BASE "/tra")); free (result); errno = 0; result = canonicalize_file_name (""); ASSERT (result == NULL); ASSERT (errno == ENOENT); errno = 0; - result = canonicalize_file_name (NULL); + result = canonicalize_file_name (null_ptr ()); ASSERT (result == NULL); ASSERT (errno == EINVAL); } + /* Check that a non-directory with trailing slash yields NULL. */ + { + char *result; + errno = 0; + result = canonicalize_file_name (BASE "/tra/"); + ASSERT (result == NULL); + ASSERT (errno == ENOTDIR); + } + + /* Check that a missing directory yields NULL. */ + { + char *result; + errno = 0; + result = canonicalize_file_name (BASE "/zzz/.."); + ASSERT (result == NULL); + ASSERT (errno == ENOENT); + } + /* From here on out, tests involve symlinks. */ if (symlink (BASE "/ket", "ise") != 0) { ASSERT (remove (BASE "/tra") == 0); ASSERT (rmdir (BASE) == 0); - fputs ("skipping test: symlinks not supported on this filesystem\n", - stderr); + fputs ("skipping test: symlinks not supported on this file system\n", + stderr); return 77; } ASSERT (symlink ("bef", BASE "/plo") == 0); @@ -97,6 +113,7 @@ main () ASSERT (symlink ("wum", BASE "/ouk") == 0); ASSERT (symlink ("../ise", BASE "/ket") == 0); ASSERT (mkdir (BASE "/lum", 0700) == 0); + ASSERT (symlink ("//.//../..", BASE "/droot") == 0); /* Check that the symbolic link to a file can be resolved. */ { @@ -106,7 +123,7 @@ main () ASSERT (result2 != NULL); ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/tra"), - "/" BASE "/tra") == 0); + "/" BASE "/tra") == 0); free (result1); free (result2); } @@ -122,7 +139,7 @@ main () ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/lum"), - "/" BASE "/lum") == 0); + "/" BASE "/lum") == 0); free (result1); free (result2); free (result3); @@ -137,6 +154,24 @@ main () ASSERT (errno == ENOENT); } + /* Check that a non-directory symlink with trailing slash yields NULL. */ + { + char *result; + errno = 0; + result = canonicalize_file_name (BASE "/huk/"); + ASSERT (result == NULL); + ASSERT (errno == ENOTDIR); + } + + /* Check that a missing directory via symlink yields NULL. */ + { + char *result; + errno = 0; + result = canonicalize_file_name (BASE "/ouk/.."); + ASSERT (result == NULL); + ASSERT (errno == ENOENT); + } + /* Check that a loop of symbolic links is detected. */ { char *result; @@ -146,7 +181,33 @@ main () ASSERT (errno == ELOOP); } + /* Check that leading // is honored correctly. */ + { + struct stat st1; + struct stat st2; + char *result1 = canonicalize_file_name ("//."); + char *result2 = canonicalize_file_name (BASE "/droot"); + ASSERT (result1); + ASSERT (result2); + ASSERT (stat ("/", &st1) == 0); + ASSERT (stat ("//", &st2) == 0); + if (SAME_INODE (st1, st2)) + { + ASSERT (strcmp (result1, "/") == 0); + ASSERT (strcmp (result2, "/") == 0); + } + else + { + ASSERT (strcmp (result1, "//") == 0); + ASSERT (strcmp (result2, "//") == 0); + } + free (result1); + free (result2); + } + + /* Cleanup. */ + ASSERT (remove (BASE "/droot") == 0); ASSERT (remove (BASE "/plo") == 0); ASSERT (remove (BASE "/huk") == 0); ASSERT (remove (BASE "/bef") == 0);