1
#include "atspi/atspi.h"
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
#include <unistd.h>
6

            
7
pid_t child_pid;
8
AtspiEventListener *listener;
9

            
10
void
11
1
basic (AtspiAccessible *obj)
12
{
13
  gchar *str;
14
  gint count;
15
  gint i;
16
  AtspiAccessible *accessible;
17
1
  GError *error = NULL;
18

            
19
1
  printf ("getting name\n");
20
1
  str = atspi_accessible_get_name (obj, &error);
21
1
  if (str)
22
1
    g_free (str);
23
1
  printf ("ok, getting parent\n");
24
1
  accessible = atspi_accessible_get_parent (obj, NULL);
25
1
  if (accessible)
26
    g_object_unref (accessible);
27
1
  printf ("ok, getting children\n");
28
1
  count = atspi_accessible_get_child_count (obj, &error);
29
2
  for (i = 0; i < count; i++)
30
    {
31
1
      accessible = atspi_accessible_get_child_at_index (obj, i, &error);
32
1
      printf ("ok %d\n", i);
33
1
      if (accessible)
34
        g_object_unref (accessible);
35
    }
36
1
  printf ("ok\n");
37
1
}
38

            
39
static gboolean
40
1
end (void *data)
41
{
42
1
  atspi_event_quit ();
43
1
  atspi_exit ();
44
1
  exit (0);
45
}
46

            
47
static gboolean
48
1
kill_child (void *data)
49
{
50
1
  g_assert_no_errno (kill (child_pid, SIGTERM));
51
1
  return FALSE;
52
}
53

            
54
void
55
2
on_event (AtspiEvent *event, void *data)
56
{
57
2
  if (atspi_accessible_get_role (event->source, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
58
    {
59
2
      printf ("memory: event: %s\n", event->type);
60
2
      if (strstr (event->type, "add"))
61
        {
62
1
          AtspiAccessible *desktop = atspi_get_desktop (0);
63
          guint id;
64
1
          basic (desktop);
65
1
          g_object_unref (desktop);
66
1
          id = g_timeout_add (3000, kill_child, NULL);
67
1
          g_source_set_name_by_id (id, "[at-spi2-core] kill_child");
68
        }
69
      else
70
        {
71
          guint id;
72
1
          id = g_idle_add (end, NULL);
73
1
          g_source_set_name_by_id (id, "[at-spi2-core] end");
74
        }
75
    }
76
2
  g_boxed_free (ATSPI_TYPE_EVENT, event);
77
2
}
78

            
79
int
80
1
main ()
81
{
82
1
  atspi_init ();
83

            
84
1
  listener = atspi_event_listener_new (on_event, NULL, NULL);
85
1
  atspi_event_listener_register (listener, "object:children-changed", NULL);
86
1
  child_pid = fork ();
87
1
  if (child_pid == 0)
88
    {
89
      g_assert_no_errno (execlp ("tests/atspi/test-application", "tests/atspi/test-application", NULL));
90
    }
91
1
  else if (child_pid == -1)
92
    {
93
      const char *error = g_strerror (errno);
94
      g_error ("could not fork test-application child: %s", error);
95
    }
96
1
  printf ("memory: child pid: %d\n", (int) child_pid);
97
1
  atspi_event_main ();
98
  return 0;
99
}