Add names to every timeout
[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       guint id;
57       basic (desktop);
58       g_object_unref (desktop);
59       id = g_timeout_add (3000, kill_child, NULL);
60       g_source_set_name_by_id (id, "[at-spi2-core] kill_child");
61     }
62     else
63     {
64       guint id;
65       id = g_idle_add (end, NULL);
66       g_source_set_name_by_id (id, "[at-spi2-core] end");
67     }
68   }
69   g_boxed_free (ATSPI_TYPE_EVENT, event);
70 }
71
72 int
73 main()
74 {
75   atspi_init ();
76
77   listener = atspi_event_listener_new (on_event, NULL, NULL);
78   atspi_event_listener_register (listener, "object:children-changed", NULL);
79   child_pid = fork ();
80   if (!child_pid)
81     execlp ("gedit", "gedit", NULL);
82   atspi_event_main ();
83   return 0;
84 }