summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-09 12:24:21 (GMT)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-09-13 06:23:43 (GMT)
commit3347defd8858272ae03b83fac097d64fb77e3d22 (patch)
tree55c117554143974e2b91253ad57b90a3520bc9cb
parent1844ec60878278915676820a17ee8bfd5e9061f4 (diff)
downloadtraprain-3347defd8858272ae03b83fac097d64fb77e3d22.tar.gz
traprain-3347defd8858272ae03b83fac097d64fb77e3d22.tar.xz
mock-service: add ClearRoutes() API
I'm going to use it to make sure the installed tests are running from a clean state when using the real mock service. 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/D4287
-rw-r--r--dbus/org.apertis.Traprain1.Mock.xml9
-rw-r--r--debian/libtraprain-client-0-0.symbols2
-rw-r--r--mock-service/mock-service.c28
-rw-r--r--tests/test-mock-service.c62
-rw-r--r--traprain-client/mock.c78
-rw-r--r--traprain-client/mock.h8
6 files changed, 187 insertions, 0 deletions
diff --git a/dbus/org.apertis.Traprain1.Mock.xml b/dbus/org.apertis.Traprain1.Mock.xml
index f346c75..b9dc9ba 100644
--- a/dbus/org.apertis.Traprain1.Mock.xml
+++ b/dbus/org.apertis.Traprain1.Mock.xml
@@ -48,6 +48,15 @@
</method>
<!--
+ ClearRoutes:
+ @since: UNRELEASED
+
+ Remove all the routes exposed by the service and reset its current route to
+ -1 (no route).
+ -->
+ <method name="ClearRoutes" />
+
+ <!--
SetCurrentRoute:
@Index: the index of the route
@since: UNRELEASED
diff --git a/debian/libtraprain-client-0-0.symbols b/debian/libtraprain-client-0-0.symbols
index 3cbed71..367cd21 100644
--- a/debian/libtraprain-client-0-0.symbols
+++ b/debian/libtraprain-client-0-0.symbols
@@ -1,6 +1,8 @@
libtraprain-client-0.so.0 libtraprain-client-0-0 #MINVER#
trp_client_mock_add_route_async@Base 0.1.0
trp_client_mock_add_route_finish@Base 0.1.0
+ trp_client_mock_clear_routes_async@Base 0.1.0
+ trp_client_mock_clear_routes_finish@Base 0.1.0
trp_client_mock_create_route@Base 0.1.0
trp_client_mock_get_type@Base 0.1.0
trp_client_mock_new_async@Base 0.1.0
diff --git a/mock-service/mock-service.c b/mock-service/mock-service.c
index 9f97799..d59a090 100644
--- a/mock-service/mock-service.c
+++ b/mock-service/mock-service.c
@@ -233,6 +233,32 @@ on_handle_set_current_route (Trp1Mock *mock,
}
static void
+on_handle_clear_routes (Trp1Mock *mock,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ TrpMockService *self = user_data;
+ GError *error = NULL;
+ GPtrArray *routes;
+
+ routes = g_ptr_array_new_with_free_func (g_object_unref);
+
+ if (!trp_service_navigation_set_routes (self->service, routes, &error))
+ {
+ g_dbus_method_invocation_take_error (invocation, error);
+ return;
+ }
+
+ if (!trp_service_navigation_set_current_route (self->service, -1, &error))
+ {
+ g_dbus_method_invocation_take_error (invocation, error);
+ return;
+ }
+
+ trp_1_mock_complete_set_current_route (mock, invocation);
+}
+
+static void
trp_mock_service_init (TrpMockService *self)
{
self->cancellable = g_cancellable_new ();
@@ -245,6 +271,8 @@ trp_mock_service_init (TrpMockService *self)
G_CALLBACK (on_handle_remove_route), self);
g_signal_connect (self->mock, "handle-set-current-route",
G_CALLBACK (on_handle_set_current_route), self);
+ g_signal_connect (self->mock, "handle-clear-routes",
+ G_CALLBACK (on_handle_clear_routes), self);
}
TrpMockService *
diff --git a/tests/test-mock-service.c b/tests/test-mock-service.c
index d4662d5..37c52b8 100644
--- a/tests/test-mock-service.c
+++ b/tests/test-mock-service.c
@@ -131,6 +131,21 @@ mock_new_cb (GObject *source,
}
static void
+clear_routes_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ Test *test = user_data;
+
+ test->result = trp_client_mock_clear_routes_finish (TRP_CLIENT_MOCK (source),
+ result, &test->error);
+
+ test->wait_count--;
+ if (test->wait_count == 0)
+ g_main_loop_quit (test->loop);
+}
+
+static void
init_mock (Test *test)
{
trp_client_mock_new_async (test->conn, NULL, mock_new_cb, test);
@@ -364,6 +379,51 @@ test_current_route (Test *test,
g_assert (!test->result);
}
+/* test ClearRoutes() */
+static void
+test_clear_routes (Test *test,
+ gconstpointer unused)
+{
+ TrpClientRoute *route;
+ GPtrArray *routes;
+
+ init_client (test);
+ init_mock (test);
+
+ g_signal_connect (test->client, "notify::routes", G_CALLBACK (notify_cb), test);
+
+ /* Add 2 routes */
+ add_route (test, create_first_mock_route (test));
+ g_assert_cmpint (test->index, ==, 0);
+
+ add_route (test, create_second_mock_route (test));
+ g_assert_cmpint (test->index, ==, 1);
+
+ route = trp_client_navigation_get_current_route (test->client);
+ g_assert (route == NULL);
+
+ /* Set the second route as current */
+ g_signal_connect (test->client, "notify::current-route", G_CALLBACK (notify_cb), test);
+
+ set_current_route (test, 1);
+ route = trp_client_navigation_get_current_route (test->client);
+ check_second_client_route (route);
+
+ /* Clear all routes */
+
+ /* Wait for clear_routes_cb and notify_cb twice (routes and current-route) */
+ test->wait_count = 3;
+ trp_client_mock_clear_routes_async (test->mock, clear_routes_cb, test);
+ g_main_loop_run (test->loop);
+ g_assert_no_error (test->error);
+ g_assert (test->result);
+
+ routes = trp_client_navigation_get_routes (test->client);
+ g_assert_cmpuint (routes->len, ==, 0);
+ route = trp_client_navigation_get_current_route (test->client);
+ g_assert (route == NULL);
+}
+
int
main (int argc, char **argv)
{
@@ -379,6 +439,8 @@ main (int argc, char **argv)
setup, test_remove_route, teardown);
g_test_add ("/mock-service/set-current-route", Test, NULL,
setup, test_current_route, teardown);
+ g_test_add ("/mock-service/clear-routes", Test, NULL,
+ setup, test_clear_routes, teardown);
return g_test_run ();
}
diff --git a/traprain-client/mock.c b/traprain-client/mock.c
index 79c5258..4305277 100644
--- a/traprain-client/mock.c
+++ b/traprain-client/mock.c
@@ -647,3 +647,81 @@ trp_client_mock_set_current_route_finish (TrpClientMock *self,
return g_task_propagate_boolean (G_TASK (result), error);
}
+
+static void
+clear_routes_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr (GTask) task = user_data;
+ GError *error = NULL;
+
+ if (!trp_1_mock_call_clear_routes_finish ((Trp1Mock *) source, result, &error))
+ {
+ g_task_return_error (task, error);
+ return;
+ }
+
+ g_task_return_boolean (task, TRUE);
+}
+
+/**
+ * trp_client_mock_clear_routes_async:
+ * @self: a #TrpClientMock
+ * @callback: callback to call when the request is satisfied.
+ * @user_data: the data to pass to @callback function.
+ *
+ * Remove all the exposed routes and reset the current one.
+ *
+ * When the operation is finished, @callback will be called.
+ * You can then call trp_client_mock_clear_routes_finish() to get the result of
+ * the operation.
+ *
+ * Since: UNRELEASED
+ */
+void
+trp_client_mock_clear_routes_async (TrpClientMock *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr (GTask) task = NULL;
+ GError *error = NULL;
+
+ g_return_if_fail (TRP_CLIENT_IS_MOCK (self));
+
+ task = g_task_new (self, self->cancellable, callback, user_data);
+
+ if (!check_invalidated (self, &error))
+ {
+ g_task_return_error (task, error);
+ return;
+ }
+
+ g_assert (self->proxy != NULL);
+
+ trp_1_mock_call_clear_routes (self->proxy, self->cancellable,
+ clear_routes_cb, g_steal_pointer (&task));
+}
+
+/**
+ * trp_client_mock_clear_routes_finish:
+ * @self: a #TrpClientMock
+ * @result: a #GAsyncResult
+ * @error: a #GError, or %NULL
+ *
+ * Finishes an operation started with trp_client_mock_clear_routes_async().
+ *
+ * Returns: %TRUE if the operation succeeded, %FALSE on error
+ * Since: UNRELEASED
+ */
+gboolean
+trp_client_mock_clear_routes_finish (TrpClientMock *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
+ g_assert_no_error (*error);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
diff --git a/traprain-client/mock.h b/traprain-client/mock.h
index 6bd8fb5..3319610 100644
--- a/traprain-client/mock.h
+++ b/traprain-client/mock.h
@@ -60,6 +60,14 @@ gboolean trp_client_mock_set_current_route_finish (TrpClientMock *self,
GAsyncResult *result,
GError **error);
+void trp_client_mock_clear_routes_async (TrpClientMock *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean trp_client_mock_clear_routes_finish (TrpClientMock *self,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#endif /* __TRAPRAIN_CLIENT_MOCK_H__ */