b42508ee908e75250224ac9c961a358e4b49276b
[platform/core/uifw/at-spi2-atk.git] / test / app.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <libbonobo.h>
4 #include <atk/atkobject.h>
5 #include "Registry.h"
6 #include "Event.h"
7 #include "accessible.h"
8 #include "atksimpleobject.h"
9 #include "application.h"
10
11 int
12 main(int argc, char **argv)
13 {
14         CORBA_Environment ev;
15         CORBA_Object oclient;
16         AtkObject *atko;
17         char *obj_id;
18         char sbuf[30];
19
20         Accessibility_Registry registry;
21         Accessibility_Event e;
22         Accessible *accessible;
23         Application *app;
24
25         CORBA_exception_init(&ev);
26
27         if (!bonobo_init (&argc, argv))
28           {
29             g_error ("Could not initialize Bonobo");
30           }
31
32         /* Create the accesssible application server object */
33         /* TODO: get app name and pid */
34         sprintf(sbuf, "application-%s", argv[1]);
35         app = application_new(sbuf, "test application for accessibility SPI", "0001");
36
37         /* Create the Accessible 'source' for the event */
38         atko = atk_simple_object_new ();
39         atk_object_set_name (atko, "dummy");
40         accessible = accessible_new (atko);
41         fprintf(stderr, "accessible created.\n");
42
43         /* FIXME: this type of event struct will leak, needs to be redefined */
44         e.target = bonobo_object_corba_objref ( bonobo_object (accessible));
45         e.type = CORBA_string_dup ("test");
46
47         obj_id = "OAFIID:Accessibility_Registry:proto0.1";
48
49         oclient = oaf_activate_from_id (obj_id, 0, NULL, &ev);
50         if (ev._major != CORBA_NO_EXCEPTION) {
51                 fprintf(stderr,
52                 ("Accessibility app error: exception during registry activation from id: %s\n"),
53                         CORBA_exception_id(&ev));
54                 CORBA_exception_free(&ev);
55                 exit(-1);
56         }
57
58         if (CORBA_Object_is_nil (oclient, &ev))
59           {
60             g_error ("Could not locate registry");
61           }
62
63         registry = (Accessibility_Registry) oclient;
64
65         Accessibility_Registry_registerApplication (registry,
66                                                     bonobo_object_corba_objref (bonobo_object (app)),
67                                                     &ev);
68         fprintf(stderr, "registerApplication has been called.\n");
69
70         Accessibility_Registry_notifyEvent (registry, &e, &ev);
71         fprintf (stderr, "notify event has been called.\n");
72
73         bonobo_main (); /* needed when app becomes a server ? */
74         exit(0);
75 }