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