diff options
author | Bruno Haible <bruno@clisp.org> | 2021-01-17 17:22:25 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-01-17 22:02:29 +0100 |
commit | b67dcfce4b8d5daf32340616b8bc1b106323c14a (patch) | |
tree | 0e3dc05620c4f9d4788e06b89a57428259aa552c /tests | |
parent | 2473046c43577acf1ab8a9960a85a3273596659c (diff) | |
download | gnulib-b67dcfce4b8d5daf32340616b8bc1b106323c14a.tar.gz |
canonicalize[-lgpl] tests: Add more tests.
* tests/test-canonicalize.c (main): Add detailed tests for // handling.
* tests/test-canonicalize-lgpl.c (main): Likewise.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-canonicalize-lgpl.c | 44 | ||||
-rw-r--r-- | tests/test-canonicalize.c | 47 |
2 files changed, 89 insertions, 2 deletions
diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index d86f7262a6..c0a5a55150 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -67,6 +67,48 @@ main (void) ASSERT (close (fd) == 0); } + /* Check // handling (the easy cases, without symlinks). + This // handling is not mandated by POSIX. However, many applications + expect that canonicalize_file_name "canonicalizes" the file name, + that is, that different results of canonicalize_file_name correspond + to different files (except for hard links). */ + { + char *result0 = canonicalize_file_name ("/etc/passwd"); + if (result0 != NULL) /* This file does not exist on native Windows. */ + { + char *result; + + result = canonicalize_file_name ("/etc//passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_file_name ("/etc///passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + /* On Windows, the syntax //host/share/filename denotes a file + in a directory named 'share', exported from host 'host'. + See also m4/double-slash-root.m4. */ +#if !(defined _WIN32 || defined __CYGWIN__) + result = canonicalize_file_name ("//etc/passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_file_name ("//etc//passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_file_name ("//etc///passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); +#endif + + result = canonicalize_file_name ("///etc/passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_file_name ("///etc//passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_file_name ("///etc///passwd"); + ASSERT (result != NULL && strcmp (result, result0) == 0); + } + } + /* Check for ., .., intermediate // handling, and for error cases. */ { char *result = canonicalize_file_name (BASE "//./..//" BASE "/tra"); @@ -209,7 +251,7 @@ main (void) ASSERT (errno == ELOOP); } - /* Check that leading // is honored correctly. */ + /* Check that leading // within symlinks is honored correctly. */ { struct stat st1; struct stat st2; diff --git a/tests/test-canonicalize.c b/tests/test-canonicalize.c index e85ca4557d..dbde6f2e98 100644 --- a/tests/test-canonicalize.c +++ b/tests/test-canonicalize.c @@ -58,6 +58,51 @@ main (void) ASSERT (close (fd) == 0); } + /* Check // handling (the easy cases, without symlinks). + This // handling is not mandated by POSIX. However, many applications + expect that canonicalize_filename_mode "canonicalizes" the file name, + that is, that different results of canonicalize_filename_mode correspond + to different files (except for hard links). */ + { + char *result0 = canonicalize_file_name ("/etc/passwd"); + if (result0 != NULL) /* This file does not exist on native Windows. */ + { + char *result; + + result = canonicalize_filename_mode ("/etc/passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_filename_mode ("/etc//passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_filename_mode ("/etc///passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + /* On Windows, the syntax //host/share/filename denotes a file + in a directory named 'share', exported from host 'host'. + See also m4/double-slash-root.m4. */ +#if !(defined _WIN32 || defined __CYGWIN__) + result = canonicalize_filename_mode ("//etc/passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_filename_mode ("//etc//passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_filename_mode ("//etc///passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); +#endif + + result = canonicalize_filename_mode ("///etc/passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_filename_mode ("///etc//passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + + result = canonicalize_filename_mode ("///etc///passwd", CAN_MISSING); + ASSERT (result != NULL && strcmp (result, result0) == 0); + } + } + /* Check for ., .., intermediate // handling, and for error cases. */ { char *result1 = canonicalize_file_name (BASE "//./..//" BASE "/tra"); @@ -334,7 +379,7 @@ main (void) free (result2); } - /* Check that leading // is honored correctly. */ + /* Check that leading // within symlinks is honored correctly. */ { struct stat st1; struct stat st2; |