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