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