1 /*
2 * Copyright © 2013 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "config.h"
25 #include "litest-config.h"
26
27 #ifndef LITEST_H
28 #define LITEST_H
29
30 #include <stdbool.h>
31 #include <stdarg.h>
32 #include <check.h>
33 #include <libevdev/libevdev.h>
34 #include <libevdev/libevdev-uinput.h>
35 #include <libinput.h>
36 #include <math.h>
37
38 #include "check-double-macros.h"
39
40 #include "libinput-private-config.h"
41 #include "libinput-util.h"
42 #include "quirks.h"
43
44 struct test_device {
45 const char *name;
46 struct litest_test_device *device;
47 } __attribute__((aligned(16)));
48
49 #define TEST_DEVICE(name, ...) \
50 static struct litest_test_device _device; \
51 \
52 static void _setup(void) { \
53 struct litest_device *d = litest_create_device(_device.type); \
54 litest_set_current_device(d); \
55 } \
56 \
57 static const struct test_device _test_device \
58 __attribute__ ((used)) \
59 __attribute__ ((section ("test_section"))) = { \
60 name, &_device \
61 }; \
62 static struct litest_test_device _device = { \
63 .setup = _setup, \
64 .shortname = name, \
65 __VA_ARGS__ \
66 };
67
68 struct test_collection {
69 const char *name;
70 void (*setup)(void);
71 } __attribute__((aligned(16)));
72
73 #define TEST_COLLECTION(name) \
74 static void (name##_setup)(void); \
75 static const struct test_collection _test_collection \
76 __attribute__ ((used)) \
77 __attribute__ ((section ("test_collection_section"))) = { \
78 #name, name##_setup \
79 }; \
80 static void (name##_setup)(void)
81
82
83 /**
84 * litest itself needs the user_data to store some test-suite-specific
85 * information. Tests must not override this pointer, any data they need
86 * they can hang off the private pointer in this struct.
87 */
88 struct litest_user_data {
89 void *private;
90 };
91
92 void
93 litest_fail_condition(const char *file,
94 int line,
95 const char *func,
96 const char *condition,
97 const char *message,
98 ...);
99 void
100 litest_fail_comparison_int(const char *file,
101 int line,
102 const char *func,
103 const char *operator,
104 int a,
105 int b,
106 const char *astr,
107 const char *bstr);
108 void
109 litest_fail_comparison_double(const char *file,
110 int line,
111 const char *func,
112 const char *operator,
113 double a,
114 double b,
115 const char *astr,
116 const char *bstr);
117 void
118 litest_fail_comparison_ptr(const char *file,
119 int line,
120 const char *func,
121 const char *comparison);
122
123 #define litest_assert(cond) \
124 do { \
125 if (!(cond)) \
126 litest_fail_condition(__FILE__, __LINE__, __func__, \
127 #cond, NULL); \
128 } while(0)
129
130 #define litest_assert_msg(cond, ...) \
131 do { \
132 if (!(cond)) \
133 litest_fail_condition(__FILE__, __LINE__, __func__, \
134 #cond, __VA_ARGS__); \
135 } while(0)
136
137 #define litest_abort_msg(...) \
138 litest_fail_condition(__FILE__, __LINE__, __func__, \
139 "aborting", __VA_ARGS__); \
140
141 #define litest_assert_notnull(cond) \
142 do { \
143 if ((cond) == NULL) \
144 litest_fail_condition(__FILE__, __LINE__, __func__, \
145 #cond, " expected to be not NULL\n"); \
146 } while(0)
147
148 #define litest_assert_comparison_int_(a_, op_, b_) \
149 do { \
150 __typeof__(a_) _a = a_; \
151 __typeof__(b_) _b = b_; \
152 if (trunc(_a) != _a || trunc(_b) != _b) \
153 litest_abort_msg("litest_assert_int_* used for non-integer value\n"); \
154 if (!((_a) op_ (_b))) \
155 litest_fail_comparison_int(__FILE__, __LINE__, __func__,\
156 #op_, _a, _b, \
157 #a_, #b_); \
158 } while(0)
159
160 #define litest_assert_int_eq(a_, b_) \
161 litest_assert_comparison_int_(a_, ==, b_)
162
163 #define litest_assert_int_ne(a_, b_) \
164 litest_assert_comparison_int_(a_, !=, b_)
165
166 #define litest_assert_int_lt(a_, b_) \
167 litest_assert_comparison_int_(a_, <, b_)
168
169 #define litest_assert_int_le(a_, b_) \
170 litest_assert_comparison_int_(a_, <=, b_)
171
172 #define litest_assert_int_ge(a_, b_) \
173 litest_assert_comparison_int_(a_, >=, b_)
174
175 #define litest_assert_int_gt(a_, b_) \
176 litest_assert_comparison_int_(a_, >, b_)
177
178 #define litest_assert_comparison_ptr_(a_, op_, b_) \
179 do { \
180 __typeof__(a_) _a = a_; \
181 __typeof__(b_) _b = b_; \
182 if (!((_a) op_ (_b))) \
183 litest_fail_comparison_ptr(__FILE__, __LINE__, __func__,\
184 #a_ " " #op_ " " #b_); \
185 } while(0)
186
187 #define litest_assert_comparison_double_(a_, op_, b_) \
188 do { \
189 const double EPSILON = 1.0/256; \
190 __typeof__(a_) _a = a_; \
191 __typeof__(b_) _b = b_; \
192 if (!((_a) op_ (_b)) && fabs((_a) - (_b)) > EPSILON) \
193 litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
194 #op_, _a, _b, \
195 #a_, #b_); \
196 } while(0)
197
198 #define litest_assert_ptr_eq(a_, b_) \
199 litest_assert_comparison_ptr_(a_, ==, b_)
200
201 #define litest_assert_ptr_ne(a_, b_) \
202 litest_assert_comparison_ptr_(a_, !=, b_)
203
204 #define litest_assert_ptr_null(a_) \
205 litest_assert_comparison_ptr_(a_, ==, NULL)
206
207 #define litest_assert_ptr_notnull(a_) \
208 litest_assert_comparison_ptr_(a_, !=, NULL)
209
210 #define litest_assert_double_eq(a_, b_)\
211 litest_assert_comparison_double_((a_), ==, (b_))
212
213 #define litest_assert_double_ne(a_, b_)\
214 litest_assert_comparison_double_((a_), !=, (b_))
215
216 #define litest_assert_double_lt(a_, b_)\
217 litest_assert_comparison_double_((a_), <, (b_))
218
219 #define litest_assert_double_le(a_, b_)\
220 litest_assert_comparison_double_((a_), <=, (b_))
221
222 #define litest_assert_double_gt(a_, b_)\
223 litest_assert_comparison_double_((a_), >, (b_))
224
225 #define litest_assert_double_ge(a_, b_)\
226 litest_assert_comparison_double_((a_), >=, (b_))
227
228 enum litest_device_type {
229 LITEST_NO_DEVICE = -1,
230 LITEST_SYNAPTICS_CLICKPAD_X220 = -1000,
231 LITEST_SYNAPTICS_TOUCHPAD,
232 LITEST_SYNAPTICS_TOPBUTTONPAD,
233 LITEST_BCM5974,
234 LITEST_KEYBOARD,
235 LITEST_TRACKPOINT,
236 LITEST_MOUSE,
237 LITEST_WACOM_TOUCH,
238 LITEST_ALPS_SEMI_MT,
239 LITEST_GENERIC_SINGLETOUCH,
240 LITEST_MS_SURFACE_COVER,
241 LITEST_QEMU_TABLET,
242 LITEST_XEN_VIRTUAL_POINTER,
243 LITEST_VMWARE_VIRTMOUSE,
244 LITEST_SYNAPTICS_HOVER_SEMI_MT,
245 LITEST_SYNAPTICS_TRACKPOINT_BUTTONS,
246 LITEST_PROTOCOL_A_SCREEN,
247 LITEST_WACOM_FINGER,
248 LITEST_KEYBOARD_BLACKWIDOW,
249 LITEST_WHEEL_ONLY,
250 LITEST_MOUSE_ROCCAT,
251 LITEST_LOGITECH_TRACKBALL,
252 LITEST_ATMEL_HOVER,
253 LITEST_ALPS_DUALPOINT,
254 LITEST_MOUSE_LOW_DPI,
255 LITEST_GENERIC_MULTITOUCH_SCREEN,
256 LITEST_NEXUS4_TOUCH_SCREEN,
257 LITEST_MAGIC_TRACKPAD,
258 LITEST_ELANTECH_TOUCHPAD,
259 LITEST_MOUSE_GLADIUS,
260 LITEST_MOUSE_WHEEL_CLICK_ANGLE,
261 LITEST_APPLE_KEYBOARD,
262 LITEST_ANKER_MOUSE_KBD,
263 LITEST_WACOM_BAMBOO,
264 LITEST_WACOM_CINTIQ,
265 LITEST_WACOM_INTUOS,
266 LITEST_WACOM_ISDV4,
267 LITEST_WALTOP,
268 LITEST_HUION_TABLET,
269 LITEST_CYBORG_RAT,
270 LITEST_YUBIKEY,
271 LITEST_SYNAPTICS_I2C,
272 LITEST_WACOM_CINTIQ_24HD,
273 LITEST_MULTITOUCH_FUZZ_SCREEN,
274 LITEST_WACOM_INTUOS3_PAD,
275 LITEST_WACOM_INTUOS5_PAD,
276 LITEST_KEYBOARD_ALL_CODES,
277 LITEST_MAGICMOUSE,
278 LITEST_WACOM_EKR,
279 LITEST_WACOM_CINTIQ_24HDT_PAD,
280 LITEST_WACOM_CINTIQ_13HDT_PEN,
281 LITEST_WACOM_CINTIQ_13HDT_PAD,
282 LITEST_WACOM_CINTIQ_13HDT_FINGER,
283 LITEST_WACOM_CINTIQ_PRO16_PAD,
284 LITEST_WACOM_CINTIQ_PRO16_PEN,
285 LITEST_WACOM_CINTIQ_PRO16_FINGER,
286 LITEST_WACOM_HID4800_PEN,
287 LITEST_MOUSE_WHEEL_CLICK_COUNT,
288 LITEST_CALIBRATED_TOUCHSCREEN,
289 LITEST_ACER_HAWAII_KEYBOARD,
290 LITEST_ACER_HAWAII_TOUCHPAD,
291 LITEST_SYNAPTICS_RMI4,
292 LITEST_MOUSE_WHEEL_TILT,
293 LITEST_LID_SWITCH,
294 LITEST_LID_SWITCH_SURFACE3,
295 LITEST_APPLETOUCH,
296 LITEST_GPIO_KEYS,
297 LITEST_IGNORED_MOUSE,
298 LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD,
299 LITEST_THINKPAD_EXTRABUTTONS,
300 LITEST_UCLOGIC_TABLET,
301 LITEST_KEYBOARD_BLADE_STEALTH,
302 LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH,
303 LITEST_WACOM_BAMBOO_2FG_PAD,
304 LITEST_WACOM_BAMBOO_2FG_PEN,
305 LITEST_WACOM_BAMBOO_2FG_FINGER,
306 LITEST_HP_WMI_HOTKEYS,
307 LITEST_MS_NANO_TRANSCEIVER_MOUSE,
308 LITEST_AIPTEK,
309 LITEST_TOUCHSCREEN_INVALID_RANGE,
310 LITEST_TOUCHSCREEN_MT_TOOL_TYPE,
311 LITEST_DELL_CANVAS_TOTEM,
312 LITEST_DELL_CANVAS_TOTEM_TOUCH,
313 LITEST_WACOM_ISDV4_4200_PEN,
314 LITEST_ALPS_3FG,
315 LITEST_ELAN_TABLET,
316 LITEST_ABSINFO_OVERRIDE,
317 LITEST_TABLET_MODE_UNRELIABLE,
318 LITEST_KEYBOARD_LOGITECH_MEDIA_KEYBOARD_ELITE,
319 LITEST_SONY_VAIO_KEYS,
320 LITEST_KEYBOARD_QUIRKED,
321 LITEST_SYNAPTICS_PRESSUREPAD,
322 LITEST_GENERIC_PRESSUREPAD,
323 LITEST_MOUSE_FORMAT_STRING,
324 };
325
326 #define LITEST_DEVICELESS -2
327 #define LITEST_DISABLE_DEVICE -1
328 #define LITEST_ANY 0
329 #define LITEST_TOUCHPAD bit(0)
330 #define LITEST_CLICKPAD bit(1)
331 #define LITEST_BUTTON bit(2)
332 #define LITEST_KEYS bit(3)
333 #define LITEST_RELATIVE bit(4)
334 #define LITEST_WHEEL bit(5)
335 #define LITEST_TOUCH bit(6)
336 #define LITEST_SINGLE_TOUCH bit(7)
337 #define LITEST_APPLE_CLICKPAD bit(8)
338 #define LITEST_TOPBUTTONPAD bit(9)
339 #define LITEST_SEMI_MT bit(10)
340 #define LITEST_POINTINGSTICK bit(11)
341 #define LITEST_FAKE_MT bit(12)
342 #define LITEST_ABSOLUTE bit(13)
343 #define LITEST_PROTOCOL_A bit(14)
344 #define LITEST_HOVER bit(15)
345 #define LITEST_ELLIPSE bit(16)
346 #define LITEST_TABLET bit(17)
347 #define LITEST_DISTANCE bit(18)
348 #define LITEST_TOOL_SERIAL bit(19)
349 #define LITEST_TILT bit(20)
350 #define LITEST_TABLET_PAD bit(21)
351 #define LITEST_RING bit(22)
352 #define LITEST_STRIP bit(23)
353 #define LITEST_TRACKBALL bit(24)
354 #define LITEST_LEDS bit(25)
355 #define LITEST_SWITCH bit(26)
356 #define LITEST_IGNORED bit(27)
357 #define LITEST_NO_DEBOUNCE bit(28)
358 #define LITEST_TOOL_MOUSE bit(29)
359 #define LITEST_DIRECT bit(30)
360 #define LITEST_TOTEM bit(31)
361 #define LITEST_FORCED_PROXOUT bit(32)
362
363 /* this is a semi-mt device, so we keep track of the touches that the tests
364 * send and modify them so that the first touch is always slot 0 and sends
365 * the top-left of the bounding box, the second is always slot 1 and sends
366 * the bottom-right of the bounding box.
367 * Lifting any of two fingers terminates slot 1
368 */
369 struct litest_semi_mt {
370 bool is_semi_mt;
371
372 int tracking_id;
373 /* The actual touches requested by the test for the two slots
374 * in the 0..100 range used by litest */
375 struct {
376 double x, y;
377 } touches[2];
378 };
379
380 struct litest_device {
381 enum litest_device_type which;
382 struct libevdev *evdev;
383 struct libevdev_uinput *uinput;
384 struct libinput *libinput;
385 struct quirks *quirks;
386 bool owns_context;
387 struct libinput_device *libinput_device;
388 struct litest_device_interface *interface;
389
390 int ntouches_down;
391 int skip_ev_syn;
392 struct litest_semi_mt semi_mt; /** only used for semi-mt device */
393
394 void *private; /* device-specific data */
395 };
396
397 struct axis_replacement {
398 int32_t evcode;
399 double value;
400 };
401
402 /**
403 * Same as litest_axis_set_value but allows for ranges outside 0..100%
404 */
405 static inline void
litest_axis_set_value_unchecked(struct axis_replacement * axes,int code,double value)406 litest_axis_set_value_unchecked(struct axis_replacement *axes, int code, double value)
407 {
408 while (axes->evcode != -1) {
409 if (axes->evcode == code) {
410 axes->value = value;
411 return;
412 }
413 axes++;
414 }
415
416 litest_abort_msg("Missing axis code %d\n", code);
417 }
418
419 /**
420 * Takes a value in percent and sets the given axis to that code.
421 */
422 static inline void
litest_axis_set_value(struct axis_replacement * axes,int code,double value)423 litest_axis_set_value(struct axis_replacement *axes, int code, double value)
424 {
425 litest_assert_double_ge(value, 0.0);
426 litest_assert_double_le(value, 100.0);
427
428 litest_axis_set_value_unchecked(axes, code, value);
429 }
430
431 /* A loop range, resolves to:
432 for (i = lower; i < upper; i++)
433 */
434 struct range {
435 int lower; /* inclusive */
436 int upper; /* exclusive */
437 };
438
439 struct libinput *litest_create_context(void);
440 void litest_destroy_context(struct libinput *li);
441 void litest_disable_log_handler(struct libinput *libinput);
442 void litest_restore_log_handler(struct libinput *libinput);
443 void litest_set_log_handler_bug(struct libinput *libinput);
444
445 #define litest_add(func_, ...) \
446 _litest_add(__FILE__, #func_, func_, __VA_ARGS__)
447 #define litest_add_ranged(func_, ...) \
448 _litest_add_ranged(__FILE__, #func_, func_, __VA_ARGS__)
449 #define litest_add_for_device(func_, ...) \
450 _litest_add_for_device(__FILE__, #func_, func_, __VA_ARGS__)
451 #define litest_add_ranged_for_device(func_, ...) \
452 _litest_add_ranged_for_device(__FILE__, #func_, func_, __VA_ARGS__)
453 #define litest_add_no_device(func_) \
454 _litest_add_no_device(__FILE__, #func_, func_)
455 #define litest_add_ranged_no_device(func_, ...) \
456 _litest_add_ranged_no_device(__FILE__, #func_, func_, __VA_ARGS__)
457 #define litest_add_deviceless(func_) \
458 _litest_add_deviceless(__FILE__, #func_, func_)
459
460 void
461 _litest_add(const char *name,
462 const char *funcname,
463 const void *func,
464 int64_t required_feature,
465 int64_t excluded_feature);
466 void
467 _litest_add_ranged(const char *name,
468 const char *funcname,
469 const void *func,
470 int64_t required,
471 int64_t excluded,
472 const struct range *range);
473 void
474 _litest_add_for_device(const char *name,
475 const char *funcname,
476 const void *func,
477 enum litest_device_type type);
478 void
479 _litest_add_ranged_for_device(const char *name,
480 const char *funcname,
481 const void *func,
482 enum litest_device_type type,
483 const struct range *range);
484 void
485 _litest_add_no_device(const char *name,
486 const char *funcname,
487 const void *func);
488 void
489 _litest_add_ranged_no_device(const char *name,
490 const char *funcname,
491 const void *func,
492 const struct range *range);
493 void
494 _litest_add_deviceless(const char *name,
495 const char *funcname,
496 const void *func);
497
498 struct litest_device *
499 litest_create_device(enum litest_device_type which);
500
501 struct litest_device *
502 litest_add_device(struct libinput *libinput,
503 enum litest_device_type which);
504 struct libevdev_uinput *
505 litest_create_uinput_device_from_description(const char *name,
506 const struct input_id *id,
507 const struct input_absinfo *abs,
508 const int *events);
509 struct litest_device *
510 litest_create(enum litest_device_type which,
511 const char *name_override,
512 struct input_id *id_override,
513 const struct input_absinfo *abs_override,
514 const int *events_override);
515
516 struct litest_device *
517 litest_create_device_with_overrides(enum litest_device_type which,
518 const char *name_override,
519 struct input_id *id_override,
520 const struct input_absinfo *abs_override,
521 const int *events_override);
522 struct litest_device *
523 litest_add_device_with_overrides(struct libinput *libinput,
524 enum litest_device_type which,
525 const char *name_override,
526 struct input_id *id_override,
527 const struct input_absinfo *abs_override,
528 const int *events_override);
529
530 struct litest_device *
531 litest_current_device(void);
532
533 void
534 litest_grab_device(struct litest_device *d);
535
536 void
537 litest_ungrab_device(struct litest_device *d);
538
539 void
540 litest_delete_device(struct litest_device *d);
541
542 void
543 litest_event(struct litest_device *t,
544 unsigned int type,
545 unsigned int code,
546 int value);
547 int
548 litest_auto_assign_value(struct litest_device *d,
549 const struct input_event *ev,
550 int slot, double x, double y,
551 struct axis_replacement *axes,
552 bool touching);
553 void
554 litest_touch_up(struct litest_device *d, unsigned int slot);
555
556 void
557 litest_touch_move(struct litest_device *d,
558 unsigned int slot,
559 double x,
560 double y);
561
562 void
563 litest_touch_move_extended(struct litest_device *d,
564 unsigned int slot,
565 double x,
566 double y,
567 struct axis_replacement *axes);
568
569 void
570 litest_touch_sequence(struct litest_device *d,
571 unsigned int slot,
572 double x1,
573 double y1,
574 double x2,
575 double y2,
576 int steps);
577
578 void
579 litest_touch_down(struct litest_device *d,
580 unsigned int slot,
581 double x,
582 double y);
583
584 void
585 litest_touch_down_extended(struct litest_device *d,
586 unsigned int slot,
587 double x,
588 double y,
589 struct axis_replacement *axes);
590
591 void
592 litest_touch_move_to(struct litest_device *d,
593 unsigned int slot,
594 double x_from, double y_from,
595 double x_to, double y_to,
596 int steps);
597
598 void
599 litest_touch_move_to_extended(struct litest_device *d,
600 unsigned int slot,
601 double x_from, double y_from,
602 double x_to, double y_to,
603 struct axis_replacement *axes,
604 int steps);
605
606 void
607 litest_touch_move_two_touches(struct litest_device *d,
608 double x0, double y0,
609 double x1, double y1,
610 double dx, double dy,
611 int steps);
612
613 void
614 litest_touch_move_three_touches(struct litest_device *d,
615 double x0, double y0,
616 double x1, double y1,
617 double x2, double y2,
618 double dx, double dy,
619 int steps);
620
621 void
622 litest_tablet_set_tool_type(struct litest_device *d,
623 unsigned int code);
624
625 void
626 litest_tablet_proximity_in(struct litest_device *d,
627 int x, int y,
628 struct axis_replacement *axes);
629
630 void
631 litest_tablet_proximity_out(struct litest_device *d);
632
633 void
634 litest_tablet_motion(struct litest_device *d,
635 int x, int y,
636 struct axis_replacement *axes);
637
638 void
639 litest_pad_ring_start(struct litest_device *d, double value);
640
641 void
642 litest_pad_ring_change(struct litest_device *d, double value);
643
644 void
645 litest_pad_ring_end(struct litest_device *d);
646
647 void
648 litest_pad_strip_start(struct litest_device *d, double value);
649
650 void
651 litest_pad_strip_change(struct litest_device *d, double value);
652
653 void
654 litest_pad_strip_end(struct litest_device *d);
655
656 void
657 litest_hover_start(struct litest_device *d,
658 unsigned int slot,
659 double x,
660 double y);
661
662 void
663 litest_hover_end(struct litest_device *d, unsigned int slot);
664
665 void litest_hover_move(struct litest_device *d,
666 unsigned int slot,
667 double x,
668 double y);
669
670 void
671 litest_hover_move_to(struct litest_device *d,
672 unsigned int slot,
673 double x_from, double y_from,
674 double x_to, double y_to,
675 int steps);
676
677 void
678 litest_hover_move_two_touches(struct litest_device *d,
679 double x0, double y0,
680 double x1, double y1,
681 double dx, double dy,
682 int steps);
683
684 void
685 litest_button_click_debounced(struct litest_device *d,
686 struct libinput *li,
687 unsigned int button,
688 bool is_press);
689
690 void
691 litest_button_click(struct litest_device *d,
692 unsigned int button,
693 bool is_press);
694
695 void
696 litest_button_scroll(struct litest_device *d,
697 unsigned int button,
698 double dx, double dy);
699 void
700 litest_button_scroll_locked(struct litest_device *d,
701 unsigned int button,
702 double dx, double dy);
703
704 void
705 litest_keyboard_key(struct litest_device *d,
706 unsigned int key,
707 bool is_press);
708
709 void litest_switch_action(struct litest_device *d,
710 enum libinput_switch sw,
711 enum libinput_switch_state state);
712
713 void
714 litest_wait_for_event(struct libinput *li);
715
716 void
717 litest_wait_for_event_of_type(struct libinput *li, ...);
718
719 void
720 litest_drain_events(struct libinput *li);
721
722 void
723 litest_drain_events_of_type(struct libinput *li, ...);
724
725 void
726 litest_assert_event_type(struct libinput_event *event,
727 enum libinput_event_type want);
728
729 void
730 litest_assert_empty_queue(struct libinput *li);
731
732 void
733 litest_assert_touch_sequence(struct libinput *li);
734
735 void
736 litest_assert_touch_motion_frame(struct libinput *li);
737 void
738 litest_assert_touch_down_frame(struct libinput *li);
739 void
740 litest_assert_touch_up_frame(struct libinput *li);
741 void
742 litest_assert_touch_cancel(struct libinput *li);
743
744 struct libinput_event_pointer *
745 litest_is_button_event(struct libinput_event *event,
746 unsigned int button,
747 enum libinput_button_state state);
748
749 struct libinput_event_pointer *
750 litest_is_axis_event(struct libinput_event *event,
751 enum libinput_event_type axis_type,
752 enum libinput_pointer_axis axis,
753 enum libinput_pointer_axis_source source);
754
755 bool
756 litest_is_high_res_axis_event(struct libinput_event *event);
757
758 struct libinput_event_pointer *
759 litest_is_motion_event(struct libinput_event *event);
760
761 struct libinput_event_touch *
762 litest_is_touch_event(struct libinput_event *event,
763 enum libinput_event_type type);
764
765 struct libinput_event_keyboard *
766 litest_is_keyboard_event(struct libinput_event *event,
767 unsigned int key,
768 enum libinput_key_state state);
769
770 struct libinput_event_gesture *
771 litest_is_gesture_event(struct libinput_event *event,
772 enum libinput_event_type type,
773 int nfingers);
774
775 struct libinput_event_tablet_tool *
776 litest_is_tablet_event(struct libinput_event *event,
777 enum libinput_event_type type);
778
779 struct libinput_event_tablet_pad *
780 litest_is_pad_button_event(struct libinput_event *event,
781 unsigned int button,
782 enum libinput_button_state state);
783 struct libinput_event_tablet_pad *
784 litest_is_pad_ring_event(struct libinput_event *event,
785 unsigned int number,
786 enum libinput_tablet_pad_ring_axis_source source);
787 struct libinput_event_tablet_pad *
788 litest_is_pad_strip_event(struct libinput_event *event,
789 unsigned int number,
790 enum libinput_tablet_pad_strip_axis_source source);
791 struct libinput_event_tablet_pad *
792 litest_is_pad_key_event(struct libinput_event *event,
793 unsigned int key,
794 enum libinput_key_state state);
795
796 struct libinput_event_switch *
797 litest_is_switch_event(struct libinput_event *event,
798 enum libinput_switch sw,
799 enum libinput_switch_state state);
800
801 struct libinput_event_tablet_tool *
802 litest_is_proximity_event(struct libinput_event *event,
803 enum libinput_tablet_tool_proximity_state state);
804
805 double
806 litest_event_pointer_get_value(struct libinput_event_pointer *ptrev,
807 enum libinput_pointer_axis axis);
808
809 enum libinput_pointer_axis_source
810 litest_event_pointer_get_axis_source(struct libinput_event_pointer *event);
811
812 void
813 litest_assert_key_event(struct libinput *li, unsigned int key,
814 enum libinput_key_state state);
815
816 void
817 litest_assert_button_event(struct libinput *li,
818 unsigned int button,
819 enum libinput_button_state state);
820
821 void
822 litest_assert_scroll(struct libinput *li,
823 enum libinput_event_type axis_type,
824 enum libinput_pointer_axis axis,
825 int minimum_movement);
826
827 void
828 litest_assert_axis_end_sequence(struct libinput *li,
829 enum libinput_event_type axis_type,
830 enum libinput_pointer_axis axis,
831 enum libinput_pointer_axis_source source);
832
833 void
834 litest_assert_only_typed_events(struct libinput *li,
835 enum libinput_event_type type);
836
837 void
838 litest_assert_only_axis_events(struct libinput *li,
839 enum libinput_event_type axis_type);
840
841 void
842 litest_assert_no_typed_events(struct libinput *li,
843 enum libinput_event_type type);
844
845 void
846 litest_assert_tablet_button_event(struct libinput *li,
847 unsigned int button,
848 enum libinput_button_state state);
849
850 void
851 litest_assert_tablet_proximity_event(struct libinput *li,
852 enum libinput_tablet_tool_proximity_state state);
853
854 void
855 litest_assert_tablet_tip_event(struct libinput *li,
856 enum libinput_tablet_tool_tip_state state);
857
858 void
859 litest_assert_pad_button_event(struct libinput *li,
860 unsigned int button,
861 enum libinput_button_state state);
862 void
863 litest_assert_pad_key_event(struct libinput *li,
864 unsigned int key,
865 enum libinput_key_state state);
866
867 void
868 litest_assert_gesture_event(struct libinput *li,
869 enum libinput_event_type type,
870 int nfingers);
871
872 struct libevdev_uinput *
873 litest_create_uinput_device(const char *name,
874 struct input_id *id,
875 ...);
876
877 struct libevdev_uinput *
878 litest_create_uinput_abs_device(const char *name,
879 struct input_id *id,
880 const struct input_absinfo *abs,
881 ...);
882
883 void
884 litest_timeout_tap(void);
885
886 void
887 litest_timeout_tapndrag(void);
888
889 void
890 litest_timeout_debounce(void);
891
892 void
893 litest_timeout_softbuttons(void);
894
895 void
896 litest_timeout_buttonscroll(void);
897
898 void
899 litest_timeout_edgescroll(void);
900
901 void
902 litest_timeout_finger_switch(void);
903
904 void
905 litest_timeout_middlebutton(void);
906
907 void
908 litest_timeout_dwt_short(void);
909
910 void
911 litest_timeout_dwt_long(void);
912
913 void
914 litest_timeout_gesture(void);
915
916 void
917 litest_timeout_gesture_scroll(void);
918
919 void
920 litest_timeout_gesture_hold(void);
921
922 void
923 litest_timeout_gesture_quick_hold(void);
924
925 void
926 litest_timeout_trackpoint(void);
927
928 void
929 litest_timeout_tablet_proxout(void);
930
931 void
932 litest_timeout_touch_arbitration(void);
933
934 void
935 litest_timeout_hysteresis(void);
936
937 void
938 litest_push_event_frame(struct litest_device *dev);
939
940 void
941 litest_pop_event_frame(struct litest_device *dev);
942
943 void
944 litest_filter_event(struct litest_device *dev,
945 unsigned int type,
946 unsigned int code);
947
948 void
949 litest_unfilter_event(struct litest_device *dev,
950 unsigned int type,
951 unsigned int code);
952 void
953 litest_semi_mt_touch_down(struct litest_device *d,
954 struct litest_semi_mt *semi_mt,
955 unsigned int slot,
956 double x, double y);
957
958 void
959 litest_semi_mt_touch_move(struct litest_device *d,
960 struct litest_semi_mt *semi_mt,
961 unsigned int slot,
962 double x, double y);
963
964 void
965 litest_semi_mt_touch_up(struct litest_device *d,
966 struct litest_semi_mt *semi_mt,
967 unsigned int slot);
968
969 #ifndef ck_assert_notnull
970 #define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL)
971 #endif
972
973 static inline void
litest_enable_tap(struct libinput_device * device)974 litest_enable_tap(struct libinput_device *device)
975 {
976 enum libinput_config_status status, expected;
977
978 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
979 status = libinput_device_config_tap_set_enabled(device,
980 LIBINPUT_CONFIG_TAP_ENABLED);
981
982 litest_assert_int_eq(status, expected);
983 }
984
985 static inline void
litest_disable_tap(struct libinput_device * device)986 litest_disable_tap(struct libinput_device *device)
987 {
988 enum libinput_config_status status, expected;
989
990 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
991 status = libinput_device_config_tap_set_enabled(device,
992 LIBINPUT_CONFIG_TAP_DISABLED);
993
994 litest_assert_int_eq(status, expected);
995 }
996
997 static inline void
litest_set_tap_map(struct libinput_device * device,enum libinput_config_tap_button_map map)998 litest_set_tap_map(struct libinput_device *device,
999 enum libinput_config_tap_button_map map)
1000 {
1001 enum libinput_config_status status, expected;
1002
1003 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1004 status = libinput_device_config_tap_set_button_map(device, map);
1005 litest_assert_int_eq(status, expected);
1006 }
1007
1008 static inline void
litest_enable_tap_drag(struct libinput_device * device)1009 litest_enable_tap_drag(struct libinput_device *device)
1010 {
1011 enum libinput_config_status status, expected;
1012
1013 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1014 status = libinput_device_config_tap_set_drag_enabled(device,
1015 LIBINPUT_CONFIG_DRAG_ENABLED);
1016
1017 litest_assert_int_eq(status, expected);
1018 }
1019
1020 static inline void
litest_disable_tap_drag(struct libinput_device * device)1021 litest_disable_tap_drag(struct libinput_device *device)
1022 {
1023 enum libinput_config_status status, expected;
1024
1025 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1026 status = libinput_device_config_tap_set_drag_enabled(device,
1027 LIBINPUT_CONFIG_DRAG_DISABLED);
1028
1029 litest_assert_int_eq(status, expected);
1030 }
1031
1032 static inline bool
litest_has_2fg_scroll(struct litest_device * dev)1033 litest_has_2fg_scroll(struct litest_device *dev)
1034 {
1035 struct libinput_device *device = dev->libinput_device;
1036
1037 return !!(libinput_device_config_scroll_get_methods(device) &
1038 LIBINPUT_CONFIG_SCROLL_2FG);
1039 }
1040
1041 static inline void
litest_enable_2fg_scroll(struct litest_device * dev)1042 litest_enable_2fg_scroll(struct litest_device *dev)
1043 {
1044 enum libinput_config_status status, expected;
1045 struct libinput_device *device = dev->libinput_device;
1046
1047 status = libinput_device_config_scroll_set_method(device,
1048 LIBINPUT_CONFIG_SCROLL_2FG);
1049
1050 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1051 litest_assert_int_eq(status, expected);
1052 }
1053
1054 static inline void
litest_enable_edge_scroll(struct litest_device * dev)1055 litest_enable_edge_scroll(struct litest_device *dev)
1056 {
1057 enum libinput_config_status status, expected;
1058 struct libinput_device *device = dev->libinput_device;
1059
1060 status = libinput_device_config_scroll_set_method(device,
1061 LIBINPUT_CONFIG_SCROLL_EDGE);
1062
1063 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1064 litest_assert_int_eq(status, expected);
1065 }
1066
1067 static inline bool
litest_has_clickfinger(struct litest_device * dev)1068 litest_has_clickfinger(struct litest_device *dev)
1069 {
1070 struct libinput_device *device = dev->libinput_device;
1071 uint32_t methods = libinput_device_config_click_get_methods(device);
1072
1073 return methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
1074 }
1075
1076 static inline bool
litest_has_btnareas(struct litest_device * dev)1077 litest_has_btnareas(struct litest_device *dev)
1078 {
1079 struct libinput_device *device = dev->libinput_device;
1080 uint32_t methods = libinput_device_config_click_get_methods(device);
1081
1082 return methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
1083 }
1084
1085 static inline void
litest_enable_clickfinger(struct litest_device * dev)1086 litest_enable_clickfinger(struct litest_device *dev)
1087 {
1088 enum libinput_config_status status, expected;
1089 struct libinput_device *device = dev->libinput_device;
1090
1091 status = libinput_device_config_click_set_method(device,
1092 LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
1093 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1094 litest_assert_int_eq(status, expected);
1095 }
1096
1097 static inline void
litest_enable_buttonareas(struct litest_device * dev)1098 litest_enable_buttonareas(struct litest_device *dev)
1099 {
1100 enum libinput_config_status status, expected;
1101 struct libinput_device *device = dev->libinput_device;
1102
1103 status = libinput_device_config_click_set_method(device,
1104 LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
1105 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1106 litest_assert_int_eq(status, expected);
1107 }
1108
1109 static inline void
litest_enable_drag_lock(struct libinput_device * device)1110 litest_enable_drag_lock(struct libinput_device *device)
1111 {
1112 enum libinput_config_status status, expected;
1113
1114 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1115 status = libinput_device_config_tap_set_drag_lock_enabled(device,
1116 LIBINPUT_CONFIG_DRAG_LOCK_ENABLED);
1117
1118 litest_assert_int_eq(status, expected);
1119 }
1120
1121 static inline void
litest_disable_drag_lock(struct libinput_device * device)1122 litest_disable_drag_lock(struct libinput_device *device)
1123 {
1124 enum libinput_config_status status, expected;
1125
1126 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1127 status = libinput_device_config_tap_set_drag_lock_enabled(device,
1128 LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);
1129
1130 litest_assert_int_eq(status, expected);
1131 }
1132
1133 static inline void
litest_enable_middleemu(struct litest_device * dev)1134 litest_enable_middleemu(struct litest_device *dev)
1135 {
1136 struct libinput_device *device = dev->libinput_device;
1137 enum libinput_config_status status, expected;
1138
1139 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1140 status = libinput_device_config_middle_emulation_set_enabled(device,
1141 LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);
1142
1143 litest_assert_int_eq(status, expected);
1144 }
1145
1146 static inline void
litest_disable_middleemu(struct litest_device * dev)1147 litest_disable_middleemu(struct litest_device *dev)
1148 {
1149 struct libinput_device *device = dev->libinput_device;
1150 enum libinput_config_status status, expected;
1151
1152 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1153 status = libinput_device_config_middle_emulation_set_enabled(device,
1154 LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);
1155
1156 litest_assert_int_eq(status, expected);
1157 }
1158
1159 static inline void
litest_sendevents_off(struct litest_device * dev)1160 litest_sendevents_off(struct litest_device *dev)
1161 {
1162 struct libinput_device *device = dev->libinput_device;
1163 enum libinput_config_status status, expected;
1164
1165 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1166 status = libinput_device_config_send_events_set_mode(device,
1167 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
1168 litest_assert_int_eq(status, expected);
1169 }
1170
1171 static inline void
litest_sendevents_on(struct litest_device * dev)1172 litest_sendevents_on(struct litest_device *dev)
1173 {
1174 struct libinput_device *device = dev->libinput_device;
1175 enum libinput_config_status status, expected;
1176
1177 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1178 status = libinput_device_config_send_events_set_mode(device,
1179 LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
1180 litest_assert_int_eq(status, expected);
1181 }
1182
1183 static inline void
litest_sendevents_ext_mouse(struct litest_device * dev)1184 litest_sendevents_ext_mouse(struct litest_device *dev)
1185 {
1186 struct libinput_device *device = dev->libinput_device;
1187 enum libinput_config_status status, expected;
1188
1189 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1190 status = libinput_device_config_send_events_set_mode(device,
1191 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
1192 litest_assert_int_eq(status, expected);
1193 }
1194
1195 static inline void
litest_enable_hold_gestures(struct libinput_device * device)1196 litest_enable_hold_gestures(struct libinput_device *device)
1197 {
1198 enum libinput_config_status status, expected;
1199
1200 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1201 status = libinput_device_config_gesture_set_hold_enabled(device,
1202 LIBINPUT_CONFIG_HOLD_ENABLED);
1203
1204 litest_assert_int_eq(status, expected);
1205 }
1206
1207 static inline void
litest_disable_hold_gestures(struct libinput_device * device)1208 litest_disable_hold_gestures(struct libinput_device *device)
1209 {
1210 enum libinput_config_status status, expected;
1211
1212 expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
1213 status = libinput_device_config_gesture_set_hold_enabled(device,
1214 LIBINPUT_CONFIG_HOLD_DISABLED);
1215
1216 litest_assert_int_eq(status, expected);
1217 }
1218
1219 static inline bool
litest_touchpad_is_external(struct litest_device * dev)1220 litest_touchpad_is_external(struct litest_device *dev)
1221 {
1222 struct udev_device *udev_device;
1223 const char *prop;
1224 bool is_external;
1225
1226 if (libinput_device_get_id_vendor(dev->libinput_device) == VENDOR_ID_WACOM)
1227 return true;
1228
1229 udev_device = libinput_device_get_udev_device(dev->libinput_device);
1230 prop = udev_device_get_property_value(udev_device,
1231 "ID_INPUT_TOUCHPAD_INTEGRATION");
1232 is_external = prop && streq(prop, "external");
1233 udev_device_unref(udev_device);
1234
1235 return is_external;
1236 }
1237
1238 static inline int
litest_send_file(int sock,int fd)1239 litest_send_file(int sock, int fd)
1240 {
1241 char buf[40960];
1242 int n = read(fd, buf, 40960);
1243 litest_assert_int_gt(n, 0);
1244 return write(sock, buf, n);
1245 }
1246
litest_slot_count(struct litest_device * dev)1247 static inline int litest_slot_count(struct litest_device *dev)
1248 {
1249 if (dev->which == LITEST_ALPS_3FG)
1250 return 2;
1251
1252 return libevdev_get_num_slots(dev->evdev);
1253 }
1254
1255 static inline bool
litest_has_palm_detect_size(struct litest_device * dev)1256 litest_has_palm_detect_size(struct litest_device *dev)
1257 {
1258 double width, height;
1259 unsigned int vendor;
1260 unsigned int bustype;
1261 int rc;
1262
1263 vendor = libinput_device_get_id_vendor(dev->libinput_device);
1264 bustype = libevdev_get_id_bustype(dev->evdev);
1265 if (vendor == VENDOR_ID_WACOM)
1266 return 0;
1267 if (bustype == BUS_BLUETOOTH)
1268 return 0;
1269 if (vendor == VENDOR_ID_APPLE)
1270 return 1;
1271
1272 rc = libinput_device_get_size(dev->libinput_device, &width, &height);
1273
1274 return rc == 0 && width >= 70;
1275 }
1276
1277 #endif /* LITEST_H */
1278