From 162a83e48461d372a5f5c31d7e662f82671d58dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 24 Jan 2021 18:21:23 +0100 Subject: [PATCH] tests/virtual-device: Add ability to enroll with a retry step and test it --- tests/virtual-device.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/virtual-device.py b/tests/virtual-device.py index b406e1a..c31de25 100644 --- a/tests/virtual-device.py +++ b/tests/virtual-device.py @@ -133,7 +133,7 @@ class VirtualDevice(unittest.TestCase): else: raise Exception('No known type found for {}'.format(obj)) - def enroll_print(self, nick, finger, username='testuser'): + def enroll_print(self, nick, finger, username='testuser', retry_scan=-1): self._enrolled = None def done_cb(dev, res): @@ -145,22 +145,38 @@ class VirtualDevice(unittest.TestCase): self._enroll_stage = stage self._enroll_progress_error = error - stage = 1 + self.assertLessEqual(retry_scan, self.dev.get_nr_enroll_stages()) + + retries = 1 + should_retry = retry_scan > 0 + def enroll_in_progress(): if self._enroll_stage < 0 and not self._enrolled: return True - nonlocal stage + nonlocal retries self.assertLessEqual(self._enroll_stage, self.dev.get_nr_enroll_stages()) - self.assertEqual(self._enroll_stage, stage) + if should_retry and retries > retry_scan: + self.assertEqual(self._enroll_stage, retries - 1) + else: + self.assertEqual(self._enroll_stage, retries) + + if retries == retry_scan + 1: + self.assertIsNotNone(self._enroll_progress_error) + self.assertEqual(self._enroll_progress_error.code, FPrint.DeviceRetry.TOO_SHORT) + else: + self.assertIsNone(self._enroll_progress_error) if self._enroll_stage < self.dev.get_nr_enroll_stages(): self._enroll_stage = -1 self.assertIsNone(self._enrolled) self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NEEDED) - GLib.idle_add(self.send_command, 'SCAN', nick) - stage += 1 + if retry_scan == retries: + GLib.idle_add(self.send_auto, FPrint.DeviceRetry.TOO_SHORT) + else: + GLib.idle_add(self.send_command, 'SCAN', nick) + retries += 1 return not self._enrolled @@ -176,7 +192,7 @@ class VirtualDevice(unittest.TestCase): while enroll_in_progress(): ctx.iteration(False) - self.assertEqual(self._enroll_stage, stage) + self.assertEqual(self._enroll_stage, retries if not should_retry else retries - 1) self.assertEqual(self._enroll_stage, self.dev.get_nr_enroll_stages()) self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE) @@ -230,6 +246,11 @@ class VirtualDevice(unittest.TestCase): self.assertEqual(matching.get_username(), 'testuser') self.assertEqual(matching.get_finger(), FPrint.Finger.LEFT_LITTLE) + def test_enroll_with_retry(self): + matching = self.enroll_print('testprint', FPrint.Finger.LEFT_LITTLE, retry_scan=2) + self.assertEqual(matching.get_username(), 'testuser') + self.assertEqual(matching.get_finger(), FPrint.Finger.LEFT_LITTLE) + def test_enroll_verify_match(self): matching = self.enroll_print('testprint', FPrint.Finger.LEFT_THUMB)