summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-08 14:34:08 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-09 13:34:48 (GMT)
commit9acfcb4751764deddcb30f3c757b5993dd2db216 (patch)
treea34611ef4223468b2cdd089609e501cc78b07bb6
parent66cb9014d811cea1ef049439b5ea0ccaec18c4f8 (diff)
downloadtraprain-9acfcb4751764deddcb30f3c757b5993dd2db216.tar.gz
traprain-9acfcb4751764deddcb30f3c757b5993dd2db216.tar.xz
client: pass a GDBusConnection when creating client
This will allow us to use the session bus when running tests even if the service is actually supposed to use the system one. 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/D4273
-rw-r--r--tests/test-client-navigation.c17
-rw-r--r--tests/test-mock-service.c17
-rw-r--r--traprain-client/navigation.c59
-rw-r--r--traprain-client/navigation.h2
4 files changed, 84 insertions, 11 deletions
diff --git a/tests/test-client-navigation.c b/tests/test-client-navigation.c
index e383759..852be2a 100644
--- a/tests/test-client-navigation.c
+++ b/tests/test-client-navigation.c
@@ -18,6 +18,7 @@
typedef struct
{
GTestDBus *dbus;
+ GDBusConnection *conn; /* owned */
GMainLoop *loop;
GError *error;
@@ -30,17 +31,28 @@ typedef struct
static void
setup (Test *test, gconstpointer unused)
{
+ const gchar *addr;
+
+ test->error = NULL;
+
test->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
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);
+ g_assert_no_error (test->error);
test->service = trp_service_navigation_new ();
g_assert (TRP_SERVICE_IS_NAVIGATION (test->service));
- test->client = trp_client_navigation_new ();
+ test->client = trp_client_navigation_new (test->conn);
g_assert (TRP_CLIENT_IS_NAVIGATION (test->client));
test->loop = g_main_loop_new (NULL, FALSE);
- test->error = NULL;
}
static void
@@ -52,6 +64,7 @@ teardown (Test *test, gconstpointer unused)
g_clear_object (&test->service);
g_clear_object (&test->client);
+ g_clear_object (&test->conn);
g_test_dbus_down (test->dbus);
g_clear_object (&test->dbus);
}
diff --git a/tests/test-mock-service.c b/tests/test-mock-service.c
index 574376f..6928bb2 100644
--- a/tests/test-mock-service.c
+++ b/tests/test-mock-service.c
@@ -21,6 +21,7 @@
typedef struct
{
GTestDBus *dbus;
+ GDBusConnection *conn; /* owned */
guint wait_count;
GMainLoop *loop;
GError *error;
@@ -35,14 +36,25 @@ typedef struct
static void
setup (Test *test, gconstpointer unused)
{
+ const gchar *addr;
+
+ 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->client = trp_client_navigation_new ();
+ 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);
+ g_assert_no_error (test->error);
+
+ test->client = trp_client_navigation_new (test->conn);
test->loop = g_main_loop_new (NULL, FALSE);
- test->error = NULL;
}
static void
@@ -54,6 +66,7 @@ teardown (Test *test, gconstpointer unused)
g_clear_object (&test->client);
g_clear_object (&test->mock);
+ g_clear_object (&test->conn);
g_test_dbus_down (test->dbus);
g_clear_object (&test->dbus);
}
diff --git a/traprain-client/navigation.c b/traprain-client/navigation.c
index 873407a..fe95325 100644
--- a/traprain-client/navigation.c
+++ b/traprain-client/navigation.c
@@ -40,6 +40,8 @@ struct _TrpClientNavigation
{
GObject parent;
+ GDBusConnection *conn; /* owned */
+
TrpOrgApertisNavigation1Routes *routes_proxy; /* owned */
GList /*<owned GTask>*/ *init_tasks; /* owned */
GCancellable *cancellable; /* owned */
@@ -54,7 +56,8 @@ struct _TrpClientNavigation
};
typedef enum {
- PROP_ROUTES = 1,
+ PROP_CONNECTION = 1,
+ PROP_ROUTES,
PROP_CURRENT_ROUTE,
/*< private >*/
PROP_LAST = PROP_CURRENT_ROUTE
@@ -86,6 +89,9 @@ trp_client_navigation_get_property (GObject *object,
switch ((TrpClientNavigationProperty) prop_id)
{
+ case PROP_CONNECTION:
+ g_value_set_object (value, self->conn);
+ break;
case PROP_ROUTES:
g_value_set_boxed (value, trp_client_navigation_get_routes (self));
break;
@@ -99,6 +105,29 @@ trp_client_navigation_get_property (GObject *object,
}
static void
+trp_client_navigation_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrpClientNavigation *self = TRP_CLIENT_NAVIGATION (object);
+
+ switch ((TrpClientNavigationProperty) prop_id)
+ {
+ case PROP_CONNECTION:
+ g_assert (self->conn == NULL); /* construct only */
+ self->conn = g_value_dup_object (value);
+ break;
+ case PROP_ROUTES:
+ case PROP_CURRENT_ROUTE:
+ /* read only */
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
trp_client_navigation_dispose (GObject *object)
{
TrpClientNavigation *self = (TrpClientNavigation *) object;
@@ -118,6 +147,7 @@ trp_client_navigation_dispose (GObject *object)
g_clear_pointer (&self->routes, g_ptr_array_unref);
g_clear_pointer (&self->routes_by_path, g_hash_table_unref);
g_clear_object (&self->current_route);
+ g_clear_object (&self->conn);
G_OBJECT_CLASS (trp_client_navigation_parent_class)
->dispose (object);
@@ -129,9 +159,21 @@ trp_client_navigation_class_init (TrpClientNavigationClass *klass)
GObjectClass *object_class = (GObjectClass *) klass;
object_class->get_property = trp_client_navigation_get_property;
+ object_class->set_property = trp_client_navigation_set_property;
object_class->dispose = trp_client_navigation_dispose;
/**
+ * TrpClientNavigation:connection:
+ *
+ * The #GDBusConnection used by the client.
+ *
+ * Since: UNRELEASED
+ */
+ properties[PROP_CONNECTION] = g_param_spec_object (
+ "connection", "Connection", "GDBusConnection", G_TYPE_DBUS_CONNECTION,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ /**
* TrpClientNavigation:routes:
*
* #GPtrArray containing the #TrpClientRoute currently exposed by the navigation service.
@@ -191,6 +233,7 @@ trp_client_navigation_init (TrpClientNavigation *self)
/**
* trp_client_navigation_new:
+ * @connection: the #GDBusConnection to use to communicate with the navigation service
*
* Create a new #TrpClientNavigation.
*
@@ -198,9 +241,11 @@ trp_client_navigation_init (TrpClientNavigation *self)
* Since: UNRELEASED
*/
TrpClientNavigation *
-trp_client_navigation_new (void)
+trp_client_navigation_new (GDBusConnection *connection)
{
- return g_object_new (TRP_CLIENT_TYPE_NAVIGATION, NULL);
+ g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
+
+ return g_object_new (TRP_CLIENT_TYPE_NAVIGATION, "connection", connection, NULL);
}
static gboolean
@@ -461,6 +506,8 @@ trp_client_navigation_init_async (GAsyncInitable *initable,
TrpClientNavigation *self = TRP_CLIENT_NAVIGATION (initable);
g_autoptr (GTask) task = NULL;
+ g_return_if_fail (self->conn != NULL);
+
task = g_task_new (initable, cancellable, callback, user_data);
if (self->routes_proxy != NULL)
@@ -471,9 +518,9 @@ trp_client_navigation_init_async (GAsyncInitable *initable,
self->init_tasks = g_list_append (self->init_tasks, g_steal_pointer (&task));
- trp_org_apertis_navigation1_routes_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE,
- NAVIGATION_BUS_NAME, NAVIGATION_ROUTES_PATH,
- self->cancellable, proxy_cb, self);
+ trp_org_apertis_navigation1_routes_proxy_new (self->conn, G_DBUS_PROXY_FLAGS_NONE,
+ NAVIGATION_BUS_NAME, NAVIGATION_ROUTES_PATH,
+ self->cancellable, proxy_cb, self);
}
static gboolean
diff --git a/traprain-client/navigation.h b/traprain-client/navigation.h
index 0b40796..1e2f5f9 100644
--- a/traprain-client/navigation.h
+++ b/traprain-client/navigation.h
@@ -21,7 +21,7 @@ G_BEGIN_DECLS
#define TRP_CLIENT_TYPE_NAVIGATION (trp_client_navigation_get_type ())
G_DECLARE_FINAL_TYPE (TrpClientNavigation, trp_client_navigation, TRP_CLIENT, NAVIGATION, GObject)
-TrpClientNavigation *trp_client_navigation_new (void);
+TrpClientNavigation *trp_client_navigation_new (GDBusConnection *connection);
GPtrArray *trp_client_navigation_get_routes (TrpClientNavigation *self);