From c9579ab21bb7ec07abc2012cbec27ef6a3c5ab9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 3 Dec 2020 04:38:15 +0100 Subject: [PATCH] test: Run all the fpi-device tests with the dynamically loaded TOD driver We can ensure better that it works as expected repeating all the device tests for it too. The nice part is that we can just do this by re-defininig its GType as the gtype of the loaded driver. --- tests/meson.build | 5 ++++- tests/test-fpi-device.c | 24 ++++++++++++++++++++++++ tests/test-utils-tod.c | 12 ++++++++++++ tests/test-utils-tod.h | 2 ++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/meson.build b/tests/meson.build index cc6992ea..52ded3eb 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -229,11 +229,14 @@ if get_option('tod') tod_unit_tests = [ 'fp-context-tod', 'fp-device-tod', + 'fpi-device', ] foreach test_name: tod_unit_tests basename = 'test-' + test_name - test_exe = executable(basename, + sufix = test_name.endswith('-tod') ? '' : '-tod' + test_name = test_name + sufix + test_exe = executable(basename + sufix, sources: basename + '.c', dependencies: libfprint_private_dep, c_args: [ diff --git a/tests/test-fpi-device.c b/tests/test-fpi-device.c index d492bc7a..e5e4964d 100644 --- a/tests/test-fpi-device.c +++ b/tests/test-fpi-device.c @@ -26,6 +26,26 @@ #include "fpi-log.h" #include "test-device-fake.h" +#ifdef TEST_TOD_DRIVER + +#include "test-utils-tod.h" + +#undef FPI_TYPE_DEVICE_FAKE +#define FPI_TYPE_DEVICE_FAKE (fpt_context_device_driver_get_type ()) + +#undef FPI_DEVICE_FAKE +#define FPI_DEVICE_FAKE(dev) (G_TYPE_CHECK_INSTANCE_CAST ((dev), FPI_TYPE_DEVICE_FAKE, FpiDeviceFake)) + +static GType +fpt_context_device_driver_get_type (void) +{ + FptContext *tctx = fpt_context_fake_dev_default (); + + return G_TYPE_FROM_CLASS (FP_DEVICE_GET_CLASS (tctx->device)); +} + +#endif + /* Utility functions */ typedef FpDevice FpAutoCloseDevice; @@ -2343,6 +2363,10 @@ test_driver_retry_error_types (void) int main (int argc, char *argv[]) { +#ifdef TEST_TOD_DRIVER + g_autoptr(FptContext) tctx = fpt_context_fake_dev_default (); +#endif + g_test_init (&argc, &argv, NULL); g_test_add_func ("/driver/get_driver", test_driver_get_driver); diff --git a/tests/test-utils-tod.c b/tests/test-utils-tod.c index d5ca5037..cab61ebb 100644 --- a/tests/test-utils-tod.c +++ b/tests/test-utils-tod.c @@ -21,6 +21,8 @@ #include "test-utils-tod.h" +static FptContext *fake_context = NULL; + FptContext * fpt_context_new_with_fake_dev (void) { @@ -50,3 +52,13 @@ fpt_context_new_with_fake_dev (void) return tctx; } + +FptContext * +fpt_context_fake_dev_default (void) +{ + if (fake_context) + return fake_context; + + fake_context = fpt_context_new_with_fake_dev (); + return fake_context; +} diff --git a/tests/test-utils-tod.h b/tests/test-utils-tod.h index 63f08375..b3d95a01 100644 --- a/tests/test-utils-tod.h +++ b/tests/test-utils-tod.h @@ -21,3 +21,5 @@ #include "test-utils.h" FptContext * fpt_context_new_with_fake_dev (void); + +FptContext * fpt_context_fake_dev_default (void);