fpi-device: Ensure we're receiving a valid number of enroll stages

This commit is contained in:
Marco Trevisan (Treviño) 2021-01-24 15:38:46 +01:00
parent a291d17f26
commit 665de7813b
2 changed files with 14 additions and 1 deletions

View file

@ -216,6 +216,7 @@ fpi_device_set_nr_enroll_stages (FpDevice *device,
FpDevicePrivate *priv = fp_device_get_instance_private (device);
g_return_if_fail (FP_IS_DEVICE (device));
g_return_if_fail (enroll_stages > 0);
priv->nr_enroll_stages = enroll_stages;
g_object_notify (G_OBJECT (device), "nr-enroll-stages");

View file

@ -433,7 +433,7 @@ test_driver_set_nr_enroll_stages (void)
g_autoptr(FpDevice) device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_autoptr(GParamSpec) pspec = NULL;
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
int expected_stages = g_random_int_range (G_MININT32, G_MAXINT32);
int expected_stages = g_random_int_range (1, G_MAXINT32);
g_signal_connect (device, "notify::nr-enroll-stages", G_CALLBACK (on_device_notify), NULL);
fpi_device_set_nr_enroll_stages (device, expected_stages);
@ -443,6 +443,18 @@ test_driver_set_nr_enroll_stages (void)
pspec = g_steal_pointer (&fake_dev->user_data);
g_assert_cmpstr (pspec->name, ==, "nr-enroll-stages");
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"*enroll_stages > 0*");
fpi_device_set_nr_enroll_stages (device, 0);
g_assert_cmpint (fp_device_get_nr_enroll_stages (device), ==, expected_stages);
g_test_assert_expected_messages ();
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"*enroll_stages > 0*");
fpi_device_set_nr_enroll_stages (device, -2);
g_assert_cmpint (fp_device_get_nr_enroll_stages (device), ==, expected_stages);
g_test_assert_expected_messages ();
}
static void