From 6fe85aee8ded23719faff64599299fd6c2ea480b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 24 Dec 2013 23:26:25 -0500 Subject: [PATCH] Improve fileutils test coverage Add some tests for g_file_read_link. --- glib/tests/fileutils.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c index 5ac5340b8..d12a34ca0 100644 --- a/glib/tests/fileutils.c +++ b/glib/tests/fileutils.c @@ -19,6 +19,7 @@ * if advised of the possibility of such damage. */ +#include "config.h" #include #include @@ -777,6 +778,47 @@ test_set_contents (void) g_free (name); } +static void +test_read_link (void) +{ +#ifdef HAVE_READLINK +#ifdef G_OS_UNIX + int ret; + const gchar *oldpath; + const gchar *newpath; + const gchar *badpath; + gchar *path; + GError *error = NULL; + + oldpath = g_test_get_filename (G_TEST_DIST, "4096-random-bytes", NULL); + newpath = g_test_get_filename (G_TEST_DIST, "page-of-junk", NULL); + badpath = g_test_get_filename (G_TEST_DIST, "4097-random-bytes", NULL); + remove (newpath); + ret = symlink (oldpath, newpath); + g_assert (ret == 0); + path = g_file_read_link (newpath, &error); + g_assert_no_error (error); + g_assert_cmpstr (path, ==, oldpath); + g_free (path); + + remove (newpath); + ret = symlink (badpath, newpath); + g_assert (ret == 0); + path = g_file_read_link (newpath, &error); + g_assert_no_error (error); + g_assert_cmpstr (path, ==, badpath); + g_free (path); + + path = g_file_read_link (oldpath, &error); + g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL); + g_assert_null (path); + +#endif +#else + g_test_skip ("Symbolic links not supported"); +#endif +} + int main (int argc, char *argv[]) @@ -796,6 +838,7 @@ main (int argc, g_test_add_func ("/fileutils/mkstemp", test_mkstemp); g_test_add_func ("/fileutils/mkdtemp", test_mkdtemp); g_test_add_func ("/fileutils/set-contents", test_set_contents); + g_test_add_func ("/fileutils/read-link", test_read_link); return g_test_run (); }