tests: Add tests for the early reporting mechanism
This adds tests to check whether the verify/identify early reporting mechanism is behaving correctly.
This commit is contained in:
parent
829fb9f873
commit
0c582230f3
1 changed files with 111 additions and 6 deletions
|
@ -543,6 +543,57 @@ test_driver_enroll_progress (void)
|
||||||
g_assert (fake_dev->last_called_function == test_driver_enroll_progress_vfunc);
|
g_assert (fake_dev->last_called_function == test_driver_enroll_progress_vfunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
gboolean called;
|
||||||
|
gboolean success;
|
||||||
|
FpPrint *match;
|
||||||
|
FpPrint *print;
|
||||||
|
GError *error;
|
||||||
|
} MatchCbData;
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_driver_match_data_clear (MatchCbData *data)
|
||||||
|
{
|
||||||
|
data->called = FALSE;
|
||||||
|
data->success = FALSE;
|
||||||
|
g_clear_object (&data->match);
|
||||||
|
g_clear_object (&data->print);
|
||||||
|
g_clear_error (&data->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_driver_match_cb (FpDevice *device,
|
||||||
|
gboolean success,
|
||||||
|
FpPrint *match,
|
||||||
|
FpPrint *print,
|
||||||
|
gpointer user_data,
|
||||||
|
GError *error)
|
||||||
|
{
|
||||||
|
MatchCbData *data = user_data;
|
||||||
|
|
||||||
|
g_assert (data->called == FALSE);
|
||||||
|
data->called = TRUE;
|
||||||
|
data->success = TRUE;
|
||||||
|
if (match)
|
||||||
|
data->match = g_object_ref (match);
|
||||||
|
if (print)
|
||||||
|
data->print = g_object_ref (print);
|
||||||
|
if (error)
|
||||||
|
data->error = g_error_copy (error);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
g_assert_null (error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_assert_nonnull (error);
|
||||||
|
g_assert_null (match);
|
||||||
|
g_assert_null (print);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_driver_verify (void)
|
test_driver_verify (void)
|
||||||
{
|
{
|
||||||
|
@ -552,17 +603,27 @@ test_driver_verify (void)
|
||||||
g_autoptr(FpPrint) out_print = NULL;
|
g_autoptr(FpPrint) out_print = NULL;
|
||||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||||
|
MatchCbData match_data = { 0, };
|
||||||
gboolean match;
|
gboolean match;
|
||||||
|
|
||||||
fake_dev->ret_result = FPI_MATCH_SUCCESS;
|
fake_dev->ret_result = FPI_MATCH_SUCCESS;
|
||||||
fp_device_verify_sync (device, enrolled_print, NULL, NULL, NULL, &match, &out_print, &error);
|
fp_device_verify_sync (device, enrolled_print, NULL,
|
||||||
|
test_driver_match_cb, &match_data,
|
||||||
|
&match, &out_print, &error);
|
||||||
|
|
||||||
g_assert (fake_dev->last_called_function == dev_class->verify);
|
g_assert (fake_dev->last_called_function == dev_class->verify);
|
||||||
g_assert (fake_dev->action_data == enrolled_print);
|
g_assert (fake_dev->action_data == enrolled_print);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
|
g_assert_true (match_data.called);
|
||||||
|
g_assert_true (match_data.success);
|
||||||
|
g_assert_true (match_data.print == out_print);
|
||||||
|
g_assert_true (match_data.match == enrolled_print);
|
||||||
|
|
||||||
g_assert (out_print == enrolled_print);
|
g_assert (out_print == enrolled_print);
|
||||||
g_assert_true (match);
|
g_assert_true (match);
|
||||||
|
|
||||||
|
test_driver_match_data_clear (&match_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -574,16 +635,26 @@ test_driver_verify_fail (void)
|
||||||
g_autoptr(FpPrint) out_print = NULL;
|
g_autoptr(FpPrint) out_print = NULL;
|
||||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||||
|
MatchCbData match_data = { 0, };
|
||||||
gboolean match;
|
gboolean match;
|
||||||
|
|
||||||
fake_dev->ret_result = FPI_MATCH_FAIL;
|
fake_dev->ret_result = FPI_MATCH_FAIL;
|
||||||
fp_device_verify_sync (device, enrolled_print, NULL, NULL, NULL, &match, &out_print, &error);
|
fp_device_verify_sync (device, enrolled_print, NULL,
|
||||||
|
test_driver_match_cb, &match_data,
|
||||||
|
&match, &out_print, &error);
|
||||||
|
|
||||||
g_assert (fake_dev->last_called_function == dev_class->verify);
|
g_assert (fake_dev->last_called_function == dev_class->verify);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
|
g_assert_true (match_data.called);
|
||||||
|
g_assert_true (match_data.success);
|
||||||
|
g_assert_true (match_data.print == out_print);
|
||||||
|
g_assert_null (match_data.match);
|
||||||
|
|
||||||
g_assert (out_print == enrolled_print);
|
g_assert (out_print == enrolled_print);
|
||||||
g_assert_false (match);
|
g_assert_false (match);
|
||||||
|
|
||||||
|
test_driver_match_data_clear (&match_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -595,16 +666,23 @@ test_driver_verify_error (void)
|
||||||
g_autoptr(FpPrint) out_print = NULL;
|
g_autoptr(FpPrint) out_print = NULL;
|
||||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||||
|
MatchCbData match_data = { 0, };
|
||||||
gboolean match;
|
gboolean match;
|
||||||
|
|
||||||
fake_dev->ret_result = FPI_MATCH_ERROR;
|
fake_dev->ret_result = FPI_MATCH_ERROR;
|
||||||
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
|
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
|
||||||
fp_device_verify_sync (device, enrolled_print, NULL, NULL, NULL, &match, &out_print, &error);
|
fp_device_verify_sync (device, enrolled_print, NULL,
|
||||||
|
test_driver_match_cb, &match_data,
|
||||||
|
&match, &out_print, &error);
|
||||||
|
|
||||||
|
g_assert_false (match_data.called);
|
||||||
|
|
||||||
g_assert (fake_dev->last_called_function == dev_class->verify);
|
g_assert (fake_dev->last_called_function == dev_class->verify);
|
||||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
||||||
g_assert (error == g_steal_pointer (&fake_dev->ret_error));
|
g_assert (error == g_steal_pointer (&fake_dev->ret_error));
|
||||||
g_assert_false (match);
|
g_assert_false (match);
|
||||||
|
|
||||||
|
test_driver_match_data_clear (&match_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -647,6 +725,7 @@ test_driver_identify (void)
|
||||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||||
FpPrint *expected_matched;
|
FpPrint *expected_matched;
|
||||||
|
MatchCbData match_data = { 0, };
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < 500; ++i)
|
for (i = 0; i < 500; ++i)
|
||||||
|
@ -658,7 +737,14 @@ test_driver_identify (void)
|
||||||
g_assert_true (fp_device_supports_identify (device));
|
g_assert_true (fp_device_supports_identify (device));
|
||||||
|
|
||||||
fake_dev->ret_print = fp_print_new (device);
|
fake_dev->ret_print = fp_print_new (device);
|
||||||
fp_device_identify_sync (device, prints, NULL, NULL, NULL, &matched_print, &print, &error);
|
fp_device_identify_sync (device, prints, NULL,
|
||||||
|
test_driver_match_cb, &match_data,
|
||||||
|
&matched_print, &print, &error);
|
||||||
|
|
||||||
|
g_assert_true (match_data.called);
|
||||||
|
g_assert_true (match_data.success);
|
||||||
|
g_assert_true (match_data.match == matched_print);
|
||||||
|
g_assert_true (match_data.print == print);
|
||||||
|
|
||||||
g_assert (fake_dev->last_called_function == dev_class->identify);
|
g_assert (fake_dev->last_called_function == dev_class->identify);
|
||||||
g_assert (fake_dev->action_data == prints);
|
g_assert (fake_dev->action_data == prints);
|
||||||
|
@ -666,6 +752,8 @@ test_driver_identify (void)
|
||||||
|
|
||||||
g_assert (print != NULL && print == fake_dev->ret_print);
|
g_assert (print != NULL && print == fake_dev->ret_print);
|
||||||
g_assert (expected_matched == matched_print);
|
g_assert (expected_matched == matched_print);
|
||||||
|
|
||||||
|
test_driver_match_data_clear (&match_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -678,6 +766,7 @@ test_driver_identify_fail (void)
|
||||||
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
|
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||||
|
MatchCbData match_data = { 0, };
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < 500; ++i)
|
for (i = 0; i < 500; ++i)
|
||||||
|
@ -686,13 +775,22 @@ test_driver_identify_fail (void)
|
||||||
g_assert_true (fp_device_supports_identify (device));
|
g_assert_true (fp_device_supports_identify (device));
|
||||||
|
|
||||||
fake_dev->ret_print = fp_print_new (device);
|
fake_dev->ret_print = fp_print_new (device);
|
||||||
fp_device_identify_sync (device, prints, NULL, NULL, NULL, &matched_print, &print, &error);
|
fp_device_identify_sync (device, prints, NULL,
|
||||||
|
test_driver_match_cb, &match_data,
|
||||||
|
&matched_print, &print, &error);
|
||||||
|
|
||||||
|
g_assert_true (match_data.called);
|
||||||
|
g_assert_true (match_data.success);
|
||||||
|
g_assert_true (match_data.match == matched_print);
|
||||||
|
g_assert_true (match_data.print == print);
|
||||||
|
|
||||||
g_assert (fake_dev->last_called_function == dev_class->identify);
|
g_assert (fake_dev->last_called_function == dev_class->identify);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_assert (print != NULL && print == fake_dev->ret_print);
|
g_assert (print != NULL && print == fake_dev->ret_print);
|
||||||
g_assert_null (matched_print);
|
g_assert_null (matched_print);
|
||||||
|
|
||||||
|
test_driver_match_data_clear (&match_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -706,6 +804,7 @@ test_driver_identify_error (void)
|
||||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||||
FpPrint *expected_matched;
|
FpPrint *expected_matched;
|
||||||
|
MatchCbData match_data = { 0, };
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < 500; ++i)
|
for (i = 0; i < 500; ++i)
|
||||||
|
@ -717,13 +816,19 @@ test_driver_identify_error (void)
|
||||||
g_assert_true (fp_device_supports_identify (device));
|
g_assert_true (fp_device_supports_identify (device));
|
||||||
|
|
||||||
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
|
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
|
||||||
fp_device_identify_sync (device, prints, NULL, NULL, NULL, &matched_print, &print, &error);
|
fp_device_identify_sync (device, prints, NULL,
|
||||||
|
test_driver_match_cb, &match_data,
|
||||||
|
&matched_print, &print, &error);
|
||||||
|
|
||||||
|
g_assert_false (match_data.called);
|
||||||
|
|
||||||
g_assert (fake_dev->last_called_function == dev_class->identify);
|
g_assert (fake_dev->last_called_function == dev_class->identify);
|
||||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
||||||
g_assert (error == g_steal_pointer (&fake_dev->ret_error));
|
g_assert (error == g_steal_pointer (&fake_dev->ret_error));
|
||||||
g_assert_null (matched_print);
|
g_assert_null (matched_print);
|
||||||
g_assert_null (print);
|
g_assert_null (print);
|
||||||
|
|
||||||
|
test_driver_match_data_clear (&match_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue