Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * FpContext 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 | #include "fpi-device.h" | ||
24 | |||
25 | static void | ||
26 | 1 | test_context_new (void) | |
27 | { | ||
28 | 1 | g_autoptr(FpContext) context = fp_context_new (); | |
29 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | g_assert_true (FP_CONTEXT (context)); |
30 | 1 | } | |
31 | |||
32 | static void | ||
33 | 1 | test_context_has_no_devices (void) | |
34 | { | ||
35 | 2 | g_autoptr(FpContext) context = NULL; | |
36 | 1 | GPtrArray *devices; | |
37 | |||
38 | 1 | context = fp_context_new (); | |
39 | 1 | devices = fp_context_get_devices (context); | |
40 | |||
41 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (devices); |
42 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | g_assert_cmpuint (devices->len, ==, 0); |
43 | 1 | } | |
44 | |||
45 | static void | ||
46 | 1 | test_context_has_virtual_device (void) | |
47 | { | ||
48 | 2 | g_autoptr(FpContext) context = NULL; | |
49 | 1 | FpDevice *virtual_device = NULL; | |
50 | 1 | GPtrArray *devices; | |
51 | 1 | unsigned int i; | |
52 | |||
53 | 1 | fpt_setup_virtual_device_environment (FPT_VIRTUAL_DEVICE_IMAGE); | |
54 | |||
55 | 1 | context = fp_context_new (); | |
56 | 1 | devices = fp_context_get_devices (context); | |
57 | |||
58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (devices); |
59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpuint (devices->len, ==, 1); |
60 | |||
61 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | for (i = 0; i < devices->len; ++i) |
62 | { | ||
63 | 1 | FpDevice *device = devices->pdata[i]; | |
64 | |||
65 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (g_strcmp0 (fp_device_get_driver (device), "virtual_image") == 0) |
66 | { | ||
67 | virtual_device = device; | ||
68 | break; | ||
69 | } | ||
70 | } | ||
71 | |||
72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (FP_IS_DEVICE (virtual_device)); |
73 | |||
74 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | fpt_teardown_virtual_device_environment (); |
75 | 1 | } | |
76 | |||
77 | static void | ||
78 | 1 | test_context_enumerates_new_devices (void) | |
79 | { | ||
80 | 2 | g_autoptr(FpContext) context = NULL; | |
81 | 1 | GPtrArray *devices; | |
82 | |||
83 | 1 | context = fp_context_new (); | |
84 | |||
85 | 1 | fpt_setup_virtual_device_environment (FPT_VIRTUAL_DEVICE_IMAGE); | |
86 | |||
87 | 1 | fp_context_enumerate (context); | |
88 | 1 | devices = fp_context_get_devices (context); | |
89 | |||
90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (devices); |
91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpuint (devices->len, ==, 1); |
92 | |||
93 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | fpt_teardown_virtual_device_environment (); |
94 | 1 | } | |
95 | |||
96 | #define DEV_REMOVED_CB 1 | ||
97 | #define CTX_DEVICE_REMOVED_CB 2 | ||
98 | |||
99 | static void | ||
100 | 5 | device_removed_cb (FpDevice *device, FptContext *tctx) | |
101 | { | ||
102 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | g_assert_nonnull (device); |
103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | g_assert_true (device == tctx->device); |
104 | |||
105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | g_assert_null (tctx->user_data); |
106 | 5 | tctx->user_data = GINT_TO_POINTER (DEV_REMOVED_CB); | |
107 | 5 | } | |
108 | |||
109 | static void | ||
110 | 5 | context_device_removed_cb (FpContext *ctx, FpDevice *device, FptContext *tctx) | |
111 | { | ||
112 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | g_assert_nonnull (device); |
113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | g_assert_true (device == tctx->device); |
114 | |||
115 | /* "device-removed" on context is always after "removed" on device */ | ||
116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
117 | 5 | tctx->user_data = GINT_TO_POINTER (CTX_DEVICE_REMOVED_CB); | |
118 | 5 | } | |
119 | |||
120 | static void | ||
121 | 1 | test_context_remove_device_closed (void) | |
122 | { | ||
123 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
124 | 1 | gboolean removed; | |
125 | |||
126 | 1 | tctx->user_data = NULL; | |
127 | 1 | g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx); | |
128 | 1 | g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx); | |
129 | |||
130 | /* Triggering remove on closed device. */ | ||
131 | 1 | fpi_device_remove (tctx->device); | |
132 | |||
133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
134 | 1 | g_object_get (tctx->device, "removed", &removed, NULL); | |
135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_true (removed); |
136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
137 | |||
138 | /* device-removed is dispatched from idle. */ | ||
139 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while (g_main_context_iteration (NULL, FALSE)) |
140 | { | ||
141 | 2 | } | |
142 | |||
143 | /* The device is now destroyed and device-removed was called. */ | ||
144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->device); |
145 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB); |
146 | |||
147 | 1 | fpt_teardown_virtual_device_environment (); | |
148 | 1 | } | |
149 | |||
150 | static void | ||
151 | 1 | close_done_cb (GObject *device, GAsyncResult *res, gpointer user_data) | |
152 | { | ||
153 | 2 | g_autoptr(FpPrint) print = NULL; | |
154 | 1 | GError **error = user_data; | |
155 | |||
156 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (error); |
157 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_false (fp_device_close_finish (FP_DEVICE (device), res, error)); |
158 | 1 | g_assert_null (print); | |
159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (*error); |
160 | 1 | } | |
161 | |||
162 | static void | ||
163 | 1 | test_context_remove_device_closing (void) | |
164 | { | ||
165 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
166 | 1 | g_autoptr(GError) close_error = NULL; | |
167 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | g_autoptr(GError) error = NULL; |
168 | 1 | gboolean removed; | |
169 | |||
170 | 1 | tctx->user_data = NULL; | |
171 | 1 | g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx); | |
172 | 1 | g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx); | |
173 | |||
174 | 1 | fp_device_open_sync (tctx->device, NULL, &error); | |
175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
176 | |||
177 | /* Triggering remove on device that is being closed. */ | ||
178 | 1 | fp_device_close (tctx->device, NULL, close_done_cb, &close_error); | |
179 | 1 | fpi_device_remove (tctx->device); | |
180 | |||
181 | /* Removed but not yet notified*/ | ||
182 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
183 | 1 | g_object_get (tctx->device, "removed", &removed, NULL); | |
184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_true (removed); |
185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->user_data); |
186 | |||
187 | /* Running the mainloop now will cause the close to fail eventually. */ | ||
188 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | while (!close_error) |
189 | 4 | g_main_context_iteration (NULL, TRUE); | |
190 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | g_assert_error (close_error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED); |
191 | |||
192 | /* Now the removed callback has been called already. */ | ||
193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
195 | |||
196 | /* While device-removed needs another idle iteration. */ | ||
197 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while (g_main_context_iteration (NULL, FALSE)) |
198 | { | ||
199 | 2 | } | |
200 | |||
201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->device); |
202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB); |
203 | |||
204 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | fpt_teardown_virtual_device_environment (); |
205 | 1 | } | |
206 | |||
207 | static void | ||
208 | 1 | test_context_remove_device_open (void) | |
209 | { | ||
210 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
211 | 1 | g_autoptr(GError) error = NULL; | |
212 | 1 | gboolean removed = FALSE; | |
213 | |||
214 | 1 | tctx->user_data = NULL; | |
215 | 1 | g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx); | |
216 | 1 | g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx); | |
217 | |||
218 | 1 | fp_device_open_sync (tctx->device, NULL, &error); | |
219 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
220 | |||
221 | /* Triggering remove on open device. */ | ||
222 | 1 | fpi_device_remove (tctx->device); | |
223 | |||
224 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
225 | 1 | g_object_get (tctx->device, "removed", &removed, NULL); | |
226 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_true (removed); |
227 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
228 | |||
229 | /* At this point, the "removed" cb on the device should have been called! | ||
230 | * Iterating the mainloop will not change anything. | ||
231 | */ | ||
232 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | while (g_main_context_iteration (NULL, FALSE)) |
233 | { | ||
234 | 1 | } | |
235 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
236 | |||
237 | /* On close, the device will be removed from the context, | ||
238 | * but only a main loop iteration later. */ | ||
239 | 1 | fp_device_close_sync (tctx->device, NULL, &error); | |
240 |
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_REMOVED); |
241 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
242 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
243 | |||
244 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while (g_main_context_iteration (NULL, FALSE)) |
245 | { | ||
246 | 2 | } | |
247 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->device); |
248 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB); |
249 | |||
250 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | fpt_teardown_virtual_device_environment (); |
251 | 1 | } | |
252 | |||
253 | static void | ||
254 | 1 | open_done_cb (GObject *device, GAsyncResult *res, gpointer user_data) | |
255 | { | ||
256 | 2 | g_autoptr(GError) error = NULL; | |
257 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_autoptr(FpPrint) print = NULL; |
258 | 1 | gboolean *data = user_data; | |
259 | |||
260 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | g_assert_true (fp_device_open_finish (FP_DEVICE (device), res, &error)); |
261 | 1 | g_assert_null (print); | |
262 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (error); |
263 | |||
264 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | *data = TRUE; |
265 | 1 | } | |
266 | |||
267 | static void | ||
268 | 1 | test_context_remove_device_opening (void) | |
269 | { | ||
270 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
271 | 1 | g_autoptr(GError) close_error = NULL; | |
272 | 1 | gboolean open_done = FALSE; | |
273 | 1 | gboolean removed; | |
274 | |||
275 | 1 | tctx->user_data = NULL; | |
276 | 1 | g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx); | |
277 | 1 | g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx); | |
278 | |||
279 | 1 | fp_device_open (tctx->device, NULL, open_done_cb, &open_done); | |
280 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_false (open_done); |
281 | |||
282 | 1 | fpi_device_remove (tctx->device); | |
283 | |||
284 | /* Removed but not yet notified*/ | ||
285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
286 | 1 | g_object_get (tctx->device, "removed", &removed, NULL); | |
287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_true (removed); |
288 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->user_data); |
289 | |||
290 | /* Running the mainloop now will cause the open to *succeed* despite removal! */ | ||
291 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | while (!open_done) |
292 | 3 | g_main_context_iteration (NULL, TRUE); | |
293 | |||
294 | /* Now the removed callback has been called already. */ | ||
295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
296 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
297 | |||
298 | 1 | fp_device_close_sync (tctx->device, NULL, &close_error); | |
299 |
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 (close_error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED); |
300 | |||
301 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
302 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
303 | |||
304 | /* The device-removed signal needs an idle iteration. */ | ||
305 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while (g_main_context_iteration (NULL, FALSE)) |
306 | { | ||
307 | 2 | } | |
308 | |||
309 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->device); |
310 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB); |
311 | |||
312 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | fpt_teardown_virtual_device_environment (); |
313 | 1 | } | |
314 | |||
315 | static void | ||
316 | 1 | enroll_done_cb (GObject *device, GAsyncResult *res, gpointer user_data) | |
317 | { | ||
318 | 2 | g_autoptr(FpPrint) print = NULL; | |
319 | 1 | GError **error = user_data; | |
320 | |||
321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (error); |
322 | 1 | print = fp_device_enroll_finish (FP_DEVICE (device), res, error); | |
323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (print); |
324 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | g_assert_nonnull (*error); |
325 | 1 | } | |
326 | |||
327 | static void | ||
328 | 1 | test_context_remove_device_active (void) | |
329 | { | ||
330 | 1 | g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_device (FPT_VIRTUAL_DEVICE_IMAGE); | |
331 | 1 | g_autoptr(GError) error = NULL; | |
332 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | g_autoptr(GCancellable) cancellable = NULL; |
333 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | g_autoptr(GError) enroll_error = NULL; |
334 | 1 | FpPrint *template; | |
335 | 1 | gboolean removed = FALSE; | |
336 | |||
337 | 1 | tctx->user_data = NULL; | |
338 | 1 | g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx); | |
339 | 1 | g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx); | |
340 | |||
341 | 1 | fp_device_open_sync (tctx->device, NULL, &error); | |
342 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_no_error (error); |
343 | |||
344 | /* Start an enroll that we can cancel/fail later. | ||
345 | * NOTE: We need to cancel explicitly as remove() does not trigger a failure! | ||
346 | */ | ||
347 | 1 | template = fp_print_new (tctx->device); | |
348 | 1 | cancellable = g_cancellable_new (); | |
349 | 1 | fp_device_enroll (tctx->device, template, cancellable, NULL, NULL, NULL, enroll_done_cb, &enroll_error); | |
350 | |||
351 | /* Triggering remove on active device. */ | ||
352 | 1 | fpi_device_remove (tctx->device); | |
353 | |||
354 | /* The removed property has changed, but the cb has *not* been called yet. */ | ||
355 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
356 | 1 | g_object_get (tctx->device, "removed", &removed, NULL); | |
357 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_true (removed); |
358 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->user_data); |
359 | |||
360 | /* Running the mainloop now will cause the operation to fail eventually. */ | ||
361 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while (!enroll_error) |
362 | 1 | g_main_context_iteration (NULL, TRUE); | |
363 | |||
364 | /* The virtual image device throws an PROTO error internally, | ||
365 | * but we should still receive a REMOVED error here. */ | ||
366 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | g_assert_error (enroll_error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED); |
367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
368 | |||
369 | /* Now we close the device, state remains unchanged mostly. */ | ||
370 | 1 | fp_device_close_sync (tctx->device, NULL, &error); | |
371 |
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_REMOVED); |
372 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_nonnull (tctx->device); |
373 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); |
374 | |||
375 | /* And "device-removed" is called */ | ||
376 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | while (g_main_context_iteration (NULL, FALSE)) |
377 | { | ||
378 | 2 | } | |
379 | |||
380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_null (tctx->device); |
381 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB); |
382 | |||
383 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | fpt_teardown_virtual_device_environment (); |
384 | 1 | } | |
385 | |||
386 | int | ||
387 | 1 | main (int argc, char *argv[]) | |
388 | { | ||
389 | 1 | g_test_init (&argc, &argv, NULL); | |
390 | |||
391 | 1 | g_test_add_func ("/context/new", test_context_new); | |
392 | 1 | g_test_add_func ("/context/no-devices", test_context_has_no_devices); | |
393 | 1 | g_test_add_func ("/context/has-virtual-device", test_context_has_virtual_device); | |
394 | 1 | g_test_add_func ("/context/enumerates-new-devices", test_context_enumerates_new_devices); | |
395 | 1 | g_test_add_func ("/context/remove-device-closed", test_context_remove_device_closed); | |
396 | 1 | g_test_add_func ("/context/remove-device-closing", test_context_remove_device_closing); | |
397 | 1 | g_test_add_func ("/context/remove-device-open", test_context_remove_device_open); | |
398 | 1 | g_test_add_func ("/context/remove-device-opening", test_context_remove_device_opening); | |
399 | 1 | g_test_add_func ("/context/remove-device-active", test_context_remove_device_active); | |
400 | |||
401 | 1 | return g_test_run (); | |
402 | } | ||
403 |