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