[glib] Adding test coverage for GTestDBus activating in-tree services.
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Adding test coverage for GTestDBus activating in-tree services.
- Date: Sat, 29 Dec 2012 05:03:17 +0000 (UTC)
commit 32c925427785895ce156f4bb428082e1952d2407
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Thu Dec 20 15:34:22 2012 +0900
Adding test coverage for GTestDBus activating in-tree services.
https://bugzilla.gnome.org/show_bug.cgi?id=690543
configure.ac | 2 +
gio/tests/Makefile.am | 9 ++-
gio/tests/gdbus-test-fixture.c | 121 ++++++++++++++++++++
gio/tests/services/Makefile.am | 2 +
...org.gtk.GDBus.Examples.ObjectManager.service.in | 3 +
5 files changed, 136 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0304dad..ba5668a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3645,6 +3645,8 @@ gio/fam/Makefile
gio/win32/Makefile
gio/tests/Makefile
gio/tests/gdbus-object-manager-example/Makefile
+gio/tests/services/Makefile
+gio/tests/services/org.gtk.GDBus.Examples.ObjectManager.service
po/Makefile.in
docs/Makefile
docs/reference/Makefile
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 5ef0825..df96bcc 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -13,7 +13,9 @@ INCLUDES = \
-I$(top_builddir)/gio \
-I$(top_srcdir)/gio \
$(DBUS1_CFLAGS) \
- -DSRCDIR=\""$(srcdir)"\"
+ -DSRCDIR=\""$(srcdir)"\" \
+ -DTEST_SERVICES=\""$(abs_top_builddir)/gio/tests/services"\"
+
noinst_PROGRAMS = $(TEST_PROGS) $(SAMPLE_PROGS)
noinst_DATA = $(MISC_STUFF)
@@ -142,6 +144,7 @@ SAMPLE_PROGS += \
gdbus-example-unix-fd-client \
gdbus-example-objectmanager-server \
gdbus-example-objectmanager-client \
+ gdbus-test-fixture \
appinfo-test \
$(NULL)
endif
@@ -370,6 +373,10 @@ gdbus_peer_SOURCES = gdbus-peer.c gdbus-tests.h gdbus-tests.c
gdbus_peer_CFLAGS = -I$(top_builddir)/gio/tests/gdbus-object-manager-example
gdbus_peer_LDADD = $(top_builddir)/gio/tests/gdbus-object-manager-example/libgdbus-example-objectmanager.la $(LDADD)
+gdbus_test_fixture_SOURCES = gdbus-test-fixture.c
+gdbus_test_fixture_CFLAGS = -I$(top_builddir)/gio/tests/gdbus-object-manager-example
+gdbus_test_fixture_LDADD = $(top_builddir)/gio/tests/gdbus-object-manager-example/libgdbus-example-objectmanager.la $(LDADD)
+
endif OS_UNIX
# -----------------------------------------------------------------------------
diff --git a/gio/tests/gdbus-test-fixture.c b/gio/tests/gdbus-test-fixture.c
new file mode 100644
index 0000000..30d7857
--- /dev/null
+++ b/gio/tests/gdbus-test-fixture.c
@@ -0,0 +1,121 @@
+/* gdbus-test-fixture.c - Test covering activation of in-tree servers.
+ *
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * This program 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 of the License, or (at your option) version 3.
+ *
+ * This program 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 the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Authors: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+#include <gio/gio.h>
+#include "gdbus-example-objectmanager-generated.h"
+
+typedef struct {
+ GTestDBus *dbus;
+ GDBusObjectManager *manager;
+} TestFixture;
+
+static void
+fixture_setup (TestFixture *fixture, gconstpointer unused)
+{
+ /* Create the global dbus-daemon for this test suite */
+ fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
+
+ /* Add the private directory with our in-tree service files */
+ g_test_dbus_add_service_dir (fixture->dbus, TEST_SERVICES);
+
+ /* Start the private D-Bus daemon */
+ g_test_dbus_up (fixture->dbus);
+}
+
+static void
+fixture_teardown (TestFixture *fixture, gconstpointer unused)
+{
+ if (fixture->manager)
+ g_object_unref (fixture->manager);
+
+ /* Stop the private D-Bus daemon */
+ g_test_dbus_down (fixture->dbus);
+
+ g_object_unref (fixture->dbus);
+}
+
+/* The gdbus-example-objectmanager-server exports 10 objects,
+ * to test the server has actually activated, let's ensure
+ * that 10 objects exist.
+ */
+static void
+assert_ten_objects (GDBusObjectManager *manager)
+{
+ GList *objects;
+
+ objects = g_dbus_object_manager_get_objects (manager);
+
+ g_assert_cmpint (g_list_length (objects), ==, 10);
+ g_list_free_full (objects, g_object_unref);
+}
+
+static gboolean
+quit_loop (gconstpointer data)
+{
+ GMainLoop *loop = (GMainLoop *)data;
+
+ g_main_loop_quit (loop);
+ return FALSE;
+}
+
+static void
+test_gtest_dbus (TestFixture *fixture, gconstpointer unused)
+{
+
+ GError *error = NULL;
+
+ fixture->manager =
+ example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
+ "org.gtk.GDBus.Examples.ObjectManager",
+ "/example/Animals",
+ NULL, /* GCancellable */
+ &error);
+ if (fixture->manager == NULL)
+ g_error ("Error getting object manager client: %s", error->message);
+
+ assert_ten_objects (fixture->manager);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+#if !GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+ g_test_init (&argc, &argv, NULL);
+
+ /* Ensure that we can bring the GTestDBus up and down a hand full of times
+ * in a row, each time successfully activating the in-tree service
+ */
+ g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL,
+ fixture_setup, test_gtest_dbus, fixture_teardown);
+ g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL,
+ fixture_setup, test_gtest_dbus, fixture_teardown);
+ g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL,
+ fixture_setup, test_gtest_dbus, fixture_teardown);
+ g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL,
+ fixture_setup, test_gtest_dbus, fixture_teardown);
+ g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL,
+ fixture_setup, test_gtest_dbus, fixture_teardown);
+
+ return g_test_run ();
+}
diff --git a/gio/tests/services/Makefile.am b/gio/tests/services/Makefile.am
new file mode 100644
index 0000000..7ab7864
--- /dev/null
+++ b/gio/tests/services/Makefile.am
@@ -0,0 +1,2 @@
+EXTRA_DIST = \
+ org.gtk.GDBus.Examples.ObjectManager.service.in
diff --git a/gio/tests/services/org.gtk.GDBus.Examples.ObjectManager.service.in b/gio/tests/services/org.gtk.GDBus.Examples.ObjectManager.service.in
new file mode 100644
index 0000000..5820b1a
--- /dev/null
+++ b/gio/tests/services/org.gtk.GDBus.Examples.ObjectManager.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gtk.GDBus.Examples.ObjectManager
+Exec= abs_top_builddir@/gio/tests/gdbus-example-objectmanager-server
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]