[glib] Improve fileutils test coverage



commit 6fe85aee8ded23719faff64599299fd6c2ea480b
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 24 23:26:25 2013 -0500

    Improve fileutils test coverage
    
    Add some tests for g_file_read_link.

 glib/tests/fileutils.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c
index 5ac5340..d12a34c 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 <string.h>
 #include <errno.h>
 
@@ -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 ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]