tests: Initialize dbus before gtk
authorAlexander Larsson <alexl@redhat.com>
Tue, 4 Feb 2020 13:13:33 +0000 (14:13 +0100)
committerAlexander Larsson <alexl@redhat.com>
Tue, 4 Feb 2020 13:13:33 +0000 (14:13 +0100)
These days initilizing gtk may create a connection to the sesson bus,
so we have to initialize GTestDBus before initalizing gtk, or we'll
use the address of the "real" session bus (and remember that in the
global).

To further muck things up, g_test_dbus_up() resets important env
vars like DISPLAY and XDG_RUNTIME_DIR, which we have to re-set.

testsuite/gtk/defaultvalue.c
testsuite/gtk/objects-finalize.c

index 0164107422d9c20a4f5767935f5b68d60cd79c3f..fd7bc37fcda63c07d6030f7a3169ed547fecbae1 100644 (file)
@@ -423,14 +423,16 @@ main (int argc, char **argv)
   GTestDBus *bus;
   GMainLoop *loop;
   gint result;
+  const char *display, *x_r_d;
 
   /* These must be set before before gtk_test_init */
   g_setenv ("GIO_USE_VFS", "local", TRUE);
   g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
   g_setenv ("G_ENABLE_DIAGNOSTIC", "0", TRUE);
 
-  gtk_test_init (&argc, &argv);
-  gtk_test_register_all_types();
+  /* g_test_dbus_up() helpfully clears these, so we have to re-set it */
+  display = g_getenv ("DISPLAY");
+  x_r_d = g_getenv ("XDG_RUNTIME_DIR");
 
   /* Create one test bus for all tests, as we have a lot of very small
    * and quick tests.
@@ -438,6 +440,14 @@ main (int argc, char **argv)
   bus = g_test_dbus_new (G_TEST_DBUS_NONE);
   g_test_dbus_up (bus);
 
+  if (display)
+    g_setenv ("DISPLAY", display, TRUE);
+  if (x_r_d)
+    g_setenv ("XDG_RUNTIME_DIR", x_r_d, TRUE);
+
+  gtk_test_init (&argc, &argv);
+  gtk_test_register_all_types();
+
   otypes = gtk_test_list_all_types (NULL);
   for (i = 0; otypes[i]; i++)
     {
index 5ee575bf3b2e06b193f72706af19e8a12efc795e..f1d85016ed4a9da10636a830bf9173631178cc3c 100644 (file)
@@ -108,14 +108,15 @@ main (int argc, char **argv)
   guint n_types = 0, i;
   GTestDBus *bus;
   gint result;
+  const char *display, *x_r_d;
 
   /* 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_dbus_up() helpfully clears these, so we have to re-set it */
+  display = g_getenv ("DISPLAY");
+  x_r_d = g_getenv ("XDG_RUNTIME_DIR");
 
   /* Create one test bus for all tests, as we have a lot of very small
    * and quick tests.
@@ -123,6 +124,16 @@ main (int argc, char **argv)
   bus = g_test_dbus_new (G_TEST_DBUS_NONE);
   g_test_dbus_up (bus);
 
+  if (display)
+    g_setenv ("DISPLAY", display, TRUE);
+  if (x_r_d)
+    g_setenv ("XDG_RUNTIME_DIR", x_r_d, TRUE);
+
+  /* initialize test program */
+  gtk_test_init (&argc, &argv);
+  gtk_test_register_all_types ();
+
+
   all_types = gtk_test_list_all_types (&n_types);
 
   for (i = 0; i < n_types; i++)