tests/integration: Test that "feedback-ended" is propagated through LfbEvent

When no feedbacks are available (either because the requested event does
not exist in the theme or because the system does not have required
capabilities, e.g. no vibration motor or LED) feedbackd will emit a
"feedback-ended" signal (with reason LFB_EVENT_STATE_REASON_NOT_FOUND)
on DBus _before_ completing the event triggering DBus call.

Since the DBus call was not completed yet, LfbEvent will not have
learned it's ID yet and therefore not emit it's own "feedback-ended"
GObject signal.

In this case the test will timeout since the main loop is never quit.
This commit is contained in:
Evangelos Ribeiro Tzaras
2022-11-09 11:54:44 +01:00
parent efca781f7f
commit 72c7d3ba25
+53
View File
@@ -122,6 +122,28 @@ test_lfb_integration_event_not_found (void)
g_assert_cmpint (lfb_event_get_end_reason (event0), ==, LFB_EVENT_END_REASON_NOT_FOUND);
}
static void
on_event_triggered (LfbEvent *event,
GAsyncResult *res,
LfbEvent **cmp)
{
g_autoptr (GError) err = NULL;
gboolean success;
g_assert_true (LFB_IS_EVENT (event));
g_assert_null (*cmp);
g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event));
success = lfb_event_trigger_feedback_finish (event, res, &err);
g_assert_no_error (err);
g_assert_true (success);
g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_RUNNING);
/* "Return" event */
*cmp = event;
}
static void
on_event_triggered_quit (LfbEvent *event,
GAsyncResult *res,
@@ -169,6 +191,32 @@ on_event_end_finished (LfbEvent *event,
g_main_loop_quit (mainloop);
}
static void
test_lfb_integration_event_not_found_async (void)
{
g_autoptr(LfbEvent) event0 = NULL;
LfbEvent *cmp = NULL;
LfbEvent *cmp2 = NULL;
event0 = lfb_event_new ("test-does-not-exist");
g_signal_connect (event0, "feedback-ended", (GCallback)on_feedback_ended, &cmp2);
/* The main loop will only quit if the "feedback-ended" signal actually gets emitted */
g_signal_connect_swapped (event0, "feedback-ended", (GCallback)g_main_loop_quit, mainloop);
lfb_event_trigger_feedback_async (event0,
NULL,
(GAsyncReadyCallback)on_event_triggered,
&cmp);
g_main_loop_run (mainloop);
/* If the signal fired cmp will match event */
g_assert_true (event0 == cmp);
g_assert_true (event0 == cmp2);
g_assert_cmpint (lfb_event_get_state (event0), ==, LFB_EVENT_STATE_ENDED);
g_assert_cmpint (lfb_event_get_end_reason (event0), ==, LFB_EVENT_END_REASON_NOT_FOUND);
}
static void
test_lfb_integration_event_async (void)
{
@@ -307,6 +355,11 @@ main (gint argc, gchar *argv[])
(gpointer)test_lfb_integration_event_not_found,
(gpointer)fixture_teardown);
g_test_add("/feedbackd/lfb-integration/event_not_found_async", TestFixture, NULL,
(gpointer)fixture_setup,
(gpointer)test_lfb_integration_event_not_found_async,
(gpointer)fixture_teardown);
g_test_add("/feedbackd/lfb-integration/profile", TestFixture, NULL,
(gpointer)fixture_setup,
(gpointer)test_lfb_integration_profile,