From 81e53c422d987703750f8729469cdd45636834f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 24 Jan 2021 17:35:29 +0100 Subject: [PATCH] virtual-device: Add support for changing the device scan type --- libfprint/drivers/virtual-device.c | 12 ++++++++++++ tests/virtual-device.py | 25 ++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/libfprint/drivers/virtual-device.c b/libfprint/drivers/virtual-device.c index 8fcff49c..ca8f885c 100644 --- a/libfprint/drivers/virtual-device.c +++ b/libfprint/drivers/virtual-device.c @@ -41,6 +41,7 @@ G_DEFINE_TYPE (FpDeviceVirtualDevice, fpi_device_virtual_device, FP_TYPE_DEVICE) #define RETRY_CMD_PREFIX "RETRY " #define FINGER_CMD_PREFIX "FINGER " #define SET_ENROLL_STAGES_PREFIX "SET_ENROLL_STAGES " +#define SET_SCAN_TYPE_PREFIX "SET_SCAN_TYPE " #define LIST_CMD "LIST" @@ -204,6 +205,17 @@ recv_instruction_cb (GObject *source_object, stages = g_ascii_strtoull (cmd + strlen (SET_ENROLL_STAGES_PREFIX), NULL, 10); fpi_device_set_nr_enroll_stages (FP_DEVICE (self), stages); } + else if (g_str_has_prefix (cmd, SET_SCAN_TYPE_PREFIX)) + { + const char *scan_type = cmd + strlen (SET_SCAN_TYPE_PREFIX); + g_autoptr(GEnumClass) scan_types = g_type_class_ref (fp_scan_type_get_type ()); + GEnumValue *value = g_enum_get_value_by_nick (scan_types, scan_type); + + if (value) + fpi_device_set_scan_type (FP_DEVICE (self), value->value); + else + g_warning ("Scan type '%s' not found", scan_type); + } else { g_ptr_array_add (self->pending_commands, g_steal_pointer (&cmd)); diff --git a/tests/virtual-device.py b/tests/virtual-device.py index 709641b9..876de661 100644 --- a/tests/virtual-device.py +++ b/tests/virtual-device.py @@ -94,7 +94,7 @@ class VirtualDevice(unittest.TestCase): def send_command(self, command, *args): self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR', 'RETRY', - 'FINGER', 'SET_ENROLL_STAGES']) + 'FINGER', 'SET_ENROLL_STAGES', 'SET_SCAN_TYPE']) with Connection(self.sockaddr) as con: params = ' '.join(str(p) for p in args) @@ -292,6 +292,29 @@ class VirtualDevice(unittest.TestCase): self.assertEqual(matching.get_username(), 'testuser') self.assertEqual(matching.get_finger(), FPrint.Finger.LEFT_LITTLE) + def test_change_scan_type(self): + notified_spec = None + def on_scan_type_changed(dev, spec): + nonlocal notified_spec + notified_spec = spec + + self.dev.connect('notify::scan-type', on_scan_type_changed) + + for scan_type in [FPrint.ScanType.PRESS, FPrint.ScanType.SWIPE]: + notified_spec = None + self.send_command('SET_SCAN_TYPE', scan_type.value_nick) + self.assertEqual(self.dev.get_scan_type(), scan_type) + self.assertEqual(notified_spec.name, 'scan-type') + + GLib.test_expect_message('libfprint-virtual_device', + GLib.LogLevelFlags.LEVEL_WARNING, '*Scan type*not found') + notified_spec = None + self.send_command('SET_SCAN_TYPE', 'eye-contact') + self.assertEqual(self.dev.get_scan_type(), FPrint.ScanType.SWIPE) + self.assertIsNone(notified_spec) + GLib.test_assert_expected_messages_internal('libfprint-device', + __file__, 0, 'test_change_scan_type') + class VirtualDeviceStorage(VirtualDevice): def cleanup_device_storage(self):