mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2025-11-15 07:38:12 +00:00
tests: Add fp-device basic unit tests
Use the virtual image device as base for now, while the new setup allows to create easily fake device drivers without including the driver in libfprint itself and test all the fpi_device functionalities.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <libfprint/fprint.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "test-utils.h"
|
||||
@@ -64,3 +65,63 @@ fpt_setup_virtual_device_environment (void)
|
||||
signal (SIGQUIT, on_signal_event);
|
||||
signal (SIGPIPE, on_signal_event);
|
||||
}
|
||||
|
||||
FptContext *
|
||||
fpt_context_new (void)
|
||||
{
|
||||
FptContext *tctx;
|
||||
|
||||
tctx = g_new0 (FptContext, 1);
|
||||
tctx->fp_context = fp_context_new ();
|
||||
|
||||
return tctx;
|
||||
}
|
||||
|
||||
FptContext *
|
||||
fpt_context_new_with_virtual_imgdev (void)
|
||||
{
|
||||
FptContext *tctx;
|
||||
GPtrArray *devices;
|
||||
unsigned int i;
|
||||
|
||||
fpt_setup_virtual_device_environment ();
|
||||
|
||||
tctx = fpt_context_new ();
|
||||
devices = fp_context_get_devices (tctx->fp_context);
|
||||
|
||||
g_assert_nonnull (devices);
|
||||
g_assert_cmpuint (devices->len, ==, 1);
|
||||
|
||||
for (i = 0; i < devices->len; ++i)
|
||||
{
|
||||
FpDevice *device = devices->pdata[i];
|
||||
|
||||
if (g_strcmp0 (fp_device_get_driver (device), "virtual_image") == 0)
|
||||
{
|
||||
tctx->device = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_assert_true (FP_IS_DEVICE (tctx->device));
|
||||
g_object_add_weak_pointer (G_OBJECT (tctx->device), (gpointer) & tctx->device);
|
||||
|
||||
return tctx;
|
||||
}
|
||||
|
||||
void
|
||||
fpt_context_free (FptContext *tctx)
|
||||
{
|
||||
if (tctx->device && fp_device_is_open (tctx->device))
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
fp_device_close_sync (tctx->device, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
|
||||
g_clear_object (&tctx->fp_context);
|
||||
g_free (tctx);
|
||||
|
||||
fpt_teardown_virtual_device_environment ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user