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