X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-canonicalize.c;h=6794cf510e07acf63358cc369a4e94209a8144de;hb=5191b3546cfb6c163228c23f214e325ddf60d46f;hp=f8dcc54d57aa437bf14d2495eca95ebee12c68ef;hpb=35bd2ff772f9bc95f8e9d8e2a9bb5fc09331ed9c;p=gnulib.git diff --git a/tests/test-canonicalize.c b/tests/test-canonicalize.c index f8dcc54d5..6794cf510 100644 --- a/tests/test-canonicalize.c +++ b/tests/test-canonicalize.c @@ -1,5 +1,5 @@ /* Test of execution of file name canonicalization. - Copyright (C) 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2007-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 @@ -29,33 +29,25 @@ #include #include "same-inode.h" - -#if !HAVE_SYMLINK -# define symlink(a,b) (-1) -#endif - -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ - while (0) +#include "ignore-value.h" +#include "macros.h" #define BASE "t-can.tmp" +static void * +null_ptr (void) +{ + return NULL; +} + int -main () +main (void) { /* Setup some hierarchy to be used by this test. Start by removing 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); @@ -71,7 +63,7 @@ main () ASSERT (result2 != NULL); ASSERT (strcmp (result1, result2) == 0); ASSERT (strstr (result1, "/" BASE "/tra") - == result1 + strlen (result1) - strlen ("/" BASE "/tra")); + == result1 + strlen (result1) - strlen ("/" BASE "/tra")); free (result1); free (result2); errno = 0; @@ -83,13 +75,16 @@ main () ASSERT (result2 == NULL); ASSERT (errno == ENOENT); errno = 0; - result1 = canonicalize_file_name (NULL); + result1 = canonicalize_file_name (null_ptr ()); ASSERT (result1 == NULL); ASSERT (errno == EINVAL); errno = 0; result2 = canonicalize_filename_mode (NULL, CAN_EXISTING); ASSERT (result2 == NULL); ASSERT (errno == EINVAL); + result2 = canonicalize_filename_mode (".", CAN_MISSING | CAN_ALL_BUT_LAST); + ASSERT (result2 == NULL); + ASSERT (errno == EINVAL); } /* Check that a non-directory with trailing slash yields NULL. */ @@ -125,8 +120,8 @@ main () { 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); @@ -142,6 +137,15 @@ main () ASSERT (symlink ("../s/2", BASE "/d/1") == 0); ASSERT (symlink ("//.//../..", BASE "/droot") == 0); + /* Check that symbolic links are not resolved, with CAN_NOLINKS. */ + { + char *result1 = canonicalize_filename_mode (BASE "/huk", CAN_NOLINKS); + ASSERT (result1 != NULL); + ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/huk"), + "/" BASE "/huk") == 0); + free (result1); + } + /* Check that the symbolic link to a file can be resolved. */ { char *result1 = canonicalize_file_name (BASE "/huk"); @@ -240,26 +244,42 @@ main () { char *result1 = canonicalize_filename_mode (BASE "/zzz", CAN_ALL_BUT_LAST); char *result2 = canonicalize_filename_mode (BASE "/zzz", CAN_MISSING); + char *result3 = canonicalize_filename_mode (BASE "/zzz/", CAN_ALL_BUT_LAST); + char *result4 = canonicalize_filename_mode (BASE "/zzz/", CAN_MISSING); ASSERT (result1 != NULL); ASSERT (result2 != NULL); + ASSERT (result3 != NULL); + ASSERT (result4 != NULL); ASSERT (strcmp (result1, result2) == 0); + ASSERT (strcmp (result2, result3) == 0); + ASSERT (strcmp (result3, result4) == 0); ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/zzz"), "/" BASE "/zzz") == 0); free (result1); free (result2); + free (result3); + free (result4); } /* Check that alternate modes can resolve broken symlink basenames. */ { char *result1 = canonicalize_filename_mode (BASE "/ouk", CAN_ALL_BUT_LAST); char *result2 = canonicalize_filename_mode (BASE "/ouk", CAN_MISSING); + char *result3 = canonicalize_filename_mode (BASE "/ouk/", CAN_ALL_BUT_LAST); + char *result4 = canonicalize_filename_mode (BASE "/ouk/", CAN_MISSING); ASSERT (result1 != NULL); ASSERT (result2 != NULL); + ASSERT (result3 != NULL); + ASSERT (result4 != NULL); ASSERT (strcmp (result1, result2) == 0); + ASSERT (strcmp (result2, result3) == 0); + ASSERT (strcmp (result3, result4) == 0); ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/wum"), "/" BASE "/wum") == 0); free (result1); free (result2); + free (result3); + free (result4); } /* Check that alternate modes can handle missing dirnames. */