]> Pileus Git - ~andy/gtk/blob - gtk/gtktestutils.c
c4e3c7f33a9748605495525272421e86557aa009
[~andy/gtk] / gtk / gtktestutils.c
1 /* Gtk+ testing utilities
2  * Copyright (C) 2007 Imendio AB
3  * Authors: Tim Janik
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21
22 #include "config.h"
23
24 #include <gtk/gtkx.h>
25 #include "gtkspinbutton.h"
26 #include "gtkmain.h"
27 #include "gtkbox.h"
28 #include "gtklabel.h"
29 #include "gtkbutton.h"
30 #include "gtktextview.h"
31 #include "gtkrange.h"
32
33 #include <locale.h>
34 #include <string.h>
35 #include <math.h>
36
37
38 /**
39  * SECTION:gtktesting
40  * @Short_description: Utilities for testing GTK+ applications
41  * @Title: Testing
42  */
43
44 /**
45  * gtk_test_init:
46  * @argcp: Address of the <parameter>argc</parameter> parameter of the
47  *        main() function. Changed if any arguments were handled.
48  * @argvp: (inout) (array length=argcp): Address of the 
49  *        <parameter>argv</parameter> parameter of main().
50  *        Any parameters understood by g_test_init() or gtk_init() are
51  *        stripped before return.
52  * @...: currently unused
53  *
54  * This function is used to initialize a GTK+ test program.
55  *
56  * It will in turn call g_test_init() and gtk_init() to properly
57  * initialize the testing framework and graphical toolkit. It'll 
58  * also set the program's locale to "C" and prevent loading of rc 
59  * files and Gtk+ modules. This is done to make tets program
60  * environments as deterministic as possible.
61  *
62  * Like gtk_init() and g_test_init(), any known arguments will be
63  * processed and stripped from @argc and @argv.
64  *
65  * Since: 2.14
66  **/
67 void
68 gtk_test_init (int    *argcp,
69                char ***argvp,
70                ...)
71 {
72   g_test_init (argcp, argvp, NULL);
73   /* - enter C locale
74    * - call g_test_init();
75    * - call gtk_init();
76    * - prevent RC files from loading;
77    * - prevent Gtk modules from loading;
78    * - supply mock object for GtkSettings
79    * FUTURE TODO:
80    * - this function could install a mock object around GtkSettings
81    */
82   g_setenv ("GTK_MODULES", "", TRUE);
83   gtk_disable_setlocale();
84   setlocale (LC_ALL, "C");
85   g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=%s");
86
87   /* XSendEvent() doesn't work yet on XI2 events.
88    * So at the moment gdk_test_simulate_* can only
89    * send events that GTK+ understands if XI2 is
90    * disabled, bummer.
91    */
92   gdk_disable_multidevice ();
93
94   gtk_init (argcp, argvp);
95 }
96
97 static GSList*
98 test_find_widget_input_windows (GtkWidget *widget,
99                                 gboolean   input_only)
100 {
101   GdkWindow *window;
102   GList *node, *children;
103   GSList *matches = NULL;
104   gpointer udata;
105
106   window = gtk_widget_get_window (widget);
107
108   gdk_window_get_user_data (window, &udata);
109   if (udata == widget && (!input_only || (GDK_IS_WINDOW (window) && gdk_window_is_input_only (GDK_WINDOW (window)))))
110     matches = g_slist_prepend (matches, window);
111   children = gdk_window_get_children (gtk_widget_get_parent_window (widget));
112   for (node = children; node; node = node->next)
113     {
114       gdk_window_get_user_data (node->data, &udata);
115       if (udata == widget && (!input_only || (GDK_IS_WINDOW (node->data) && gdk_window_is_input_only (GDK_WINDOW (node->data)))))
116         matches = g_slist_prepend (matches, node->data);
117     }
118   return g_slist_reverse (matches);
119 }
120
121 /**
122  * gtk_test_widget_send_key:
123  * @widget: Widget to generate a key press and release on.
124  * @keyval: A Gdk keyboard value.
125  * @modifiers: Keyboard modifiers the event is setup with.
126  *
127  * This function will generate keyboard press and release events in
128  * the middle of the first GdkWindow found that belongs to @widget.
129  * For %GTK_NO_WINDOW widgets like GtkButton, this will often be an
130  * input-only event window. For other widgets, this is usually widget->window.
131  * Certain caveats should be considered when using this function, in
132  * particular because the mouse pointer is warped to the key press
133  * location, see gdk_test_simulate_key() for details.
134  *
135  * Returns: wether all actions neccessary for the key event simulation were carried out successfully.
136  *
137  * Since: 2.14
138  **/
139 gboolean
140 gtk_test_widget_send_key (GtkWidget      *widget,
141                           guint           keyval,
142                           GdkModifierType modifiers)
143 {
144   gboolean k1res, k2res;
145   GSList *iwindows = test_find_widget_input_windows (widget, FALSE);
146   if (!iwindows)
147     iwindows = test_find_widget_input_windows (widget, TRUE);
148   if (!iwindows)
149     return FALSE;
150   k1res = gdk_test_simulate_key (iwindows->data, -1, -1, keyval, modifiers, GDK_KEY_PRESS);
151   k2res = gdk_test_simulate_key (iwindows->data, -1, -1, keyval, modifiers, GDK_KEY_RELEASE);
152   g_slist_free (iwindows);
153   return k1res && k2res;
154 }
155
156 /**
157  * gtk_test_widget_click:
158  * @widget: Widget to generate a button click on.
159  * @button: Number of the pointer button for the event, usually 1, 2 or 3.
160  * @modifiers: Keyboard modifiers the event is setup with.
161  *
162  * This function will generate a @button click (button press and button
163  * release event) in the middle of the first GdkWindow found that belongs
164  * to @widget.
165  * For %GTK_NO_WINDOW widgets like GtkButton, this will often be an
166  * input-only event window. For other widgets, this is usually widget->window.
167  * Certain caveats should be considered when using this function, in
168  * particular because the mouse pointer is warped to the button click
169  * location, see gdk_test_simulate_button() for details.
170  *
171  * Returns: wether all actions neccessary for the button click simulation were carried out successfully.
172  *
173  * Since: 2.14
174  **/
175 gboolean
176 gtk_test_widget_click (GtkWidget      *widget,
177                        guint           button,
178                        GdkModifierType modifiers)
179 {
180   gboolean b1res, b2res;
181   GSList *iwindows = test_find_widget_input_windows (widget, FALSE);
182   if (!iwindows)
183     iwindows = test_find_widget_input_windows (widget, TRUE);
184   if (!iwindows)
185     return FALSE;
186   b1res = gdk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, GDK_BUTTON_PRESS);
187   b2res = gdk_test_simulate_button (iwindows->data, -1, -1, button, modifiers, GDK_BUTTON_RELEASE);
188   g_slist_free (iwindows);
189   return b1res && b2res;
190 }
191
192 /**
193  * gtk_test_spin_button_click:
194  * @spinner: valid GtkSpinButton widget.
195  * @button:  Number of the pointer button for the event, usually 1, 2 or 3.
196  * @upwards: %TRUE for upwards arrow click, %FALSE for downwards arrow click.
197  *
198  * This function will generate a @button click in the upwards or downwards
199  * spin button arrow areas, usually leading to an increase or decrease of
200  * spin button's value.
201  *
202  * Returns: wether all actions neccessary for the button click simulation were carried out successfully.
203  *
204  * Since: 2.14
205  **/
206 gboolean
207 gtk_test_spin_button_click (GtkSpinButton  *spinner,
208                             guint           button,
209                             gboolean        upwards)
210 {
211   GdkWindow *down_panel = NULL, *up_panel = NULL, *panel;
212   gboolean b1res = FALSE, b2res = FALSE;
213
214   _gtk_spin_button_get_panels (spinner, &down_panel, &up_panel);
215
216   panel = (upwards) ? up_panel : down_panel;
217
218   if (panel)
219     {
220       gint width = gdk_window_get_width (panel);
221       b1res = gdk_test_simulate_button (panel, width - 1, 1, button, 0, GDK_BUTTON_PRESS);
222       b2res = gdk_test_simulate_button (panel, width - 1, 1, button, 0, GDK_BUTTON_RELEASE);
223     }
224   return b1res && b2res;
225 }
226
227 /**
228  * gtk_test_find_label:
229  * @widget:        Valid label or container widget.
230  * @label_pattern: Shell-glob pattern to match a label string.
231  *
232  * This function will search @widget and all its descendants for a GtkLabel
233  * widget with a text string matching @label_pattern.
234  * The @label_pattern may contain asterisks '*' and question marks '?' as
235  * placeholders, g_pattern_match() is used for the matching.
236  * Note that locales other than "C" tend to alter (translate" label strings,
237  * so this function is genrally only useful in test programs with
238  * predetermined locales, see gtk_test_init() for more details.
239  *
240  * Returns: (transfer none): a GtkLabel widget if any is found.
241  *
242  * Since: 2.14
243  **/
244 GtkWidget*
245 gtk_test_find_label (GtkWidget    *widget,
246                      const gchar  *label_pattern)
247 {
248   if (GTK_IS_LABEL (widget))
249     {
250       const gchar *text = gtk_label_get_text (GTK_LABEL (widget));
251       if (g_pattern_match_simple (label_pattern, text))
252         return widget;
253     }
254   if (GTK_IS_CONTAINER (widget))
255     {
256       GList *node, *list = gtk_container_get_children (GTK_CONTAINER (widget));
257       for (node = list; node; node = node->next)
258         {
259           GtkWidget *label = gtk_test_find_label (node->data, label_pattern);
260           if (label)
261             return label;
262         }
263       g_list_free (list);
264     }
265   return NULL;
266 }
267
268 static GList*
269 test_list_descendants (GtkWidget *widget,
270                        GType      widget_type)
271 {
272   GList *results = NULL;
273   if (GTK_IS_CONTAINER (widget))
274     {
275       GList *node, *list = gtk_container_get_children (GTK_CONTAINER (widget));
276       for (node = list; node; node = node->next)
277         {
278           if (!widget_type || g_type_is_a (G_OBJECT_TYPE (node->data), widget_type))
279             results = g_list_prepend (results, node->data);
280           else
281             results = g_list_concat (results, test_list_descendants (node->data, widget_type));
282         }
283       g_list_free (list);
284     }
285   return results;
286 }
287
288 static int
289 widget_geo_dist (GtkWidget *a,
290                  GtkWidget *b,
291                  GtkWidget *base)
292 {
293   GtkAllocation allocation;
294   int ax0, ay0, ax1, ay1, bx0, by0, bx1, by1, xdist = 0, ydist = 0;
295
296   gtk_widget_get_allocation (a, &allocation);
297   if (!gtk_widget_translate_coordinates (a, base, 0, 0, &ax0, &ay0) ||
298       !gtk_widget_translate_coordinates (a, base, allocation.width, allocation.height, &ax1, &ay1))
299     return -G_MAXINT;
300
301   gtk_widget_get_allocation (b, &allocation);
302   if (!gtk_widget_translate_coordinates (b, base, 0, 0, &bx0, &by0) ||
303       !gtk_widget_translate_coordinates (b, base, allocation.width, allocation.height, &bx1, &by1))
304     return +G_MAXINT;
305
306   if (bx0 >= ax1)
307     xdist = bx0 - ax1;
308   else if (ax0 >= bx1)
309     xdist = ax0 - bx1;
310   if (by0 >= ay1)
311     ydist = by0 - ay1;
312   else if (ay0 >= by1)
313     ydist = ay0 - by1;
314
315   return xdist + ydist;
316 }
317
318 static int
319 widget_geo_cmp (gconstpointer a,
320                 gconstpointer b,
321                 gpointer      user_data)
322 {
323   gpointer *data = user_data;
324   GtkWidget *wa = (void*) a, *wb = (void*) b, *toplevel = data[0], *base_widget = data[1];
325   int adist = widget_geo_dist (wa, base_widget, toplevel);
326   int bdist = widget_geo_dist (wb, base_widget, toplevel);
327   return adist > bdist ? +1 : adist == bdist ? 0 : -1;
328 }
329
330 /**
331  * gtk_test_find_sibling:
332  * @base_widget:        Valid widget, part of a widget hierarchy
333  * @widget_type:        Type of a aearched for sibling widget
334  *
335  * This function will search siblings of @base_widget and siblings of its
336  * ancestors for all widgets matching @widget_type.
337  * Of the matching widgets, the one that is geometrically closest to
338  * @base_widget will be returned.
339  * The general purpose of this function is to find the most likely "action"
340  * widget, relative to another labeling widget. Such as finding a
341  * button or text entry widget, given its corresponding label widget.
342  *
343  * Returns: (transfer none): a widget of type @widget_type if any is found.
344  *
345  * Since: 2.14
346  **/
347 GtkWidget*
348 gtk_test_find_sibling (GtkWidget *base_widget,
349                        GType      widget_type)
350 {
351   GList *siblings = NULL;
352   GtkWidget *tmpwidget = base_widget;
353   gpointer data[2];
354   /* find all sibling candidates */
355   while (tmpwidget)
356     {
357       tmpwidget = gtk_widget_get_parent (tmpwidget);
358       siblings = g_list_concat (siblings, test_list_descendants (tmpwidget, widget_type));
359     }
360   /* sort them by distance to base_widget */
361   data[0] = gtk_widget_get_toplevel (base_widget);
362   data[1] = base_widget;
363   siblings = g_list_sort_with_data (siblings, widget_geo_cmp, data);
364   /* pick nearest != base_widget */
365   siblings = g_list_remove (siblings, base_widget);
366   tmpwidget = siblings ? siblings->data : NULL;
367   g_list_free (siblings);
368   return tmpwidget;
369 }
370
371 /**
372  * gtk_test_find_widget:
373  * @widget:        Container widget, usually a GtkWindow.
374  * @label_pattern: Shell-glob pattern to match a label string.
375  * @widget_type:   Type of a aearched for label sibling widget.
376  *
377  * This function will search the descendants of @widget for a widget
378  * of type @widget_type that has a label matching @label_pattern next
379  * to it. This is most useful for automated GUI testing, e.g. to find
380  * the "OK" button in a dialog and synthesize clicks on it.
381  * However see gtk_test_find_label(), gtk_test_find_sibling() and
382  * gtk_test_widget_click() for possible caveats involving the search of
383  * such widgets and synthesizing widget events.
384  *
385  * Returns: (transfer none): a valid widget if any is found or %NULL.
386  *
387  * Since: 2.14
388  **/
389 GtkWidget*
390 gtk_test_find_widget (GtkWidget    *widget,
391                       const gchar  *label_pattern,
392                       GType         widget_type)
393 {
394   GtkWidget *label = gtk_test_find_label (widget, label_pattern);
395   if (!label)
396     label = gtk_test_find_label (gtk_widget_get_toplevel (widget), label_pattern);
397   if (label)
398     return gtk_test_find_sibling (label, widget_type);
399   return NULL;
400 }
401
402 /**
403  * gtk_test_slider_set_perc:
404  * @widget:     valid widget pointer.
405  * @percentage: value between 0 and 100.
406  *
407  * This function will adjust the slider position of all GtkRange
408  * based widgets, such as scrollbars or scales, it'll also adjust
409  * spin buttons. The adjustment value of these widgets is set to
410  * a value between the lower and upper limits, according to the
411  * @percentage argument.
412  *
413  * Since: 2.14
414  **/
415 void
416 gtk_test_slider_set_perc (GtkWidget      *widget,
417                           double          percentage)
418 {
419   GtkAdjustment *adjustment = NULL;
420   if (GTK_IS_RANGE (widget))
421     adjustment = gtk_range_get_adjustment (GTK_RANGE (widget));
422   else if (GTK_IS_SPIN_BUTTON (widget))
423     adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
424   if (adjustment)
425     gtk_adjustment_set_value (adjustment, 
426                               gtk_adjustment_get_lower (adjustment) 
427                               + (gtk_adjustment_get_upper (adjustment) 
428                                  - gtk_adjustment_get_lower (adjustment) 
429                                  - gtk_adjustment_get_page_size (adjustment))
430                                 * percentage * 0.01);
431 }
432
433 /**
434  * gtk_test_slider_get_value:
435  * @widget:     valid widget pointer.
436  *
437  * Retrive the literal adjustment value for GtkRange based
438  * widgets and spin buttons. Note that the value returned by
439  * this function is anything between the lower and upper bounds
440  * of the adjustment belonging to @widget, and is not a percentage
441  * as passed in to gtk_test_slider_set_perc().
442  *
443  * Returns: gtk_adjustment_get_value (adjustment) for an adjustment belonging to @widget.
444  *
445  * Since: 2.14
446  **/
447 double
448 gtk_test_slider_get_value (GtkWidget *widget)
449 {
450   GtkAdjustment *adjustment = NULL;
451   if (GTK_IS_RANGE (widget))
452     adjustment = gtk_range_get_adjustment (GTK_RANGE (widget));
453   else if (GTK_IS_SPIN_BUTTON (widget))
454     adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
455   return adjustment ? gtk_adjustment_get_value (adjustment) : 0;
456 }
457
458 /**
459  * gtk_test_text_set:
460  * @widget:     valid widget pointer.
461  * @string:     a 0-terminated C string
462  *
463  * Set the text string of @widget to @string if it is a GtkLabel,
464  * GtkEditable (entry and text widgets) or GtkTextView.
465  *
466  * Since: 2.14
467  **/
468 void
469 gtk_test_text_set (GtkWidget   *widget,
470                    const gchar *string)
471 {
472   if (GTK_IS_LABEL (widget))
473     gtk_label_set_text (GTK_LABEL (widget), string);
474   else if (GTK_IS_EDITABLE (widget))
475     {
476       int pos = 0;
477       gtk_editable_delete_text (GTK_EDITABLE (widget), 0, -1);
478       gtk_editable_insert_text (GTK_EDITABLE (widget), string, -1, &pos);
479     }
480   else if (GTK_IS_TEXT_VIEW (widget))
481     {
482       GtkTextBuffer *tbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
483       gtk_text_buffer_set_text (tbuffer, string, -1);
484     }
485 }
486
487 /**
488  * gtk_test_text_get:
489  * @widget:     valid widget pointer.
490  *
491  * Retrive the text string of @widget if it is a GtkLabel,
492  * GtkEditable (entry and text widgets) or GtkTextView.
493  *
494  * Returns: new 0-terminated C string, needs to be released with g_free().
495  *
496  * Since: 2.14
497  **/
498 gchar*
499 gtk_test_text_get (GtkWidget *widget)
500 {
501   if (GTK_IS_LABEL (widget))
502     return g_strdup (gtk_label_get_text (GTK_LABEL (widget)));
503   else if (GTK_IS_EDITABLE (widget))
504     {
505       return g_strdup (gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1));
506     }
507   else if (GTK_IS_TEXT_VIEW (widget))
508     {
509       GtkTextBuffer *tbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
510       GtkTextIter start, end;
511       gtk_text_buffer_get_start_iter (tbuffer, &start);
512       gtk_text_buffer_get_end_iter (tbuffer, &end);
513       return gtk_text_buffer_get_text (tbuffer, &start, &end, FALSE);
514     }
515   return NULL;
516 }
517
518 /**
519  * gtk_test_create_widget:
520  * @widget_type: a valid widget type.
521  * @first_property_name: (allow-none): Name of first property to set or %NULL
522  * @...: value to set the first property to, followed by more
523  *    name-value pairs, terminated by %NULL
524  *
525  * This function wraps g_object_new() for widget types.
526  * It'll automatically show all created non window widgets, also
527  * g_object_ref_sink() them (to keep them alive across a running test)
528  * and set them up for destruction during the next test teardown phase.
529  *
530  * Returns: (transfer none): a newly created widget.
531  *
532  * Since: 2.14
533  */
534 GtkWidget*
535 gtk_test_create_widget (GType        widget_type,
536                         const gchar *first_property_name,
537                         ...)
538 {
539   GtkWidget *widget;
540   va_list var_args;
541   g_return_val_if_fail (g_type_is_a (widget_type, GTK_TYPE_WIDGET), NULL);
542   va_start (var_args, first_property_name);
543   widget = (GtkWidget*) g_object_new_valist (widget_type, first_property_name, var_args);
544   va_end (var_args);
545   if (widget)
546     {
547       if (!GTK_IS_WINDOW (widget))
548         gtk_widget_show (widget);
549       g_object_ref_sink (widget);
550       g_test_queue_unref (widget);
551       g_test_queue_destroy ((GDestroyNotify) gtk_widget_destroy, widget);
552     }
553   return widget;
554 }
555
556 static void
557 try_main_quit (void)
558 {
559   if (gtk_main_level())
560     gtk_main_quit();
561 }
562
563 static int
564 test_increment_intp (int *intp)
565 {
566   if (intp != NULL)
567     *intp += 1;
568   return 1; /* TRUE in case we're connected to event signals */
569 }
570
571 /**
572  * gtk_test_display_button_window:
573  * @window_title:       Title of the window to be displayed.
574  * @dialog_text:        Text inside the window to be displayed.
575  * @...:                %NULL terminated list of (const char *label, int *nump) pairs.
576  *
577  * Create a window with window title @window_title, text contents @dialog_text,
578  * and a number of buttons, according to the paired argument list given
579  * as @... parameters.
580  * Each button is created with a @label and a ::clicked signal handler that
581  * incremrents the integer stored in @nump.
582  * The window will be automatically shown with gtk_widget_show_now() after
583  * creation, so when this function returns it has already been mapped,
584  * resized and positioned on screen.
585  * The window will quit any running gtk_main()-loop when destroyed, and it
586  * will automatically be destroyed upon test function teardown.
587  *
588  * Returns: (transfer full): a widget pointer to the newly created GtkWindow.
589  *
590  * Since: 2.14
591  **/
592 GtkWidget*
593 gtk_test_display_button_window (const gchar *window_title,
594                                 const gchar *dialog_text,
595                                 ...) /* NULL terminated list of (label, &int) pairs */
596 {
597   va_list var_args;
598   GtkWidget *window = gtk_test_create_widget (GTK_TYPE_WINDOW, "title", window_title, NULL);
599   GtkWidget *vbox = gtk_test_create_widget (GTK_TYPE_BOX, "parent", window, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
600   const char *arg1;
601   gtk_test_create_widget (GTK_TYPE_LABEL, "label", dialog_text, "parent", vbox, NULL);
602   g_signal_connect (window, "destroy", G_CALLBACK (try_main_quit), NULL);
603   va_start (var_args, dialog_text);
604   arg1 = va_arg (var_args, const char*);
605   while (arg1)
606     {
607       int *arg2 = va_arg (var_args, int*);
608       GtkWidget *button = gtk_test_create_widget (GTK_TYPE_BUTTON, "label", arg1, "parent", vbox, NULL);
609       g_signal_connect_swapped (button, "clicked", G_CALLBACK (test_increment_intp), arg2);
610       arg1 = va_arg (var_args, const char*);
611     }
612   va_end (var_args);
613   gtk_widget_show_all (vbox);
614   gtk_widget_show_now (window);
615   while (gtk_events_pending ())
616     gtk_main_iteration ();
617   return window;
618 }
619
620 /**
621  * gtk_test_create_simple_window:
622  * @window_title:       Title of the window to be displayed.
623  * @dialog_text:        Text inside the window to be displayed.
624  *
625  * Create a simple window with window title @window_title and
626  * text contents @dialog_text.
627  * The window will quit any running gtk_main()-loop when destroyed, and it
628  * will automatically be destroyed upon test function teardown.
629  *
630  * Returns: (transfer none): a widget pointer to the newly created GtkWindow.
631  *
632  * Since: 2.14
633  **/
634 GtkWidget*
635 gtk_test_create_simple_window (const gchar *window_title,
636                                const gchar *dialog_text)
637 {
638   GtkWidget *window = gtk_test_create_widget (GTK_TYPE_WINDOW, "title", window_title, NULL);
639   GtkWidget *vbox = gtk_test_create_widget (GTK_TYPE_BOX, "parent", window, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
640   gtk_test_create_widget (GTK_TYPE_LABEL, "label", dialog_text, "parent", vbox, NULL);
641   g_signal_connect (window, "destroy", G_CALLBACK (try_main_quit), NULL);
642   gtk_widget_show_all (vbox);
643   return window;
644 }
645
646 static GType *all_registered_types = NULL;
647 static guint  n_all_registered_types = 0;
648
649 /**
650  * gtk_test_list_all_types:
651  * @n_types: location to store number of types
652  *
653  * Return the type ids that have been registered after
654  * calling gtk_test_register_all_types().
655  *
656  * Returns: (array length=n_types zero-terminated=1) (transfer none):
657  *    0-terminated array of type ids
658  *
659  * Since: 2.14
660  */
661 const GType*
662 gtk_test_list_all_types (guint *n_types)
663 {
664   if (n_types)
665     *n_types = n_all_registered_types;
666   return all_registered_types;
667 }
668
669 /**
670  * gtk_test_register_all_types:
671  *
672  * Force registration of all core Gtk+ and Gdk object types.
673  * This allowes to refer to any of those object types via
674  * g_type_from_name() after calling this function.
675  *
676  * Since: 2.14
677  **/
678 void
679 gtk_test_register_all_types (void)
680 {
681   if (!all_registered_types)
682     {
683       const guint max_gtk_types = 999;
684       GType *tp;
685       all_registered_types = g_new0 (GType, max_gtk_types);
686       tp = all_registered_types;
687 #include "gtktypefuncs.c"
688       n_all_registered_types = tp - all_registered_types;
689       g_assert (n_all_registered_types + 1 < max_gtk_types);
690       *tp = 0;
691     }
692 }