diff --git a/tests/virtual-device.py b/tests/virtual-device.py index a77a18a..10684e6 100644 --- a/tests/virtual-device.py +++ b/tests/virtual-device.py @@ -62,7 +62,7 @@ class GLibErrorMessage: GLib.test_assert_expected_messages_internal(self.component, filename, line, func_name) -class VirtualDevice(unittest.TestCase): +class VirtualDeviceBase(unittest.TestCase): @classmethod def setUpClass(cls): @@ -327,6 +327,9 @@ class VirtualDevice(unittest.TestCase): if isinstance(scan_nick, str): self.assertEqual(self._verify_fp.props.fpi_data.get_string(), scan_nick) + +class VirtualDevice(VirtualDeviceBase): + def test_device_properties(self): self.assertEqual(self.dev.get_driver(), 'virtual_device') self.assertEqual(self.dev.get_device_id(), '0') @@ -658,6 +661,118 @@ class VirtualDevice(unittest.TestCase): self.assertEqual(close_res.code, int(FPrint.DeviceError.BUSY)) + +class VirtualDeviceClosed(VirtualDeviceBase): + + driver_name = 'virtual_device' + + def setUp(self): + super().setUp() + self._close_on_teardown = False + self.dev.close_sync() + self.assertFalse(self.dev.is_open()) + + def test_close(self): + with self.assertRaises(GLib.Error) as error: + self.dev.close_sync() + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.NOT_OPEN)) + + def test_enroll(self): + with self.assertRaises(GLib.Error) as error: + self.dev.enroll_sync(FPrint.Print.new(self.dev)) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.NOT_OPEN)) + + def test_verify(self): + with self.assertRaises(GLib.Error) as error: + self.dev.verify_sync(FPrint.Print.new(self.dev)) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.NOT_OPEN)) + + def test_identify(self): + with self.assertRaises(GLib.Error) as error: + self.dev.identify_sync([FPrint.Print.new(self.dev)]) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.NOT_OPEN)) + + def test_capture(self): + with self.assertRaises(GLib.Error) as error: + self.dev.capture_sync(wait_for_finger=False) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.NOT_OPEN)) + + def test_delete_print(self): + with self.assertRaises(GLib.Error) as error: + self.dev.delete_print_sync(FPrint.Print.new(self.dev)) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.NOT_OPEN)) + + def test_list_prints(self): + with self.assertRaises(GLib.Error) as error: + self.dev.list_prints_sync() + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.NOT_OPEN)) + + +class VirtualDeviceBusyDeviceOperations(VirtualDeviceBase): + + driver_name = 'virtual_device' + + def setUp(self): + super().setUp() + self._close_on_teardown = False + self.send_sleep(200) + self.dev.close() + + def tearDown(self): + while self.dev.is_open(): + ctx.iteration(True) + super().tearDown() + + def test_close(self): + with self.assertRaises(GLib.Error) as error: + self.dev.close_sync() + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.BUSY)) + + def test_enroll(self): + with self.assertRaises(GLib.Error) as error: + self.dev.enroll_sync(FPrint.Print.new(self.dev)) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.BUSY)) + + def test_verify(self): + with self.assertRaises(GLib.Error) as error: + self.dev.verify_sync(FPrint.Print.new(self.dev)) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.BUSY)) + + def test_identify(self): + with self.assertRaises(GLib.Error) as error: + self.dev.identify_sync([FPrint.Print.new(self.dev)]) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.BUSY)) + + def test_capture(self): + with self.assertRaises(GLib.Error) as error: + self.dev.capture_sync(wait_for_finger=False) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.BUSY)) + + def test_delete_print(self): + with self.assertRaises(GLib.Error) as error: + self.dev.delete_print_sync(FPrint.Print.new(self.dev)) + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.BUSY)) + + def test_list_prints(self): + with self.assertRaises(GLib.Error) as error: + self.dev.list_prints_sync() + self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(), + FPrint.DeviceError.BUSY)) + + class VirtualDeviceStorage(VirtualDevice): def tearDown(self):