summaryrefslogtreecommitdiff
path: root/test/memory.c
blob: 5105fffc512a9e6e0de84fe82d4417cb253740fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "atspi/atspi.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

pid_t child_pid;
AtspiEventListener *listener;

void
basic (AtspiAccessible *obj)
{
  gchar *str;
  gint count;
  gint i;
  AtspiAccessible *accessible;
  GError *error = NULL;

  printf ("getting name\n");
  str = atspi_accessible_get_name (obj, &error);
  if (str)
    g_free (str);
  printf ("ok, getting parent\n");
  accessible = atspi_accessible_get_parent (obj, NULL);
  if (accessible)
    g_object_unref (accessible);
  printf ("ok, getting children\n");
  count = atspi_accessible_get_child_count (obj, &error);
  for (i = 0; i < count; i++)
  {
    accessible = atspi_accessible_get_child_at_index (obj, i, &error);
    printf ("ok %d\n", i);
    if (accessible)
      g_object_unref (accessible);
  }
  printf ("ok\n");
}

static gboolean
end (void *data)
{
  atspi_event_quit ();
  atspi_exit ();
  exit (0);
}

static gboolean
kill_child (void *data)
{
  kill (child_pid, SIGTERM);
  return FALSE;
}

void
on_event (AtspiEvent *event, void *data)
{
  if (atspi_accessible_get_role (event->source, NULL) == ATSPI_ROLE_DESKTOP_FRAME)
  {
    if (strstr (event->type, "add"))
    {
      AtspiAccessible *desktop = atspi_get_desktop (0);
      guint id;
      basic (desktop);
      g_object_unref (desktop);
      id = g_timeout_add (3000, kill_child, NULL);
      g_source_set_name_by_id (id, "[at-spi2-core] kill_child");
    }
    else
    {
      guint id;
      id = g_idle_add (end, NULL);
      g_source_set_name_by_id (id, "[at-spi2-core] end");
    }
  }
  g_boxed_free (ATSPI_TYPE_EVENT, event);
}

int
main()
{
  atspi_init ();

  listener = atspi_event_listener_new (on_event, NULL, NULL);
  atspi_event_listener_register (listener, "object:children-changed", NULL);
  child_pid = fork ();
  if (!child_pid)
    execlp ("test/test-application", "test/test-application", NULL);
  atspi_event_main ();
  return 0;
}