/* Gtk+ testing utilities
- * Copyright (C) 2007 Tim Janik
+ * 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gtktestutils.h"
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-#include <x11/gdkx.h>
-#include "gtkalias.h"
-#include <X11/Xlib.h>
+
+#include "config.h"
+
+#include <gtk/gtkx.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>
-/* --- test utilities --- */
+/**
+ * SECTION:gtktesting
+ * @Short_description: Utilities for testing GTK+ applications
+ * @Title: Testing
+ */
+
/**
* gtk_test_init:
- * @argc: Address of the <parameter>argc</parameter> parameter of the
+ * @argcp: Address of the <parameter>argc</parameter> parameter of the
* main() function. Changed if any arguments were handled.
- * @argv: Address of the <parameter>argv</parameter> parameter of main().
+ * @argvp: (inout) (array length=argcp): Address of the
+ * <parameter>argv</parameter> parameter of main().
* Any parameters understood by g_test_init() or gtk_init() are
* stripped before return.
+ * @...: currently unused
+ *
+ * This function is used to initialize a GTK+ test program.
*
- * This function is used to initialize a Gtk+ test program.
* It will in turn call g_test_init() and gtk_init() to properly
- * initialize the testing framework and graphical toolkit.
- * It'll also set the program's locale to "C" and prevent loading of
- * rc files and Gtk+ modules. This is done to make tets program
+ * initialize the testing framework and graphical toolkit. It'll
+ * also set the program's locale to "C" and prevent loading of rc
+ * files and Gtk+ modules. This is done to make tets 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.
+ *
+ * Since: 2.14
**/
void
gtk_test_init (int *argcp,
char ***argvp,
...)
{
+ g_test_init (argcp, argvp, NULL);
/* - enter C locale
* - call g_test_init();
* - call gtk_init();
* FUTURE TODO:
* - this function could install a mock object around GtkSettings
*/
- // FIXME: g_test_init (argcp, argvp, NULL);
g_setenv ("GTK_MODULES", "", TRUE);
- g_setenv ("GTK2_RC_FILES", "/dev/null", TRUE);
gtk_disable_setlocale();
setlocale (LC_ALL, "C");
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=%s");
+
+ /* XSendEvent() doesn't work yet on XI2 events.
+ * So at the moment gdk_test_simulate_* can only
+ * send events that GTK+ understands if XI2 is
+ * disabled, bummer.
+ */
+ gdk_disable_multidevice ();
+
gtk_init (argcp, argvp);
}
test_find_widget_input_windows (GtkWidget *widget,
gboolean input_only)
{
+ GdkWindow *window;
GList *node, *children;
GSList *matches = NULL;
gpointer udata;
- gdk_window_get_user_data (widget->window, &udata);
- if (udata == widget && (!input_only || (GDK_IS_WINDOW (widget->window) && GDK_WINDOW_OBJECT (widget->window)->input_only)))
- matches = g_slist_prepend (matches, widget->window);
+
+ window = gtk_widget_get_window (widget);
+
+ gdk_window_get_user_data (window, &udata);
+ if (udata == widget && (!input_only || (GDK_IS_WINDOW (window) && gdk_window_is_input_only (GDK_WINDOW (window)))))
+ matches = g_slist_prepend (matches, window);
children = gdk_window_get_children (gtk_widget_get_parent_window (widget));
for (node = children; node; node = node->next)
{
gdk_window_get_user_data (node->data, &udata);
- if (udata == widget && (!input_only || (GDK_IS_WINDOW (node->data) && GDK_WINDOW_OBJECT (node->data)->input_only)))
+ if (udata == widget && (!input_only || (GDK_IS_WINDOW (node->data) && gdk_window_is_input_only (GDK_WINDOW (node->data)))))
matches = g_slist_prepend (matches, node->data);
}
return g_slist_reverse (matches);
}
/**
- * gtk_test_simulate_key
- * @window: Gdk window to simulate a key event for.
- * @x: x coordinate within @window for the key event.
- * @y: y coordinate within @window for the key event.
- * @keyval: A Gdk keyboard value.
- * @modifiers: Keyboard modifiers the event is setup with.
- * @press_or_release: %TRUE to generate key press events, %FALSE to generate key release events.
- *
- * This function is intended to be used in Gtk+ test programs.
- * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
- * the given (@x,@y) corrdinates within @window and simulate a
- * key press or release event.
- * When the mouse pointer is warped to the target location, use
- * of this function outside of test programs that run in their
- * own virtual windowing system (e.g. Xvfb) is not recommended.
- * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
- * be warped and @window origin will be used as mouse pointer
- * location for the event.
- * Also, gtk_test_simulate_key() is a fairly low level function,
- * for most testing purposes, gtk_test_widget_send_key() is the
- * right function to call which will generate a key press event
- * followed by its accompanying key release event.
- *
- * Returns: wether all actions neccessary for a key event simulation were carried out successfully.
- **/
-gboolean
-gtk_test_simulate_key (GdkWindow *window,
- gint x,
- gint y,
- guint keyval,
- GdkModifierType modifiers,
- gboolean press_or_release)
-{
- GdkScreen *screen = gdk_colormap_get_screen (gdk_drawable_get_colormap (window));
- GdkKeymapKey *keys = NULL;
- gboolean success;
- gint n_keys = 0;
- XKeyEvent xev = {
- 0, /* type */
- 0, /* serial */
- 1, /* send_event */
- };
- if (x < 0 && y < 0)
- {
- gdk_drawable_get_size (window, &x, &y);
- x /= 2;
- y /= 2;
- }
- xev.type = press_or_release ? KeyPress : KeyRelease;
- xev.display = GDK_DRAWABLE_XDISPLAY (window);
- xev.window = GDK_WINDOW_XID (window);
- xev.root = RootWindow (xev.display, GDK_SCREEN_XNUMBER (screen));
- xev.subwindow = 0;
- xev.time = 0;
- xev.x = MAX (x, 0);
- xev.y = MAX (y, 0);
- xev.x_root = 0;
- xev.y_root = 0;
- xev.state = modifiers;
- xev.keycode = 0;
- success = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_for_display (gdk_drawable_get_display (window)), keyval, &keys, &n_keys);
- success &= n_keys > 0;
- if (success)
- {
- gint i;
- for (i = 0; i < n_keys; i++)
- if (keys[i].group == 0 && keys[i].level == 0)
- {
- xev.keycode = keys[i].keycode;
- break;
- }
- if (i >= n_keys) /* no match for group==0 and level==0 */
- xev.keycode = keys[0].keycode;
- }
- g_free (keys);
- if (!success)
- return FALSE;
- gdk_error_trap_push ();
- xev.same_screen = XTranslateCoordinates (xev.display, xev.window, xev.root,
- xev.x, xev.y, &xev.x_root, &xev.y_root,
- &xev.subwindow);
- if (!xev.subwindow)
- xev.subwindow = xev.window;
- success &= xev.same_screen;
- if (x >= 0 && y >= 0)
- success &= 0 != XWarpPointer (xev.display, None, xev.window, 0, 0, 0, 0, xev.x, xev.y);
- success &= 0 != XSendEvent (xev.display, xev.window, True, press_or_release ? KeyPressMask : KeyReleaseMask, (XEvent*) &xev);
- XSync (xev.display, False);
- success &= 0 == gdk_error_trap_pop();
- return success;
-}
-
-/**
- * gtk_test_widget_send_key
+ * gtk_test_widget_send_key:
* @widget: Widget to generate a key press and release on.
* @keyval: A Gdk keyboard value.
* @modifiers: Keyboard modifiers the event is setup with.
* input-only event window. For other widgets, this is usually widget->window.
* Certain caveats should be considered when using this function, in
* particular because the mouse pointer is warped to the key press
- * location, see gtk_test_simulate_key() for details.
+ * location, see gdk_test_simulate_key() for details.
+ *
+ * Returns: whether all actions neccessary for the key event simulation were carried out successfully.
*
- * Returns: wether all actions neccessary for the key event simulation were carried out successfully.
+ * Since: 2.14
**/
gboolean
gtk_test_widget_send_key (GtkWidget *widget,
iwindows = test_find_widget_input_windows (widget, TRUE);
if (!iwindows)
return FALSE;
- k1res = gtk_test_simulate_key (iwindows->data, -1, -1, keyval, modifiers, TRUE);
- k2res = gtk_test_simulate_key (iwindows->data, -1, -1, keyval, modifiers, FALSE);
+ k1res = gdk_test_simulate_key (iwindows->data, -1, -1, keyval, modifiers, GDK_KEY_PRESS);
+ k2res = gdk_test_simulate_key (iwindows->data, -1, -1, keyval, modifiers, GDK_KEY_RELEASE);
g_slist_free (iwindows);
return k1res && k2res;
}
/**
- * gtk_test_simulate_button
- * @window: Gdk window to simulate a button event for.
- * @x: x coordinate within @window for the button event.
- * @y: y coordinate within @window for the button event.
- * @button: Number of the pointer button for the event, usually 1, 2 or 3.
- * @modifiers: Keyboard modifiers the event is setup with.
- * @press_or_release: %TRUE to generate button press events, %FALSE to generate button release events.
- *
- * This function is intended to be used in Gtk+ test programs.
- * It will warp the mouse pointer to the given (@x,@y) corrdinates
- * within @window and simulate a button press or release event.
- * Because the mouse pointer needs to be warped to the target
- * location, use of this function outside of test programs that
- * run in their own virtual windowing system (e.g. Xvfb) is not
- * recommended.
- * Also, gtk_test_simulate_button() is a fairly low level function,
- * for most testing purposes, gtk_test_widget_click() is the right
- * function to call which will generate a button press event followed
- * by its accompanying button release event.
- *
- * Returns: wether all actions neccessary for a button event simulation were carried out successfully.
- **/
-gboolean
-gtk_test_simulate_button (GdkWindow *window,
- gint x,
- gint y,
- guint button, /*1..3*/
- GdkModifierType modifiers,
- gboolean press_or_release)
-{
- GdkScreen *screen = gdk_colormap_get_screen (gdk_drawable_get_colormap (window));
- XButtonEvent xev = {
- 0, /* type */
- 0, /* serial */
- 1, /* send_event */
- };
- if (x < 0 && y < 0)
- {
- gdk_drawable_get_size (window, &x, &y);
- x /= 2;
- y /= 2;
- }
- xev.type = press_or_release ? ButtonPress : ButtonRelease;
- xev.display = GDK_DRAWABLE_XDISPLAY (window);
- xev.window = GDK_WINDOW_XID (window);
- xev.root = RootWindow (xev.display, GDK_SCREEN_XNUMBER (screen));
- xev.subwindow = 0;
- xev.time = 0;
- xev.x = x;
- xev.y = y;
- xev.x_root = 0;
- xev.y_root = 0;
- xev.state = modifiers;
- xev.button = button;
- gdk_error_trap_push ();
- xev.same_screen = XTranslateCoordinates (xev.display, xev.window, xev.root,
- xev.x, xev.y, &xev.x_root, &xev.y_root,
- &xev.subwindow);
- if (!xev.subwindow)
- xev.subwindow = xev.window;
- gboolean success = xev.same_screen;
- success &= 0 != XWarpPointer (xev.display, None, xev.window, 0, 0, 0, 0, xev.x, xev.y);
- success &= 0 != XSendEvent (xev.display, xev.window, True, press_or_release ? ButtonPressMask : ButtonReleaseMask, (XEvent*) &xev);
- XSync (xev.display, False);
- success &= 0 == gdk_error_trap_pop();
- return success;
-}
-
-/**
- * gtk_test_widget_click
+ * gtk_test_widget_click:
* @widget: Widget to generate a button click on.
* @button: Number of the pointer button for the event, usually 1, 2 or 3.
* @modifiers: Keyboard modifiers the event is setup with.
* input-only event window. For other widgets, this is usually widget->window.
* Certain caveats should be considered when using this function, in
* particular because the mouse pointer is warped to the button click
- * location, see gtk_test_simulate_button() for details.
+ * location, see gdk_test_simulate_button() for details.
+ *
+ * Returns: whether all actions neccessary for the button click simulation were carried out successfully.
*
- * Returns: wether all actions neccessary for the button click simulation were carried out successfully.
+ * Since: 2.14
**/
gboolean
gtk_test_widget_click (GtkWidget *widget,
iwindows = test_find_widget_input_windows (widget, TRUE);
if (!iwindows)
return FALSE;
- b1res = gtk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, TRUE);
- b2res = gtk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, FALSE);
+ b1res = gdk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, GDK_BUTTON_PRESS);
+ b2res = gdk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, GDK_BUTTON_RELEASE);
g_slist_free (iwindows);
return b1res && b2res;
}
/**
- * gtk_test_spin_button_click
+ * gtk_test_spin_button_click:
* @spinner: valid GtkSpinButton widget.
* @button: Number of the pointer button for the event, usually 1, 2 or 3.
* @upwards: %TRUE for upwards arrow click, %FALSE for downwards arrow click.
* spin button arrow areas, usually leading to an increase or decrease of
* spin button's value.
*
- * Returns: wether all actions neccessary for the button click simulation were carried out successfully.
+ * Returns: whether all actions neccessary for the button click simulation were carried out successfully.
+ *
+ * Since: 2.14
**/
gboolean
gtk_test_spin_button_click (GtkSpinButton *spinner,
guint button,
gboolean upwards)
{
+ GdkWindow *down_panel = NULL, *up_panel = NULL, *panel;
gboolean b1res = FALSE, b2res = FALSE;
- if (spinner->panel)
+
+ _gtk_spin_button_get_panels (spinner, &down_panel, &up_panel);
+
+ panel = (upwards) ? up_panel : down_panel;
+
+ if (panel)
{
- gint width, height, pos;
- gdk_drawable_get_size (spinner->panel, &width, &height);
- pos = upwards ? 0 : height - 1;
- b1res = gtk_test_simulate_button (spinner->panel, width - 1, pos, button, 0, TRUE);
- b2res = gtk_test_simulate_button (spinner->panel, width - 1, pos, button, 0, FALSE);
+ gint width = gdk_window_get_width (panel);
+ b1res = gdk_test_simulate_button (panel, width - 1, 1, button, 0, GDK_BUTTON_PRESS);
+ b2res = gdk_test_simulate_button (panel, width - 1, 1, button, 0, GDK_BUTTON_RELEASE);
}
return b1res && b2res;
}
/**
- * gtk_test_find_label
+ * gtk_test_find_label:
* @widget: Valid label or container widget.
* @label_pattern: Shell-glob pattern to match a label string.
*
* so this function is genrally only useful in test programs with
* predetermined locales, see gtk_test_init() for more details.
*
- * Returns: a GtkLabel widget if any is found.
+ * Returns: (transfer none): a GtkLabel widget if any is found.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_find_label (GtkWidget *widget,
GtkWidget *b,
GtkWidget *base)
{
+ GtkAllocation allocation;
int ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, xdist = 0, ydist = 0;
+
+ gtk_widget_get_allocation (a, &allocation);
if (!gtk_widget_translate_coordinates (a, base, 0, 0, &ax0, &ay0) ||
- !gtk_widget_translate_coordinates (a, base, a->allocation.width, a->allocation.height, &ax1, &ay1))
+ !gtk_widget_translate_coordinates (a, base, allocation.width, allocation.height, &ax1, &ay1))
return -G_MAXINT;
+
+ gtk_widget_get_allocation (b, &allocation);
if (!gtk_widget_translate_coordinates (b, base, 0, 0, &bx0, &by0) ||
- !gtk_widget_translate_coordinates (b, base, b->allocation.width, b->allocation.height, &bx1, &by1))
+ !gtk_widget_translate_coordinates (b, base, allocation.width, allocation.height, &bx1, &by1))
return +G_MAXINT;
+
if (bx0 >= ax1)
xdist = bx0 - ax1;
else if (ax0 >= bx1)
ydist = by0 - ay1;
else if (ay0 >= by1)
ydist = ay0 - by1;
+
return xdist + ydist;
}
}
/**
- * gtk_test_find_sibling
+ * gtk_test_find_sibling:
* @base_widget: Valid widget, part of a widget hierarchy
* @widget_type: Type of a aearched for sibling widget
*
* @base_widget will be returned.
* The general purpose of this function is to find the most likely "action"
* widget, relative to another labeling widget. Such as finding a
- * button or text entry widget, given it's corresponding label widget.
+ * button or text entry widget, given its corresponding label widget.
+ *
+ * Returns: (transfer none): a widget of type @widget_type if any is found.
*
- * Returns: a widget of type @widget_type if any is found.
+ * Since: 2.14
**/
GtkWidget*
gtk_test_find_sibling (GtkWidget *base_widget,
/* find all sibling candidates */
while (tmpwidget)
{
- tmpwidget = tmpwidget->parent;
+ tmpwidget = gtk_widget_get_parent (tmpwidget);
siblings = g_list_concat (siblings, test_list_descendants (tmpwidget, widget_type));
}
/* sort them by distance to base_widget */
}
/**
- * gtk_test_find_widget
+ * gtk_test_find_widget:
* @widget: Container widget, usually a GtkWindow.
* @label_pattern: Shell-glob pattern to match a label string.
* @widget_type: Type of a aearched for label sibling widget.
* gtk_test_widget_click() for possible caveats involving the search of
* such widgets and synthesizing widget events.
*
- * Returns: a valid widget if any is found or %NULL.
+ * Returns: (transfer none): a valid widget if any is found or %NULL.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_find_widget (GtkWidget *widget,
}
/**
- * gtk_test_slider_set_perc
+ * gtk_test_slider_set_perc:
* @widget: valid widget pointer.
* @percentage: value between 0 and 100.
*
- * This function will adjust theslider position of all GtkRange
+ * This function will adjust the slider position of all GtkRange
* based widgets, such as scrollbars or scales, it'll also adjust
- * spin buttons. The adjustment value of tehse widgets is set to
+ * spin buttons. The adjustment value of these widgets is set to
* a value between the lower and upper limits, according to the
* @percentage argument.
+ *
+ * Since: 2.14
**/
void
gtk_test_slider_set_perc (GtkWidget *widget,
else if (GTK_IS_SPIN_BUTTON (widget))
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
if (adjustment)
- gtk_adjustment_set_value (adjustment, adjustment->lower + (adjustment->upper - adjustment->lower - adjustment->page_size) * percentage * 0.01);
+ gtk_adjustment_set_value (adjustment,
+ gtk_adjustment_get_lower (adjustment)
+ + (gtk_adjustment_get_upper (adjustment)
+ - gtk_adjustment_get_lower (adjustment)
+ - gtk_adjustment_get_page_size (adjustment))
+ * percentage * 0.01);
}
/**
- * gtk_test_slider_get_value
+ * gtk_test_slider_get_value:
* @widget: valid widget pointer.
*
* Retrive the literal adjustment value for GtkRange based
* of the adjustment belonging to @widget, and is not a percentage
* as passed in to gtk_test_slider_set_perc().
*
- * Returns: adjustment->value for an adjustment belonging to @widget.
+ * Returns: gtk_adjustment_get_value (adjustment) for an adjustment belonging to @widget.
+ *
+ * Since: 2.14
**/
double
gtk_test_slider_get_value (GtkWidget *widget)
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget));
else if (GTK_IS_SPIN_BUTTON (widget))
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
- return adjustment ? adjustment->value : 0;
+ return adjustment ? gtk_adjustment_get_value (adjustment) : 0;
}
/**
- * gtk_test_text_set
+ * gtk_test_text_set:
* @widget: valid widget pointer.
* @string: a 0-terminated C string
*
* Set the text string of @widget to @string if it is a GtkLabel,
* GtkEditable (entry and text widgets) or GtkTextView.
+ *
+ * Since: 2.14
**/
void
gtk_test_text_set (GtkWidget *widget,
}
/**
- * gtk_test_text_get
+ * gtk_test_text_get:
* @widget: valid widget pointer.
*
* Retrive the text string of @widget if it is a GtkLabel,
* GtkEditable (entry and text widgets) or GtkTextView.
*
- * Returns: new 0-terminated C string, needs to be releaed with g_free().
+ * Returns: new 0-terminated C string, needs to be released with g_free().
+ *
+ * Since: 2.14
**/
gchar*
gtk_test_text_get (GtkWidget *widget)
}
/**
- * gtk_test_create_widget
- * @widget_type: valid widget type.
- * @first_property_name: Name of first property to set or %NULL
+ * gtk_test_create_widget:
+ * @widget_type: a valid widget type.
+ * @first_property_name: (allow-none): Name of first property to set or %NULL
+ * @...: value to set the first property to, followed by more
+ * name-value pairs, terminated by %NULL
*
* This function wraps g_object_new() for widget types.
* It'll automatically show all created non window widgets, also
* g_object_ref_sink() them (to keep them alive across a running test)
- * and set them up for destruction during test teardown phase.
+ * and set them up for destruction during the next test teardown phase.
*
- * Returns: a newly created widget.
+ * Returns: (transfer none): a newly created widget.
+ *
+ * Since: 2.14
*/
GtkWidget*
gtk_test_create_widget (GType widget_type,
if (!GTK_IS_WINDOW (widget))
gtk_widget_show (widget);
g_object_ref_sink (widget);
-#ifdef __G_TESTFRAMEWORK_H__ /* FIXME */
g_test_queue_unref (widget);
g_test_queue_destroy ((GDestroyNotify) gtk_widget_destroy, widget);
-#endif
}
return widget;
}
static int
test_increment_intp (int *intp)
{
- *intp += 1;
+ if (intp != NULL)
+ *intp += 1;
return 1; /* TRUE in case we're connected to event signals */
}
/**
- * gtk_test_display_button_window
+ * gtk_test_display_button_window:
* @window_title: Title of the window to be displayed.
* @dialog_text: Text inside the window to be displayed.
* @...: %NULL terminated list of (const char *label, int *nump) pairs.
* The window will quit any running gtk_main()-loop when destroyed, and it
* will automatically be destroyed upon test function teardown.
*
- * Returns: a widget pointer to the newly created GtkWindow.
+ * Returns: (transfer full): a widget pointer to the newly created GtkWindow.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_display_button_window (const gchar *window_title,
{
va_list var_args;
GtkWidget *window = gtk_test_create_widget (GTK_TYPE_WINDOW, "title", window_title, NULL);
- GtkWidget *vbox = gtk_test_create_widget (GTK_TYPE_VBOX, "parent", window, NULL);
+ GtkWidget *vbox = gtk_test_create_widget (GTK_TYPE_BOX, "parent", window, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
const char *arg1;
gtk_test_create_widget (GTK_TYPE_LABEL, "label", dialog_text, "parent", vbox, NULL);
g_signal_connect (window, "destroy", G_CALLBACK (try_main_quit), NULL);
}
/**
- * gtk_test_create_simple_window
+ * gtk_test_create_simple_window:
* @window_title: Title of the window to be displayed.
* @dialog_text: Text inside the window to be displayed.
*
* The window will quit any running gtk_main()-loop when destroyed, and it
* will automatically be destroyed upon test function teardown.
*
- * Returns: a widget pointer to the newly created GtkWindow.
+ * Returns: (transfer none): a widget pointer to the newly created GtkWindow.
+ *
+ * Since: 2.14
**/
GtkWidget*
gtk_test_create_simple_window (const gchar *window_title,
const gchar *dialog_text)
{
GtkWidget *window = gtk_test_create_widget (GTK_TYPE_WINDOW, "title", window_title, NULL);
- GtkWidget *vbox = gtk_test_create_widget (GTK_TYPE_VBOX, "parent", window, NULL);
+ GtkWidget *vbox = gtk_test_create_widget (GTK_TYPE_BOX, "parent", window, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
gtk_test_create_widget (GTK_TYPE_LABEL, "label", dialog_text, "parent", vbox, NULL);
g_signal_connect (window, "destroy", G_CALLBACK (try_main_quit), NULL);
gtk_widget_show_all (vbox);
return window;
}
+static GType *all_registered_types = NULL;
+static guint n_all_registered_types = 0;
+
/**
- * gtk_test_xserver_render_sync
- * @window: a mapped GdkWindow
+ * gtk_test_list_all_types:
+ * @n_types: location to store number of types
*
- * This function retrives a pixel from @window to force the windowing
- * system to carry out any pending rendering commands.
- * This function is intended to be used to syncronize with rendering
- * pipelines, to benchmark windowing system rendering operations.
- **/
-void
-gtk_test_xserver_render_sync (GdkWindow *window)
+ * Return the type ids that have been registered after
+ * calling gtk_test_register_all_types().
+ *
+ * Returns: (array length=n_types zero-terminated=1) (transfer none):
+ * 0-terminated array of type ids
+ *
+ * Since: 2.14
+ */
+const GType*
+gtk_test_list_all_types (guint *n_types)
{
- static GdkImage *p1image = NULL;
- /* syncronize to X drawing queue, see:
- * http://mail.gnome.org/archives/gtk-devel-list/2006-October/msg00103.html
- */
- p1image = gdk_drawable_copy_to_image (window, p1image, 0, 0, 0, 0, 1, 1);
+ if (n_types)
+ *n_types = n_all_registered_types;
+ return all_registered_types;
}
/**
- * gtk_test_register_all_types
+ * gtk_test_register_all_types:
*
* Force registration of all core Gtk+ and Gdk object types.
* This allowes to refer to any of those object types via
* g_type_from_name() after calling this function.
+ *
+ * Since: 2.14
**/
void
gtk_test_register_all_types (void)
{
- volatile GType vgt;
+ 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.c"
+ n_all_registered_types = tp - all_registered_types;
+ g_assert (n_all_registered_types + 1 < max_gtk_types);
+ *tp = 0;
+ }
}
-
-#define __GTK_TEST_UTILS_C__
-#include "gtkaliasdef.c"