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