litest.h 30.9 KB
Newer Older
Peter Hutterer's avatar
Peter Hutterer committed
1 2 3
/*
 * Copyright © 2013 Red Hat, Inc.
 *
4 5 6 7 8 9
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
Peter Hutterer's avatar
Peter Hutterer committed
10
 *
11 12 13 14 15 16 17 18 19 20 21
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
Peter Hutterer's avatar
Peter Hutterer committed
22 23 24
 */

#include "config.h"
25
#include "litest-config.h"
Peter Hutterer's avatar
Peter Hutterer committed
26 27 28 29 30

#ifndef LITEST_H
#define LITEST_H

#include <stdbool.h>
31
#include <stdarg.h>
Peter Hutterer's avatar
Peter Hutterer committed
32 33 34 35
#include <check.h>
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
#include <libinput.h>
36 37
#include <math.h>

38 39
#include "check-double-macros.h"

40
#include "libinput-util.h"
41
#include "quirks.h"
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
struct test_device {
	const char *name;
	struct litest_test_device *device;
} __attribute__((aligned(16)));

#define TEST_DEVICE(name, ...) \
	static struct litest_test_device _device; \
	\
	static void _setup(void) { \
		struct litest_device *d = litest_create_device(_device.type); \
		litest_set_current_device(d); \
	} \
	\
	static const struct test_device _test_device \
		__attribute__ ((used)) \
		__attribute__ ((section ("test_section"))) = { \
		name, &_device \
	}; \
	static struct litest_test_device _device = { \
		.setup = _setup, \
		.shortname = name, \
		__VA_ARGS__ \
	};

67 68 69 70 71 72 73 74 75 76 77 78 79 80
struct test_collection {
	const char *name;
	void (*setup)(void);
} __attribute__((aligned(16)));

#define TEST_COLLECTION(name) \
	static void (name##_setup)(void); \
	static const struct test_collection _test_collection \
	__attribute__ ((used)) \
	__attribute__ ((section ("test_collection_section"))) = { \
		#name, name##_setup \
	}; \
	static void (name##_setup)(void)

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
void
litest_fail_condition(const char *file,
		      int line,
		      const char *func,
		      const char *condition,
		      const char *message,
		      ...);
void
litest_fail_comparison_int(const char *file,
			   int line,
			   const char *func,
			   const char *operator,
			   int a,
			   int b,
			   const char *astr,
			   const char *bstr);
void
98 99 100 101 102 103 104 105 106
litest_fail_comparison_double(const char *file,
			      int line,
			      const char *func,
			      const char *operator,
			      double a,
			      double b,
			      const char *astr,
			      const char *bstr);
void
107 108 109 110 111
litest_fail_comparison_ptr(const char *file,
			   int line,
			   const char *func,
			   const char *comparison);

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
#define litest_assert(cond) \
	do { \
		if (!(cond)) \
			litest_fail_condition(__FILE__, __LINE__, __func__, \
					      #cond, NULL); \
	} while(0)

#define litest_assert_msg(cond, ...) \
	do { \
		if (!(cond)) \
			litest_fail_condition(__FILE__, __LINE__, __func__, \
					      #cond, __VA_ARGS__); \
	} while(0)

#define litest_abort_msg(...) \
	litest_fail_condition(__FILE__, __LINE__, __func__, \
			      "aborting", __VA_ARGS__); \

#define litest_assert_notnull(cond) \
	do { \
		if ((cond) == NULL) \
			litest_fail_condition(__FILE__, __LINE__, __func__, \
134
					      #cond, " expected to be not NULL\n"); \
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	} while(0)

#define litest_assert_comparison_int_(a_, op_, b_) \
	do { \
		__typeof__(a_) _a = a_; \
		__typeof__(b_) _b = b_; \
		if (trunc(_a) != _a || trunc(_b) != _b) \
			litest_abort_msg("litest_assert_int_* used for non-integer value\n"); \
		if (!((_a) op_ (_b))) \
			litest_fail_comparison_int(__FILE__, __LINE__, __func__,\
						   #op_, _a, _b, \
						   #a_, #b_); \
	} while(0)

#define litest_assert_int_eq(a_, b_) \
	litest_assert_comparison_int_(a_, ==, b_)

#define litest_assert_int_ne(a_, b_) \
	litest_assert_comparison_int_(a_, !=, b_)

#define litest_assert_int_lt(a_, b_) \
	litest_assert_comparison_int_(a_, <, b_)

#define litest_assert_int_le(a_, b_) \
	litest_assert_comparison_int_(a_, <=, b_)

#define litest_assert_int_ge(a_, b_) \
	litest_assert_comparison_int_(a_, >=, b_)

#define litest_assert_int_gt(a_, b_) \
	litest_assert_comparison_int_(a_, >, b_)
Peter Hutterer's avatar
Peter Hutterer committed
166

167 168 169 170 171 172 173 174 175
#define litest_assert_comparison_ptr_(a_, op_, b_) \
	do { \
		__typeof__(a_) _a = a_; \
		__typeof__(b_) _b = b_; \
		if (!((_a) op_ (_b))) \
			litest_fail_comparison_ptr(__FILE__, __LINE__, __func__,\
						   #a_ " " #op_ " " #b_); \
	} while(0)

176 177 178 179 180 181 182 183 184 185 186
#define litest_assert_comparison_double_(a_, op_, b_) \
	do { \
		const double EPSILON = 1.0/256; \
		__typeof__(a_) _a = a_; \
		__typeof__(b_) _b = b_; \
		if (!((_a) op_ (_b)) && fabs((_a) - (_b)) > EPSILON)  \
			litest_fail_comparison_double(__FILE__, __LINE__, __func__,\
						      #op_, _a, _b, \
						      #a_, #b_); \
	} while(0)

187 188 189 190 191 192 193 194 195 196 197
#define litest_assert_ptr_eq(a_, b_) \
	litest_assert_comparison_ptr_(a_, ==, b_)

#define litest_assert_ptr_ne(a_, b_) \
	litest_assert_comparison_ptr_(a_, !=, b_)

#define litest_assert_ptr_null(a_) \
	litest_assert_comparison_ptr_(a_, ==, NULL)

#define litest_assert_ptr_notnull(a_) \
	litest_assert_comparison_ptr_(a_, !=, NULL)
Peter Hutterer's avatar
Peter Hutterer committed
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

Peter Hutterer's avatar
Peter Hutterer committed
217 218
enum litest_device_type {
	LITEST_NO_DEVICE = -1,
219
	LITEST_SYNAPTICS_CLICKPAD_X220 = -1000,
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
	LITEST_SYNAPTICS_TOUCHPAD,
	LITEST_SYNAPTICS_TOPBUTTONPAD,
	LITEST_BCM5974,
	LITEST_KEYBOARD,
	LITEST_TRACKPOINT,
	LITEST_MOUSE,
	LITEST_WACOM_TOUCH,
	LITEST_ALPS_SEMI_MT,
	LITEST_GENERIC_SINGLETOUCH,
	LITEST_MS_SURFACE_COVER,
	LITEST_QEMU_TABLET,
	LITEST_XEN_VIRTUAL_POINTER,
	LITEST_VMWARE_VIRTMOUSE,
	LITEST_SYNAPTICS_HOVER_SEMI_MT,
	LITEST_SYNAPTICS_TRACKPOINT_BUTTONS,
	LITEST_PROTOCOL_A_SCREEN,
	LITEST_WACOM_FINGER,
	LITEST_KEYBOARD_BLACKWIDOW,
	LITEST_WHEEL_ONLY,
	LITEST_MOUSE_ROCCAT,
	LITEST_LOGITECH_TRACKBALL,
	LITEST_ATMEL_HOVER,
	LITEST_ALPS_DUALPOINT,
	LITEST_MOUSE_LOW_DPI,
	LITEST_GENERIC_MULTITOUCH_SCREEN,
	LITEST_NEXUS4_TOUCH_SCREEN,
	LITEST_MAGIC_TRACKPAD,
	LITEST_ELANTECH_TOUCHPAD,
	LITEST_MOUSE_GLADIUS,
	LITEST_MOUSE_WHEEL_CLICK_ANGLE,
	LITEST_APPLE_KEYBOARD,
	LITEST_ANKER_MOUSE_KBD,
	LITEST_WACOM_BAMBOO,
	LITEST_WACOM_CINTIQ,
	LITEST_WACOM_INTUOS,
	LITEST_WACOM_ISDV4,
	LITEST_WALTOP,
	LITEST_HUION_TABLET,
	LITEST_CYBORG_RAT,
	LITEST_YUBIKEY,
	LITEST_SYNAPTICS_I2C,
	LITEST_WACOM_CINTIQ_24HD,
	LITEST_MULTITOUCH_FUZZ_SCREEN,
	LITEST_WACOM_INTUOS3_PAD,
	LITEST_WACOM_INTUOS5_PAD,
265
	LITEST_KEYBOARD_ALL_CODES,
266
	LITEST_MAGICMOUSE,
267
	LITEST_WACOM_EKR,
268
	LITEST_WACOM_CINTIQ_24HDT_PAD,
269 270 271
	LITEST_WACOM_CINTIQ_13HDT_PEN,
	LITEST_WACOM_CINTIQ_13HDT_PAD,
	LITEST_WACOM_CINTIQ_13HDT_FINGER,
272 273 274
	LITEST_WACOM_CINTIQ_PRO16_PAD,
	LITEST_WACOM_CINTIQ_PRO16_PEN,
	LITEST_WACOM_CINTIQ_PRO16_FINGER,
275
	LITEST_WACOM_HID4800_PEN,
276
	LITEST_MOUSE_WHEEL_CLICK_COUNT,
277
	LITEST_CALIBRATED_TOUCHSCREEN,
278 279
	LITEST_ACER_HAWAII_KEYBOARD,
	LITEST_ACER_HAWAII_TOUCHPAD,
280
	LITEST_SYNAPTICS_RMI4,
Peter Hutterer's avatar
Peter Hutterer committed
281
	LITEST_MOUSE_WHEEL_TILT,
James Ye's avatar
James Ye committed
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 291
	LITEST_KEYBOARD_BLADE_STEALTH,
	LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH,
292 293 294
	LITEST_WACOM_BAMBOO_2FG_PAD,
	LITEST_WACOM_BAMBOO_2FG_PEN,
	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 301
	LITEST_DELL_CANVAS_TOTEM,
	LITEST_DELL_CANVAS_TOTEM_TOUCH,
302
	LITEST_WACOM_ISDV4_4200_PEN,
303
	LITEST_ALPS_3FG,
304
	LITEST_ELAN_TABLET,
305
	LITEST_ABSINFO_OVERRIDE,
Peter Hutterer's avatar
Peter Hutterer committed
306 307
};

308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
#define LITEST_DEVICELESS	-2
#define LITEST_DISABLE_DEVICE	-1
#define LITEST_ANY		0
#define LITEST_TOUCHPAD		bit(0)
#define LITEST_CLICKPAD		bit(1)
#define LITEST_BUTTON		bit(2)
#define LITEST_KEYS		bit(3)
#define LITEST_RELATIVE		bit(4)
#define LITEST_WHEEL		bit(5)
#define LITEST_TOUCH		bit(6)
#define LITEST_SINGLE_TOUCH	bit(7)
#define LITEST_APPLE_CLICKPAD	bit(8)
#define LITEST_TOPBUTTONPAD	bit(9)
#define LITEST_SEMI_MT		bit(10)
#define LITEST_POINTINGSTICK	bit(11)
#define LITEST_FAKE_MT		bit(12)
#define LITEST_ABSOLUTE		bit(13)
#define LITEST_PROTOCOL_A	bit(14)
#define LITEST_HOVER		bit(15)
#define LITEST_ELLIPSE		bit(16)
#define LITEST_TABLET		bit(17)
#define LITEST_DISTANCE		bit(18)
#define LITEST_TOOL_SERIAL	bit(19)
#define LITEST_TILT		bit(20)
#define LITEST_TABLET_PAD	bit(21)
#define LITEST_RING		bit(22)
#define LITEST_STRIP		bit(23)
#define LITEST_TRACKBALL	bit(24)
#define LITEST_LEDS		bit(25)
#define LITEST_SWITCH		bit(26)
#define LITEST_IGNORED		bit(27)
#define LITEST_NO_DEBOUNCE	bit(28)
#define LITEST_TOOL_MOUSE	bit(29)
#define LITEST_DIRECT		bit(30)
#define LITEST_TOTEM		bit(31)
343
#define LITEST_FORCED_PROXOUT	bit(32)
344

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
/* this is a semi-mt device, so we keep track of the touches that the tests
 * send and modify them so that the first touch is always slot 0 and sends
 * the top-left of the bounding box, the second is always slot 1 and sends
 * the bottom-right of the bounding box.
 * Lifting any of two fingers terminates slot 1
 */
struct litest_semi_mt {
	bool is_semi_mt;

	int tracking_id;
	/* The actual touches requested by the test for the two slots
	 * in the 0..100 range used by litest */
	struct {
		double x, y;
	} touches[2];
};

Peter Hutterer's avatar
Peter Hutterer committed
362
struct litest_device {
363
	enum litest_device_type which;
Peter Hutterer's avatar
Peter Hutterer committed
364 365 366
	struct libevdev *evdev;
	struct libevdev_uinput *uinput;
	struct libinput *libinput;
367
	struct quirks *quirks;
368
	bool owns_context;
369
	struct libinput_device *libinput_device;
Peter Hutterer's avatar
Peter Hutterer committed
370
	struct litest_device_interface *interface;
371 372

	int ntouches_down;
373
	int skip_ev_syn;
374
	struct litest_semi_mt semi_mt; /** only used for semi-mt device */
375

376
	void *private; /* device-specific data */
Peter Hutterer's avatar
Peter Hutterer committed
377 378
};

379 380
struct axis_replacement {
	int32_t evcode;
381
	double value;
382
};
383

384 385 386
/**
 * Same as litest_axis_set_value but allows for ranges outside 0..100%
 */
Peter Hutterer's avatar
Peter Hutterer committed
387
static inline void
388
litest_axis_set_value_unchecked(struct axis_replacement *axes, int code, double value)
389 390 391 392 393 394 395 396 397 398 399 400
{
	while (axes->evcode != -1) {
		if (axes->evcode == code) {
			axes->value = value;
			return;
		}
		axes++;
	}

	litest_abort_msg("Missing axis code %d\n", code);
}

401 402 403 404 405 406 407 408 409 410 411 412
/**
 * Takes a value in percent and sets the given axis to that code.
 */
static inline void
litest_axis_set_value(struct axis_replacement *axes, int code, double value)
{
	litest_assert_double_ge(value, 0.0);
	litest_assert_double_le(value, 100.0);

	litest_axis_set_value_unchecked(axes, code, value);
}

413 414 415 416 417 418 419 420
/* A loop range, resolves to:
   for (i = lower; i < upper; i++)
 */
struct range {
	int lower; /* inclusive */
	int upper; /* exclusive */
};

421
struct libinput *litest_create_context(void);
422 423
void litest_disable_log_handler(struct libinput *libinput);
void litest_restore_log_handler(struct libinput *libinput);
424
void litest_set_log_handler_bug(struct libinput *libinput);
425

426 427 428 429 430 431 432 433 434 435 436 437
#define litest_add(name_, func_, ...) \
	_litest_add(name_, #func_, func_, __VA_ARGS__)
#define litest_add_ranged(name_, func_, ...) \
	_litest_add_ranged(name_, #func_, func_, __VA_ARGS__)
#define litest_add_for_device(name_, func_, ...) \
	_litest_add_for_device(name_, #func_, func_, __VA_ARGS__)
#define litest_add_ranged_for_device(name_, func_, ...) \
	_litest_add_ranged_for_device(name_, #func_, func_, __VA_ARGS__)
#define litest_add_no_device(name_, func_) \
	_litest_add_no_device(name_, #func_, func_)
#define litest_add_ranged_no_device(name_, func_, ...) \
	_litest_add_ranged_no_device(name_, #func_, func_, __VA_ARGS__)
438 439 440
#define litest_add_deviceless(name_, func_) \
	_litest_add_deviceless(name_, #func_, func_)

Peter Hutterer's avatar
Peter Hutterer committed
441 442 443
void
_litest_add(const char *name,
	    const char *funcname,
444
	    const void *func,
445 446
	    int64_t required_feature,
	    int64_t excluded_feature);
Peter Hutterer's avatar
Peter Hutterer committed
447 448 449
void
_litest_add_ranged(const char *name,
		   const char *funcname,
450
		   const void *func,
451 452
		   int64_t required,
		   int64_t excluded,
Peter Hutterer's avatar
Peter Hutterer committed
453 454 455 456
		   const struct range *range);
void
_litest_add_for_device(const char *name,
		       const char *funcname,
457
		       const void *func,
Peter Hutterer's avatar
Peter Hutterer committed
458 459 460 461
		       enum litest_device_type type);
void
_litest_add_ranged_for_device(const char *name,
			      const char *funcname,
462
			      const void *func,
Peter Hutterer's avatar
Peter Hutterer committed
463 464 465 466 467
			      enum litest_device_type type,
			      const struct range *range);
void
_litest_add_no_device(const char *name,
		      const char *funcname,
468
		      const void *func);
Peter Hutterer's avatar
Peter Hutterer committed
469 470 471
void
_litest_add_ranged_no_device(const char *name,
			     const char *funcname,
472
			     const void *func,
Peter Hutterer's avatar
Peter Hutterer committed
473
			     const struct range *range);
474 475 476
void
_litest_add_deviceless(const char *name,
		       const char *funcname,
477
		       const void *func);
Peter Hutterer's avatar
Peter Hutterer committed
478 479 480 481 482 483 484

struct litest_device *
litest_create_device(enum litest_device_type which);

struct litest_device *
litest_add_device(struct libinput *libinput,
		  enum litest_device_type which);
485 486 487 488 489
struct libevdev_uinput *
litest_create_uinput_device_from_description(const char *name,
					     const struct input_id *id,
					     const struct input_absinfo *abs,
					     const int *events);
490
struct litest_device *
491 492 493 494 495 496 497
litest_create(enum litest_device_type which,
	      const char *name_override,
	      struct input_id *id_override,
	      const struct input_absinfo *abs_override,
	      const int *events_override);

struct litest_device *
498 499 500 501 502
litest_create_device_with_overrides(enum litest_device_type which,
				    const char *name_override,
				    struct input_id *id_override,
				    const struct input_absinfo *abs_override,
				    const int *events_override);
503 504 505 506 507 508 509 510
struct litest_device *
litest_add_device_with_overrides(struct libinput *libinput,
				 enum litest_device_type which,
				 const char *name_override,
				 struct input_id *id_override,
				 const struct input_absinfo *abs_override,
				 const int *events_override);

Peter Hutterer's avatar
Peter Hutterer committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
struct litest_device *
litest_current_device(void);

void
litest_delete_device(struct litest_device *d);

void
litest_event(struct litest_device *t,
	     unsigned int type,
	     unsigned int code,
	     int value);
int
litest_auto_assign_value(struct litest_device *d,
			 const struct input_event *ev,
			 int slot, double x, double y,
			 struct axis_replacement *axes,
			 bool touching);
void
litest_touch_up(struct litest_device *d, unsigned int slot);

void
litest_touch_move(struct litest_device *d,
		  unsigned int slot,
		  double x,
		  double y);

void
litest_touch_move_extended(struct litest_device *d,
			   unsigned int slot,
			   double x,
			   double y,
			   struct axis_replacement *axes);

544 545 546 547 548 549 550 551 552
void
litest_touch_sequence(struct litest_device *d,
		      unsigned int slot,
		      double x1,
		      double y1,
		      double x2,
		      double y2,
		      int steps);

Peter Hutterer's avatar
Peter Hutterer committed
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
void
litest_touch_down(struct litest_device *d,
		  unsigned int slot,
		  double x,
		  double y);

void
litest_touch_down_extended(struct litest_device *d,
			   unsigned int slot,
			   double x,
			   double y,
			   struct axis_replacement *axes);

void
litest_touch_move_to(struct litest_device *d,
		     unsigned int slot,
		     double x_from, double y_from,
		     double x_to, double y_to,
571
		     int steps);
Peter Hutterer's avatar
Peter Hutterer committed
572

573 574 575 576 577 578
void
litest_touch_move_to_extended(struct litest_device *d,
			      unsigned int slot,
			      double x_from, double y_from,
			      double x_to, double y_to,
			      struct axis_replacement *axes,
579
			      int steps);
580

Peter Hutterer's avatar
Peter Hutterer committed
581 582 583 584 585
void
litest_touch_move_two_touches(struct litest_device *d,
			      double x0, double y0,
			      double x1, double y1,
			      double dx, double dy,
586
			      int steps);
Peter Hutterer's avatar
Peter Hutterer committed
587 588 589 590 591 592 593

void
litest_touch_move_three_touches(struct litest_device *d,
				double x0, double y0,
				double x1, double y1,
				double x2, double y2,
				double dx, double dy,
594
				int steps);
Peter Hutterer's avatar
Peter Hutterer committed
595 596 597 598 599 600 601 602 603 604 605 606 607 608

void
litest_tablet_proximity_in(struct litest_device *d,
			   int x, int y,
			   struct axis_replacement *axes);

void
litest_tablet_proximity_out(struct litest_device *d);

void
litest_tablet_motion(struct litest_device *d,
		     int x, int y,
		     struct axis_replacement *axes);

Peter Hutterer's avatar
Peter Hutterer committed
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
void
litest_pad_ring_start(struct litest_device *d, double value);

void
litest_pad_ring_change(struct litest_device *d, double value);

void
litest_pad_ring_end(struct litest_device *d);

void
litest_pad_strip_start(struct litest_device *d, double value);

void
litest_pad_strip_change(struct litest_device *d, double value);

void
litest_pad_strip_end(struct litest_device *d);

Peter Hutterer's avatar
Peter Hutterer committed
627 628 629 630 631 632 633 634 635
void
litest_hover_start(struct litest_device *d,
		   unsigned int slot,
		   double x,
		   double y);

void
litest_hover_end(struct litest_device *d, unsigned int slot);

636 637 638 639
void litest_hover_move(struct litest_device *d,
		       unsigned int slot,
		       double x,
		       double y);
Peter Hutterer's avatar
Peter Hutterer committed
640 641 642 643 644 645

void
litest_hover_move_to(struct litest_device *d,
		     unsigned int slot,
		     double x_from, double y_from,
		     double x_to, double y_to,
646
		     int steps);
Peter Hutterer's avatar
Peter Hutterer committed
647 648 649 650 651 652

void
litest_hover_move_two_touches(struct litest_device *d,
			      double x0, double y0,
			      double x1, double y1,
			      double dx, double dy,
653
			      int steps);
Peter Hutterer's avatar
Peter Hutterer committed
654 655

void
656 657 658 659
litest_button_click_debounced(struct litest_device *d,
			      struct libinput *li,
			      unsigned int button,
			      bool is_press);
Peter Hutterer's avatar
Peter Hutterer committed
660

661 662 663 664 665
void
litest_button_click(struct litest_device *d,
		    unsigned int button,
		    bool is_press);

Peter Hutterer's avatar
Peter Hutterer committed
666 667 668 669
void
litest_button_scroll(struct litest_device *d,
		     unsigned int button,
		     double dx, double dy);
670 671 672 673
void
litest_button_scroll_locked(struct litest_device *d,
			    unsigned int button,
			    double dx, double dy);
Peter Hutterer's avatar
Peter Hutterer committed
674 675 676 677 678 679

void
litest_keyboard_key(struct litest_device *d,
		    unsigned int key,
		    bool is_press);

680 681 682
void litest_switch_action(struct litest_device *d,
			  enum libinput_switch sw,
			  enum libinput_switch_state state);
James Ye's avatar
James Ye committed
683

Peter Hutterer's avatar
Peter Hutterer committed
684 685 686 687 688 689 690 691 692
void
litest_wait_for_event(struct libinput *li);

void
litest_wait_for_event_of_type(struct libinput *li, ...);

void
litest_drain_events(struct libinput *li);

693 694 695
void
litest_drain_events_of_type(struct libinput *li, ...);

696 697 698 699
void
litest_assert_event_type(struct libinput_event *event,
			 enum libinput_event_type want);

Peter Hutterer's avatar
Peter Hutterer committed
700 701 702
void
litest_assert_empty_queue(struct libinput *li);

703 704 705
void
litest_assert_touch_sequence(struct libinput *li);

706 707 708 709 710 711 712 713 714
void
litest_assert_touch_motion_frame(struct libinput *li);
void
litest_assert_touch_down_frame(struct libinput *li);
void
litest_assert_touch_up_frame(struct libinput *li);
void
litest_assert_touch_cancel(struct libinput *li);

Peter Hutterer's avatar
Peter Hutterer committed
715 716
struct libinput_event_pointer *
litest_is_button_event(struct libinput_event *event,
717
		       unsigned int button,
718
		       enum libinput_button_state state);
Peter Hutterer's avatar
Peter Hutterer committed
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743

struct libinput_event_pointer *
litest_is_axis_event(struct libinput_event *event,
		     enum libinput_pointer_axis axis,
		     enum libinput_pointer_axis_source source);

struct libinput_event_pointer *
litest_is_motion_event(struct libinput_event *event);

struct libinput_event_touch *
litest_is_touch_event(struct libinput_event *event,
		      enum libinput_event_type type);

struct libinput_event_keyboard *
litest_is_keyboard_event(struct libinput_event *event,
			 unsigned int key,
			 enum libinput_key_state state);

struct libinput_event_gesture *
litest_is_gesture_event(struct libinput_event *event,
			enum libinput_event_type type,
			int nfingers);

struct libinput_event_tablet_tool *
litest_is_tablet_event(struct libinput_event *event,
Peter Hutterer's avatar
Peter Hutterer committed
744
		       enum libinput_event_type type);
745

Peter Hutterer's avatar
Peter Hutterer committed
746 747 748 749 750 751 752 753 754 755 756 757
struct libinput_event_tablet_pad *
litest_is_pad_button_event(struct libinput_event *event,
			   unsigned int button,
			   enum libinput_button_state state);
struct libinput_event_tablet_pad *
litest_is_pad_ring_event(struct libinput_event *event,
			 unsigned int number,
			 enum libinput_tablet_pad_ring_axis_source source);
struct libinput_event_tablet_pad *
litest_is_pad_strip_event(struct libinput_event *event,
			  unsigned int number,
			  enum libinput_tablet_pad_strip_axis_source source);
758 759 760 761
struct libinput_event_tablet_pad *
litest_is_pad_key_event(struct libinput_event *event,
			unsigned int key,
			enum libinput_key_state state);
Peter Hutterer's avatar
Peter Hutterer committed
762

James Ye's avatar
James Ye committed
763 764 765 766 767
struct libinput_event_switch *
litest_is_switch_event(struct libinput_event *event,
		       enum libinput_switch sw,
		       enum libinput_switch_state state);

768 769 770 771
struct libinput_event_tablet_tool *
litest_is_proximity_event(struct libinput_event *event,
			  enum libinput_tablet_tool_proximity_state state);

772 773 774 775
void
litest_assert_key_event(struct libinput *li, unsigned int key,
			enum libinput_key_state state);

Peter Hutterer's avatar
Peter Hutterer committed
776 777 778 779 780 781 782 783 784 785 786 787 788 789
void
litest_assert_button_event(struct libinput *li,
			   unsigned int button,
			   enum libinput_button_state state);

void
litest_assert_scroll(struct libinput *li,
		     enum libinput_pointer_axis axis,
		     int minimum_movement);

void
litest_assert_only_typed_events(struct libinput *li,
				enum libinput_event_type type);

790 791 792 793
void
litest_assert_no_typed_events(struct libinput *li,
			      enum libinput_event_type type);

Peter Hutterer's avatar
Peter Hutterer committed
794 795 796 797 798 799 800 801 802
void
litest_assert_tablet_button_event(struct libinput *li,
				  unsigned int button,
				  enum libinput_button_state state);

void
litest_assert_tablet_proximity_event(struct libinput *li,
				     enum libinput_tablet_tool_proximity_state state);

803 804 805 806
void
litest_assert_tablet_tip_event(struct libinput *li,
			       enum libinput_tablet_tool_tip_state state);

Peter Hutterer's avatar
Peter Hutterer committed
807 808 809 810
void
litest_assert_pad_button_event(struct libinput *li,
				    unsigned int button,
				    enum libinput_button_state state);
811 812 813 814
void
litest_assert_pad_key_event(struct libinput *li,
			    unsigned int key,
			    enum libinput_key_state state);
Peter Hutterer's avatar
Peter Hutterer committed
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
struct libevdev_uinput *
litest_create_uinput_device(const char *name,
			    struct input_id *id,
			    ...);

struct libevdev_uinput *
litest_create_uinput_abs_device(const char *name,
				struct input_id *id,
				const struct input_absinfo *abs,
				...);

void
litest_timeout_tap(void);

void
litest_timeout_tapndrag(void);

832 833 834
void
litest_timeout_debounce(void);

Peter Hutterer's avatar
Peter Hutterer committed
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
void
litest_timeout_softbuttons(void);

void
litest_timeout_buttonscroll(void);

void
litest_timeout_edgescroll(void);

void
litest_timeout_finger_switch(void);

void
litest_timeout_middlebutton(void);

void
litest_timeout_dwt_short(void);

void
litest_timeout_dwt_long(void);

void
litest_timeout_gesture(void);

859 860 861
void
litest_timeout_gesture_scroll(void);

862 863 864
void
litest_timeout_trackpoint(void);

865 866 867
void
litest_timeout_tablet_proxout(void);

868 869 870
void
litest_timeout_touch_arbitration(void);

871 872 873
void
litest_timeout_hysteresis(void);

Peter Hutterer's avatar
Peter Hutterer committed
874 875 876 877 878
void
litest_push_event_frame(struct litest_device *dev);

void
litest_pop_event_frame(struct litest_device *dev);
879

880 881 882 883 884 885 886 887 888
void
litest_filter_event(struct litest_device *dev,
		    unsigned int type,
		    unsigned int code);

void
litest_unfilter_event(struct litest_device *dev,
		      unsigned int type,
		      unsigned int code);
Peter Hutterer's avatar
Peter Hutterer committed
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
void
litest_semi_mt_touch_down(struct litest_device *d,
			  struct litest_semi_mt *semi_mt,
			  unsigned int slot,
			  double x, double y);

void
litest_semi_mt_touch_move(struct litest_device *d,
			  struct litest_semi_mt *semi_mt,
			  unsigned int slot,
			  double x, double y);

void
litest_semi_mt_touch_up(struct litest_device *d,
			struct litest_semi_mt *semi_mt,
			unsigned int slot);
905

906 907 908 909
#ifndef ck_assert_notnull
#define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL)
#endif

910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
static inline void
litest_enable_tap(struct libinput_device *device)
{
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_tap_set_enabled(device,
							LIBINPUT_CONFIG_TAP_ENABLED);

	litest_assert_int_eq(status, expected);
}

static inline void
litest_disable_tap(struct libinput_device *device)
{
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_tap_set_enabled(device,
							LIBINPUT_CONFIG_TAP_DISABLED);

	litest_assert_int_eq(status, expected);
}

934 935 936 937 938 939 940 941 942 943 944
static inline void
litest_set_tap_map(struct libinput_device *device,
		   enum libinput_config_tap_button_map map)
{
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_tap_set_button_map(device, map);
	litest_assert_int_eq(status, expected);
}

945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
static inline void
litest_enable_tap_drag(struct libinput_device *device)
{
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_tap_set_drag_enabled(device,
							     LIBINPUT_CONFIG_DRAG_ENABLED);

	litest_assert_int_eq(status, expected);
}

static inline void
litest_disable_tap_drag(struct libinput_device *device)
{
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_tap_set_drag_enabled(device,
							     LIBINPUT_CONFIG_DRAG_DISABLED);

	litest_assert_int_eq(status, expected);
}

969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
static inline bool
litest_has_2fg_scroll(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;

	return !!(libinput_device_config_scroll_get_methods(device) &
		  LIBINPUT_CONFIG_SCROLL_2FG);
}

static inline void
litest_enable_2fg_scroll(struct litest_device *dev)
{
	enum libinput_config_status status, expected;
	struct libinput_device *device = dev->libinput_device;

	status = libinput_device_config_scroll_set_method(device,
					  LIBINPUT_CONFIG_SCROLL_2FG);

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	litest_assert_int_eq(status, expected);
}

static inline void
litest_enable_edge_scroll(struct litest_device *dev)
{
	enum libinput_config_status status, expected;
	struct libinput_device *device = dev->libinput_device;

	status = libinput_device_config_scroll_set_method(device,
					  LIBINPUT_CONFIG_SCROLL_EDGE);

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	litest_assert_int_eq(status, expected);
}

1004 1005 1006 1007 1008 1009 1010 1011 1012
static inline bool
litest_has_clickfinger(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;
	uint32_t methods = libinput_device_config_click_get_methods(device);

	return methods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
}

1013 1014 1015 1016 1017 1018 1019 1020 1021
static inline bool
litest_has_btnareas(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;
	uint32_t methods = libinput_device_config_click_get_methods(device);

	return methods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
}

1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
static inline void
litest_enable_clickfinger(struct litest_device *dev)
{
	enum libinput_config_status status, expected;
	struct libinput_device *device = dev->libinput_device;

	status = libinput_device_config_click_set_method(device,
				 LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	litest_assert_int_eq(status, expected);
}

static inline void
litest_enable_buttonareas(struct litest_device *dev)
{
	enum libinput_config_status status, expected;
	struct libinput_device *device = dev->libinput_device;

	status = libinput_device_config_click_set_method(device,
				 LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	litest_assert_int_eq(status, expected);
}

static inline void
litest_enable_drag_lock(struct libinput_device *device)
{
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_tap_set_drag_lock_enabled(device,
								  LIBINPUT_CONFIG_DRAG_LOCK_ENABLED);

	litest_assert_int_eq(status, expected);
}

static inline void
litest_disable_drag_lock(struct libinput_device *device)
{
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_tap_set_drag_lock_enabled(device,
								  LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);

	litest_assert_int_eq(status, expected);
}

1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
static inline void
litest_enable_middleemu(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_middle_emulation_set_enabled(device,
								     LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED);

	litest_assert_int_eq(status, expected);
}

static inline void
litest_disable_middleemu(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_middle_emulation_set_enabled(device,
								     LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);

	litest_assert_int_eq(status, expected);
}

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
static inline void
litest_sendevents_off(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_send_events_set_mode(device,
				    LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
	litest_assert_int_eq(status, expected);
}

static inline void
litest_sendevents_on(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_send_events_set_mode(device,
				    LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
	litest_assert_int_eq(status, expected);
}

static inline void
litest_sendevents_ext_mouse(struct litest_device *dev)
{
	struct libinput_device *device = dev->libinput_device;
	enum libinput_config_status status, expected;

	expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
	status = libinput_device_config_send_events_set_mode(device,
				    LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE);
	litest_assert_int_eq(status, expected);
}

1132 1133 1134 1135 1136 1137 1138
static inline bool
litest_touchpad_is_external(struct litest_device *dev)
{
	struct udev_device *udev_device;
	const char *prop;
	bool is_external;

1139 1140 1141
	if (libinput_device_get_id_vendor(dev->libinput_device) == VENDOR_ID_WACOM)
		return true;

1142 1143 1144 1145 1146 1147 1148 1149 1150
	udev_device = libinput_device_get_udev_device(dev->libinput_device);
	prop = udev_device_get_property_value(udev_device,
					      "ID_INPUT_TOUCHPAD_INTEGRATION");
	is_external = prop && streq(prop, "external");
	udev_device_unref(udev_device);

	return is_external;
}

myfreeweb's avatar
myfreeweb committed
1151 1152 1153 1154 1155
static inline int
litest_send_file(int sock, int fd)
{
	char buf[40960];
	int n = read(fd, buf, 40960);
1156
	litest_assert_int_gt(n, 0);
myfreeweb's avatar
myfreeweb committed
1157 1158 1159
	return write(sock, buf, n);
}

1160 1161
static inline int litest_slot_count(struct litest_device *dev)
{
1162 1163 1164
	if (dev->which == LITEST_ALPS_3FG)
		return 2;

1165 1166 1167
	return libevdev_get_num_slots(dev->evdev);
}

1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
static inline bool
litest_has_palm_detect_size(struct litest_device *dev)
{
	double width, height;
	unsigned int vendor;
	unsigned int bustype;
	int rc;

	vendor = libinput_device_get_id_vendor(dev->libinput_device);
	bustype = libevdev_get_id_bustype(dev->evdev);
	if (vendor == VENDOR_ID_WACOM)
		return 0;
	if (bustype == BUS_BLUETOOTH)
		return 0;
	if (vendor == VENDOR_ID_APPLE)
		return 1;

	rc = libinput_device_get_size(dev->libinput_device, &width, &height);

	return rc == 0 && width >= 70;
}

Peter Hutterer's avatar
Peter Hutterer committed
1190
#endif /* LITEST_H */