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