Changes to introspection generation to remove DOCTYPE and XML
[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         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 ((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_getLocale (application, LC_MESSAGES);
237         g_assert (!strcmp (str, setlocale (LC_MESSAGES, NULL)));
238         SPI_freeString (str);
239
240         str = AccessibleApplication_getVersion (application);
241         g_assert (str != NULL);
242         SPI_freeString (str);
243
244         AccessibleApplication_getID (application);
245 }
246
247 static void
248 test_editable_text (AccessibleEditableText *etext)
249 {
250         char *str;
251         AccessibleText *text;
252
253         fprintf (stderr, "Testing editable text ...\n");
254         
255         g_assert (Accessible_isText (etext));
256         text = Accessible_getText (etext);
257
258         AccessibleEditableText_setTextContents (
259                 etext, TEST_STRING_B);
260
261         str = AccessibleText_getText (text, 0, WHOLE_STRING);
262         g_assert (!strcmp (str, TEST_STRING_B));
263
264         SPI_freeString (str);
265
266         /* FIXME: lots more editing here */
267
268         AccessibleEditableText_setTextContents (
269                 etext, TEST_STRING_A);
270
271         AccessibleText_unref (text);
272 }
273
274 static void
275 test_table (AccessibleTable *table)
276 {
277         Accessible *header;
278         gint index;
279         gint rows, columns;
280
281         fprintf (stderr, "Testing table ...\n");
282
283         rows = AccessibleTable_getNRows (table);
284         g_assert (rows > 0);
285
286         columns = AccessibleTable_getNColumns (table);
287         g_assert (columns > 0);
288
289         index = AccessibleTable_getIndexAt (table, rows - 1, columns - 1);
290
291         g_assert (AccessibleTable_getRowAtIndex (table, index) == rows - 1);
292
293         g_assert (AccessibleTable_getColumnAtIndex (table, index) == columns - 1);
294
295         g_assert ((header = AccessibleTable_getColumnHeader (table, 0)));
296         Accessible_unref (header);
297
298         AccessibleTable_isSelected (table, 0, 0);
299         
300         /* FIXME: lots more tests */
301 }
302
303 static void
304 test_text (AccessibleText *text)
305 {
306         char *str;
307
308         fprintf (stderr, "Testing text ...\n");
309
310         g_assert (AccessibleText_getCharacterCount (text) ==
311                   strlen (TEST_STRING_A));
312
313         str = AccessibleText_getText (text, 0, WHOLE_STRING);
314         g_assert (!strcmp (str, TEST_STRING_A));
315         SPI_freeString (str);
316
317         str = AccessibleText_getText (text, 0, 5);
318         g_assert (!strncmp (str, TEST_STRING_A, 5));
319         SPI_freeString (str);
320
321         AccessibleText_setCaretOffset (text, 7);
322         g_assert (AccessibleText_getCaretOffset (text) == 7);
323
324         /* FIXME: lots more tests - selections etc. etc. */
325 }
326
327 static void
328 test_value (AccessibleValue *value)
329 {
330         float original_value;
331         
332         fprintf (stderr, "Testing value ...\n");
333
334         original_value = AccessibleValue_getCurrentValue (value);
335         
336         g_assert (AccessibleValue_getCurrentValue (value) <=
337                   AccessibleValue_getMaximumValue (value));
338
339         g_assert (AccessibleValue_getCurrentValue (value) >=
340                   AccessibleValue_getMinimumValue (value));
341
342         AccessibleValue_setCurrentValue (value, 
343                   AccessibleValue_getMinimumValue (value));
344         
345         g_assert (AccessibleValue_getCurrentValue (value) ==
346                   AccessibleValue_getMinimumValue (value));
347
348         AccessibleValue_setCurrentValue (value, 
349                   AccessibleValue_getMaximumValue (value));
350         
351         g_assert (AccessibleValue_getCurrentValue (value) ==
352                   AccessibleValue_getMaximumValue (value));
353
354         AccessibleValue_setCurrentValue (value, original_value);
355         
356         g_assert (AccessibleValue_getCurrentValue (value) == original_value);
357 }
358
359 static void
360 test_component (AccessibleComponent *component)
361 {
362         long x, y, width, height;
363
364         fprintf (stderr, "Testing component...\n");
365
366         AccessibleComponent_getExtents (
367                 component, &x, &y, &width, &height, SPI_COORD_TYPE_SCREEN);
368
369         AccessibleComponent_getPosition (
370                 component, &x, &y, SPI_COORD_TYPE_SCREEN);
371
372         AccessibleComponent_getSize (component, &width, &height);
373
374         if (width > 0 && height > 0) {
375 #ifdef FIXME
376                 Accessible *accessible, *componentb;
377 #endif
378
379                 g_assert (AccessibleComponent_contains (
380                         component, x, y, SPI_COORD_TYPE_SCREEN));
381
382                 g_assert (AccessibleComponent_contains (
383                         component, x + width - 1, y, SPI_COORD_TYPE_SCREEN));
384
385                 g_assert (AccessibleComponent_contains (
386                         component, x + width - 1, y + height - 1,
387                         SPI_COORD_TYPE_SCREEN));
388
389 #ifdef FIXME
390                 accessible = AccessibleComponent_getAccessibleAtPoint (
391                         component, x, y, SPI_COORD_TYPE_SCREEN);
392
393                 g_assert (Accessible_isComponent (accessible));
394                 componentb = Accessible_getComponent (accessible);
395                 g_assert (componentb == component);
396
397                 AccessibleComponent_unref (componentb);
398                 Accessible_unref (accessible);
399 #endif
400         }
401
402         AccessibleComponent_getLayer (component);
403         AccessibleComponent_getMDIZOrder (component);
404 /*      AccessibleComponent_grabFocus (component); */
405 }
406
407 static void
408 test_image (AccessibleImage *image)
409 {
410         char *desc;
411         long int x = -1, y = -1, width = -1, height = -1;
412
413         desc = AccessibleImage_getImageDescription (image);
414         g_assert (desc != NULL);
415         SPI_freeString (desc);
416
417         AccessibleImage_getImagePosition (image, &x, &y,
418                                           SPI_COORD_TYPE_SCREEN);
419         AccessibleImage_getImageSize     (image, &width, &height);
420         AccessibleImage_getImageExtents  (image, &x, &y, &width, &height,
421                                           SPI_COORD_TYPE_WINDOW);
422 }
423
424 static void
425 validate_tree (Accessible *accessible,
426                gboolean    has_parent,
427                gboolean    recurse_down)
428 {
429         Accessible  *parent;
430         long         len, i;
431
432         parent = Accessible_getParent (accessible);
433         if (has_parent) {
434                 long        index;
435                 Accessible *child_at_index;
436
437                 g_assert (parent != NULL);
438
439                 index = Accessible_getIndexInParent (accessible);
440                 g_assert (index >= 0); 
441
442                 child_at_index = Accessible_getChildAtIndex (parent, index);
443
444                 g_assert (child_at_index == accessible);
445
446                 Accessible_unref (child_at_index);
447                 Accessible_unref (parent);
448         }
449
450         len = Accessible_getChildCount (accessible);
451         print_tree_depth++;
452         for (i = 0; i < len; i++) {
453                 Accessible *child;
454
455                 child = Accessible_getChildAtIndex (accessible, i);
456 #ifdef ROPEY
457                 if (!child)
458                         fprintf (stderr, "Unusual - ChildGone at %ld\n", i);
459
460                 g_assert (Accessible_getIndexInParent (child) == i);
461                 g_assert (Accessible_getParent (child) == accessible);
462 #endif
463
464                 if (recurse_down && child)
465                         validate_accessible (child, has_parent, recurse_down);
466
467                 Accessible_unref (child);
468         }
469         print_tree_depth--;
470 }
471
472 static void
473 validate_accessible (Accessible *accessible,
474                      gboolean    has_parent,
475                      gboolean    recurse_down)
476 {
477         Accessible          *tmp;
478         char                *name, *descr;
479         AccessibleRole       role;
480         AccessibleRelation **relations;
481         char                *role_name;
482         GString             *item_str = g_string_new ("");
483         int                  i;
484
485         name = Accessible_getName (accessible);
486         g_assert (name != NULL);
487         
488         descr = Accessible_getDescription (accessible);
489         g_assert (descr != NULL);
490
491         role = Accessible_getRole (accessible);
492         g_assert (role != SPI_ROLE_INVALID);
493         role_name = Accessible_getRoleName (accessible);
494         g_assert (role_name != NULL);
495
496         relations = Accessible_getRelationSet (accessible);
497         g_assert (relations != NULL);
498
499         for (i = 0; relations [i]; i++) {
500                 AccessibleRelationType type;
501                 int                    targets;
502
503                 fprintf (stderr, "relation %d\n", i);
504
505                 type = AccessibleRelation_getRelationType (relations [i]);
506                 g_assert (type != SPI_RELATION_NULL);
507
508                 targets = AccessibleRelation_getNTargets (relations [i]);
509                 g_assert (targets != -1);
510
511                 AccessibleRelation_unref (relations [i]);
512                 relations [i] = NULL;
513         }
514         free (relations);
515
516         if (print_tree) {
517                 int i;
518
519                 for (i = 0; i < print_tree_depth; i++)
520                         fputc (' ', stderr);
521                 fputs ("|-> [ ", stderr);
522         }
523
524         if (Accessible_isAction (accessible)) {
525                 tmp = Accessible_getAction (accessible);
526                 g_assert (tmp != NULL);
527                 if (print_tree)
528                         fprintf (stderr, "At");
529                 else
530                         test_action (tmp);
531                 AccessibleAction_unref (tmp);
532         }
533
534         if (Accessible_isApplication (accessible)) {
535                 tmp = Accessible_getApplication (accessible);
536                 if (print_tree)
537                         fprintf (stderr, "Ap");
538                 else
539                         test_application (tmp);
540                 AccessibleApplication_unref (tmp);
541         }
542
543         if (Accessible_isComponent (accessible)) {
544                 tmp = Accessible_getComponent (accessible);
545                 g_assert (tmp != NULL);
546                 if (print_tree)
547                         fprintf (stderr, "Co");
548                 else
549                         test_component (tmp);
550                 AccessibleComponent_unref (tmp);
551         }
552
553         if (Accessible_isEditableText (accessible)) {
554                 tmp = Accessible_getEditableText (accessible);
555                 g_assert (tmp != NULL);
556                 if (print_tree)
557                         fprintf (stderr, "Et");
558                 else
559                         test_editable_text (tmp);
560                 AccessibleEditableText_unref (tmp);
561         }
562
563         if (Accessible_isHypertext (accessible)) {
564                 tmp = Accessible_getHypertext (accessible);
565                 g_assert (tmp != NULL);
566                 if (print_tree)
567                         fprintf (stderr, "Ht");
568                 AccessibleHypertext_unref (tmp);
569         }
570
571         if (Accessible_isImage (accessible)) {
572                 tmp = Accessible_getImage (accessible);
573                 g_assert (tmp != NULL);
574                 if (print_tree) {
575                         char *desc;
576
577                         fprintf (stderr, "Im");
578
579                         desc = AccessibleImage_getImageDescription (tmp);
580                         g_string_append_printf (
581                                 item_str, " image descr: '%s'", desc);
582                         SPI_freeString (desc);
583                 } else
584                         test_image (tmp);
585
586                 AccessibleImage_unref (tmp);
587         }
588
589         if (Accessible_isSelection (accessible)) {
590                 tmp = Accessible_getSelection (accessible);
591                 g_assert (tmp != NULL);
592                 if (print_tree)
593                         fprintf (stderr, "Se");
594                 AccessibleSelection_unref (tmp);
595         }
596
597         if (Accessible_isTable (accessible)) {
598                 tmp = Accessible_getTable (accessible);
599                 g_assert (tmp != NULL);
600                 if (print_tree)
601                         fprintf (stderr, "Ta");
602                 else
603                         test_table (tmp);
604                 AccessibleTable_unref (tmp);
605         }
606
607         if (Accessible_isText (accessible)) {
608                 tmp = Accessible_getText (accessible);
609                 g_assert (tmp != NULL);
610                 if (print_tree)
611                         fprintf (stderr, "Te");
612                 else {
613                         if (strcmp (name, TEST_STRING_A_OBJECT) == 0)   
614                                 test_text (tmp);
615                 }
616                 AccessibleText_unref (tmp);
617         }
618
619         if (Accessible_isValue (accessible)) {
620                 tmp = Accessible_getValue (accessible);
621                 g_assert (tmp != NULL);
622                 if (print_tree)
623                         fprintf (stderr, "Va");
624                 else
625                         test_value (tmp); 
626                 AccessibleValue_unref (tmp);
627         }
628
629         if (print_tree)
630                 fprintf (stderr, " ] '%s' (%s) - %s: %s\n",
631                          name, descr, role_name, item_str->str);
632
633         SPI_freeString (name);
634         SPI_freeString (descr);
635         SPI_freeString (role_name);
636         g_string_free (item_str, TRUE);
637
638         validate_tree (accessible, has_parent, recurse_down);
639 }
640
641 static void
642 test_misc (void)
643 {
644         fprintf (stderr, "Testing misc bits ...\n");
645
646         g_assert (!Accessible_isComponent (NULL));
647         g_assert (Accessible_getComponent (NULL) == NULL);
648         SPI_freeString (NULL);
649 }
650
651 static void
652 global_listener_cb (const AccessibleEvent *event,
653                     void                  *user_data)
654 {
655         TestWindow *win = user_data;
656         Accessible *desktop;
657         AccessibleApplication *application;
658
659         g_assert (win->magic == WINDOW_MAGIC);
660         g_assert (!strcmp (event->type, "focus:"));
661
662         fprintf (stderr, "Fielded focus event ...\n");
663
664         if (!do_poke) {
665                 desktop = SPI_getDesktop (0);
666                 application = Accessible_getChildAtIndex (desktop, 0);
667                 g_assert (application != NULL);
668                 Accessible_unref (desktop);
669                 
670                 test_application (application);
671                 
672                 AccessibleApplication_unref (application);
673                 
674                 print_tree = FALSE;
675
676                 validate_accessible (event->source, TRUE, TRUE);
677
678                 fprintf (stderr, "quitting mainloop.\n");
679                 gtk_main_quit ();
680         }
681
682         print_tree = TRUE;
683         validate_accessible (event->source, TRUE, TRUE);
684 }
685
686 static SPIBoolean
687 key_listener_cb (const AccessibleKeystroke *stroke,
688                  void                      *user_data)
689 {
690         AccessibleKeystroke *s = user_data;
691         
692         *s = *stroke;
693         if (stroke->keystring) s->keystring = g_strdup (stroke->keystring);
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 [%s]", stroke.keystring);
732                 g_assert (!strcmp (stroke.keystring, "="));
733                 while (!(key_release_received))
734                         g_main_context_iteration (NULL, TRUE);
735                 fprintf (stderr, "r [%s]", stroke.keystring);
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 }