Make AtspiEventListenerCb not call for a const datum
[platform/upstream/at-spi2-core.git] / test / memory.c
1 #include "atspi/atspi.h"
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5
6 pid_t child_pid;
7 AtspiEventListener *listener;
8
9 void
10 basic (AtspiAccessible *obj)
11 {
12   gchar *str;
13   gint count;
14   gint i;
15   AtspiAccessible *accessible;
16   GError *error = NULL;
17
18   str = atspi_accessible_get_name (obj, &error);
19   if (str)
20     g_free (str);
21   accessible = atspi_accessible_get_parent (obj, NULL);
22   if (accessible)
23     g_object_unref (accessible);
24   count = atspi_accessible_get_child_count (obj, &error);
25   for (i = 0; i < count; i++)
26   {
27     accessible = atspi_accessible_get_child_at_index (obj, i, &error);
28     if (accessible)
29       g_object_unref (accessible);
30   }
31 }
32
33 static gboolean
34 end (void *data)
35 {
36   atspi_event_quit ();
37   atspi_exit ();
38   exit (0);
39 }
40
41 static gboolean
42 kill_child (void *data)
43 {
44   kill (child_pid, SIGTERM);
45   return FALSE;
46 }
47
48 void
49 on_event (AtspiEvent *event, void *data)
50 {
51   if (atspi_accessible_get_role (event->source, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
52   {
53     if (strstr (event->type, "add"))
54     {
55       AtspiAccessible *desktop = atspi_get_desktop (0);
56       basic (desktop);
57       g_object_unref (desktop);
58       g_timeout_add (3000, kill_child, NULL);
59     }
60     else
61     {
62       g_idle_add (end, NULL);
63     }
64   }
65   g_boxed_free (ATSPI_TYPE_EVENT, event);
66 }
67
68 int
69 main()
70 {
71   atspi_init ();
72
73   listener = atspi_event_listener_new (on_event, NULL, NULL);
74   atspi_event_listener_register (listener, "object:children-changed", NULL);
75   child_pid = fork ();
76   if (!child_pid)
77     execlp ("gedit", "gedit", NULL);
78   atspi_event_main ();
79   return 0;
80 }