fp-device: Gracefully handle capture calls on devices with no support
This commit is contained in:
parent
3717468a8a
commit
bd99f865d8
3 changed files with 40 additions and 1 deletions
|
@ -1191,6 +1191,7 @@ fp_device_capture (FpDevice *device,
|
|||
{
|
||||
g_autoptr(GTask) task = NULL;
|
||||
FpDevicePrivate *priv = fp_device_get_instance_private (device);
|
||||
FpDeviceClass *cls = FP_DEVICE_GET_CLASS (device);
|
||||
|
||||
task = g_task_new (device, cancellable, callback, user_data);
|
||||
if (g_task_return_error_if_cancelled (task))
|
||||
|
@ -1210,13 +1211,21 @@ fp_device_capture (FpDevice *device,
|
|||
return;
|
||||
}
|
||||
|
||||
if (!cls->capture || !(cls->features & FPI_DEVICE_FEATURE_CAPTURE))
|
||||
{
|
||||
g_task_return_error (task,
|
||||
fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED,
|
||||
"Device has no verification support"));
|
||||
return;
|
||||
}
|
||||
|
||||
priv->current_action = FPI_DEVICE_ACTION_CAPTURE;
|
||||
priv->current_task = g_steal_pointer (&task);
|
||||
maybe_cancel_on_cancelled (device, cancellable);
|
||||
|
||||
priv->wait_for_finger = wait_for_finger;
|
||||
|
||||
FP_DEVICE_GET_CLASS (device)->capture (device);
|
||||
cls->capture (device);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1880,6 +1880,29 @@ test_driver_capture (void)
|
|||
g_assert (image == fake_dev->ret_image);
|
||||
}
|
||||
|
||||
static void
|
||||
test_driver_capture_not_supported (void)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(FpImage) image = NULL;
|
||||
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
|
||||
g_autoptr(FpAutoCloseDevice) device = NULL;
|
||||
gboolean wait_for_finger = TRUE;
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
dev_class->features &= ~FPI_DEVICE_FEATURE_CAPTURE;
|
||||
|
||||
device = auto_close_fake_device_new ();
|
||||
fake_dev = FPI_DEVICE_FAKE (device);
|
||||
fake_dev->last_called_function = NULL;
|
||||
|
||||
image = fp_device_capture_sync (device, wait_for_finger, NULL, &error);
|
||||
g_assert_null (fake_dev->last_called_function);
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_NOT_SUPPORTED);
|
||||
|
||||
g_assert_null (image);
|
||||
}
|
||||
|
||||
static void
|
||||
test_driver_capture_error (void)
|
||||
{
|
||||
|
@ -2674,6 +2697,7 @@ main (int argc, char *argv[])
|
|||
g_test_add_func ("/driver/identify/complete_retry", test_driver_identify_complete_retry);
|
||||
g_test_add_func ("/driver/identify/report_no_cb", test_driver_identify_report_no_callback);
|
||||
g_test_add_func ("/driver/capture", test_driver_capture);
|
||||
g_test_add_func ("/driver/capture/not_supported", test_driver_capture_not_supported);
|
||||
g_test_add_func ("/driver/capture/error", test_driver_capture_error);
|
||||
g_test_add_func ("/driver/list", test_driver_list);
|
||||
g_test_add_func ("/driver/list/error", test_driver_list_error);
|
||||
|
|
|
@ -858,6 +858,12 @@ class VirtualDevice(VirtualDeviceBase):
|
|||
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
|
||||
FPrint.DeviceError.NOT_SUPPORTED))
|
||||
|
||||
def test_capture_unsupported(self):
|
||||
with self.assertRaises(GLib.Error) as error:
|
||||
self.dev.capture_sync(wait_for_finger=False)
|
||||
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
|
||||
FPrint.DeviceError.NOT_SUPPORTED))
|
||||
|
||||
|
||||
class VirtualDeviceClosed(VirtualDeviceBase):
|
||||
|
||||
|
|
Loading…
Reference in a new issue