From 67cb61cc180f2636f63565b575646edd60cd9147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 24 Jan 2021 20:01:53 +0100 Subject: [PATCH] tests/virtual-device: Add identification tests Reusing most of the logic of the `check_verify` utility function --- libfprint/drivers/virtual-device-storage.c | 2 + tests/virtual-device.py | 50 +++++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/libfprint/drivers/virtual-device-storage.c b/libfprint/drivers/virtual-device-storage.c index c948a6b4..1fcee3c7 100644 --- a/libfprint/drivers/virtual-device-storage.c +++ b/libfprint/drivers/virtual-device-storage.c @@ -62,6 +62,8 @@ dev_identify (FpDevice *dev) data = g_variant_new_string (scan_id); g_object_set (new_scan, "fpi-data", data, NULL); + g_debug ("Trying to identify print '%s' against a gallery of %u prints", scan_id, prints->len); + if (g_ptr_array_find_with_equal_func (prints, new_scan, (GEqualFunc) fp_print_equal, diff --git a/tests/virtual-device.py b/tests/virtual-device.py index 44664d7d..82beaa72 100644 --- a/tests/virtual-device.py +++ b/tests/virtual-device.py @@ -201,10 +201,14 @@ class VirtualDevice(unittest.TestCase): return self._enrolled - def check_verify(self, p, scan_nick, match): + def check_verify(self, p, scan_nick, match, identify=False): self._verify_match = None self._verify_fp = None self._verify_error = None + self._verify_completed = False + + if identify: + self.assertTrue(self.dev.supports_identify()) if isinstance(scan_nick, str): self.send_command('SCAN', scan_nick) @@ -213,16 +217,31 @@ class VirtualDevice(unittest.TestCase): def verify_cb(dev, res): try: - self._verify_match, self._verify_fp = dev.verify_finish(res) + self._verify_match, self._verify_fp = ( + dev.identify_finish(res) if identify else dev.verify_finish(res)) except gi.repository.GLib.Error as e: self._verify_error = e - self.dev.verify(p, callback=verify_cb) - while self._verify_match is None and self._verify_error is None: + self._verify_completed = True + + if identify: + self.dev.identify(p if isinstance(p, list) else [p], callback=verify_cb) + else: + self.dev.verify(p, callback=verify_cb) + + while not self._verify_completed: ctx.iteration(True) - if match: - assert self._verify_fp.equal(p) + if identify: + if match: + self.assertIsNotNone(self._verify_match) + else: + self.assertIsNone(self._verify_match) + else: + if self._verify_fp: + self.assertEqual(self._verify_fp.equal(p), match) + else: + self.assertFalse(match) if isinstance(scan_nick, str): self.assertEqual(self._verify_fp.props.fpi_data.get_string(), scan_nick) @@ -401,6 +420,25 @@ class VirtualDeviceStorage(VirtualDevice): with self.assertRaisesRegex(GLib.GError, 'Print was not found'): self.dev.delete_print_sync(p) + def test_identify_match(self): + rt = self.enroll_print('right-thumb', FPrint.Finger.RIGHT_THUMB) + lt = self.enroll_print('left-thumb', FPrint.Finger.LEFT_THUMB) + + self.check_verify([rt, lt], 'right-thumb', identify=True, match=True) + self.check_verify([rt, lt], 'left-thumb', identify=True, match=True) + + def test_identify_no_match(self): + rt = self.enroll_print('right-thumb', FPrint.Finger.RIGHT_THUMB) + lt = self.enroll_print('left-thumb', FPrint.Finger.LEFT_THUMB) + + self.check_verify(lt, 'right-thumb', identify=True, match=False) + self.check_verify(rt, 'left-thumb', identify=True, match=False) + + def test_identify_retry(self): + with self.assertRaisesRegex(GLib.GError, 'too short'): + self.check_verify(FPrint.Print.new(self.dev), + FPrint.DeviceRetry.TOO_SHORT, identify=True, match=False) + if __name__ == '__main__': try: