Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * FpDevice Unit tests | ||
3 | * Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com> | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2.1 of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this library; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | |||
20 | #include <libfprint/fprint.h> | ||
21 | |||
22 | #include "test-utils.h" | ||
23 | |||
24 | static void | ||
25 | 2 | on_device_opened (FpDevice *dev, GAsyncResult *res, FptContext *tctx) | |
26 | { | ||
27 | 4 | g_autoptr(GError) error = NULL; | |
28 | |||
29 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | g_assert_true (fp_device_open_finish (dev, res, &error)); |
30 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | g_assert_no_error (error); |
31 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | g_assert_true (fp_device_is_open (tctx->device)); |
32 | |||
33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | tctx->user_data = GUINT_TO_POINTER (TRUE); |
34 | 2 | } | |
35 | |||
36 | static void | ||
37 | 1 | test_device_open_async (void) | |
38 | { | ||
39 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
40 | |||
41 | 1 | fp_device_open (tctx->device, NULL, (GAsyncReadyCallback) on_device_opened, tctx); | |
42 | |||
43 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
|
4 | while (!GPOINTER_TO_UINT (tctx->user_data)) |
44 | 3 | g_main_context_iteration (NULL, TRUE); | |
45 | 1 | } | |
46 | |||
47 | static void | ||
48 | 1 | on_device_closed (FpDevice *dev, GAsyncResult *res, FptContext *tctx) | |
49 | { | ||
50 | 2 | g_autoptr(GError) error = NULL; | |
51 | |||
52 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (fp_device_close_finish (dev, res, &error)); |
53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
54 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_false (fp_device_is_open (tctx->device)); |
55 | |||
56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | tctx->user_data = GUINT_TO_POINTER (TRUE); |
57 | 1 | } | |
58 | |||
59 | static void | ||
60 | 1 | test_device_close_async (void) | |
61 | { | ||
62 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
63 | |||
64 | 1 | fp_device_open (tctx->device, NULL, (GAsyncReadyCallback) on_device_opened, tctx); | |
65 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
|
4 | while (!tctx->user_data) |
66 | 3 | g_main_context_iteration (NULL, TRUE); | |
67 | |||
68 | 1 | tctx->user_data = GUINT_TO_POINTER (FALSE); | |
69 | 1 | fp_device_close (tctx->device, NULL, (GAsyncReadyCallback) on_device_closed, tctx); | |
70 | |||
71 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
|
5 | while (!GPOINTER_TO_UINT (tctx->user_data)) |
72 | 4 | g_main_context_iteration (NULL, TRUE); | |
73 | 1 | } | |
74 | |||
75 | static void | ||
76 | 1 | test_device_open_sync (void) | |
77 | { | ||
78 | 2 | g_autoptr(GError) error = NULL; | |
79 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); |
80 | |||
81 | 1 | fp_device_open_sync (tctx->device, NULL, &error); | |
82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
83 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (fp_device_is_open (tctx->device)); |
84 | |||
85 | 1 | fp_device_open_sync (tctx->device, NULL, &error); | |
86 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
1 | g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_ALREADY_OPEN); |
87 | 1 | } | |
88 | |||
89 | static void | ||
90 | 2 | on_open_notify (FpDevice *rdev, GParamSpec *spec, FptContext *tctx) | |
91 | { | ||
92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | g_assert_cmpstr (spec->name, ==, "open"); |
93 | 2 | tctx->user_data = GUINT_TO_POINTER (TRUE); | |
94 | 2 | } | |
95 | |||
96 | static void | ||
97 | 1 | test_device_open_sync_notify (void) | |
98 | { | ||
99 | 2 | g_autoptr(GError) error = NULL; | |
100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
2 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); |
101 | |||
102 | 1 | g_signal_connect (tctx->device, "notify::open", G_CALLBACK (on_open_notify), tctx); | |
103 | 1 | fp_device_open_sync (tctx->device, NULL, &error); | |
104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_true (GPOINTER_TO_INT (tctx->user_data)); |
106 | 1 | } | |
107 | |||
108 | static void | ||
109 | 1 | test_device_close_sync (void) | |
110 | { | ||
111 | 2 | g_autoptr(GError) error = NULL; | |
112 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); |
113 | |||
114 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
115 | 1 | fp_device_close_sync (tctx->device, NULL, &error); | |
116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_false (fp_device_is_open (tctx->device)); |
118 | |||
119 | 1 | fp_device_close_sync (tctx->device, NULL, &error); | |
120 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
1 | g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_NOT_OPEN); |
121 | 1 | } | |
122 | |||
123 | static void | ||
124 | 1 | on_close_notify (FpDevice *rdev, GParamSpec *spec, FptContext *tctx) | |
125 | { | ||
126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_cmpstr (spec->name, ==, "open"); |
127 | 1 | tctx->user_data = GUINT_TO_POINTER (TRUE); | |
128 | 1 | } | |
129 | |||
130 | static void | ||
131 | 1 | test_device_close_sync_notify (void) | |
132 | { | ||
133 | 2 | g_autoptr(GError) error = NULL; | |
134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
2 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); |
135 | |||
136 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
137 | |||
138 | 1 | g_signal_connect (tctx->device, "notify::open", G_CALLBACK (on_close_notify), tctx); | |
139 | 1 | fp_device_close_sync (tctx->device, NULL, &error); | |
140 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_true (GPOINTER_TO_INT (tctx->user_data)); |
142 | 1 | } | |
143 | |||
144 | static void | ||
145 | 1 | test_device_get_driver (void) | |
146 | { | ||
147 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
148 | |||
149 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
150 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | g_assert_cmpstr (fp_device_get_driver (tctx->device), ==, "virtual_image"); |
151 | 1 | } | |
152 | |||
153 | static void | ||
154 | 1 | test_device_get_device_id (void) | |
155 | { | ||
156 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
157 | |||
158 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
159 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | g_assert_cmpstr (fp_device_get_device_id (tctx->device), ==, "0"); |
160 | 1 | } | |
161 | |||
162 | static void | ||
163 | 1 | test_device_get_name (void) | |
164 | { | ||
165 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
166 | |||
167 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
168 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | g_assert_cmpstr (fp_device_get_name (tctx->device), ==, |
169 | "Virtual image device for debugging"); | ||
170 | 1 | } | |
171 | |||
172 | static void | ||
173 | 1 | test_device_get_scan_type (void) | |
174 | { | ||
175 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
176 | |||
177 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
178 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_cmpint (fp_device_get_scan_type (tctx->device), ==, FP_SCAN_TYPE_SWIPE); |
179 | 1 | } | |
180 | |||
181 | static void | ||
182 | 1 | test_device_get_finger_status (void) | |
183 | { | ||
184 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
185 | |||
186 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
187 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_cmpint (fp_device_get_finger_status (tctx->device), ==, FP_FINGER_STATUS_NONE); |
188 | 1 | } | |
189 | |||
190 | static void | ||
191 | 1 | test_device_get_nr_enroll_stages (void) | |
192 | { | ||
193 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
194 | |||
195 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
196 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_cmpuint (fp_device_get_nr_enroll_stages (tctx->device), ==, 5); |
197 | 1 | } | |
198 | |||
199 | static void | ||
200 | 1 | test_device_supports_identify (void) | |
201 | { | ||
202 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
203 | |||
204 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
205 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (fp_device_has_feature (tctx->device, FP_DEVICE_FEATURE_IDENTIFY)); |
206 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS | ||
207 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (fp_device_supports_identify (tctx->device)); |
208 | G_GNUC_END_IGNORE_DEPRECATIONS | ||
209 | 1 | } | |
210 | |||
211 | static void | ||
212 | 1 | test_device_supports_capture (void) | |
213 | { | ||
214 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
215 | |||
216 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
217 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (fp_device_has_feature (tctx->device, FP_DEVICE_FEATURE_CAPTURE)); |
218 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS | ||
219 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (fp_device_supports_capture (tctx->device)); |
220 | G_GNUC_END_IGNORE_DEPRECATIONS | ||
221 | 1 | } | |
222 | |||
223 | static void | ||
224 | 1 | test_device_has_storage (void) | |
225 | { | ||
226 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
227 | |||
228 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
229 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_false (fp_device_has_feature (tctx->device, FP_DEVICE_FEATURE_STORAGE)); |
230 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS | ||
231 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_false (fp_device_has_storage (tctx->device)); |
232 | G_GNUC_END_IGNORE_DEPRECATIONS | ||
233 | 1 | } | |
234 | |||
235 | static void | ||
236 | 1 | test_device_identify_cancelled (void) | |
237 | { | ||
238 | 2 | g_autoptr(GCancellable) cancellable = NULL; | |
239 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | g_autoptr(GPtrArray) prints = NULL; |
240 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | g_autoptr(GError) error = NULL; |
241 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); |
242 | |||
243 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
244 | |||
245 | 1 | prints = g_ptr_array_new (); | |
246 | 1 | cancellable = g_cancellable_new (); | |
247 | 1 | g_cancellable_cancel (cancellable); | |
248 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_false (fp_device_identify_sync (tctx->device, prints, cancellable, |
249 | NULL, NULL, NULL, NULL, &error)); | ||
250 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
1 | g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED); |
251 | 1 | } | |
252 | |||
253 | static void | ||
254 | 1 | test_device_identify_null_prints (void) | |
255 | { | ||
256 | 2 | g_autoptr(GError) error = NULL; | |
257 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); |
258 | |||
259 | 1 | fp_device_open_sync (tctx->device, NULL, NULL); | |
260 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_false (fp_device_identify_sync (tctx->device, NULL, NULL, NULL, |
261 | NULL, NULL, NULL, &error)); | ||
262 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
1 | g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID); |
263 | 1 | } | |
264 | |||
265 | int | ||
266 | 1 | main (int argc, char *argv[]) | |
267 | { | ||
268 | 1 | g_test_init (&argc, &argv, NULL); | |
269 | |||
270 | 1 | g_test_add_func ("/device/async/open", test_device_open_async); | |
271 | 1 | g_test_add_func ("/device/async/close", test_device_close_async); | |
272 | 1 | g_test_add_func ("/device/sync/open", test_device_open_sync); | |
273 | 1 | g_test_add_func ("/device/sync/open/notify", test_device_open_sync_notify); | |
274 | 1 | g_test_add_func ("/device/sync/close", test_device_close_sync); | |
275 | 1 | g_test_add_func ("/device/sync/close/notify", test_device_close_sync_notify); | |
276 | 1 | g_test_add_func ("/device/sync/get_driver", test_device_get_driver); | |
277 | 1 | g_test_add_func ("/device/sync/get_device_id", test_device_get_device_id); | |
278 | 1 | g_test_add_func ("/device/sync/get_name", test_device_get_name); | |
279 | 1 | g_test_add_func ("/device/sync/get_scan_type", test_device_get_scan_type); | |
280 | 1 | g_test_add_func ("/device/sync/get_finger_status", test_device_get_finger_status); | |
281 | 1 | g_test_add_func ("/device/sync/get_nr_enroll_stages", test_device_get_nr_enroll_stages); | |
282 | 1 | g_test_add_func ("/device/sync/supports_identify", test_device_supports_identify); | |
283 | 1 | g_test_add_func ("/device/sync/supports_capture", test_device_supports_capture); | |
284 | 1 | g_test_add_func ("/device/sync/has_storage", test_device_has_storage); | |
285 | 1 | g_test_add_func ("/device/sync/identify/cancelled", test_device_identify_cancelled); | |
286 | 1 | g_test_add_func ("/device/sync/identify/null-prints", test_device_identify_null_prints); | |
287 | |||
288 | 1 | return g_test_run (); | |
289 | } | ||
290 |