Remove X related lines
[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 #include <cspi/spi-private.h>
34
35 #include "dbus/dbus.h"
36
37 /* Known bugs */
38 #define WHOLE_STRING -1
39
40 static void validate_accessible (Accessible *accessible,
41                                  gboolean    has_parent,
42                                  gboolean    recurse_down);
43
44 #define WINDOW_MAGIC 0x123456a
45 #define TEST_STRING_A "A test string"
46 #define TEST_STRING_A_OBJECT "A_test_string_object"
47 #define TEST_STRING_B "Another test string"
48
49 static int      print_tree_depth = 0;
50 static gboolean print_tree = FALSE;
51 static gboolean do_poke = FALSE;
52 static gboolean key_press_received = FALSE;
53 static gboolean key_release_received = FALSE;
54
55 typedef struct {
56         gulong     magic;
57         GtkWidget *window;
58 } TestWindow;
59
60 static gboolean
61 focus_me (GtkWidget *widget)
62 {
63         AtkObject *aobject = atk_implementor_ref_accessible (
64                 ATK_IMPLEMENTOR (widget));
65         
66         /* Force a focus event - even if the WM focused
67          * us before our at-bridge's idle handler registered
68          * our interest */
69         if (!GTK_WIDGET_HAS_FOCUS (widget))
70                 gtk_widget_grab_focus (widget);
71 /*      else: FIXME - gtk_widget_grab_focus should send a notify */
72                 atk_focus_tracker_notify (aobject);
73         
74         g_object_unref (G_OBJECT (aobject));
75
76         return FALSE;
77 }
78
79 static void
80 test_window_add_and_show (GtkContainer *container, GtkWidget *widget)
81 {
82         gtk_container_add (container, widget);
83         gtk_widget_show (widget);
84 }
85
86 static GtkWidget *
87 create_tree (void)
88 {
89         GtkWidget         *widget;
90         GtkTreeIter        iter;
91         GtkListStore      *store;
92         GtkTreeViewColumn *column;
93
94         store = gtk_list_store_new (1, G_TYPE_STRING);
95         gtk_list_store_append (store, &iter);
96         gtk_list_store_set (store, &iter, 0, TEST_STRING_A, -1); 
97         column = gtk_tree_view_column_new_with_attributes ("String",
98                 gtk_cell_renderer_text_new (), "text", 0, NULL);
99         widget = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); 
100         g_object_unref (G_OBJECT (store));
101         gtk_tree_view_append_column (GTK_TREE_VIEW (widget), column);
102
103         return widget;
104 }
105
106 static TestWindow *
107 create_test_window (void)
108 {
109         TestWindow *win = g_new0 (TestWindow, 1);
110         GtkWidget  *widget, *vbox;
111         AtkObject *obj;
112
113         win->magic  = WINDOW_MAGIC;
114         win->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
115  
116         gtk_widget_show (win->window);
117
118         vbox = gtk_vbox_new (0, 0);
119         gtk_container_add (GTK_CONTAINER (win->window), vbox);
120         gtk_widget_show (vbox);
121
122         widget = gtk_entry_new ();
123         gtk_entry_set_text (GTK_ENTRY (widget), TEST_STRING_A);
124         obj = gtk_widget_get_accessible (widget);
125         atk_object_set_name (obj, TEST_STRING_A_OBJECT);
126
127         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
128
129         widget = gtk_button_new_with_label ("_Foobar");
130         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
131
132         widget = gtk_hseparator_new ();
133         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
134
135         widget = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION,
136                                            GTK_ICON_SIZE_LARGE_TOOLBAR);
137         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
138
139         widget = g_object_new (GTK_TYPE_HSCALE, NULL);
140         gtk_range_set_range (GTK_RANGE (widget), 0.0, 100.0);
141         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
142
143         widget = create_tree ();
144         test_window_add_and_show (GTK_CONTAINER (vbox), widget);
145
146         g_idle_add ((GSourceFunc) focus_me, win->window);
147
148         return win;
149 }
150
151 static void
152 test_window_destroy (TestWindow *win)
153 {
154         gtk_widget_destroy (win->window);
155         g_free (win);
156 }
157
158 static void
159 test_roles (void)
160 {
161         int i;
162
163         fprintf (stderr, "Testing roles...\n");
164         for (i = -1; i < 1000; i++)
165                 g_assert (AccessibleRole_getName (i) != NULL);
166
167         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_FILE_CHOOSER), "file-chooser"));
168         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_RADIO_BUTTON), "radio-button"));
169         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_TABLE), "table"));
170         g_assert (!strcmp (AccessibleRole_getName (SPI_ROLE_WINDOW), "window"));
171 }
172
173 static void
174 test_action (AccessibleAction *action)
175 {
176         gint n_actions, i;
177         gchar *s, *sd;
178         g_assert ((n_actions = AccessibleAction_getNActions (action)) >= 0);
179
180         fprintf (stderr, "Testing actions...");
181         for (i = 0; i < n_actions; ++i)
182         {
183                 s = AccessibleAction_getName (action, i);
184                 g_assert (s);
185                 sd = AccessibleAction_getDescription (action, i);
186                 g_assert (sd);
187                 fprintf (stderr, "%d: %s (%s);  ", i, s, sd);
188                 SPI_freeString (s);
189                 SPI_freeString (sd);
190                 g_assert (AccessibleAction_doAction (action, i));
191         }
192         fprintf (stderr, "\n");
193 }
194
195 static void
196 test_desktop (void)
197 {
198         Accessible  *desktop;
199         Accessible  *application;
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 ((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         if (stroke->keystring) s->keystring = g_strdup (stroke->keystring);
695         
696         if (s->type == SPI_KEY_PRESSED)
697                 key_press_received = TRUE;
698         else if (s->type == SPI_KEY_RELEASED)
699                 key_release_received = TRUE;
700
701         return TRUE;
702 }
703
704
705 static void
706 test_keylisteners (void)
707 {
708         int i;
709         AccessibleKeystroke stroke;
710         AccessibleKeystrokeListener *key_listener;
711         AccessibleKeySet *test_keyset;
712
713         fprintf (stderr, "Testing keyboard listeners ...\n");
714
715         key_listener = SPI_createAccessibleKeystrokeListener (
716                 key_listener_cb, &stroke);
717
718         test_keyset = SPI_createAccessibleKeySet (1, "=", NULL, NULL);
719
720         g_assert (SPI_registerAccessibleKeystrokeListener (
721                 key_listener,
722                 test_keyset,
723                 0,
724                 SPI_KEY_PRESSED | SPI_KEY_RELEASED,
725                 SPI_KEYLISTENER_CANCONSUME | SPI_KEYLISTENER_ALL_WINDOWS));
726
727         for (i = 0; i < 3; i++) {
728                 memset (&stroke, 0, sizeof (AccessibleKeystroke));
729                 g_assert (SPI_generateKeyboardEvent ('=', NULL, SPI_KEY_SYM));
730                 while (!(key_press_received))
731                         g_main_context_iteration (NULL, TRUE);
732                 fprintf (stderr, "p [%s]", stroke.keystring);
733                 g_assert (!strcmp (stroke.keystring, "="));
734                 while (!(key_release_received))
735                         g_main_context_iteration (NULL, TRUE);
736                 fprintf (stderr, "r [%s]", stroke.keystring);
737                 key_press_received = FALSE;
738                 key_release_received = FALSE;
739         }
740         g_assert (SPI_deregisterAccessibleKeystrokeListener (key_listener, 0));
741         SPI_freeAccessibleKeySet (test_keyset);
742
743         fprintf (stderr, "\n");
744
745         AccessibleKeystrokeListener_unref (key_listener);
746
747         g_assert (SPI_generateMouseEvent (100, 100, "rel"));
748         g_assert (SPI_generateMouseEvent (-50, -50, "rel"));              
749         g_assert (SPI_generateMouseEvent (-50, -50, "rel"));              
750         g_assert (SPI_generateMouseEvent (-1, -1, "b1c")); 
751 }
752
753 int
754 main (int argc, char **argv)
755 {
756         int leaked, i;
757         TestWindow *win;
758         const char *modules;
759         AccessibleEventListener *global_listener;
760
761         modules = g_getenv ("GTK_MODULES");
762         if (!modules || modules [0] == '\0')
763                 putenv ("GTK_MODULES=gail:atk-bridge");
764         modules = NULL;
765
766         for (i = 1; i < argc; i++) {
767                 if (!g_strcasecmp (argv [i], "--poke"))
768                         do_poke = TRUE;
769         }
770
771         gtk_init (&argc, &argv);
772
773         g_assert (!SPI_init ());
774         g_assert (SPI_init ());
775         g_assert (SPI_getDesktopCount () == 1);
776
777         test_roles ();
778         test_misc ();
779         test_desktop ();
780         test_keylisteners (); 
781
782         win = create_test_window ();
783
784         global_listener = SPI_createAccessibleEventListener (global_listener_cb, win);
785
786         g_assert (SPI_registerGlobalEventListener (global_listener, "focus:"));
787
788         fprintf (stderr, "Waiting for focus event ...\n");
789         gtk_main ();
790
791         g_assert (SPI_deregisterGlobalEventListenerAll (global_listener));
792         AccessibleEventListener_unref (global_listener);
793
794         test_window_destroy (win);
795
796         /* Wait for any pending events from the registry */
797         g_usleep (500*1000);
798         for (i = 0; i < 100; i++)
799                 dbus_connection_read_write_dispatch (SPI_bus(), 5);
800
801         if ((leaked = SPI_exit ()))
802                 g_error ("Leaked %d SPI handles", leaked);
803
804         g_assert (!SPI_exit ());
805
806         fprintf (stderr, "All tests passed\n");
807
808         if (g_getenv ("_MEMPROF_SOCKET")) {
809                 fprintf (stderr, "Waiting for memprof\n");
810                 gtk_main ();
811         }
812
813         putenv ("AT_BRIDGE_SHUTDOWN=1");
814
815         return 0;
816 }