Merge branch 'master' of git+ssh://git.codethink.co.uk/git/atspi-dbus
[platform/core/uifw/at-spi2-atk.git] / tests / cspi / 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
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         Accessible **list;
199
200         fprintf (stderr, "Testing desktop...\n");
201
202         g_assert (SPI_getDesktop (-1) == NULL);
203         desktop = SPI_getDesktop (0);
204         g_assert (desktop != NULL);
205
206         g_assert ((SPI_getDesktopList (&list)) > 0);
207         g_assert (list[0] == desktop);
208         SPI_freeDesktopList (list);
209
210         validate_accessible (desktop, FALSE, FALSE);
211
212         application = Accessible_getChildAtIndex (desktop, 0);
213         g_assert (application != NULL);
214         AccessibleApplication_unref (application);
215
216         Accessible_unref (desktop);
217 }
218
219 static void
220 test_application (Accessible *application)
221 {
222         char *str;
223
224         fprintf (stderr, "Testing application ...\n");
225         g_assert (Accessible_isApplication (application));
226         g_assert (Accessible_getApplication (application) ==
227                   application);
228         AccessibleApplication_unref (application);
229
230         str = AccessibleApplication_getToolkitName (application);
231         g_assert (str != NULL);
232         g_assert (!strcmp (str, "GAIL"));
233         SPI_freeString (str);
234
235         str = AccessibleApplication_getLocale (application, LC_MESSAGES);
236         g_assert (!strcmp (str, setlocale (LC_MESSAGES, NULL)));
237         SPI_freeString (str);
238
239         str = AccessibleApplication_getVersion (application);
240         g_assert (str != NULL);
241         SPI_freeString (str);
242
243         AccessibleApplication_getID (application);
244 }
245
246 static void
247 test_editable_text (AccessibleEditableText *etext)
248 {
249         char *str;
250         AccessibleText *text;
251
252         fprintf (stderr, "Testing editable text ...\n");
253         
254         g_assert (Accessible_isText (etext));
255         text = Accessible_getText (etext);
256
257         AccessibleEditableText_setTextContents (
258                 etext, TEST_STRING_B);
259
260         str = AccessibleText_getText (text, 0, WHOLE_STRING);
261         g_assert (!strcmp (str, TEST_STRING_B));
262
263         SPI_freeString (str);
264
265         /* FIXME: lots more editing here */
266
267         AccessibleEditableText_setTextContents (
268                 etext, TEST_STRING_A);
269
270         AccessibleText_unref (text);
271 }
272
273 static void
274 test_table (AccessibleTable *table)
275 {
276         Accessible *header;
277         gint index;
278         gint rows, columns;
279
280         fprintf (stderr, "Testing table ...\n");
281
282         rows = AccessibleTable_getNRows (table);
283         g_assert (rows > 0);
284
285         columns = AccessibleTable_getNColumns (table);
286         g_assert (columns > 0);
287
288         index = AccessibleTable_getIndexAt (table, rows - 1, columns - 1);
289
290         g_assert (AccessibleTable_getRowAtIndex (table, index) == rows - 1);
291
292         g_assert (AccessibleTable_getColumnAtIndex (table, index) == columns - 1);
293
294         g_assert ((header = AccessibleTable_getColumnHeader (table, 0)));
295         Accessible_unref (header);
296
297         AccessibleTable_isSelected (table, 0, 0);
298         
299         /* FIXME: lots more tests */
300 }
301
302 static void
303 test_text (AccessibleText *text)
304 {
305         char *str;
306
307         fprintf (stderr, "Testing text ...\n");
308
309         g_assert (AccessibleText_getCharacterCount (text) ==
310                   strlen (TEST_STRING_A));
311
312         str = AccessibleText_getText (text, 0, WHOLE_STRING);
313         g_assert (!strcmp (str, TEST_STRING_A));
314         SPI_freeString (str);
315
316         str = AccessibleText_getText (text, 0, 5);
317         g_assert (!strncmp (str, TEST_STRING_A, 5));
318         SPI_freeString (str);
319
320         AccessibleText_setCaretOffset (text, 7);
321         g_assert (AccessibleText_getCaretOffset (text) == 7);
322
323         /* FIXME: lots more tests - selections etc. etc. */
324 }
325
326 static void
327 test_value (AccessibleValue *value)
328 {
329         float original_value;
330         
331         fprintf (stderr, "Testing value ...\n");
332
333         original_value = AccessibleValue_getCurrentValue (value);
334         
335         g_assert (AccessibleValue_getCurrentValue (value) <=
336                   AccessibleValue_getMaximumValue (value));
337
338         g_assert (AccessibleValue_getCurrentValue (value) >=
339                   AccessibleValue_getMinimumValue (value));
340
341         AccessibleValue_setCurrentValue (value, 
342                   AccessibleValue_getMinimumValue (value));
343         
344         g_assert (AccessibleValue_getCurrentValue (value) ==
345                   AccessibleValue_getMinimumValue (value));
346
347         AccessibleValue_setCurrentValue (value, 
348                   AccessibleValue_getMaximumValue (value));
349         
350         g_assert (AccessibleValue_getCurrentValue (value) ==
351                   AccessibleValue_getMaximumValue (value));
352
353         AccessibleValue_setCurrentValue (value, original_value);
354         
355         g_assert (AccessibleValue_getCurrentValue (value) == original_value);
356 }
357
358 static void
359 test_component (AccessibleComponent *component)
360 {
361         long x, y, width, height;
362
363         fprintf (stderr, "Testing component...\n");
364
365         AccessibleComponent_getExtents (
366                 component, &x, &y, &width, &height, SPI_COORD_TYPE_SCREEN);
367
368         AccessibleComponent_getPosition (
369                 component, &x, &y, SPI_COORD_TYPE_SCREEN);
370
371         AccessibleComponent_getSize (component, &width, &height);
372
373         if (width > 0 && height > 0) {
374 #ifdef FIXME
375                 Accessible *accessible, *componentb;
376 #endif
377
378                 g_assert (AccessibleComponent_contains (
379                         component, x, y, SPI_COORD_TYPE_SCREEN));
380
381                 g_assert (AccessibleComponent_contains (
382                         component, x + width - 1, y, SPI_COORD_TYPE_SCREEN));
383
384                 g_assert (AccessibleComponent_contains (
385                         component, x + width - 1, y + height - 1,
386                         SPI_COORD_TYPE_SCREEN));
387
388 #ifdef FIXME
389                 accessible = AccessibleComponent_getAccessibleAtPoint (
390                         component, x, y, SPI_COORD_TYPE_SCREEN);
391
392                 g_assert (Accessible_isComponent (accessible));
393                 componentb = Accessible_getComponent (accessible);
394                 g_assert (componentb == component);
395
396                 AccessibleComponent_unref (componentb);
397                 Accessible_unref (accessible);
398 #endif
399         }
400
401         AccessibleComponent_getLayer (component);
402         AccessibleComponent_getMDIZOrder (component);
403 /*      AccessibleComponent_grabFocus (component); */
404 }
405
406 static void
407 test_image (AccessibleImage *image)
408 {
409         char *desc;
410         long int x = -1, y = -1, width = -1, height = -1;
411
412         desc = AccessibleImage_getImageDescription (image);
413         g_assert (desc != NULL);
414         SPI_freeString (desc);
415
416         AccessibleImage_getImagePosition (image, &x, &y,
417                                           SPI_COORD_TYPE_SCREEN);
418         AccessibleImage_getImageSize     (image, &width, &height);
419         AccessibleImage_getImageExtents  (image, &x, &y, &width, &height,
420                                           SPI_COORD_TYPE_WINDOW);
421 }
422
423 static void
424 validate_tree (Accessible *accessible,
425                gboolean    has_parent,
426                gboolean    recurse_down)
427 {
428         Accessible  *parent;
429         long         len, i;
430
431         parent = Accessible_getParent (accessible);
432         if (has_parent) {
433                 long        index;
434                 Accessible *child_at_index;
435
436                 g_assert (parent != NULL);
437
438                 index = Accessible_getIndexInParent (accessible);
439                 g_assert (index >= 0); 
440
441                 child_at_index = Accessible_getChildAtIndex (parent, index);
442
443                 g_assert (child_at_index == accessible);
444
445                 Accessible_unref (child_at_index);
446                 Accessible_unref (parent);
447         }
448
449         len = Accessible_getChildCount (accessible);
450         print_tree_depth++;
451         for (i = 0; i < len; i++) {
452                 Accessible *child;
453
454                 child = Accessible_getChildAtIndex (accessible, i);
455 #ifdef ROPEY
456                 if (!child)
457                         fprintf (stderr, "Unusual - ChildGone at %ld\n", i);
458
459                 g_assert (Accessible_getIndexInParent (child) == i);
460                 g_assert (Accessible_getParent (child) == accessible);
461 #endif
462
463                 if (recurse_down && child)
464                         validate_accessible (child, has_parent, recurse_down);
465
466                 Accessible_unref (child);
467         }
468         print_tree_depth--;
469 }
470
471 static void
472 validate_accessible (Accessible *accessible,
473                      gboolean    has_parent,
474                      gboolean    recurse_down)
475 {
476         Accessible          *tmp;
477         char                *name, *descr;
478         AccessibleRole       role;
479         AccessibleRelation **relations;
480         char                *role_name;
481         GString             *item_str = g_string_new ("");
482         int                  i;
483
484         name = Accessible_getName (accessible);
485         g_assert (name != NULL);
486         
487         descr = Accessible_getDescription (accessible);
488         g_assert (descr != NULL);
489
490         role = Accessible_getRole (accessible);
491         g_assert (role != SPI_ROLE_INVALID);
492         role_name = Accessible_getRoleName (accessible);
493         g_assert (role_name != NULL);
494
495         relations = Accessible_getRelationSet (accessible);
496         g_assert (relations != NULL);
497
498         for (i = 0; relations [i]; i++) {
499                 AccessibleRelationType type;
500                 int                    targets;
501
502                 fprintf (stderr, "relation %d\n", i);
503
504                 type = AccessibleRelation_getRelationType (relations [i]);
505                 g_assert (type != SPI_RELATION_NULL);
506
507                 targets = AccessibleRelation_getNTargets (relations [i]);
508                 g_assert (targets != -1);
509
510                 AccessibleRelation_unref (relations [i]);
511                 relations [i] = NULL;
512         }
513         free (relations);
514
515         if (print_tree) {
516                 int i;
517
518                 for (i = 0; i < print_tree_depth; i++)
519                         fputc (' ', stderr);
520                 fputs ("|-> [ ", stderr);
521         }
522
523         if (Accessible_isAction (accessible)) {
524                 tmp = Accessible_getAction (accessible);
525                 g_assert (tmp != NULL);
526                 if (print_tree)
527                         fprintf (stderr, "At");
528                 else
529                         test_action (tmp);
530                 AccessibleAction_unref (tmp);
531         }
532
533         if (Accessible_isApplication (accessible)) {
534                 tmp = Accessible_getApplication (accessible);
535                 if (print_tree)
536                         fprintf (stderr, "Ap");
537                 else
538                         test_application (tmp);
539                 AccessibleApplication_unref (tmp);
540         }
541
542         if (Accessible_isComponent (accessible)) {
543                 tmp = Accessible_getComponent (accessible);
544                 g_assert (tmp != NULL);
545                 if (print_tree)
546                         fprintf (stderr, "Co");
547                 else
548                         test_component (tmp);
549                 AccessibleComponent_unref (tmp);
550         }
551
552         if (Accessible_isEditableText (accessible)) {
553                 tmp = Accessible_getEditableText (accessible);
554                 g_assert (tmp != NULL);
555                 if (print_tree)
556                         fprintf (stderr, "Et");
557                 else
558                         test_editable_text (tmp);
559                 AccessibleEditableText_unref (tmp);
560         }
561
562         if (Accessible_isHypertext (accessible)) {
563                 tmp = Accessible_getHypertext (accessible);
564                 g_assert (tmp != NULL);
565                 if (print_tree)
566                         fprintf (stderr, "Ht");
567                 AccessibleHypertext_unref (tmp);
568         }
569
570         if (Accessible_isImage (accessible)) {
571                 tmp = Accessible_getImage (accessible);
572                 g_assert (tmp != NULL);
573                 if (print_tree) {
574                         char *desc;
575
576                         fprintf (stderr, "Im");
577
578                         desc = AccessibleImage_getImageDescription (tmp);
579                         g_string_append_printf (
580                                 item_str, " image descr: '%s'", desc);
581                         SPI_freeString (desc);
582                 } else
583                         test_image (tmp);
584
585                 AccessibleImage_unref (tmp);
586         }
587
588         if (Accessible_isSelection (accessible)) {
589                 tmp = Accessible_getSelection (accessible);
590                 g_assert (tmp != NULL);
591                 if (print_tree)
592                         fprintf (stderr, "Se");
593                 AccessibleSelection_unref (tmp);
594         }
595
596         if (Accessible_isTable (accessible)) {
597                 tmp = Accessible_getTable (accessible);
598                 g_assert (tmp != NULL);
599                 if (print_tree)
600                         fprintf (stderr, "Ta");
601                 else
602                         test_table (tmp);
603                 AccessibleTable_unref (tmp);
604         }
605
606         if (Accessible_isText (accessible)) {
607                 tmp = Accessible_getText (accessible);
608                 g_assert (tmp != NULL);
609                 if (print_tree)
610                         fprintf (stderr, "Te");
611                 else {
612                         if (strcmp (name, TEST_STRING_A_OBJECT) == 0)   
613                                 test_text (tmp);
614                 }
615                 AccessibleText_unref (tmp);
616         }
617
618         if (Accessible_isValue (accessible)) {
619                 tmp = Accessible_getValue (accessible);
620                 g_assert (tmp != NULL);
621                 if (print_tree)
622                         fprintf (stderr, "Va");
623                 else
624                         test_value (tmp); 
625                 AccessibleValue_unref (tmp);
626         }
627
628         if (print_tree)
629                 fprintf (stderr, " ] '%s' (%s) - %s: %s\n",
630                          name, descr, role_name, item_str->str);
631
632         SPI_freeString (name);
633         SPI_freeString (descr);
634         SPI_freeString (role_name);
635         g_string_free (item_str, TRUE);
636
637         validate_tree (accessible, has_parent, recurse_down);
638 }
639
640 static void
641 test_misc (void)
642 {
643         fprintf (stderr, "Testing misc bits ...\n");
644
645         g_assert (!Accessible_isComponent (NULL));
646         g_assert (Accessible_getComponent (NULL) == NULL);
647         SPI_freeString (NULL);
648 }
649
650 static void
651 global_listener_cb (const AccessibleEvent *event,
652                     void                  *user_data)
653 {
654         TestWindow *win = user_data;
655         Accessible *desktop;
656         AccessibleApplication *application;
657
658         g_assert (win->magic == WINDOW_MAGIC);
659         g_assert (!strcmp (event->type, "focus:"));
660
661         fprintf (stderr, "Fielded focus event ...\n");
662
663         if (!do_poke) {
664                 desktop = SPI_getDesktop (0);
665                 application = Accessible_getChildAtIndex (desktop, 0);
666                 g_assert (application != NULL);
667                 Accessible_unref (desktop);
668                 
669                 test_application (application);
670                 
671                 AccessibleApplication_unref (application);
672                 
673                 print_tree = FALSE;
674
675                 validate_accessible (event->source, TRUE, TRUE);
676
677                 fprintf (stderr, "quitting mainloop.\n");
678                 gtk_main_quit ();
679         }
680
681         print_tree = TRUE;
682         validate_accessible (event->source, TRUE, TRUE);
683 }
684
685 static SPIBoolean
686 key_listener_cb (const AccessibleKeystroke *stroke,
687                  void                      *user_data)
688 {
689         AccessibleKeystroke *s = user_data;
690         
691         *s = *stroke;
692         if (stroke->keystring) s->keystring = g_strdup (stroke->keystring);
693         
694         if (s->type == SPI_KEY_PRESSED)
695                 key_press_received = TRUE;
696         else if (s->type == SPI_KEY_RELEASED)
697                 key_release_received = TRUE;
698
699         return TRUE;
700 }
701
702
703 static void
704 test_keylisteners (void)
705 {
706         int i;
707         AccessibleKeystroke stroke;
708         AccessibleKeystrokeListener *key_listener;
709         AccessibleKeySet *test_keyset;
710
711         fprintf (stderr, "Testing keyboard listeners ...\n");
712
713         key_listener = SPI_createAccessibleKeystrokeListener (
714                 key_listener_cb, &stroke);
715
716         test_keyset = SPI_createAccessibleKeySet (1, "=", NULL, NULL);
717
718         g_assert (SPI_registerAccessibleKeystrokeListener (
719                 key_listener,
720                 test_keyset,
721                 0,
722                 SPI_KEY_PRESSED | SPI_KEY_RELEASED,
723                 SPI_KEYLISTENER_CANCONSUME | SPI_KEYLISTENER_ALL_WINDOWS));
724
725         for (i = 0; i < 3; i++) {
726                 memset (&stroke, 0, sizeof (AccessibleKeystroke));
727                 g_assert (SPI_generateKeyboardEvent ('=', NULL, SPI_KEY_SYM));
728                 while (!(key_press_received))
729                         g_main_context_iteration (NULL, TRUE);
730                 fprintf (stderr, "p [%s]", stroke.keystring);
731                 g_assert (!strcmp (stroke.keystring, "="));
732                 while (!(key_release_received))
733                         g_main_context_iteration (NULL, TRUE);
734                 fprintf (stderr, "r [%s]", stroke.keystring);
735                 key_press_received = FALSE;
736                 key_release_received = FALSE;
737         }
738         g_assert (SPI_deregisterAccessibleKeystrokeListener (key_listener, 0));
739         SPI_freeAccessibleKeySet (test_keyset);
740
741         fprintf (stderr, "\n");
742
743         AccessibleKeystrokeListener_unref (key_listener);
744
745         g_assert (SPI_generateMouseEvent (100, 100, "rel"));
746         g_assert (SPI_generateMouseEvent (-50, -50, "rel"));              
747         g_assert (SPI_generateMouseEvent (-50, -50, "rel"));              
748         g_assert (SPI_generateMouseEvent (-1, -1, "b1c")); 
749 }
750
751 int
752 main (int argc, char **argv)
753 {
754         int leaked, i;
755         TestWindow *win;
756         const char *modules;
757         AccessibleEventListener *global_listener;
758
759         modules = g_getenv ("GTK_MODULES");
760         if (!modules || modules [0] == '\0')
761                 putenv ("GTK_MODULES=gail:atk-bridge");
762         modules = NULL;
763
764         for (i = 1; i < argc; i++) {
765                 if (!g_strcasecmp (argv [i], "--poke"))
766                         do_poke = TRUE;
767         }
768
769         gtk_init (&argc, &argv);
770
771         g_assert (!SPI_init ());
772         g_assert (SPI_init ());
773         g_assert (SPI_getDesktopCount () == 1);
774
775         test_roles ();
776         test_misc ();
777         test_desktop ();
778         test_keylisteners (); 
779
780         win = create_test_window ();
781
782         global_listener = SPI_createAccessibleEventListener (global_listener_cb, win);
783
784         g_assert (SPI_registerGlobalEventListener (global_listener, "focus:"));
785
786         fprintf (stderr, "Waiting for focus event ...\n");
787         gtk_main ();
788
789         g_assert (SPI_deregisterGlobalEventListenerAll (global_listener));
790         AccessibleEventListener_unref (global_listener);
791
792         test_window_destroy (win);
793
794         /* Wait for any pending events from the registry */
795         g_usleep (500*1000);
796         for (i = 0; i < 100; i++)
797                 dbus_connection_read_write_dispatch (SPI_bus(), 5);
798
799         if ((leaked = SPI_exit ()))
800                 g_error ("Leaked %d SPI handles", leaked);
801
802         g_assert (!SPI_exit ());
803
804         fprintf (stderr, "All tests passed\n");
805
806         if (g_getenv ("_MEMPROF_SOCKET")) {
807                 fprintf (stderr, "Waiting for memprof\n");
808                 gtk_main ();
809         }
810
811         putenv ("AT_BRIDGE_SHUTDOWN=1");
812
813         return 0;
814 }