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