2007-11-20 15:03:26 +00:00
|
|
|
|
/* Gtk+ testing utilities
|
2007-11-20 17:44:06 +00:00
|
|
|
|
* Copyright (C) 2007 Imendio AB
|
|
|
|
|
* Authors: Tim Janik
|
2007-11-20 15:03:26 +00:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2007-11-20 15:03:26 +00:00
|
|
|
|
*/
|
2008-02-15 23:13:30 +00:00
|
|
|
|
|
2008-06-17 09:58:09 +00:00
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2008-02-15 23:13:30 +00:00
|
|
|
|
|
2010-07-12 22:11:39 +00:00
|
|
|
|
#include "gtkspinbutton.h"
|
2011-11-02 05:15:21 +00:00
|
|
|
|
#include "gtkmain.h"
|
|
|
|
|
#include "gtkbox.h"
|
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkbutton.h"
|
|
|
|
|
#include "gtktextview.h"
|
|
|
|
|
#include "gtkrange.h"
|
2007-11-20 15:03:26 +00:00
|
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
2014-07-12 03:29:54 +00:00
|
|
|
|
/* This is a hack.
|
|
|
|
|
* We want to include the same headers as gtktypefuncs.c but we are not
|
|
|
|
|
* allowed to include gtkx.h directly during GTK compilation.
|
|
|
|
|
* So....
|
|
|
|
|
*/
|
|
|
|
|
#undef GTK_COMPILATION
|
2016-10-03 16:30:40 +00:00
|
|
|
|
#include <gtk/gtk.h>
|
2014-07-12 03:29:54 +00:00
|
|
|
|
#define GTK_COMPILATION
|
2007-11-20 15:03:26 +00:00
|
|
|
|
|
2021-10-07 03:15:25 +00:00
|
|
|
|
#include <gsk/gl/gskglrenderer.h>
|
2020-11-16 19:16:53 +00:00
|
|
|
|
|
|
|
|
|
#ifdef GDK_WINDOWING_BROADWAY
|
|
|
|
|
#include <gsk/broadway/gskbroadwayrenderer.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef GDK_RENDERING_VULKAN
|
|
|
|
|
#include <gsk/vulkan/gskvulkanrenderer.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-11-23 21:11:48 +00:00
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
|
#include <gdk/x11/gdkx.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-11-20 15:03:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_test_init:
|
2014-02-04 23:30:46 +00:00
|
|
|
|
* @argcp: Address of the `argc` parameter of the
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* main() function. Changed if any arguments were handled.
|
|
|
|
|
* @argvp: (inout) (array length=argcp): Address of the `argv`
|
|
|
|
|
* parameter of main(). Any parameters understood by g_test_init()
|
|
|
|
|
* or gtk_init() are stripped before return.
|
2011-07-23 02:00:34 +00:00
|
|
|
|
* @...: currently unused
|
2008-07-21 23:23:41 +00:00
|
|
|
|
*
|
2020-09-12 16:01:04 +00:00
|
|
|
|
* This function is used to initialize a GTK test program.
|
2007-11-20 15:03:26 +00:00
|
|
|
|
*
|
|
|
|
|
* It will in turn call g_test_init() and gtk_init() to properly
|
2021-03-02 03:53:25 +00:00
|
|
|
|
* initialize the testing framework and graphical toolkit. It’ll
|
2018-04-16 01:32:51 +00:00
|
|
|
|
* also set the program’s locale to “C”. This is done to make test
|
|
|
|
|
* program environments as deterministic as possible.
|
2008-07-21 23:23:41 +00:00
|
|
|
|
*
|
2007-11-20 15:03:26 +00:00
|
|
|
|
* Like gtk_init() and g_test_init(), any known arguments will be
|
|
|
|
|
* processed and stripped from @argc and @argv.
|
2021-03-02 03:53:25 +00:00
|
|
|
|
*/
|
2007-11-20 15:03:26 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_test_init (int *argcp,
|
|
|
|
|
char ***argvp,
|
|
|
|
|
...)
|
|
|
|
|
{
|
2021-04-13 00:57:02 +00:00
|
|
|
|
/* g_test_init is defined as a macro that aborts if assertions
|
|
|
|
|
* are disabled. We don't want that, so we call the function.
|
|
|
|
|
*/
|
|
|
|
|
(g_test_init) (argcp, argvp, NULL);
|
2007-11-20 15:03:26 +00:00
|
|
|
|
gtk_disable_setlocale();
|
2019-04-12 04:08:28 +00:00
|
|
|
|
setlocale (LC_ALL, "en_US.UTF-8");
|
2010-12-20 12:48:10 +00:00
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
|
gtk_init ();
|
2007-11-20 15:03:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-16 23:35:04 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
quit_main_loop_callback (GtkWidget *widget,
|
|
|
|
|
GdkFrameClock *frame_clock,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2020-02-10 03:24:47 +00:00
|
|
|
|
gboolean *done = user_data;
|
|
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
2013-05-16 23:35:04 +00:00
|
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_test_widget_wait_for_draw:
|
|
|
|
|
* @widget: the widget to wait for
|
|
|
|
|
*
|
2021-03-02 03:53:25 +00:00
|
|
|
|
* Enters the main loop and waits for @widget to be “drawn”.
|
|
|
|
|
*
|
|
|
|
|
* In this context that means it waits for the frame clock of
|
|
|
|
|
* @widget to have run a full styling, layout and drawing cycle.
|
2013-05-16 23:35:04 +00:00
|
|
|
|
*
|
|
|
|
|
* This function is intended to be used for syncing with actions that
|
|
|
|
|
* depend on @widget relayouting or on interaction with the display
|
|
|
|
|
* server.
|
2021-03-02 03:53:25 +00:00
|
|
|
|
*/
|
2013-05-16 23:35:04 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_test_widget_wait_for_draw (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
2020-02-10 03:24:47 +00:00
|
|
|
|
gboolean done = FALSE;
|
2013-05-16 23:35:04 +00:00
|
|
|
|
|
|
|
|
|
/* We can do this here because the whole tick procedure does not
|
|
|
|
|
* reenter the main loop. Otherwise we'd need to manually get the
|
|
|
|
|
* frame clock and connect to the after-paint signal.
|
|
|
|
|
*/
|
|
|
|
|
gtk_widget_add_tick_callback (widget,
|
|
|
|
|
quit_main_loop_callback,
|
2020-02-10 03:24:47 +00:00
|
|
|
|
&done,
|
2013-05-16 23:35:04 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
|
while (!done)
|
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-05-16 23:35:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-05 16:58:44 +00:00
|
|
|
|
static GType *all_registered_types = NULL;
|
|
|
|
|
static guint n_all_registered_types = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-20 14:08:11 +00:00
|
|
|
|
* gtk_test_list_all_types:
|
2007-12-05 16:58:44 +00:00
|
|
|
|
* @n_types: location to store number of types
|
|
|
|
|
*
|
|
|
|
|
* Return the type ids that have been registered after
|
|
|
|
|
* calling gtk_test_register_all_types().
|
2008-08-15 18:01:00 +00:00
|
|
|
|
*
|
2011-07-23 02:00:34 +00:00
|
|
|
|
* Returns: (array length=n_types zero-terminated=1) (transfer none):
|
|
|
|
|
* 0-terminated array of type ids
|
|
|
|
|
*/
|
2007-12-05 16:58:44 +00:00
|
|
|
|
const GType*
|
|
|
|
|
gtk_test_list_all_types (guint *n_types)
|
|
|
|
|
{
|
|
|
|
|
if (n_types)
|
|
|
|
|
*n_types = n_all_registered_types;
|
|
|
|
|
return all_registered_types;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-20 15:03:26 +00:00
|
|
|
|
/**
|
2011-01-20 14:08:11 +00:00
|
|
|
|
* gtk_test_register_all_types:
|
2007-11-20 15:03:26 +00:00
|
|
|
|
*
|
2020-10-03 16:52:19 +00:00
|
|
|
|
* Force registration of all core GTK object types.
|
|
|
|
|
*
|
2022-11-18 03:24:18 +00:00
|
|
|
|
* This allows to refer to any of those object types via
|
2007-11-20 15:03:26 +00:00
|
|
|
|
* g_type_from_name() after calling this function.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_test_register_all_types (void)
|
|
|
|
|
{
|
2007-12-05 16:58:44 +00:00
|
|
|
|
if (!all_registered_types)
|
|
|
|
|
{
|
|
|
|
|
const guint max_gtk_types = 999;
|
|
|
|
|
GType *tp;
|
|
|
|
|
all_registered_types = g_new0 (GType, max_gtk_types);
|
|
|
|
|
tp = all_registered_types;
|
2017-02-05 13:41:38 +00:00
|
|
|
|
#include <gtktypefuncs.inc>
|
2007-12-05 16:58:44 +00:00
|
|
|
|
n_all_registered_types = tp - all_registered_types;
|
|
|
|
|
g_assert (n_all_registered_types + 1 < max_gtk_types);
|
|
|
|
|
*tp = 0;
|
|
|
|
|
}
|
2007-11-20 15:03:26 +00:00
|
|
|
|
}
|