gtk2/gtk/gtktestutils.c

184 lines
4.9 KiB
C
Raw Normal View History

/* Gtk+ testing utilities
* Copyright (C) 2007 Imendio AB
* Authors: Tim Janik
*
* 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/>.
*/
#include "config.h"
#include "gtkspinbutton.h"
#include "gtkmain.h"
#include "gtkbox.h"
#include "gtklabel.h"
#include "gtkbutton.h"
#include "gtktextview.h"
#include "gtkrange.h"
#include <locale.h>
#include <string.h>
#include <math.h>
/* 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
#include <gtk/gtk.h>
#define GTK_COMPILATION
#include <gsk/gl/gskglrenderer.h>
#ifdef GDK_WINDOWING_BROADWAY
#include <gsk/broadway/gskbroadwayrenderer.h>
#endif
#ifdef GDK_RENDERING_VULKAN
#include <gsk/vulkan/gskvulkanrenderer.h>
#endif
#ifdef GDK_WINDOWING_X11
#include <gdk/x11/gdkx.h>
#endif
/**
* SECTION:gtktesting
* @Short_description: Utilities for testing GTK applications
* @Title: Testing
*/
/**
* gtk_test_init:
2014-02-04 23:30:46 +00:00
* @argcp: Address of the `argc` parameter of the
* main() function. Changed if any arguments were handled.
* @argvp: (inout) (array length=argcp): Address of the
2014-02-04 23:30:46 +00:00
* `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
*
* This function is used to initialize a GTK test program.
*
* It will in turn call g_test_init() and gtk_init() to properly
2014-02-07 18:35:54 +00:00
* initialize the testing framework and graphical toolkit. Itll
* also set the programs locale to C. This is done to make test
* program environments as deterministic as possible.
*
* Like gtk_init() and g_test_init(), any known arguments will be
* processed and stripped from @argc and @argv.
**/
void
gtk_test_init (int *argcp,
char ***argvp,
...)
{
call g_test_init() from gtk_test_init(). 2007-11-22 15:39:40 Tim Janik <timj@imendio.com> * gtk/gtktestutils.c: call g_test_init() from gtk_test_init(). * gtk/tests/testing.c: use g_test_add_func() to register tests and use g_test_run() to run the tests to integrate with the testing framework. * gtk/tests/Makefile.am: removed exemplary testing rules. * Makefile.am, gtk/tests/Makefile.am, gtk/Makefile.am: * gtk/xdgmime/Makefile.am, gtk/theme-bits/Makefile.am: * tests/Makefile.am, docs/reference/gdk-pixbuf/Makefile.am: * docs/reference/gdk/Makefile.am, docs/reference/gtk/Makefile.am: * docs/reference/Makefile.am, docs/tools/Makefile.am: * docs/tutorial/Makefile.am, docs/faq/Makefile.am, docs/Makefile.am: * gdk-pixbuf/pixops/Makefile.am, gdk-pixbuf/Makefile.am: * demos/gtk-demo/Makefile.am, demos/Makefile.am: * modules/input/Makefile.am, modules/printbackends/file/Makefile.am: * modules/printbackends/test/Makefile.am, modules/printbackends/Makefile.am: * modules/printbackends/cups/Makefile.am, modules/printbackends/lpr/Makefile.am: * modules/engines/ms-windows/Theme/gtk-2.0/Makefile.am: * modules/engines/ms-windows/Theme/Makefile.am: * modules/engines/ms-windows/Makefile.am: * modules/engines/Makefile.am, modules/engines/pixbuf/Makefile.am: * modules/Makefile.am, m4macros/Makefile.am, perf/Makefile.am: * contrib/Makefile.am, contrib/gdk-pixbuf-xlib/Makefile.am: * gdk/directfb/Makefile.am, gdk/linux-fb/Makefile.am: * gdk/quartz/Makefile.am, gdk/win32/rc/Makefile.am: * gdk/win32/Makefile.am, gdk/x11/Makefile.am, gdk/Makefile.am: include $(top_srcdir)/Makefile.decl, adapted EXTRA_DIST assignments. svn path=/trunk/; revision=19033
2007-11-22 14:38:26 +00:00
g_test_init (argcp, argvp, NULL);
gtk_disable_setlocale();
setlocale (LC_ALL, "en_US.UTF-8");
gtk_init ();
}
static gboolean
quit_main_loop_callback (GtkWidget *widget,
GdkFrameClock *frame_clock,
gpointer user_data)
{
gboolean *done = user_data;
*done = TRUE;
g_main_context_wakeup (NULL);
return G_SOURCE_REMOVE;
}
/**
* gtk_test_widget_wait_for_draw:
* @widget: the widget to wait for
*
2014-02-05 18:07:34 +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.
*
* This function is intended to be used for syncing with actions that
* depend on @widget relayouting or on interaction with the display
* server.
**/
void
gtk_test_widget_wait_for_draw (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
gboolean done = FALSE;
/* 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,
&done,
NULL);
while (!done)
g_main_context_iteration (NULL, TRUE);
}
static GType *all_registered_types = NULL;
static guint n_all_registered_types = 0;
/**
* gtk_test_list_all_types:
* @n_types: location to store number of types
*
* Return the type ids that have been registered after
* calling gtk_test_register_all_types().
*
2011-07-23 02:00:34 +00:00
* Returns: (array length=n_types zero-terminated=1) (transfer none):
* 0-terminated array of type ids
*/
const GType*
gtk_test_list_all_types (guint *n_types)
{
if (n_types)
*n_types = n_all_registered_types;
return all_registered_types;
}
/**
* gtk_test_register_all_types:
*
2020-10-03 16:52:19 +00:00
* Force registration of all core GTK object types.
*
* This allowes to refer to any of those object types via
* g_type_from_name() after calling this function.
**/
void
gtk_test_register_all_types (void)
{
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;
#include <gtktypefuncs.inc>
n_all_registered_types = tp - all_registered_types;
g_assert (n_all_registered_types + 1 < max_gtk_types);
*tp = 0;
}
}