tests/virtual-device: Add identification tests

Reusing most of the logic of the `check_verify` utility function
This commit is contained in:
Marco Trevisan (Treviño) 2021-01-24 20:01:53 +01:00
parent 33ffadf402
commit 67cb61cc18
2 changed files with 46 additions and 6 deletions

View file

@ -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,

View file

@ -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: