test-fp-context: Add more cases for closing device during removal

This commit is contained in:
Marco Trevisan (Treviño) 2023-06-23 02:08:47 +02:00 committed by Marco Trevisan
parent d66e9470d8
commit 18661aae0e

View file

@ -286,6 +286,53 @@ test_context_remove_device_opening (void)
fpt_teardown_virtual_device_environment ();
}
static void
open_close_cb (GObject *device, GAsyncResult *res, gpointer user_data)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpPrint) print = NULL;
gboolean *data = user_data;
g_assert_true (fp_device_open_finish (FP_DEVICE (device), res, &error));
g_assert_null (print);
g_assert_null (error);
g_assert_false (fp_device_close_sync (FP_DEVICE (device), NULL, &error));
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
*data = TRUE;
}
static void
test_context_remove_device_closes_on_open_callback (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE);
gboolean open_done = FALSE;
gboolean removed;
tctx->user_data = NULL;
g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx);
g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx);
fp_device_open (tctx->device, NULL, open_close_cb, &open_done);
g_assert_false (open_done);
fpi_device_remove (tctx->device);
/* Removed but not yet notified*/
g_assert_nonnull (tctx->device);
g_object_get (tctx->device, "removed", &removed, NULL);
g_assert_true (removed);
g_assert_null (tctx->user_data);
/* Running the mainloop now will cause the open to *succeed* despite removal! */
while (!open_done)
g_main_context_iteration (NULL, TRUE);
g_assert_null (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
}
static void
enroll_done_cb (GObject *device, GAsyncResult *res, gpointer user_data)
{
@ -345,8 +392,40 @@ test_context_remove_device_active (void)
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
g_assert_null (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
}
fpt_teardown_virtual_device_environment ();
static void
device_removed_close_cb (FpDevice *device, FptContext *tctx)
{
g_autoptr(GError) error = NULL;
g_assert_nonnull (device);
g_assert_true (device == tctx->device);
g_assert_null (tctx->user_data);
tctx->user_data = GINT_TO_POINTER (DEV_REMOVED_CB);
g_assert_true (fp_device_is_open (tctx->device));
fp_device_close_sync (tctx->device, NULL, &error);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
g_assert_false (fp_device_is_open (tctx->device));
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
}
static void
test_context_remove_device_close_on_removal (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE);
g_autoptr(GError) error = NULL;
fp_device_open_sync (tctx->device, NULL, &error);
g_assert_no_error (error);
g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx);
g_signal_connect (tctx->device, "removed", (GCallback) device_removed_close_cb, tctx);
fpi_device_remove (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
}
int
@ -363,6 +442,8 @@ main (int argc, char *argv[])
g_test_add_func ("/context/remove-device-open", test_context_remove_device_open);
g_test_add_func ("/context/remove-device-opening", test_context_remove_device_opening);
g_test_add_func ("/context/remove-device-active", test_context_remove_device_active);
g_test_add_func ("/context/remove-device-close-on-removal", test_context_remove_device_close_on_removal);
g_test_add_func ("/context/remove-device-closes-on-open-callback", test_context_remove_device_closes_on_open_callback);
return g_test_run ();
}