From 91dd69475ffd2d02b07111eb07db6316dbbdac9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 10 Jul 2026 02:20:00 +0200 Subject: [PATCH] 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. --- tests/test-fpi-device.c | 71 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/tests/test-fpi-device.c b/tests/test-fpi-device.c index 8ad3caa0..71a9f75d 100644 --- a/tests/test-fpi-device.c +++ b/tests/test-fpi-device.c @@ -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);