mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2026-06-11 02:28:05 +00:00
fpi-device: Ensure FpDeviceClass is still compatible with TODv1 ABI
Tests are ensuring it, adapt internal tests to ignore new features when using old drivers
This commit is contained in:
@@ -161,10 +161,6 @@ struct _FpDeviceClass
|
||||
gint nr_enroll_stages;
|
||||
FpScanType scan_type;
|
||||
|
||||
/* Simple device temperature model constants */
|
||||
gint32 temp_hot_seconds;
|
||||
gint32 temp_cold_seconds;
|
||||
|
||||
/* Callbacks */
|
||||
gint (*usb_discover) (GUsbDevice *usb_device);
|
||||
void (*probe) (FpDevice *device);
|
||||
@@ -176,18 +172,23 @@ struct _FpDeviceClass
|
||||
void (*capture) (FpDevice *device);
|
||||
void (*list) (FpDevice *device);
|
||||
void (*delete) (FpDevice * device);
|
||||
void (*clear_storage) (FpDevice * device);
|
||||
|
||||
void (*cancel) (FpDevice *device);
|
||||
void (*suspend) (FpDevice *device);
|
||||
void (*resume) (FpDevice *device);
|
||||
|
||||
/* Class elements added after tod-v1 */
|
||||
FpDeviceFeature features;
|
||||
|
||||
/* Simple device temperature model constants */
|
||||
gint32 temp_hot_seconds;
|
||||
gint32 temp_cold_seconds;
|
||||
|
||||
void (*clear_storage) (FpDevice * device);
|
||||
void (*suspend) (FpDevice *device);
|
||||
void (*resume) (FpDevice *device);
|
||||
|
||||
/*< private >*/
|
||||
/* padding for future expansion */
|
||||
gpointer _padding_dummy[31];
|
||||
gpointer _padding_dummy[27];
|
||||
};
|
||||
|
||||
void fpi_device_class_auto_initialize_features (FpDeviceClass *device_class);
|
||||
|
||||
@@ -32,8 +32,6 @@ struct _FpiDeviceFake
|
||||
gpointer last_called_function;
|
||||
gboolean return_action_error;
|
||||
|
||||
GCancellable *ext_cancellable;
|
||||
|
||||
GError *ret_error;
|
||||
FpPrint *ret_print;
|
||||
FpPrint *ret_match;
|
||||
@@ -41,12 +39,14 @@ struct _FpiDeviceFake
|
||||
FpImage *ret_image;
|
||||
GPtrArray *ret_list;
|
||||
|
||||
GError *ret_suspend;
|
||||
GError *ret_resume;
|
||||
|
||||
gpointer action_data;
|
||||
gpointer user_data;
|
||||
|
||||
GCancellable *ext_cancellable;
|
||||
|
||||
GError *ret_suspend;
|
||||
GError *ret_resume;
|
||||
|
||||
FpDeviceFeature probe_features_update;
|
||||
FpDeviceFeature probe_features_value;
|
||||
};
|
||||
|
||||
+147
-23
@@ -48,6 +48,24 @@ fpt_context_device_driver_get_type (void)
|
||||
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
tod_is_v1_class (FpDeviceClass *device_class)
|
||||
{
|
||||
#ifdef TEST_TOD_DRIVER
|
||||
return g_str_has_suffix (device_class->id, "_tod_v1");
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
tod_is_v1_device (FpDevice *device)
|
||||
{
|
||||
#ifdef TEST_TOD_DRIVER
|
||||
return tod_is_v1_class (FP_DEVICE_GET_CLASS (device));
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Utility functions */
|
||||
|
||||
typedef FpDevice FpAutoCloseDevice;
|
||||
@@ -539,6 +557,12 @@ test_driver_features_probe_updates (void)
|
||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
g_assert_cmpuint (dev_class->features, !=, FP_DEVICE_FEATURE_NONE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_CAPTURE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_IDENTIFY);
|
||||
@@ -592,7 +616,10 @@ test_driver_initial_features (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
if (!tod_is_v1_device (device))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
|
||||
g_async_initable_init_async (G_ASYNC_INITABLE (device),
|
||||
G_PRIORITY_DEFAULT, NULL, NULL, NULL);
|
||||
@@ -606,7 +633,10 @@ test_driver_initial_features (void)
|
||||
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE));
|
||||
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE_LIST));
|
||||
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE_DELETE));
|
||||
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE_CLEAR));
|
||||
if (!tod_is_v1_device (device))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
|
||||
g_assert_cmpuint (fp_device_get_features (device),
|
||||
==,
|
||||
@@ -616,7 +646,8 @@ test_driver_initial_features (void)
|
||||
FP_DEVICE_FEATURE_STORAGE |
|
||||
FP_DEVICE_FEATURE_STORAGE_LIST |
|
||||
FP_DEVICE_FEATURE_STORAGE_DELETE |
|
||||
FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
(tod_is_v1_device (device) ?
|
||||
0 : FP_DEVICE_FEATURE_STORAGE_CLEAR));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -663,7 +694,10 @@ test_driver_initial_features_no_capture (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -684,7 +718,10 @@ test_driver_initial_features_no_verify (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -705,7 +742,10 @@ test_driver_initial_features_no_identify (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -726,7 +766,10 @@ test_driver_initial_features_no_storage (void)
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -744,10 +787,16 @@ test_driver_initial_features_no_list (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_IDENTIFY);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_VERIFY);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_DUPLICATES_CHECK);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -768,7 +817,10 @@ test_driver_initial_features_no_delete (void)
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2005,6 +2057,12 @@ test_driver_identify_suspend_continues (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
FpPrint *expected_matched;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
|
||||
fake_dev = FPI_DEVICE_FAKE (device);
|
||||
orig_identify = dev_class->identify;
|
||||
@@ -2071,6 +2129,12 @@ test_driver_identify_suspend_succeeds (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
FpPrint *expected_matched;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
|
||||
fake_dev = FPI_DEVICE_FAKE (device);
|
||||
orig_identify = dev_class->identify;
|
||||
@@ -2133,6 +2197,12 @@ test_driver_identify_suspend_busy_error (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
FpPrint *expected_matched;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
|
||||
fake_dev = FPI_DEVICE_FAKE (device);
|
||||
orig_identify = dev_class->identify;
|
||||
@@ -2190,6 +2260,12 @@ test_driver_identify_suspend_while_idle (void)
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
|
||||
fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
@@ -2234,6 +2310,12 @@ test_driver_identify_warmup_cooldown (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
gint64 start_time;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
dev_class->temp_hot_seconds = 2;
|
||||
dev_class->temp_cold_seconds = 5;
|
||||
|
||||
@@ -2532,6 +2614,12 @@ test_driver_clear_storage (void)
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
gboolean ret;
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = fp_device_clear_storage_sync (device, NULL, &error);
|
||||
g_assert (fake_dev->last_called_function == dev_class->clear_storage);
|
||||
g_assert_no_error (error);
|
||||
@@ -2547,6 +2635,12 @@ test_driver_clear_storage_error (void)
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
gboolean ret;
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
|
||||
ret = fp_device_clear_storage_sync (device, NULL, &error);
|
||||
g_assert (fake_dev->last_called_function == dev_class->clear_storage);
|
||||
@@ -2653,6 +2747,12 @@ test_driver_critical (void)
|
||||
void (*orig_verify) (FpDevice *device) = dev_class->verify;
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
fake_dev->last_called_function = NULL;
|
||||
|
||||
dev_class->verify = fake_device_stub_verify;
|
||||
@@ -2861,6 +2961,12 @@ test_driver_action_is_cancelled_open (void)
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
dev_class->open = test_driver_action_is_cancelled_open_vfunc;
|
||||
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
|
||||
fake_dev = FPI_DEVICE_FAKE (device);
|
||||
@@ -2881,6 +2987,12 @@ test_driver_action_internally_cancelled_open (void)
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
return;
|
||||
}
|
||||
|
||||
dev_class->open = test_driver_action_is_cancelled_open_vfunc;
|
||||
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
|
||||
fake_dev = FPI_DEVICE_FAKE (device);
|
||||
@@ -3030,11 +3142,20 @@ test_driver_action_error_all (void)
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
|
||||
g_clear_error (&error);
|
||||
|
||||
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID);
|
||||
g_assert_false (fp_device_clear_storage_sync (device, NULL, &error));
|
||||
g_assert_true (fake_dev->last_called_function == dev_class->clear_storage);
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
|
||||
g_clear_error (&error);
|
||||
if (!tod_is_v1_device (device))
|
||||
{
|
||||
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID);
|
||||
g_assert_false (fp_device_clear_storage_sync (device, NULL, &error));
|
||||
g_assert_true (fake_dev->last_called_function == dev_class->clear_storage);
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_false (fp_device_clear_storage_sync (device, NULL, &error));
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_NOT_SUPPORTED);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
/* Test close last, as we can't operate on a closed device. */
|
||||
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID);
|
||||
@@ -3135,15 +3256,18 @@ test_driver_action_error_fallback_all (void)
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
||||
g_clear_error (&error);
|
||||
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||
"*Device failed to pass an error to generic action "
|
||||
"error function*");
|
||||
if (!tod_is_v1_device (device))
|
||||
{
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||
"*Device failed to pass an error to generic action "
|
||||
"error function*");
|
||||
|
||||
g_assert_false (fp_device_clear_storage_sync (device, NULL, &error));
|
||||
g_test_assert_expected_messages ();
|
||||
g_assert_true (fake_dev->last_called_function == dev_class->clear_storage);
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
||||
g_clear_error (&error);
|
||||
g_assert_false (fp_device_clear_storage_sync (device, NULL, &error));
|
||||
g_test_assert_expected_messages ();
|
||||
g_assert_true (fake_dev->last_called_function == dev_class->clear_storage);
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
/* Test close last, as we can't operate on a closed device. */
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||
|
||||
Reference in New Issue
Block a user