1dfafdc906d87ec3b9c6eff7358396854377f296
[platform/core/uifw/at-spi2-atk.git] / test / app.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems 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 #include <stdio.h>
24 #include <stdlib.h>
25 #include <libbonobo.h>
26 #include <atk/atkobject.h>
27 #include <libspi/Accessibility.h>
28 #include "accessible.h"
29 #include "application.h"
30
31 int
32 main(int argc, char **argv)
33 {
34         CORBA_Environment ev;
35         CORBA_Object oclient;
36         AtkObject *atko;
37         char *obj_id;
38         char sbuf[30];
39
40         Accessibility_Registry registry;
41         Accessibility_Event e;
42         Accessible *accessible;
43         Application *app;
44
45         CORBA_exception_init(&ev);
46
47         if (!bonobo_init (&argc, argv))
48           {
49             g_error ("Could not initialize Bonobo");
50           }
51
52         /* Create the accesssible application server object */
53         /* TODO: get app name and pid */
54         sprintf(sbuf, "application-%s", argv[1]);
55         atko = g_object_new (atk_object_get_type(), NULL);
56         atk_object_set_name (atko, "sbuf");
57         atk_object_set_description( atko, "test application for accessibility SPI");
58         app = application_new(atko);
59
60         /* Create the Accessible 'source' for the event */
61         accessible = accessible_new (atko);
62         fprintf(stderr, "accessible created.\n");
63
64         /* FIXME: this type of event struct will leak, needs to be redefined */
65         e.target = bonobo_object_corba_objref ( bonobo_object (accessible));
66         e.type = CORBA_string_dup ("test");
67
68         obj_id = "OAFIID:Accessibility_Registry:proto0.1";
69
70         oclient = bonobo_activation_activate_from_id (obj_id, 0, NULL, &ev);
71         if (ev._major != CORBA_NO_EXCEPTION) {
72                 fprintf(stderr,
73                 ("Accessibility app error: exception during registry activation from id: %s\n"),
74                         CORBA_exception_id(&ev));
75                 CORBA_exception_free(&ev);
76                 exit(-1);
77         }
78
79         if (CORBA_Object_is_nil (oclient, &ev))
80           {
81             g_error ("Could not locate registry");
82           }
83
84         registry = (Accessibility_Registry) oclient;
85
86         Accessibility_Registry_registerApplication (registry,
87                                                     bonobo_object_corba_objref (bonobo_object (app)),
88                                                     &ev);
89         fprintf(stderr, "registerApplication has been called.\n");
90
91         Accessibility_Registry_notifyEvent (registry, &e, &ev);
92         fprintf (stderr, "notify event has been called.\n");
93
94         bonobo_main (); /* needed when app becomes a server ? */
95         exit(0);
96 }