Blame SOURCES/0119-test-device-fake-Add-fake-test-driver-to-verify-fpi-.patch

73b847
From abbd2950fdc3c3eee479a5bbecbe009df7cf87ce Mon Sep 17 00:00:00 2001
73b847
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
73b847
Date: Fri, 6 Dec 2019 17:20:52 +0100
73b847
Subject: [PATCH 119/181] test-device-fake: Add fake test driver to verify fpi
73b847
 functions
73b847
73b847
---
73b847
 tests/meson.build        |   5 +-
73b847
 tests/test-device-fake.c | 205 +++++++++++++++++++++++++++++++++++++++
73b847
 tests/test-device-fake.h |  43 ++++++++
73b847
 3 files changed, 252 insertions(+), 1 deletion(-)
73b847
 create mode 100644 tests/test-device-fake.c
73b847
 create mode 100644 tests/test-device-fake.h
73b847
73b847
diff --git a/tests/meson.build b/tests/meson.build
73b847
index 1ef6e34..e37991d 100644
73b847
--- a/tests/meson.build
73b847
+++ b/tests/meson.build
73b847
@@ -50,7 +50,10 @@ endif
73b847
 
73b847
 if 'virtual_image' in drivers
73b847
     test_utils = static_library('fprint-test-utils',
73b847
-        sources: ['test-utils.c'],
73b847
+        sources: [
73b847
+            'test-utils.c',
73b847
+            'test-device-fake.c',
73b847
+        ],
73b847
         dependencies: libfprint_private_dep,
73b847
         install: false)
73b847
 
73b847
diff --git a/tests/test-device-fake.c b/tests/test-device-fake.c
73b847
new file mode 100644
73b847
index 0000000..e3b6f38
73b847
--- /dev/null
73b847
+++ b/tests/test-device-fake.c
73b847
@@ -0,0 +1,205 @@
73b847
+/*
73b847
+ * Virtual driver for device debugging
73b847
+ *
73b847
+ * Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
73b847
+ *
73b847
+ * This library is free software; you can redistribute it and/or
73b847
+ * modify it under the terms of the GNU Lesser General Public
73b847
+ * License as published by the Free Software Foundation; either
73b847
+ * version 2.1 of the License, or (at your option) any later version.
73b847
+ *
73b847
+ * This library is distributed in the hope that it will be useful,
73b847
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
73b847
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
73b847
+ * Lesser General Public License for more details.
73b847
+ *
73b847
+ * You should have received a copy of the GNU Lesser General Public
73b847
+ * License along with this library; if not, write to the Free Software
73b847
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73b847
+ */
73b847
+
73b847
+#define FP_COMPONENT "fake_test_dev"
73b847
+
73b847
+#include "test-device-fake.h"
73b847
+
73b847
+G_DEFINE_TYPE (FpiDeviceFake, fpi_device_fake, FP_TYPE_DEVICE)
73b847
+
73b847
+static const FpIdEntry driver_ids[] = {
73b847
+  { .virtual_envvar = "FP_VIRTUAL_FAKE_DEVICE" },
73b847
+  { .virtual_envvar = NULL }
73b847
+};
73b847
+
73b847
+static void
73b847
+fpi_device_fake_probe (FpDevice *device)
73b847
+{
73b847
+  FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_PROBE);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_probe;
73b847
+  fpi_device_probe_complete (device, dev_class->id, dev_class->full_name,
73b847
+                             fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_open (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_OPEN);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_open;
73b847
+  fpi_device_open_complete (device, fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_close (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_CLOSE);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_close;
73b847
+  fpi_device_close_complete (device, fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_enroll (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+  FpPrint *print = fake_dev->ret_print;
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_ENROLL);
73b847
+  fpi_device_get_enroll_data (device, (FpPrint **) &fake_dev->action_data);
73b847
+
73b847
+  if (!print && !fake_dev->ret_error)
73b847
+    fpi_device_get_enroll_data (device, &print);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_enroll;
73b847
+  fpi_device_enroll_complete (device, print, fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_verify (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+  FpPrint *print = fake_dev->ret_print;
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_VERIFY);
73b847
+  fpi_device_get_verify_data (device, (FpPrint **) &fake_dev->action_data);
73b847
+
73b847
+  if (!print && !fake_dev->ret_error)
73b847
+    fpi_device_get_verify_data (device, &print);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_verify;
73b847
+  fpi_device_verify_complete (device, fake_dev->ret_result, print,
73b847
+                              fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_identify (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+  FpPrint *match = fake_dev->ret_match;
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_IDENTIFY);
73b847
+  fpi_device_get_identify_data (device, (GPtrArray **) &fake_dev->action_data);
73b847
+
73b847
+  if (!match && !fake_dev->ret_error)
73b847
+    {
73b847
+      GPtrArray *prints;
73b847
+      unsigned int i;
73b847
+
73b847
+      fpi_device_get_identify_data (device, &prints);
73b847
+
73b847
+      for (i = 0; prints && i < prints->len; ++i)
73b847
+        {
73b847
+          FpPrint *print = g_ptr_array_index (prints, i);
73b847
+
73b847
+          if (g_strcmp0 (fp_print_get_description (print), "fake-verified") == 0)
73b847
+            {
73b847
+              match = print;
73b847
+              break;
73b847
+            }
73b847
+        }
73b847
+    }
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_identify;
73b847
+  fpi_device_identify_complete (device, match, fake_dev->ret_print,
73b847
+                                fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_capture (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_CAPTURE);
73b847
+  fpi_device_get_capture_data (device, (gboolean *) &fake_dev->action_data);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_capture;
73b847
+  fpi_device_capture_complete (device, fake_dev->ret_image, fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_list (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_LIST);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_list;
73b847
+  fpi_device_list_complete (device, fake_dev->ret_list, fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_delete (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), ==, FP_DEVICE_ACTION_DELETE);
73b847
+  fpi_device_get_delete_data (device, (gpointer) & fake_dev->action_data);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_delete;
73b847
+  fpi_device_delete_complete (device, fake_dev->ret_error);
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_cancel (FpDevice *device)
73b847
+{
73b847
+  FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
73b847
+
73b847
+  g_assert_cmpuint (fpi_device_get_current_action (device), !=, FP_DEVICE_ACTION_NONE);
73b847
+
73b847
+  fake_dev->last_called_function = fpi_device_fake_cancel;
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_init (FpiDeviceFake *self)
73b847
+{
73b847
+}
73b847
+
73b847
+static void
73b847
+fpi_device_fake_class_init (FpiDeviceFakeClass *klass)
73b847
+{
73b847
+  FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass);
73b847
+
73b847
+  dev_class->id = FP_COMPONENT;
73b847
+  dev_class->full_name = "Virtual device for debugging";
73b847
+  dev_class->type = FP_DEVICE_TYPE_VIRTUAL;
73b847
+  dev_class->id_table = driver_ids;
73b847
+  dev_class->nr_enroll_stages = 5;
73b847
+  dev_class->scan_type = FP_SCAN_TYPE_PRESS;
73b847
+
73b847
+  dev_class->probe = fpi_device_fake_probe;
73b847
+  dev_class->open = fpi_device_fake_open;
73b847
+  dev_class->close = fpi_device_fake_close;
73b847
+  dev_class->enroll = fpi_device_fake_enroll;
73b847
+  dev_class->verify = fpi_device_fake_verify;
73b847
+  dev_class->identify = fpi_device_fake_identify;
73b847
+  dev_class->capture = fpi_device_fake_capture;
73b847
+  dev_class->list = fpi_device_fake_list;
73b847
+  dev_class->delete = fpi_device_fake_delete;
73b847
+  dev_class->cancel = fpi_device_fake_cancel;
73b847
+}
73b847
diff --git a/tests/test-device-fake.h b/tests/test-device-fake.h
73b847
new file mode 100644
73b847
index 0000000..e8a0919
73b847
--- /dev/null
73b847
+++ b/tests/test-device-fake.h
73b847
@@ -0,0 +1,43 @@
73b847
+/*
73b847
+ * Virtual driver for device debugging
73b847
+ *
73b847
+ * Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
73b847
+ *
73b847
+ * This library is free software; you can redistribute it and/or
73b847
+ * modify it under the terms of the GNU Lesser General Public
73b847
+ * License as published by the Free Software Foundation; either
73b847
+ * version 2.1 of the License, or (at your option) any later version.
73b847
+ *
73b847
+ * This library is distributed in the hope that it will be useful,
73b847
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
73b847
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
73b847
+ * Lesser General Public License for more details.
73b847
+ *
73b847
+ * You should have received a copy of the GNU Lesser General Public
73b847
+ * License along with this library; if not, write to the Free Software
73b847
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73b847
+ */
73b847
+
73b847
+#pragma once
73b847
+
73b847
+#include "fpi-device.h"
73b847
+
73b847
+#define FPI_TYPE_DEVICE_FAKE (fpi_device_fake_get_type ())
73b847
+G_DECLARE_FINAL_TYPE (FpiDeviceFake, fpi_device_fake, FPI, DEVICE_FAKE, FpDevice)
73b847
+
73b847
+struct _FpiDeviceFake
73b847
+{
73b847
+  FpDevice       parent;
73b847
+
73b847
+  gpointer       last_called_function;
73b847
+
73b847
+  GError        *ret_error;
73b847
+  FpPrint       *ret_print;
73b847
+  FpPrint       *ret_match;
73b847
+  FpiMatchResult ret_result;
73b847
+  FpImage       *ret_image;
73b847
+  GPtrArray     *ret_list;
73b847
+
73b847
+  gpointer       action_data;
73b847
+  gpointer       user_data;
73b847
+};
73b847
-- 
73b847
2.24.1
73b847