Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Virtual driver for device debugging | ||
3 | * | ||
4 | * Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com> | ||
5 | * | ||
6 | * This library is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This library is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #define FP_COMPONENT "fake_test_dev" | ||
22 | |||
23 | #include "fpi-log.h" | ||
24 | #include "test-device-fake.h" | ||
25 | |||
26 |
4/5✓ Branch 0 taken 2 times.
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
300 | G_DEFINE_TYPE (FpiDeviceFake, fpi_device_fake, FP_TYPE_DEVICE) |
27 | |||
28 | static const FpIdEntry driver_ids[] = { | ||
29 | { .virtual_envvar = "FP_VIRTUAL_FAKE_DEVICE" }, | ||
30 | { .virtual_envvar = NULL } | ||
31 | }; | ||
32 | |||
33 | static void | ||
34 | 155 | (debug_action) (FpDevice * device, | |
35 | const gchar *func) | ||
36 | { | ||
37 | 310 | g_autofree char *action_str = NULL; | |
38 | |||
39 | 155 | action_str = g_enum_to_string (FPI_TYPE_DEVICE_ACTION, | |
40 | 155 | fpi_device_get_current_action (device)); | |
41 | |||
42 | 155 | fp_dbg ("%s: Device %s in action %s\n", | |
43 | func, fp_device_get_name (device), action_str); | ||
44 | 155 | } | |
45 | |||
46 | #define debug_action(d) (debug_action) ((d), G_STRFUNC) | ||
47 | |||
48 | static void | ||
49 | 3 | fpi_device_fake_probe (FpDevice *device) | |
50 | { | ||
51 | 3 | FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device); | |
52 | 3 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
53 | |||
54 | 3 | debug_action (device); | |
55 | 3 | fake_dev->last_called_function = fpi_device_fake_probe; | |
56 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_PROBE); |
57 | |||
58 | 3 | fpi_device_update_features (device, fake_dev->probe_features_update, fake_dev->probe_features_value); | |
59 | |||
60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (fake_dev->return_action_error) |
61 | { | ||
62 | ✗ | fpi_device_action_error (device, fake_dev->ret_error); | |
63 | ✗ | return; | |
64 | } | ||
65 | |||
66 | 3 | fpi_device_probe_complete (device, dev_class->id, dev_class->full_name, | |
67 | fake_dev->ret_error); | ||
68 | } | ||
69 | |||
70 | static void | ||
71 | 50 | fpi_device_fake_open (FpDevice *device) | |
72 | { | ||
73 | 50 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
74 | |||
75 | 50 | debug_action (device); | |
76 | 50 | fake_dev->last_called_function = fpi_device_fake_open; | |
77 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
|
50 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_OPEN); |
78 | |||
79 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 48 times.
|
50 | if (fake_dev->return_action_error) |
80 | { | ||
81 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
82 | 2 | return; | |
83 | } | ||
84 | |||
85 | 48 | fpi_device_open_complete (device, fake_dev->ret_error); | |
86 | } | ||
87 | |||
88 | static void | ||
89 | 52 | fpi_device_fake_close (FpDevice *device) | |
90 | { | ||
91 | 52 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
92 | |||
93 | 52 | debug_action (device); | |
94 | 52 | fake_dev->last_called_function = fpi_device_fake_close; | |
95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
|
52 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_CLOSE); |
96 | |||
97 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 50 times.
|
52 | if (fake_dev->return_action_error) |
98 | { | ||
99 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
100 | 2 | return; | |
101 | } | ||
102 | |||
103 | 50 | fpi_device_close_complete (device, fake_dev->ret_error); | |
104 | } | ||
105 | |||
106 | static void | ||
107 | 6 | fpi_device_fake_enroll (FpDevice *device) | |
108 | { | ||
109 | 6 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
110 | 6 | FpPrint *print = fake_dev->ret_print; | |
111 | |||
112 | 6 | debug_action (device); | |
113 | 6 | fake_dev->last_called_function = fpi_device_fake_enroll; | |
114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_ENROLL); |
115 | |||
116 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if (fake_dev->return_action_error) |
117 | { | ||
118 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
119 | 2 | return; | |
120 | } | ||
121 | |||
122 | 4 | fpi_device_get_enroll_data (device, (FpPrint **) &fake_dev->action_data); | |
123 | |||
124 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
|
4 | if (!print && !fake_dev->ret_error) |
125 | { | ||
126 | 2 | fpi_device_get_enroll_data (device, &print); | |
127 | 2 | fpi_print_set_type (print, FPI_PRINT_RAW); | |
128 | } | ||
129 | |||
130 | 4 | fpi_device_enroll_complete (device, | |
131 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | print ? g_object_ref (print) : NULL, |
132 | fake_dev->ret_error); | ||
133 | } | ||
134 | |||
135 | static void | ||
136 | 7 | fpi_device_fake_verify (FpDevice *device) | |
137 | { | ||
138 | 7 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
139 | 7 | FpPrint *print = fake_dev->ret_print; | |
140 | |||
141 | 7 | debug_action (device); | |
142 | 7 | fake_dev->last_called_function = fpi_device_fake_verify; | |
143 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
|
7 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_VERIFY); |
144 | |||
145 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | if (fake_dev->return_action_error) |
146 | { | ||
147 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
148 | 2 | return; | |
149 | } | ||
150 | |||
151 | 5 | fpi_device_get_verify_data (device, (FpPrint **) &fake_dev->action_data); | |
152 | |||
153 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
|
5 | if (!print && !fake_dev->ret_error) |
154 | 3 | fpi_device_get_verify_data (device, &print); | |
155 | |||
156 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
|
5 | if (!fake_dev->ret_error || fake_dev->ret_error->domain == FP_DEVICE_RETRY) |
157 | { | ||
158 | 4 | fpi_device_verify_report (device, fake_dev->ret_result, print, fake_dev->ret_error); | |
159 | 4 | fpi_device_verify_complete (device, NULL); | |
160 | } | ||
161 | else | ||
162 | { | ||
163 | 1 | fpi_device_verify_complete (device, fake_dev->ret_error); | |
164 | } | ||
165 | } | ||
166 | |||
167 | static void | ||
168 | 10 | fpi_device_fake_identify (FpDevice *device) | |
169 | { | ||
170 | 10 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
171 | 10 | FpPrint *match = fake_dev->ret_match; | |
172 | |||
173 | 10 | debug_action (device); | |
174 | 10 | fake_dev->last_called_function = fpi_device_fake_identify; | |
175 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_IDENTIFY); |
176 | |||
177 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
|
10 | if (fake_dev->return_action_error) |
178 | { | ||
179 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
180 | 2 | return; | |
181 | } | ||
182 | |||
183 | 8 | fpi_device_get_identify_data (device, (GPtrArray **) &fake_dev->action_data); | |
184 | |||
185 |
3/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
|
8 | if (!match && !fake_dev->ret_error) |
186 | { | ||
187 | 4 | GPtrArray *prints; | |
188 | 4 | unsigned int i; | |
189 | |||
190 | 4 | fpi_device_get_identify_data (device, &prints); | |
191 | |||
192 |
3/4✓ Branch 1 taken 1439 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1438 times.
✓ Branch 4 taken 1 times.
|
1443 | for (i = 0; prints && i < prints->len; ++i) |
193 | { | ||
194 | 1438 | FpPrint *print = g_ptr_array_index (prints, i); | |
195 | |||
196 |
2/2✓ Branch 2 taken 1435 times.
✓ Branch 3 taken 3 times.
|
1438 | if (g_strcmp0 (fp_print_get_description (print), "fake-verified") == 0) |
197 | { | ||
198 | match = print; | ||
199 | break; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 |
4/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 3 times.
|
8 | if (!fake_dev->ret_error || fake_dev->ret_error->domain == FP_DEVICE_RETRY) |
205 | { | ||
206 | 5 | fpi_device_identify_report (device, match, fake_dev->ret_print, fake_dev->ret_error); | |
207 | 5 | fpi_device_identify_complete (device, NULL); | |
208 | } | ||
209 | else | ||
210 | { | ||
211 | 3 | fpi_device_identify_complete (device, fake_dev->ret_error); | |
212 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | g_clear_object (&fake_dev->ret_print); |
213 | } | ||
214 | } | ||
215 | |||
216 | static void | ||
217 | 4 | fpi_device_fake_capture (FpDevice *device) | |
218 | { | ||
219 | 4 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
220 | 4 | gboolean wait_for_finger; | |
221 | |||
222 | 4 | debug_action (device); | |
223 | 4 | fake_dev->last_called_function = fpi_device_fake_capture; | |
224 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_CAPTURE); |
225 | |||
226 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (fake_dev->return_action_error) |
227 | { | ||
228 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
229 | 2 | return; | |
230 | } | ||
231 | |||
232 | 2 | fpi_device_get_capture_data (device, &wait_for_finger); | |
233 | 2 | fake_dev->action_data = GINT_TO_POINTER (wait_for_finger); | |
234 | 2 | fpi_device_capture_complete (device, fake_dev->ret_image, fake_dev->ret_error); | |
235 | } | ||
236 | |||
237 | static void | ||
238 | 4 | fpi_device_fake_list (FpDevice *device) | |
239 | { | ||
240 | 4 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
241 | |||
242 | 4 | debug_action (device); | |
243 | 4 | fake_dev->last_called_function = fpi_device_fake_list; | |
244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_LIST); |
245 | |||
246 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (fake_dev->return_action_error) |
247 | { | ||
248 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
249 | 2 | return; | |
250 | } | ||
251 | |||
252 | 2 | fpi_device_list_complete (device, fake_dev->ret_list, fake_dev->ret_error); | |
253 | } | ||
254 | |||
255 | static void | ||
256 | 6 | fpi_device_fake_delete (FpDevice *device) | |
257 | { | ||
258 | 6 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
259 | |||
260 | 6 | debug_action (device); | |
261 | 6 | fake_dev->last_called_function = fpi_device_fake_delete; | |
262 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_DELETE); |
263 | |||
264 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if (fake_dev->return_action_error) |
265 | { | ||
266 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
267 | 2 | return; | |
268 | } | ||
269 | |||
270 | 4 | fpi_device_get_delete_data (device, (FpPrint **) (&fake_dev->action_data)); | |
271 | 4 | fpi_device_delete_complete (device, fake_dev->ret_error); | |
272 | } | ||
273 | |||
274 | static void | ||
275 | 4 | fpi_device_fake_clear_storage (FpDevice *device) | |
276 | { | ||
277 | 4 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
278 | |||
279 | 4 | debug_action (device); | |
280 | 4 | fake_dev->last_called_function = fpi_device_fake_clear_storage; | |
281 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_CLEAR_STORAGE); |
282 | |||
283 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (fake_dev->return_action_error) |
284 | { | ||
285 | 2 | fpi_device_action_error (device, fake_dev->ret_error); | |
286 | 2 | return; | |
287 | } | ||
288 | |||
289 | 2 | fpi_device_clear_storage_complete (device, fake_dev->ret_error); | |
290 | } | ||
291 | |||
292 | static void | ||
293 | 3 | fpi_device_fake_cancel (FpDevice *device) | |
294 | { | ||
295 | 3 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
296 | |||
297 | 3 | debug_action (device); | |
298 | 3 | fake_dev->last_called_function = fpi_device_fake_cancel; | |
299 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | g_assert_cmpuint (fpi_device_get_current_action (device), !=, FPI_DEVICE_ACTION_NONE); |
300 | 3 | } | |
301 | |||
302 | static void | ||
303 | 4 | fpi_device_fake_suspend (FpDevice *device) | |
304 | { | ||
305 | 4 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
306 | |||
307 | 4 | debug_action (device); | |
308 | 4 | fake_dev->last_called_function = fpi_device_fake_suspend; | |
309 | |||
310 | 4 | fpi_device_suspend_complete (device, g_steal_pointer (&fake_dev->ret_suspend)); | |
311 | 4 | } | |
312 | |||
313 | static void | ||
314 | 2 | fpi_device_fake_resume (FpDevice *device) | |
315 | { | ||
316 | 2 | FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device); | |
317 | |||
318 | 2 | debug_action (device); | |
319 | 2 | fake_dev->last_called_function = fpi_device_fake_resume; | |
320 | |||
321 | 2 | fpi_device_resume_complete (device, g_steal_pointer (&fake_dev->ret_resume)); | |
322 | 2 | } | |
323 | |||
324 | static void | ||
325 | 94 | fpi_device_fake_init (FpiDeviceFake *self) | |
326 | { | ||
327 | 94 | } | |
328 | |||
329 | static void | ||
330 | 2 | fpi_device_fake_class_init (FpiDeviceFakeClass *klass) | |
331 | { | ||
332 | 2 | FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass); | |
333 | |||
334 | 2 | dev_class->id = FP_COMPONENT; | |
335 | 2 | dev_class->full_name = "Virtual device for debugging"; | |
336 | 2 | dev_class->type = FP_DEVICE_TYPE_VIRTUAL; | |
337 | 2 | dev_class->id_table = driver_ids; | |
338 | 2 | dev_class->nr_enroll_stages = 5; | |
339 | 2 | dev_class->scan_type = FP_SCAN_TYPE_PRESS; | |
340 | |||
341 | 2 | dev_class->probe = fpi_device_fake_probe; | |
342 | 2 | dev_class->open = fpi_device_fake_open; | |
343 | 2 | dev_class->close = fpi_device_fake_close; | |
344 | 2 | dev_class->enroll = fpi_device_fake_enroll; | |
345 | 2 | dev_class->verify = fpi_device_fake_verify; | |
346 | 2 | dev_class->identify = fpi_device_fake_identify; | |
347 | 2 | dev_class->capture = fpi_device_fake_capture; | |
348 | 2 | dev_class->list = fpi_device_fake_list; | |
349 | 2 | dev_class->delete = fpi_device_fake_delete; | |
350 | 2 | dev_class->cancel = fpi_device_fake_cancel; | |
351 | 2 | dev_class->clear_storage = fpi_device_fake_clear_storage; | |
352 | 2 | dev_class->suspend = fpi_device_fake_suspend; | |
353 | 2 | dev_class->resume = fpi_device_fake_resume; | |
354 | |||
355 | 2 | fpi_device_class_auto_initialize_features (dev_class); | |
356 | 2 | } | |
357 |