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