summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Gorse <mgorse@suse.com>2012-12-27 16:50:04 -0500
committerMike Gorse <mgorse@suse.com>2012-12-27 16:50:04 -0500
commit233ec0f562e12adfbe1ca5182bebd22c19c31ea4 (patch)
treef9ee06c6a15c854cb6196e1d054487a2723c0fae /test
parentaa13890a6ad1c7b7c743a343ea94995598c4709d (diff)
downloadat-spi2-core-233ec0f562e12adfbe1ca5182bebd22c19c31ea4.tar.gz
Fix some ref count issues
Add refs in some places where they were previously not present, and be more thorough about removing refs when disposing. This should fix some leaks, though it is likely that many still remain. Also add a test program that can be used to test for some leaks.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am5
-rw-r--r--test/memory.c78
2 files changed, 83 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 00000000..ab47b948
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,5 @@
+LDADD = $(top_builddir)/atspi/libatspi.la
+noinst_PROGRAMS = memory
+memory_SOURCES = memory.c
+memory_CFLAGS = $(GLIB_CFLAGS) $(DBUS_CFLAGS)
+memory_LDFLAGS =
diff --git a/test/memory.c b/test/memory.c
new file mode 100644
index 00000000..28c3a8ec
--- /dev/null
+++ b/test/memory.c
@@ -0,0 +1,78 @@
+#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;
+
+ str = atspi_accessible_get_name (obj, &error);
+ if (str)
+ g_free (str);
+ accessible = atspi_accessible_get_parent (obj, NULL);
+ if (accessible)
+ g_object_unref (accessible);
+ count = atspi_accessible_get_child_count (obj, &error);
+ for (i = 0; i < count; i++)
+ {
+ accessible = atspi_accessible_get_child_at_index (obj, i, &error);
+ if (accessible)
+ g_object_unref (accessible);
+ }
+}
+
+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);
+ basic (desktop);
+ g_object_unref (desktop);
+ g_timeout_add (3000, kill_child, NULL);
+ }
+ else
+ {
+ g_idle_add (end, NULL);
+ }
+ }
+ g_boxed_free (ATSPI_TYPE_EVENT, event);
+}
+
+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 ("gedit", "gedit", NULL);
+ atspi_event_main ();
+}