tests/fpi-device: Add test identifying with an empty gallery

We're still going into the device in this case because technically the
identify operation may still return a print, although never a match of
course.

Adding tests so that we are not tempted to modify the behavior of the
identify function to return an error on prints->len == 0 or to just not
call the driver on such case.
This commit is contained in:
Marco Trevisan (Treviño)
2026-07-12 13:17:35 +02:00
parent 7e579f0f36
commit 91dd69475f
+70 -1
View File
@@ -1376,7 +1376,7 @@ test_driver_match_cb (FpDevice *device,
if (match)
g_assert_no_error (error);
/* Compar gallery if this is an identify operation */
/* Compare gallery if this is an identify operation */
if (data->gallery)
{
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
@@ -2251,6 +2251,72 @@ test_driver_identify (void)
g_assert (expected_matched == matched_print);
}
static void
test_driver_identify_empty_gallery (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 0);
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
match_data->gallery = prints;
g_assert_true (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error));
g_assert_true (match_data->called);
g_assert_null (match_data->match);
g_assert_true (match_data->match == matched_print);
g_assert_true (match_data->print == print);
g_assert_true (fake_dev->last_called_function == dev_class->identify);
g_assert_no_error (error);
g_assert_null (print);
g_assert_null (matched_print);
}
static void
test_driver_identify_empty_gallery_with_scanned_print (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 0);
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
match_data->gallery = prints;
fake_dev->ret_print = make_fake_print (device, NULL);
match_data->print = fake_dev->ret_print;
g_assert_true (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error));
g_assert_true (match_data->called);
g_assert_null (match_data->match);
g_assert_true (match_data->match == matched_print);
g_assert_true (match_data->print == print);
g_assert_true (fake_dev->last_called_function == dev_class->identify);
g_assert_no_error (error);
g_assert_true (print == fake_dev->ret_print);
g_assert_null (matched_print);
}
static void
test_driver_identify_fail (void)
{
@@ -4245,6 +4311,9 @@ main (int argc, char *argv[])
g_test_add_func ("/driver/identify/report_no_cb", test_driver_identify_report_no_callback);
g_test_add_func ("/driver/identify/mismatched_scanned_print",
test_driver_identify_mismatched_scanned_print);
g_test_add_func ("/driver/identify/empty-gallery", test_driver_identify_empty_gallery);
g_test_add_func ("/driver/identify/empty-gallery-with-scanned-print",
test_driver_identify_empty_gallery_with_scanned_print);
g_test_add_func ("/driver/identify/suspend_continues", test_driver_identify_suspend_continues);
g_test_add_func ("/driver/identify/suspend_succeeds", test_driver_identify_suspend_succeeds);