[glib/glib-2-22] Don't fail a couple of tests when running as root



commit bc8a748291dbd37698564fb3417e2b7465023974
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date:   Fri Feb 19 19:00:02 2010 +0100

    Don't fail a couple of tests when running as root
    
    root can access and write to a directory when it doesn't have
    exec and write permissions respectively. So expect the tests that
    check that to succeed rather than to fail when running as root.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=552912
    (cherry picked from commit 202d7d37d6ce066291504276810c350c9a3feb7a)

 gio/tests/live-g-file.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/gio/tests/live-g-file.c b/gio/tests/live-g-file.c
index e0f9bff..1ca70ce 100644
--- a/gio/tests/live-g-file.c
+++ b/gio/tests/live-g-file.c
@@ -23,6 +23,8 @@
 #include <glib/glib.h>
 #include <gio/gio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
 #include <string.h>
 #include <sys/stat.h>
 
@@ -100,6 +102,7 @@ static const struct StructureItem sample_struct[] = {
 	{"lost_symlink",		"nowhere",	G_FILE_TYPE_SYMBOLIC_LINK, G_FILE_CREATE_NONE, 0, 0, TEST_COPY | TEST_DELETE_NORMAL | TEST_OPEN | TEST_INVALID_SYMLINK},
   };
 
+static gboolean test_suite;
 static gboolean write_test;
 static gboolean verbose;
 static gboolean posix_compat;
@@ -715,8 +718,17 @@ do_copy_move (GFile * root, struct StructureItem item, const char *target_dir,
   else if (((item.extra_flags & TEST_NO_ACCESS) == TEST_NO_ACCESS) ||
 	   (extra_flags == TEST_NO_ACCESS))
     {
-      g_assert_cmpint (res, ==, FALSE);
-      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED);
+      /* This works for root, see bug #552912 */
+      if (test_suite && getuid () == 0)
+	{
+	  g_assert_cmpint (res, ==, TRUE);
+	  g_assert_no_error (error);
+	}
+      else
+	{
+	  g_assert_cmpint (res, ==, FALSE);
+	  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED);
+	}
     }
   /*  no error should be found, all exceptions defined above  */
   else
@@ -1111,6 +1123,7 @@ main (int argc, char *argv[])
     {NULL}
   };
 
+  test_suite = FALSE;
   verbose = FALSE;
   write_test = FALSE;
   only_create_struct = FALSE;
@@ -1124,6 +1137,7 @@ main (int argc, char *argv[])
   /*  no extra parameters specified, assume we're executed from glib test suite  */ 
   if (argc < 2)
     {
+	  test_suite = TRUE;
 	  verbose = TRUE;
 	  write_test = TRUE;
 	  only_create_struct = FALSE;



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