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