[gtk+] gtk object tests: run under local environment



commit e5828073c28b47c7ef7cc7aacbb54d7cb511bf4a
Author: Lars Uebernickel <lars uebernickel canonical com>
Date:   Sat Nov 9 01:15:33 2013 +0100

    gtk object tests: run under local environment
    
    Make sure that the tests don't access the host's session bus or
    installed gsettings schemas.
    
    Also disable tests for some classes that leak a connection to the
    session bus.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711715

 testsuite/gtk/Makefile.am        |   14 ++++++++++++++
 testsuite/gtk/defaultvalue.c     |   36 +++++++++++++++++++++++++++++++++++-
 testsuite/gtk/object.c           |   11 +++++++++++
 testsuite/gtk/objects-finalize.c |   25 ++++++++++++++++++++++++-
 testsuite/gtk/templates.c        |   12 ++++++++++++
 5 files changed, 96 insertions(+), 2 deletions(-)
---
diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am
index 75e92dd..0c11ef4 100644
--- a/testsuite/gtk/Makefile.am
+++ b/testsuite/gtk/Makefile.am
@@ -129,6 +129,20 @@ EXTRA_DIST +=                              \
        file-chooser-test-dir/text.txt  \
        $(NULL)
 
+GTK_GSETTINGS_SCHEMAS = \
+       $(top_srcdir)/gtk/org.gtk.Settings.ColorChooser.gschema.xml \
+       $(top_srcdir)/gtk/org.gtk.Settings.FileChooser.gschema.xml \
+       $(NULL)
+
+BUILT_SOURCES = gschemas.compiled
+
+gschemas.compiled: $(GTK_GSETTINGS_SCHEMAS)
+       $(GLIB_COMPILE_SCHEMAS) \
+               $(addprefix --schema-file=,$(GTK_GSETTINGS_SCHEMAS)) \
+               --targetdir=$(builddir)
+
+all-am: gschemas.compiled
+
 if BUILDOPT_INSTALL_TESTS
 insttestdir = $(pkglibexecdir)/installed-tests
 insttest_PROGRAMS = $(TEST_PROGS)
diff --git a/testsuite/gtk/defaultvalue.c b/testsuite/gtk/defaultvalue.c
index bdb0bb6..9b2bcaf 100644
--- a/testsuite/gtk/defaultvalue.c
+++ b/testsuite/gtk/defaultvalue.c
@@ -87,6 +87,17 @@ test_type (gconstpointer data)
       g_str_equal (g_type_name (type), "GdkX11Screen"))
     return;
 
+  /* This throws a critical when the connection is dropped */
+  if (g_type_is_a (type, GTK_TYPE_APP_CHOOSER_DIALOG))
+    return;
+
+  /* These leak their GDBusConnections */
+  if (g_type_is_a (type, GTK_TYPE_FILE_CHOOSER_BUTTON) ||
+      g_type_is_a (type, GTK_TYPE_FILE_CHOOSER_DIALOG) ||
+      g_type_is_a (type, GTK_TYPE_FILE_CHOOSER_WIDGET) ||
+      g_type_is_a (type, GTK_TYPE_PLACES_SIDEBAR))
+    return;
+
   klass = g_type_class_ref (type);
 
   if (g_type_is_a (type, GTK_TYPE_SETTINGS))
@@ -384,10 +395,27 @@ main (int argc, char **argv)
 {
   const GType *otypes;
   guint i;
+  gchar *schema_dir;
+  GTestDBus *bus;
+  gint result;
+
+  /* These must be set before before gtk_test_init */
+  g_setenv ("GIO_USE_VFS", "local", TRUE);
+  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
 
   gtk_test_init (&argc, &argv);
   gtk_test_register_all_types();
 
+  /* g_test_build_filename must be called after gtk_test_init */
+  schema_dir = g_test_build_filename (G_TEST_BUILT, "", NULL);
+  g_setenv ("GSETTINGS_SCHEMA_DIR", schema_dir, TRUE);
+
+  /* Create one test bus for all tests, as we have a lot of very small
+   * and quick tests.
+   */
+  bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+  g_test_dbus_up (bus);
+
   otypes = gtk_test_list_all_types (NULL);
   for (i = 0; otypes[i]; i++)
     {
@@ -401,5 +429,11 @@ main (int argc, char **argv)
       g_free (testname);
     }
 
-  return g_test_run();
+  result = g_test_run();
+
+  g_test_dbus_down (bus);
+  g_object_unref (bus);
+  g_free (schema_dir);
+
+  return result;
 }
diff --git a/testsuite/gtk/object.c b/testsuite/gtk/object.c
index 055fc3a..d80b475 100644
--- a/testsuite/gtk/object.c
+++ b/testsuite/gtk/object.c
@@ -308,9 +308,18 @@ main (int   argc,
 {
   const GType *otypes;
   guint i;
+  gchar *schema_dir;
+
+  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
+
   /* initialize test program */
   gtk_test_init (&argc, &argv);
   gtk_test_register_all_types ();
+
+  /* g_test_build_filename must be called after gtk_test_init */
+  schema_dir = g_test_build_filename (G_TEST_BUILT, "", NULL);
+  g_setenv ("GSETTINGS_SCHEMA_DIR", schema_dir, TRUE);
+
   /* install a property test for each widget type */
   otypes = gtk_test_list_all_types (NULL);
   for (i = 0; otypes[i]; i++)
@@ -322,5 +331,7 @@ main (int   argc,
         g_test_add_data_func (testpath, (void*) otypes[i], widget_property_tests);
         g_free (testpath);
       }
+
+  g_free (schema_dir);
   return g_test_run ();
 }
diff --git a/testsuite/gtk/objects-finalize.c b/testsuite/gtk/objects-finalize.c
index 0e1eae0..fd28f88 100644
--- a/testsuite/gtk/objects-finalize.c
+++ b/testsuite/gtk/objects-finalize.c
@@ -78,11 +78,28 @@ main (int argc, char **argv)
 {
   const GType *all_types;
   guint n_types = 0, i;
+  gchar *schema_dir;
+  GTestDBus *bus;
+  gint result;
+
+  /* These must be set before before gtk_test_init */
+  g_setenv ("GIO_USE_VFS", "local", TRUE);
+  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
 
   /* initialize test program */
   gtk_test_init (&argc, &argv);
   gtk_test_register_all_types ();
 
+  /* g_test_build_filename must be called after gtk_test_init */
+  schema_dir = g_test_build_filename (G_TEST_BUILT, "", NULL);
+  g_setenv ("GSETTINGS_SCHEMA_DIR", schema_dir, TRUE);
+
+  /* Create one test bus for all tests, as we have a lot of very small
+   * and quick tests.
+   */
+  bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+  g_test_dbus_up (bus);
+
   all_types = gtk_test_list_all_types (&n_types);
 
   for (i = 0; i < n_types; i++)
@@ -110,5 +127,11 @@ main (int argc, char **argv)
        }
     }
 
-  return g_test_run();
+  result = g_test_run();
+
+  g_test_dbus_down (bus);
+  g_object_unref (bus);
+  g_free (schema_dir);
+
+  return result;
 }
diff --git a/testsuite/gtk/templates.c b/testsuite/gtk/templates.c
index 66ccd1f..e66c835 100644
--- a/testsuite/gtk/templates.c
+++ b/testsuite/gtk/templates.c
@@ -320,9 +320,19 @@ test_print_unix_dialog_basic (void)
 int
 main (int argc, char **argv)
 {
+  gchar *schema_dir;
+
+  /* These must be set before before gtk_test_init */
+  g_setenv ("GIO_USE_VFS", "local", TRUE);
+  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
+
   /* initialize test program */
   gtk_test_init (&argc, &argv);
 
+  /* g_test_build_filename must be called after gtk_test_init */
+  schema_dir = g_test_build_filename (G_TEST_BUILT, "", NULL);
+  g_setenv ("GSETTINGS_SCHEMA_DIR", schema_dir, TRUE);
+
   /* This environment variable cooperates with gtk_widget_destroy()
    * to assert that all automated compoenents are properly finalized
    * when a given composite widget is destroyed.
@@ -355,5 +365,7 @@ main (int argc, char **argv)
   g_test_add_func ("/Template/UnixPrint/GtkPrintUnixDialog/Basic", test_print_unix_dialog_basic);
 #endif
 
+  g_free (schema_dir);
+
   return g_test_run();
 }


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