Fix upstream in .gbs.conf
[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
17   str = atspi_accessible_get_name (obj, NULL);
18   if (str)
19     g_free (str);
20   accessible = atspi_accessible_get_parent (obj, NULL);
21   if (accessible)
22     g_object_unref (accessible);
23   count = atspi_accessible_get_child_count (obj, NULL);
24   for (i = 0; i < count; i++)
25   {
26     accessible = atspi_accessible_get_child_at_index (obj, i, NULL);
27     if (accessible)
28       g_object_unref (accessible);
29   }
30 }
31
32 static gboolean
33 end (void *data)
34 {
35   atspi_event_quit ();
36   atspi_exit ();
37   exit (0);
38 }
39
40 static gboolean
41 kill_child (void *data)
42 {
43   kill (child_pid, SIGTERM);
44   return FALSE;
45 }
46
47 void
48 on_event (AtspiEvent *event, void *data)
49 {
50   if (atspi_accessible_get_role (event->source, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
51   {
52     if (strstr (event->type, "add"))
53     {
54       AtspiAccessible *desktop = atspi_get_desktop (0);
55       guint id;
56       basic (desktop);
57       g_object_unref (desktop);
58       id = g_timeout_add (3000, kill_child, NULL);
59       g_source_set_name_by_id (id, "[at-spi2-core] kill_child");
60     }
61     else
62     {
63       guint id;
64       id = g_idle_add (end, NULL);
65       g_source_set_name_by_id (id, "[at-spi2-core] end");
66     }
67   }
68   g_boxed_free (ATSPI_TYPE_EVENT, event);
69 }
70
71 int
72 main()
73 {
74   atspi_init ();
75
76   listener = atspi_event_listener_new (on_event, NULL, NULL);
77   atspi_event_listener_register (listener, "object:children-changed", NULL);
78   child_pid = fork ();
79   if (!child_pid)
80     execlp ("gedit", "gedit", NULL);
81   atspi_event_main ();
82   return 0;
83 }