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