summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-08 15:29:46 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-09 13:34:50 (GMT)
commit6e0fc57af9df1a01b717624c1adcd1ac2acdbc05 (patch)
tree416ff4319dbbbf4f451ea0c5c52f97f4d0f8d141
parent17b9735455e0d4c6cf97c0d75f65b169d38f09e2 (diff)
downloadtraprain-6e0fc57af9df1a01b717624c1adcd1ac2acdbc05.tar.gz
traprain-6e0fc57af9df1a01b717624c1adcd1ac2acdbc05.tar.xz
mock-service: run on the system bus
We are moving Traprain to the system bus as it's closer to a system service than a user one. Adding a command line option to the mock service to keep running on the session bus for easy testing. The service is tested in real condition (on the system bus) when running the installed test. Signed-off-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk> Differential Revision: https://phabricator.apertis.org/D4276
-rw-r--r--Makefile.am4
-rw-r--r--mock-service/main.c22
-rw-r--r--mock-service/mock-service.c6
-rw-r--r--mock-service/mock-service.h1
-rw-r--r--tests/services/org.apertis.Navigation1.service.in2
-rw-r--r--tests/services/org.apertis.Traprain1.Mock.service.in2
-rw-r--r--tests/test-mock-service.c36
7 files changed, 57 insertions, 16 deletions
diff --git a/Makefile.am b/Makefile.am
index e8404eb..1cd6c05 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -467,6 +467,10 @@ CLEANFILES += \
installed_testdir = $(libexecdir)/installed-tests/traprain-@TRP_API_VERSION@
installed_test_metadir = $(datadir)/installed-tests/traprain-@TRP_API_VERSION@
+AM_TESTS_ENVIRONMENT = \
+ export TRAPRAIN_TESTS_UNINSTALLED=1; \
+ $(NULL)
+
noinst_LTLIBRARIES += tests/libtraprain-test-helper.la
tests_libtraprain_test_helper_la_SOURCES = \
diff --git a/mock-service/main.c b/mock-service/main.c
index 4b9b74f..342c9ca 100644
--- a/mock-service/main.c
+++ b/mock-service/main.c
@@ -18,10 +18,30 @@ main (int argc,
{
g_autoptr (TrpMockService) service = NULL;
g_autoptr (GError) error = NULL;
+ GOptionContext *context;
+
+ /* command line parameters */
+ gboolean use_session_bus = FALSE;
+ const GOptionEntry entries[] =
+ {
+ { "use-session-bus", 's', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &use_session_bus,
+ "Use the session bus instead of the system one. Only used for testing", NULL },
+ {
+ NULL,
+ },
+ };
+
+ context = g_option_context_new ("- Traprain Mock Service");
+ g_option_context_add_main_entries (context, entries, NULL);
+ if (!g_option_context_parse (context, &argc, &argv, &error))
+ {
+ g_print ("Option parsing failed: %s\n", error->message);
+ return -1;
+ }
service = trp_mock_service_new ();
- trp_mock_service_run (service, &error);
+ trp_mock_service_run (service, use_session_bus, &error);
if (error != NULL)
{
diff --git a/mock-service/mock-service.c b/mock-service/mock-service.c
index 62c7442..9f97799 100644
--- a/mock-service/mock-service.c
+++ b/mock-service/mock-service.c
@@ -315,6 +315,7 @@ bus_get_cb (GObject *source,
void
trp_mock_service_run (TrpMockService *self,
+ gboolean use_session_bus,
GError **error)
{
/* Ensure we are not running as root — we don’t need those privileges. */
@@ -326,7 +327,10 @@ trp_mock_service_run (TrpMockService *self,
return;
}
- g_bus_get (G_BUS_TYPE_SESSION, self->cancellable, bus_get_cb, self);
+ g_debug ("Use %s bus", use_session_bus ? "session" : "system");
+
+ g_bus_get (use_session_bus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,
+ self->cancellable, bus_get_cb, self);
while (self->run_error == NULL && !self->run_exited)
g_main_context_iteration (NULL, TRUE);
diff --git a/mock-service/mock-service.h b/mock-service/mock-service.h
index 61188dc..3bcce51 100644
--- a/mock-service/mock-service.h
+++ b/mock-service/mock-service.h
@@ -21,6 +21,7 @@ G_DECLARE_FINAL_TYPE (TrpMockService, trp_mock_service, TRP_MOCK, SERVICE, GObje
TrpMockService *trp_mock_service_new (void);
void trp_mock_service_run (TrpMockService *self,
+ gboolean use_session_bus,
GError **error);
G_END_DECLS
diff --git a/tests/services/org.apertis.Navigation1.service.in b/tests/services/org.apertis.Navigation1.service.in
index d96035b..03a4fa1 100644
--- a/tests/services/org.apertis.Navigation1.service.in
+++ b/tests/services/org.apertis.Navigation1.service.in
@@ -1,3 +1,3 @@
[D-BUS Service]
Name=org.apertis.Navigation1
-Exec=@abs_top_builddir@/mock-service/traprain-mock-service
+Exec=@abs_top_builddir@/mock-service/traprain-mock-service --use-session-bus
diff --git a/tests/services/org.apertis.Traprain1.Mock.service.in b/tests/services/org.apertis.Traprain1.Mock.service.in
index 97c02cd..ed8fb80 100644
--- a/tests/services/org.apertis.Traprain1.Mock.service.in
+++ b/tests/services/org.apertis.Traprain1.Mock.service.in
@@ -1,3 +1,3 @@
[D-BUS Service]
Name=org.apertis.Traprain1.Mock
-Exec=@abs_top_builddir@/mock-service/traprain-mock-service
+Exec=@abs_top_builddir@/mock-service/traprain-mock-service --use-session-bus
diff --git a/tests/test-mock-service.c b/tests/test-mock-service.c
index 7fcf34e..afc181f 100644
--- a/tests/test-mock-service.c
+++ b/tests/test-mock-service.c
@@ -40,16 +40,25 @@ setup (Test *test, gconstpointer unused)
test->error = NULL;
- test->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
- g_test_dbus_add_service_dir (test->dbus, TEST_SERVICES_DIR);
- g_test_dbus_up (test->dbus);
- addr = g_test_dbus_get_bus_address (test->dbus);
- g_assert (addr != NULL);
-
- test->conn = g_dbus_connection_new_for_address_sync (addr,
- G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
- G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
- NULL, NULL, &test->error);
+ if (g_getenv ("TRAPRAIN_TESTS_UNINSTALLED") != NULL)
+ {
+ /* Test is not installed, running the mock service on the session bus for easy testing */
+ test->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
+ g_test_dbus_add_service_dir (test->dbus, TEST_SERVICES_DIR);
+ g_test_dbus_up (test->dbus);
+ addr = g_test_dbus_get_bus_address (test->dbus);
+ g_assert (addr != NULL);
+
+ test->conn = g_dbus_connection_new_for_address_sync (addr,
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+ G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+ NULL, NULL, &test->error);
+ }
+ else
+ {
+ test->conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &test->error);
+ }
+
g_assert_no_error (test->error);
test->client = trp_client_navigation_new (test->conn);
@@ -67,8 +76,11 @@ teardown (Test *test, gconstpointer unused)
g_clear_object (&test->mock);
g_clear_object (&test->conn);
- g_test_dbus_down (test->dbus);
- g_clear_object (&test->dbus);
+ if (test->dbus != NULL)
+ {
+ g_test_dbus_down (test->dbus);
+ g_clear_object (&test->dbus);
+ }
}
static void