From: Alexander Larsson Date: Tue, 4 Feb 2020 13:13:33 +0000 (+0100) Subject: tests: Initialize dbus before gtk X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~89^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=008eb0412596ef9a76d5338b86f25399a29f830e;p=gtk4.git tests: Initialize dbus before gtk 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. --- diff --git a/testsuite/gtk/defaultvalue.c b/testsuite/gtk/defaultvalue.c index 0164107422..fd7bc37fcd 100644 --- a/testsuite/gtk/defaultvalue.c +++ b/testsuite/gtk/defaultvalue.c @@ -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++) { diff --git a/testsuite/gtk/objects-finalize.c b/testsuite/gtk/objects-finalize.c index 5ee575bf3b..f1d85016ed 100644 --- a/testsuite/gtk/objects-finalize.c +++ b/testsuite/gtk/objects-finalize.c @@ -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++)