[at-spi2-core: 1/2] Replace gedit with a light-weight test application




commit 6f5c54054060e8b93ffbfe4a1635defe3b52bfa2
Author: Glady Handschumaker <gladyhandschumaker fake-box com>
Date:   Sat Jul 25 10:16:44 2020 +0200

    Replace gedit with a light-weight test application
    
    The test `memory` depends on `gedit` being installed. Create our own
    small test application which can be used instead of `gedit`.
    
    Note: The 'depends' argument for tests need at least meson version
    0.46.0. Thus, bump that requirement.

 meson.build             |   2 +-
 test/memory.c           |   2 +-
 test/meson.build        |  17 ++++++--
 test/test-application.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 6 deletions(-)
---
diff --git a/meson.build b/meson.build
index 8f1943b4..c22ef3ce 100644
--- a/meson.build
+++ b/meson.build
@@ -6,7 +6,7 @@ project('at-spi2-core', 'c',
           'warning_level=1',
           'c_std=c99',
         ],
-        meson_version: '>= 0.40.1')
+        meson_version: '>= 0.46.0')
 
 add_project_arguments([ '-D_POSIX_C_SOURCE=200809L', '-D_DEFAULT_SOURCE' ], language: 'c')
 
diff --git a/test/memory.c b/test/memory.c
index df5e0a16..e8357fec 100644
--- a/test/memory.c
+++ b/test/memory.c
@@ -78,7 +78,7 @@ main()
   atspi_event_listener_register (listener, "object:children-changed", NULL);
   child_pid = fork ();
   if (!child_pid)
-    execlp ("gedit", "gedit", NULL);
+    execlp ("test/test-application", "test/test-application", NULL);
   atspi_event_main ();
   return 0;
 }
diff --git a/test/meson.build b/test/meson.build
index 1fb35a8a..cd3db669 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,4 +1,13 @@
-test('memory',
-     executable('memory', 'memory.c',
-                include_directories: root_inc,
-                dependencies: [ atspi_dep ]))
+testapp = executable('test-application',
+                     'test-application.c',
+                     include_directories: root_inc,
+                     dependencies: [ atspi_dep ],
+                    )
+
+memory = executable('memory',
+                    'memory.c',
+                    include_directories: root_inc,
+                    dependencies: [ atspi_dep ],
+                   )
+
+test('memory', memory, depends: testapp)
diff --git a/test/test-application.c b/test/test-application.c
new file mode 100644
index 00000000..621d1de4
--- /dev/null
+++ b/test/test-application.c
@@ -0,0 +1,105 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+/*
+ * Simple test application for AT-SPI.
+ *
+ * The only thing this application does, is registering itself to the AT-SPI
+ * registry and then waiting to get killed by some external force.
+ */
+
+#include <stdio.h>
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <atspi/atspi.h>
+
+static GMainLoop *mainloop;
+
+int
+register_app ()
+{
+  DBusConnection *connection = NULL;
+  DBusMessage *message;
+  DBusMessageIter iter;
+  DBusMessageIter subiter;
+  DBusError error;
+  DBusMessage *reply;
+  const gchar *name;
+  gchar *path;
+
+
+  /* Set up D-Bus connection and register bus name */
+  dbus_error_init (&error);
+  connection = atspi_get_a11y_bus ();
+  if (!connection)
+    {
+      printf("Couldn't get a11y bus!\n");
+      return -1;
+    }
+
+  /* Register this app by sending a signal out to AT-SPI registry daemon */
+  message = dbus_message_new_method_call (ATSPI_DBUS_NAME_REGISTRY,
+                                          ATSPI_DBUS_PATH_ROOT,
+                                          ATSPI_DBUS_INTERFACE_SOCKET,
+                                          "Embed");
+
+  dbus_message_iter_init_append (message, &iter);
+
+  name = dbus_bus_get_unique_name (connection);
+  path = g_strdup (ATSPI_DBUS_PATH_NULL);
+
+  dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
+                                    &subiter);
+  dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &name);
+  dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &path);
+  dbus_message_iter_close_container (&iter, &subiter);
+
+  g_free (path);
+
+  reply = dbus_connection_send_with_reply_and_block(connection, message, -1, &error);
+  if (!reply)
+    {
+      printf("Did not get a reply from the registry.\n");
+      dbus_message_unref (message);
+      dbus_error_free (&error);
+      return -1;
+    }
+
+  dbus_message_unref (message);
+  dbus_message_unref (reply);
+  dbus_error_free (&error);
+  return 0;
+}
+
+int main (int argc, char *argv[])
+{
+  int ret = register_app ();
+  if (ret) {
+    printf("Failed to send dbus signals. Aborting.\n");
+    return ret;
+  }
+
+  // This keeps the test-application runnig indefinitely, i.e.
+  // until killed by an external signal.
+  mainloop = g_main_loop_new (NULL, FALSE);
+  g_main_loop_run (mainloop);
+
+  return 0;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]