2013-04-05 07:32:56 +00:00
|
|
|
/* objects-finalize.c
|
|
|
|
* Copyright (C) 2013 Openismus GmbH
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: Tristan Van Berkom <tristanvb@openismus.com>
|
|
|
|
*/
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
2017-11-17 04:00:01 +00:00
|
|
|
# include <gdk/x11/gdkx.h>
|
2013-04-05 07:32:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
typedef GType (*GTypeGetFunc) (void);
|
|
|
|
|
2013-05-03 00:42:24 +00:00
|
|
|
static gboolean finalized = FALSE;
|
|
|
|
|
2013-04-05 07:32:56 +00:00
|
|
|
static gboolean
|
|
|
|
main_loop_quit_cb (gpointer data)
|
|
|
|
{
|
2020-02-10 01:06:58 +00:00
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
2013-04-05 07:32:56 +00:00
|
|
|
|
2013-05-03 00:42:24 +00:00
|
|
|
g_assert (finalized);
|
2013-04-05 07:32:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_finalized (gpointer data,
|
|
|
|
GObject *where_the_object_was)
|
|
|
|
{
|
|
|
|
gboolean *did_finalize = (gboolean *)data;
|
|
|
|
|
|
|
|
*did_finalize = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_finalize_object (gconstpointer data)
|
|
|
|
{
|
|
|
|
GType test_type = GPOINTER_TO_SIZE (data);
|
|
|
|
GObject *object;
|
2020-02-10 01:06:58 +00:00
|
|
|
gboolean done;
|
2013-04-05 07:32:56 +00:00
|
|
|
|
2018-04-27 10:32:17 +00:00
|
|
|
if (g_str_equal (g_type_name (test_type), "GdkClipboard"))
|
2017-12-27 01:10:34 +00:00
|
|
|
object = g_object_new (test_type, "display", gdk_display_get_default (), NULL);
|
2018-07-14 17:02:42 +00:00
|
|
|
else if (g_str_equal (g_type_name (test_type), "GdkDrag") ||
|
2018-04-30 12:10:44 +00:00
|
|
|
g_str_equal (g_type_name (test_type), "GdkDrop"))
|
2018-05-07 15:31:26 +00:00
|
|
|
{
|
|
|
|
GdkContentFormats *formats = gdk_content_formats_new_for_gtype (G_TYPE_STRING);
|
|
|
|
object = g_object_new (test_type,
|
|
|
|
"device", gdk_seat_get_pointer (gdk_display_get_default_seat (gdk_display_get_default ())),
|
|
|
|
"formats", formats,
|
|
|
|
NULL);
|
|
|
|
gdk_content_formats_unref (formats);
|
|
|
|
}
|
2019-10-07 04:36:25 +00:00
|
|
|
else if (g_type_is_a (test_type, GTK_TYPE_FILTER_LIST_MODEL) ||
|
2019-10-07 04:28:28 +00:00
|
|
|
g_type_is_a (test_type, GTK_TYPE_NO_SELECTION) ||
|
2019-12-09 06:19:38 +00:00
|
|
|
g_type_is_a (test_type, GTK_TYPE_SINGLE_SELECTION) ||
|
|
|
|
g_type_is_a (test_type, GTK_TYPE_MULTI_SELECTION))
|
2018-08-31 03:34:18 +00:00
|
|
|
{
|
|
|
|
GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
|
|
|
|
object = g_object_new (test_type,
|
|
|
|
"model", list_store,
|
|
|
|
NULL);
|
|
|
|
g_object_unref (list_store);
|
|
|
|
}
|
2020-06-06 13:40:04 +00:00
|
|
|
else if (g_type_is_a (test_type, GTK_TYPE_LAYOUT_CHILD) ||
|
|
|
|
g_type_is_a (test_type, GTK_TYPE_PROPERTY_SELECTION))
|
2019-03-26 18:05:48 +00:00
|
|
|
{
|
2020-06-06 13:40:04 +00:00
|
|
|
char *msg = g_strdup_printf ("Skipping %s", g_type_name (test_type));
|
|
|
|
g_test_skip (msg);
|
|
|
|
g_free (msg);
|
2019-03-26 18:05:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-27 01:10:34 +00:00
|
|
|
else
|
2018-04-27 10:32:17 +00:00
|
|
|
object = g_object_new (test_type, NULL);
|
2013-04-05 07:32:56 +00:00
|
|
|
g_assert (G_IS_OBJECT (object));
|
|
|
|
|
|
|
|
/* Make sure we have the only reference */
|
|
|
|
if (g_object_is_floating (object))
|
|
|
|
g_object_ref_sink (object);
|
|
|
|
|
|
|
|
/* Assert that the object finalizes properly */
|
|
|
|
g_object_weak_ref (object, check_finalized, &finalized);
|
|
|
|
|
|
|
|
/* Toplevels are owned by GTK+, just tell GTK+ to destroy it */
|
2019-02-06 07:06:19 +00:00
|
|
|
if (GTK_IS_WINDOW (object))
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (object));
|
2013-04-05 07:32:56 +00:00
|
|
|
else
|
|
|
|
g_object_unref (object);
|
|
|
|
|
|
|
|
/* Even if the object did finalize, it may have left some dangerous stuff in the GMainContext */
|
2020-02-10 01:06:58 +00:00
|
|
|
done = FALSE;
|
|
|
|
g_timeout_add (50, main_loop_quit_cb, &done);
|
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-04-05 07:32:56 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 03:24:39 +00:00
|
|
|
static gboolean
|
|
|
|
dbind_warning_handler (const char *log_domain,
|
|
|
|
GLogLevelFlags log_level,
|
|
|
|
const char *message,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (strcmp (log_domain, "dbind") == 0 &&
|
|
|
|
log_level == (G_LOG_LEVEL_WARNING|G_LOG_FLAG_FATAL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-04-05 07:32:56 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
const GType *all_types;
|
|
|
|
guint n_types = 0, i;
|
2013-11-09 00:15:33 +00:00
|
|
|
gint result;
|
2020-02-04 13:13:33 +00:00
|
|
|
const char *display, *x_r_d;
|
2013-11-09 00:15:33 +00:00
|
|
|
|
2020-05-28 08:00:03 +00:00
|
|
|
/* These must be set before gtk_test_init */
|
2013-11-09 00:15:33 +00:00
|
|
|
g_setenv ("GIO_USE_VFS", "local", TRUE);
|
|
|
|
g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
|
2013-04-05 07:32:56 +00:00
|
|
|
|
2020-02-04 13:13:33 +00:00
|
|
|
/* 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");
|
2013-04-05 07:32:56 +00:00
|
|
|
|
2020-02-04 13:13:33 +00:00
|
|
|
if (display)
|
|
|
|
g_setenv ("DISPLAY", display, TRUE);
|
|
|
|
if (x_r_d)
|
|
|
|
g_setenv ("XDG_RUNTIME_DIR", x_r_d, TRUE);
|
|
|
|
|
2020-02-06 03:24:39 +00:00
|
|
|
g_test_log_set_fatal_handler (dbind_warning_handler, NULL);
|
|
|
|
|
2020-02-04 13:13:33 +00:00
|
|
|
/* initialize test program */
|
|
|
|
gtk_test_init (&argc, &argv);
|
|
|
|
gtk_test_register_all_types ();
|
|
|
|
|
2013-04-05 07:32:56 +00:00
|
|
|
all_types = gtk_test_list_all_types (&n_types);
|
|
|
|
|
|
|
|
for (i = 0; i < n_types; i++)
|
|
|
|
{
|
|
|
|
if (g_type_is_a (all_types[i], G_TYPE_OBJECT) &&
|
|
|
|
G_TYPE_IS_INSTANTIATABLE (all_types[i]) &&
|
|
|
|
!G_TYPE_IS_ABSTRACT (all_types[i]) &&
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
2018-03-20 10:40:08 +00:00
|
|
|
all_types[i] != GDK_TYPE_X11_SURFACE &&
|
2013-04-05 07:32:56 +00:00
|
|
|
all_types[i] != GDK_TYPE_X11_SCREEN &&
|
|
|
|
all_types[i] != GDK_TYPE_X11_DISPLAY &&
|
|
|
|
all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_XI2 &&
|
2014-10-22 03:46:11 +00:00
|
|
|
all_types[i] != GDK_TYPE_X11_GL_CONTEXT &&
|
2013-04-05 07:32:56 +00:00
|
|
|
#endif
|
|
|
|
/* Not allowed to finalize a GdkPixbufLoader without calling gdk_pixbuf_loader_close() */
|
2013-04-05 11:44:12 +00:00
|
|
|
all_types[i] != GDK_TYPE_PIXBUF_LOADER &&
|
2020-03-19 15:57:02 +00:00
|
|
|
all_types[i] != gdk_pixbuf_simple_anim_iter_get_type() &&
|
2020-03-20 15:19:45 +00:00
|
|
|
!g_type_is_a (all_types[i], GTK_TYPE_SHORTCUT_TRIGGER) &&
|
|
|
|
!g_type_is_a (all_types[i], GTK_TYPE_SHORTCUT_ACTION))
|
2013-04-05 07:32:56 +00:00
|
|
|
{
|
|
|
|
gchar *test_path = g_strdup_printf ("/FinalizeObject/%s", g_type_name (all_types[i]));
|
|
|
|
|
|
|
|
g_test_add_data_func (test_path, GSIZE_TO_POINTER (all_types[i]), test_finalize_object);
|
|
|
|
|
|
|
|
g_free (test_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-09 00:15:33 +00:00
|
|
|
result = g_test_run();
|
|
|
|
|
|
|
|
return result;
|
2013-04-05 07:32:56 +00:00
|
|
|
}
|