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
This commit is contained in:
Lars Uebernickel 2013-11-09 01:15:33 +01:00
parent 9d8a32b07d
commit e5828073c2
5 changed files with 96 additions and 2 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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 ();
}

View File

@ -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;
}

View File

@ -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();
}