2002-03-19 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / test / test-simple.c
1 /*
2  * test-simple.c: A set of simple regression tests
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Ximian, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  * ******** Do not copy this code as an example *********
25  */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <gtk/gtk.h>
31 #include <cspi/spi.h>
32 #include <libbonobo.h>
33
34
35 /* Known bugs */
36 #undef  KEY_IMPL_WORKS
37 #define WHOLE_STRING -1
38
39 static void validate_accessible (Accessible *accessible,
40                                  gboolean    has_parent,
41                                  gboolean    recurse_down);
42
43 #define WINDOW_MAGIC 0x123456a
44 #define TEST_STRING_A "A test string"
45 #define TEST_STRING_B "Another test string"
46
47 static int      print_tree_depth = 0;
48 static gboolean print_tree = FALSE;
49 static gboolean do_poke = FALSE;
50
51 typedef struct {
52         gulong     magic;
53         GtkWidget *window;
54 } TestWindow;
55
56 static gboolean
57 focus_me (GtkWidget *widget)
58 {
59         AtkObject *aobject = atk_implementor_ref_accessible (
60                 ATK_IMPLEMENTOR (widget));
61         
62         /* Force a focus event - even if the WM focused
63          * us before our at-bridge's idle handler registered
64          * our interest */
65         if (!GTK_WIDGET_HAS_FOCUS (widget))
66                 gtk_widget_grab_focus (widget);
67 /*      else: FIXME - gtk_widget_grab_focus should send a notify */
68                 atk_focus_tracker_notify (aobject);
69         
70         g_object_unref (G_OBJECT (aobject));
71
72         return FALSE;
73 }
74
75 static void
76 test_window_add_and_show (GtkContainer *container, GtkWidget *widget)
77 {
78         gtk_container_add (container, widget);
79         gtk_widget_show (widget);
80 }
81
82 static GtkWidget *
83 create_tree (void)
84 {
85         GtkWidget         *widget;
86         GtkTreeIter        iter;
87         GtkListStore      *store;
88         GtkTreeViewColumn *column;
89
90         store = gtk_list_store_new (1, G_TYPE_STRING);
91         gtk_list_store_append (store, &iter);
92         gtk_list_store_set (store, &iter, 0, TEST_STRING_A, -1); 
93         column = gtk_tree_view_column_new_with_attributes ("String",
94                 gtk_cell_renderer_text_new (), "text", 0, NULL);
95         widget = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); 
96         g_object_unref (G_OBJECT (store));
97         gtk_tree_view_append_column (GTK_TREE_VIEW (widget), column);
98
99         return widget;
100 }
101
102 static TestWindow *
103 create_test_window (void)
104 {
105         TestWindow *win = g_new0 (TestWindow, 1);
106         GtkWidget  *widget, *vbox;
107
108         win->magic  = WINDOW_MAGIC;
109         win->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
110  
111         gtk_widget_show (win->window);
112
113         vbox = gtk_vbox_new (0, 0);
114         gtk_container_add (GTK_CONTAINER (win->window), vbox);
115         gtk_widget_show (vbox);
116
117         widget = gtk_entry_new ();
118         gtk_entry_set_text (GTK_ENTRY (widget), TEST_STRING_A);
119         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
120
121         widget = gtk_button_new_with_label ("_Foobar");
122         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
123
124         widget = gtk_hseparator_new ();
125         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
126
127         widget = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION,
128                                            GTK_ICON_SIZE_LARGE_TOOLBAR);
129         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
130
131         widget = g_object_new (GTK_TYPE_RANGE, NULL);
132         gtk_range_set_range (GTK_RANGE (widget), 0.0, 100.0);
133         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
134
135         widget = create_tree ();
136         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
137
138         g_idle_add ((GSourceFunc) focus_me, win->window);
139
140         return win;
141 }
142
143 static void
144 test_window_destroy (TestWindow *win)
145 {
146         gtk_widget_destroy (win->window);
147         g_free (win);
148 }
149
150 static void
151 test_roles (void)
152 {
153         int i;
154
155         fprintf (stderr, "Testing roles...\n");
156         for (i = -1; i < 1000; i++)
157                 g_assert (AccessibleRole_getName (i) != NULL);
158
159         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_FILE_CHOOSER), "file chooser"));
160         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_RADIO_BUTTON), "radiobutton"));
161         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_TABLE), "table"));
162         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_WINDOW), "window"));
163 }
164
165 static void
166 test_action (AccessibleAction *action)
167 {
168         gint n_actions, i;
169         gchar *s, *sd;
170         g_assert ((n_actions = AccessibleAction_getNActions (action)) >= 0);
171
172         fprintf (stderr, "Testing actions...");
173         for (i = 0; i < n_actions; ++i)
174         {
175                 s = AccessibleAction_getName (action, i);
176                 g_assert (s);
177                 sd = AccessibleAction_getDescription (action, i);
178                 g_assert (sd);
179                 fprintf (stderr, "%d: %s (%s);  ", i, s, sd);
180                 SPI_freeString (s);
181                 SPI_freeString (sd);
182                 g_assert (AccessibleAction_doAction (action, i));
183         }
184         fprintf (stderr, "\n");
185 }
186
187 static void
188 test_desktop (void)
189 {
190         Accessible  *desktop;
191         Accessible  *application;
192         int          length;
193         Accessible **list;
194
195         fprintf (stderr, "Testing desktop...\n");
196
197         g_assert (SPI_getDesktop (-1) == NULL);
198         desktop = SPI_getDesktop (0);
199         g_assert (desktop != NULL);
200
201         g_assert ((length = SPI_getDesktopList (&list)) > 0);
202         g_assert (list[0] == desktop);
203         SPI_freeDesktopList (list);
204
205         validate_accessible (desktop, FALSE, FALSE);
206
207         application = Accessible_getChildAtIndex (desktop, 0);
208         g_assert (application != NULL);
209         AccessibleApplication_unref (application);
210
211         Accessible_unref (desktop);
212 }
213
214 static void
215 test_application (Accessible *application)
216 {
217         char *str;
218
219         fprintf (stderr, "Testing application ...\n");
220         g_assert (Accessible_isApplication (application));
221         g_assert (Accessible_getApplication (application) ==
222                   application);
223         AccessibleApplication_unref (application);
224
225         str = AccessibleApplication_getToolkitName (application);
226         g_assert (str != NULL);
227         g_assert (!strcmp (str, "GAIL"));
228         SPI_freeString (str);
229
230         str = AccessibleApplication_getVersion (application);
231         g_assert (str != NULL);
232         SPI_freeString (str);
233
234         AccessibleApplication_getID (application);
235 }
236
237 static void
238 test_editable_text (AccessibleEditableText *etext)
239 {
240         char *str;
241         AccessibleText *text;
242
243         fprintf (stderr, "Testing editable text ...\n");
244         
245         g_assert (Accessible_isText (etext));
246         text = Accessible_getText (etext);
247
248         AccessibleEditableText_setTextContents (
249                 etext, TEST_STRING_B);
250
251         str = AccessibleText_getText (text, 0, WHOLE_STRING);
252         g_assert (!strcmp (str, TEST_STRING_B));
253
254         SPI_freeString (str);
255
256         /* FIXME: lots more editing here */
257
258         AccessibleEditableText_setTextContents (
259                 etext, TEST_STRING_A);
260
261         AccessibleText_unref (text);
262 }
263
264 static void
265 test_table (AccessibleTable *table)
266 {
267         Accessible *header;
268         gint index;
269         gint rows, columns;
270
271         fprintf (stderr, "Testing table ...\n");
272
273         rows = AccessibleTable_getNRows (table);
274         g_assert (rows > 0);
275
276         columns = AccessibleTable_getNColumns (table);
277         g_assert (columns > 0);
278
279         index = AccessibleTable_getIndexAt (table, rows - 1, columns - 1);
280
281         g_assert (AccessibleTable_getRowAtIndex (table, index) == rows - 1);
282
283         g_assert (AccessibleTable_getColumnAtIndex (table, index) == columns - 1);
284
285         g_assert ((header = AccessibleTable_getColumnHeader (table, 0)));
286         Accessible_unref (header);
287
288         AccessibleTable_isSelected (table, 0, 0);
289         
290         /* FIXME: lots more tests */
291 }
292
293 static void
294 test_text (AccessibleText *text)
295 {
296         char *str;
297
298         fprintf (stderr, "Testing text ...\n");
299
300         g_assert (AccessibleText_getCharacterCount (text) ==
301                   strlen (TEST_STRING_A));
302
303         str = AccessibleText_getText (text, 0, WHOLE_STRING);
304         g_assert (!strcmp (str, TEST_STRING_A));
305         SPI_freeString (str);
306
307         str = AccessibleText_getText (text, 0, 5);
308         g_assert (!strncmp (str, TEST_STRING_A, 5));
309         SPI_freeString (str);
310
311         AccessibleText_setCaretOffset (text, 7);
312         g_assert (AccessibleText_getCaretOffset (text) == 7);
313
314         /* FIXME: lots more tests - selections etc. etc. */
315 }
316
317 static void
318 test_value (AccessibleValue *value)
319 {
320         float original_value;
321         
322         fprintf (stderr, "Testing value ...\n");
323
324         original_value = AccessibleValue_getCurrentValue (value);
325         
326         g_assert (AccessibleValue_getCurrentValue (value) <=
327                   AccessibleValue_getMaximumValue (value));
328
329         g_assert (AccessibleValue_getCurrentValue (value) >=
330                   AccessibleValue_getMinimumValue (value));
331
332         AccessibleValue_setCurrentValue (value, 
333                   AccessibleValue_getMinimumValue (value));
334         
335         g_assert (AccessibleValue_getCurrentValue (value) ==
336                   AccessibleValue_getMinimumValue (value));
337
338         AccessibleValue_setCurrentValue (value, 
339                   AccessibleValue_getMaximumValue (value));
340         
341         g_assert (AccessibleValue_getCurrentValue (value) ==
342                   AccessibleValue_getMaximumValue (value));
343
344         AccessibleValue_setCurrentValue (value, original_value);
345         
346         g_assert (AccessibleValue_getCurrentValue (value) == original_value);
347 }
348
349 static void
350 test_component (AccessibleComponent *component)
351 {
352         long x, y, width, height;
353
354         fprintf (stderr, "Testing component...\n");
355
356         AccessibleComponent_getExtents (
357                 component, &x, &y, &width, &height, SPI_COORD_TYPE_SCREEN);
358
359         AccessibleComponent_getPosition (
360                 component, &x, &y, SPI_COORD_TYPE_SCREEN);
361
362         AccessibleComponent_getSize (component, &width, &height);
363
364         if (width > 0 && height > 0) {
365 #ifdef FIXME
366                 Accessible *accessible, *componentb;
367 #endif
368
369                 g_assert (AccessibleComponent_contains (
370                         component, x, y, SPI_COORD_TYPE_SCREEN));
371
372                 g_assert (AccessibleComponent_contains (
373                         component, x + width - 1, y, SPI_COORD_TYPE_SCREEN));
374
375                 g_assert (AccessibleComponent_contains (
376                         component, x + width - 1, y + height - 1,
377                         SPI_COORD_TYPE_SCREEN));
378
379 #ifdef FIXME
380                 accessible = AccessibleComponent_getAccessibleAtPoint (
381                         component, x, y, SPI_COORD_TYPE_SCREEN);
382
383                 g_assert (Accessible_isComponent (accessible));
384                 componentb = Accessible_getComponent (accessible);
385                 g_assert (componentb == component);
386
387                 AccessibleComponent_unref (componentb);
388                 Accessible_unref (accessible);
389 #endif
390         }
391
392         AccessibleComponent_getLayer (component);
393         AccessibleComponent_getMDIZOrder (component);
394 /*      AccessibleComponent_grabFocus (component); */
395 }
396
397 static void
398 test_image (AccessibleImage *image)
399 {
400         char *desc;
401         long int x = -1, y = -1, width = -1, height = -1;
402
403         desc = AccessibleImage_getImageDescription (image);
404         g_assert (desc != NULL);
405         SPI_freeString (desc);
406
407         AccessibleImage_getImagePosition (image, &x, &y,
408                                           SPI_COORD_TYPE_SCREEN);
409         AccessibleImage_getImageSize     (image, &width, &height);
410         AccessibleImage_getImageExtents  (image, &x, &y, &width, &height,
411                                           SPI_COORD_TYPE_WINDOW);
412 }
413
414 static void
415 validate_tree (Accessible *accessible,
416                gboolean    has_parent,
417                gboolean    recurse_down)
418 {
419         Accessible  *parent;
420         long         len, i;
421
422         parent = Accessible_getParent (accessible);
423         if (has_parent) {
424                 long        index;
425                 Accessible *child_at_index;
426
427                 g_assert (parent != NULL);
428
429                 index = Accessible_getIndexInParent (accessible);
430                 g_assert (index >= 0); 
431
432                 child_at_index = Accessible_getChildAtIndex (parent, index);
433
434                 g_assert (child_at_index == accessible);
435
436                 Accessible_unref (child_at_index);
437                 Accessible_unref (parent);
438         }
439
440         len = Accessible_getChildCount (accessible);
441         print_tree_depth++;
442         for (i = 0; i < len; i++) {
443                 Accessible *child;
444
445                 child = Accessible_getChildAtIndex (accessible, i);
446 #ifdef ROPEY
447                 if (!child)
448                         fprintf (stderr, "Unusual - ChildGone at %ld\n", i);
449
450                 g_assert (Accessible_getIndexInParent (child) == i);
451                 g_assert (Accessible_getParent (child) == accessible);
452 #endif
453
454                 if (recurse_down && child)
455                         validate_accessible (child, has_parent, recurse_down);
456
457                 Accessible_unref (child);
458         }
459         print_tree_depth--;
460 }
461
462 static void
463 validate_accessible (Accessible *accessible,
464                      gboolean    has_parent,
465                      gboolean    recurse_down)
466 {
467         Accessible          *tmp;
468         char                *name, *descr;
469         AccessibleRole       role;
470         AccessibleRelation **relations;
471         char                *role_name;
472         GString             *item_str = g_string_new ("");
473         int                  i;
474
475         name = Accessible_getName (accessible);
476         g_assert (name != NULL);
477         
478         descr = Accessible_getDescription (accessible);
479         g_assert (descr != NULL);
480
481         role = Accessible_getRole (accessible);
482         g_assert (role != SPI_ROLE_INVALID);
483         role_name = Accessible_getRoleName (accessible);
484         g_assert (role_name != NULL);
485
486         relations = Accessible_getRelationSet (accessible);
487         g_assert (relations != NULL);
488
489         for (i = 0; relations [i]; i++) {
490                 AccessibleRelationType type;
491                 int                    targets;
492
493                 fprintf (stderr, "relation %d\n", i);
494
495                 type = AccessibleRelation_getRelationType (relations [i]);
496                 g_assert (type != SPI_RELATION_NULL);
497
498                 targets = AccessibleRelation_getNTargets (relations [i]);
499                 g_assert (targets != -1);
500
501                 AccessibleRelation_unref (relations [i]);
502                 relations [i] = NULL;
503         }
504         free (relations);
505
506         if (print_tree) {
507                 int i;
508
509                 for (i = 0; i < print_tree_depth; i++)
510                         fputc (' ', stderr);
511                 fputs ("|-> [ ", stderr);
512         }
513
514         if (Accessible_isAction (accessible)) {
515                 tmp = Accessible_getAction (accessible);
516                 g_assert (tmp != NULL);
517                 if (print_tree)
518                         fprintf (stderr, "At");
519                 else
520                         test_action (tmp);
521                 AccessibleAction_unref (tmp);
522         }
523
524         if (Accessible_isApplication (accessible)) {
525                 tmp = Accessible_getApplication (accessible);
526                 if (print_tree)
527                         fprintf (stderr, "Ap");
528                 else
529                         test_application (tmp);
530                 AccessibleApplication_unref (tmp);
531         }
532
533         if (Accessible_isComponent (accessible)) {
534                 tmp = Accessible_getComponent (accessible);
535                 g_assert (tmp != NULL);
536                 if (print_tree)
537                         fprintf (stderr, "Co");
538                 else
539                         test_component (tmp);
540                 AccessibleComponent_unref (tmp);
541         }
542
543         if (Accessible_isEditableText (accessible)) {
544                 tmp = Accessible_getEditableText (accessible);
545                 g_assert (tmp != NULL);
546                 if (print_tree)
547                         fprintf (stderr, "Et");
548                 else
549                         test_editable_text (tmp);
550                 AccessibleEditableText_unref (tmp);
551         }
552
553         if (Accessible_isHypertext (accessible)) {
554                 tmp = Accessible_getHypertext (accessible);
555                 g_assert (tmp != NULL);
556                 if (print_tree)
557                         fprintf (stderr, "Ht");
558                 AccessibleHypertext_unref (tmp);
559         }
560
561         if (Accessible_isImage (accessible)) {
562                 tmp = Accessible_getImage (accessible);
563                 g_assert (tmp != NULL);
564                 if (print_tree) {
565                         char *desc;
566
567                         fprintf (stderr, "Im");
568
569                         desc = AccessibleImage_getImageDescription (tmp);
570                         g_string_append_printf (
571                                 item_str, " image descr: '%s'", desc);
572                         SPI_freeString (desc);
573                 } else
574                         test_image (tmp);
575
576                 AccessibleImage_unref (tmp);
577         }
578
579         if (Accessible_isSelection (accessible)) {
580                 tmp = Accessible_getSelection (accessible);
581                 g_assert (tmp != NULL);
582                 if (print_tree)
583                         fprintf (stderr, "Se");
584                 AccessibleSelection_unref (tmp);
585         }
586
587         if (Accessible_isTable (accessible)) {
588                 tmp = Accessible_getTable (accessible);
589                 g_assert (tmp != NULL);
590                 if (print_tree)
591                         fprintf (stderr, "Ta");
592                 else
593                         test_table (tmp);
594                 AccessibleTable_unref (tmp);
595         }
596
597         if (Accessible_isText (accessible)) {
598                 tmp = Accessible_getText (accessible);
599                 g_assert (tmp != NULL);
600                 if (print_tree)
601                         fprintf (stderr, "Te");
602                 else
603                         test_text (tmp);
604                 AccessibleText_unref (tmp);
605         }
606
607         if (Accessible_isValue (accessible)) {
608                 tmp = Accessible_getValue (accessible);
609                 g_assert (tmp != NULL);
610                 if (print_tree)
611                         fprintf (stderr, "Va");
612                 else
613                         test_value (tmp); 
614                 AccessibleValue_unref (tmp);
615         }
616
617         if (print_tree)
618                 fprintf (stderr, " ] '%s' (%s) - %s: %s\n",
619                          name, descr, role_name, item_str->str);
620
621         SPI_freeString (name);
622         SPI_freeString (descr);
623         SPI_freeString (role_name);
624         g_string_free (item_str, TRUE);
625
626         validate_tree (accessible, has_parent, recurse_down);
627 }
628
629 static void
630 test_misc (void)
631 {
632         fprintf (stderr, "Testing misc bits ...\n");
633
634         g_assert (!Accessible_isComponent (NULL));
635         g_assert (Accessible_getComponent (NULL) == NULL);
636         SPI_freeString (NULL);
637 }
638
639 static void
640 global_listener_cb (const AccessibleEvent *event,
641                     void                  *user_data)
642 {
643         TestWindow *win = user_data;
644         Accessible *desktop;
645         AccessibleApplication *application;
646
647         g_assert (win->magic == WINDOW_MAGIC);
648         g_assert (!strcmp (event->type, "focus:"));
649
650         fprintf (stderr, "Fielded focus event ...\n");
651
652         if (!do_poke) {
653                 desktop = SPI_getDesktop (0);
654                 application = Accessible_getChildAtIndex (desktop, 0);
655                 g_assert (application != NULL);
656                 Accessible_unref (desktop);
657                 
658                 test_application (application);
659                 
660                 AccessibleApplication_unref (application);
661                 
662                 print_tree = FALSE;
663                 validate_accessible (event->source, TRUE, TRUE);
664
665                 gtk_main_quit ();
666         }
667
668         print_tree = TRUE;
669         validate_accessible (event->source, TRUE, TRUE);
670 }
671
672 #ifdef KEY_IMPL_WORKS
673 static SPIBoolean
674 key_listener_cb (const AccessibleKeystroke *stroke,
675                  void                      *user_data)
676 {
677         AccessibleKeystroke *s = user_data;
678
679         *s = *stroke;
680
681         return TRUE;
682 }
683 #endif
684
685 static void
686 test_keylisteners (void)
687 {
688 #ifdef KEY_IMPL_WORKS
689         int i;
690         AccessibleKeystroke stroke;
691         AccessibleKeystrokeListener *key_listener;
692         AccessibleKeySet *test_keyset;
693 #endif
694
695         fprintf (stderr, "Testing keyboard listeners ...\n");
696
697 #ifdef KEY_IMPL_WORKS
698         key_listener = SPI_createAccessibleKeystrokeListener (
699                 key_listener_cb, &stroke);
700
701         test_keyset = SPI_createAccessibleKeySet (1, "=", NULL, NULL);
702         
703         g_assert (SPI_registerAccessibleKeystrokeListener (
704                 key_listener,
705                 test_keyset,
706                 0,
707                 SPI_KEY_PRESSED | SPI_KEY_RELEASED,
708                 SPI_KEYLISTENER_CANCONSUME | SPI_KEYLISTENER_ALL_WINDOWS));
709
710         for (i = 0; i < 3; i++) {
711                 memset (&stroke, 0, sizeof (AccessibleKeystroke));
712                 g_assert (SPI_generateKeyboardEvent ('=', NULL, SPI_KEY_SYM));
713                 while (!(stroke.type & SPI_KEY_PRESSED))
714                         g_main_context_iteration (NULL, TRUE);
715                 fprintf (stderr, "p");
716                 while (!(stroke.type & SPI_KEY_RELEASED))
717                         g_main_context_iteration (NULL, TRUE);
718                 fprintf (stderr, "r ");
719         }
720         g_assert (SPI_deregisterAccessibleKeystrokeListener (key_listener, 0));
721         SPI_freeAccessibleKeySet (test_keyset);
722
723         g_assert (!strcmp (stroke.keystring, "="));
724         fprintf (stderr, "\n");
725
726         AccessibleKeystrokeListener_unref (key_listener);
727 #else
728         fprintf (stderr, " key impl. impossibly broken\n");
729 #endif
730
731         g_assert (SPI_generateMouseEvent (100, 100, "rel"));
732         g_assert (SPI_generateMouseEvent (-50, -50, "rel"));              
733         g_assert (SPI_generateMouseEvent (-50, -50, "rel"));              
734         g_assert (SPI_generateMouseEvent (-1, -1, "b1c")); 
735 }
736
737 int
738 main (int argc, char **argv)
739 {
740         int leaked, i;
741         TestWindow *win;
742         const char *modules;
743         AccessibleEventListener *global_listener;
744
745         modules = g_getenv ("GTK_MODULES");
746         if (!modules || modules [0] == '\0')
747                 putenv ("GTK_MODULES=gail:atk-bridge");
748         modules = NULL;
749
750         for (i = 1; i < argc; i++) {
751                 if (!g_strcasecmp (argv [i], "--poke"))
752                         do_poke = TRUE;
753         }
754
755         gtk_init (&argc, &argv);
756
757         g_assert (!SPI_init ());
758         g_assert (SPI_init ());
759         g_assert (SPI_getDesktopCount () == 1);
760
761         test_roles ();
762         test_misc ();
763         test_desktop ();
764         test_keylisteners (); 
765
766         win = create_test_window ();
767
768         global_listener = SPI_createAccessibleEventListener (global_listener_cb, win);
769         g_assert (SPI_registerGlobalEventListener (global_listener, "focus:"));
770
771         fprintf (stderr, "Waiting for focus event ...\n");
772         gtk_main ();
773
774         g_assert (SPI_deregisterGlobalEventListenerAll (global_listener));
775         AccessibleEventListener_unref (global_listener);
776
777         test_window_destroy (win);
778
779         /* Wait for any pending events from the registry */
780         g_usleep (500*1000);
781         for (i = 0; i < 100; i++)
782                 linc_main_iteration (FALSE);
783
784         if ((leaked = SPI_exit ()))
785                 g_error ("Leaked %d SPI handles", leaked);
786
787         g_assert (!SPI_exit ());
788
789         fprintf (stderr, "All tests passed\n");
790
791         if (g_getenv ("_MEMPROF_SOCKET")) {
792                 fprintf (stderr, "Waiting for memprof\n");
793                 gtk_main ();
794         }
795
796         putenv ("AT_BRIDGE_SHUTDOWN=1");
797
798         return 0;
799 }