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