| 1 |
/* |
| 2 |
* Copyright © 2014 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 |
#include <errno.h> |
| 27 |
#include <fcntl.h> |
| 28 |
#include <libinput.h> |
| 29 |
#include <libudev.h> |
| 30 |
#include <unistd.h> |
| 31 |
|
| 32 |
#include "libinput-util.h" |
| 33 |
#include "litest.h" |
| 34 |
|
| 35 |
START_TEST(device_sendevents_config) |
| 36 |
{ |
| 37 |
struct litest_device *dev = litest_current_device(); |
| 38 |
struct libinput_device *device; |
| 39 |
uint32_t modes; |
| 40 |
|
| 41 |
device = dev->libinput_device; |
| 42 |
|
| 43 |
modes = libinput_device_config_send_events_get_modes(device); |
| 44 |
litest_assert_int_eq(modes, (uint32_t)LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 45 |
} |
| 46 |
END_TEST |
| 47 |
|
| 48 |
START_TEST(device_sendevents_config_invalid) |
| 49 |
{ |
| 50 |
struct litest_device *dev = litest_current_device(); |
| 51 |
struct libinput_device *device; |
| 52 |
enum libinput_config_status status; |
| 53 |
|
| 54 |
device = dev->libinput_device; |
| 55 |
|
| 56 |
status = libinput_device_config_send_events_set_mode( |
| 57 |
device, |
| 58 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | bit(4)); |
| 59 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); |
| 60 |
} |
| 61 |
END_TEST |
| 62 |
|
| 63 |
START_TEST(device_sendevents_config_touchpad) |
| 64 |
{ |
| 65 |
struct litest_device *dev = litest_current_device(); |
| 66 |
struct libinput_device *device; |
| 67 |
uint32_t modes, expected; |
| 68 |
|
| 69 |
expected = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; |
| 70 |
|
| 71 |
/* The wacom devices in the test suite are external */ |
| 72 |
if (libevdev_get_id_vendor(dev->evdev) != VENDOR_ID_WACOM && |
| 73 |
!litest_touchpad_is_external(dev)) |
| 74 |
expected |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; |
| 75 |
|
| 76 |
device = dev->libinput_device; |
| 77 |
|
| 78 |
modes = libinput_device_config_send_events_get_modes(device); |
| 79 |
litest_assert_int_eq(modes, expected); |
| 80 |
} |
| 81 |
END_TEST |
| 82 |
|
| 83 |
START_TEST(device_sendevents_config_touchpad_superset) |
| 84 |
{ |
| 85 |
struct litest_device *dev = litest_current_device(); |
| 86 |
struct libinput_device *device; |
| 87 |
enum libinput_config_status status; |
| 88 |
uint32_t modes; |
| 89 |
|
| 90 |
/* The wacom devices in the test suite are external */ |
| 91 |
if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM || |
| 92 |
litest_touchpad_is_external(dev)) |
| 93 |
return LITEST_NOT_APPLICABLE; |
| 94 |
|
| 95 |
device = dev->libinput_device; |
| 96 |
|
| 97 |
modes = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED | |
| 98 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; |
| 99 |
|
| 100 |
status = libinput_device_config_send_events_set_mode(device, modes); |
| 101 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 102 |
|
| 103 |
/* DISABLED supersedes the rest, expect the rest to be dropped */ |
| 104 |
modes = libinput_device_config_send_events_get_mode(device); |
| 105 |
litest_assert_enum_eq(modes, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 106 |
} |
| 107 |
END_TEST |
| 108 |
|
| 109 |
START_TEST(device_sendevents_config_default) |
| 110 |
{ |
| 111 |
struct litest_device *dev = litest_current_device(); |
| 112 |
struct libinput_device *device; |
| 113 |
uint32_t mode; |
| 114 |
|
| 115 |
device = dev->libinput_device; |
| 116 |
|
| 117 |
mode = libinput_device_config_send_events_get_mode(device); |
| 118 |
litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 119 |
|
| 120 |
mode = libinput_device_config_send_events_get_default_mode(device); |
| 121 |
litest_assert_enum_eq(mode, LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 122 |
} |
| 123 |
END_TEST |
| 124 |
|
| 125 |
START_TEST(device_disable) |
| 126 |
{ |
| 127 |
struct litest_device *dev = litest_current_device(); |
| 128 |
struct libinput *li = dev->libinput; |
| 129 |
struct libinput_device *device; |
| 130 |
enum libinput_config_status status; |
| 131 |
struct libinput_event *event; |
| 132 |
struct litest_device *tmp; |
| 133 |
|
| 134 |
device = dev->libinput_device; |
| 135 |
|
| 136 |
litest_drain_events(li); |
| 137 |
|
| 138 |
status = libinput_device_config_send_events_set_mode( |
| 139 |
device, |
| 140 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 141 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 142 |
|
| 143 |
/* no event from disabling */ |
| 144 |
litest_assert_empty_queue(li); |
| 145 |
|
| 146 |
/* no event from disabled device */ |
| 147 |
litest_event(dev, EV_REL, REL_X, 10); |
| 148 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 149 |
litest_assert_empty_queue(li); |
| 150 |
|
| 151 |
/* create a new device so the resumed fd isn't the same as the |
| 152 |
suspended one */ |
| 153 |
tmp = litest_add_device(li, LITEST_KEYBOARD); |
| 154 |
litest_assert_notnull(tmp); |
| 155 |
litest_drain_events(li); |
| 156 |
|
| 157 |
/* no event from resuming */ |
| 158 |
status = libinput_device_config_send_events_set_mode( |
| 159 |
device, |
| 160 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 161 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 162 |
litest_assert_empty_queue(li); |
| 163 |
|
| 164 |
/* event from re-enabled device */ |
| 165 |
litest_event(dev, EV_REL, REL_X, 10); |
| 166 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 167 |
|
| 168 |
litest_dispatch(li); |
| 169 |
event = libinput_get_event(li); |
| 170 |
litest_assert_notnull(event); |
| 171 |
litest_assert_enum_eq(libinput_event_get_type(event), |
| 172 |
LIBINPUT_EVENT_POINTER_MOTION); |
| 173 |
libinput_event_destroy(event); |
| 174 |
|
| 175 |
litest_device_destroy(tmp); |
| 176 |
} |
| 177 |
END_TEST |
| 178 |
|
| 179 |
START_TEST(device_disable_tablet) |
| 180 |
{ |
| 181 |
struct litest_device *dev = litest_current_device(); |
| 182 |
struct libinput *li = dev->libinput; |
| 183 |
struct libinput_device *device; |
| 184 |
enum libinput_config_status status; |
| 185 |
struct axis_replacement axes[] = { |
| 186 |
{ ABS_DISTANCE, 10 }, |
| 187 |
{ ABS_PRESSURE, 0 }, |
| 188 |
{ -1, -1 }, |
| 189 |
}; |
| 190 |
|
| 191 |
device = dev->libinput_device; |
| 192 |
|
| 193 |
litest_drain_events(li); |
| 194 |
|
| 195 |
status = libinput_device_config_send_events_set_mode( |
| 196 |
device, |
| 197 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 198 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 199 |
|
| 200 |
/* no event from disabling */ |
| 201 |
litest_assert_empty_queue(li); |
| 202 |
|
| 203 |
litest_tablet_proximity_in(dev, 60, 60, axes); |
| 204 |
for (int i = 60; i < 70; i++) { |
| 205 |
litest_tablet_motion(dev, i, i, axes); |
| 206 |
litest_dispatch(li); |
| 207 |
} |
| 208 |
litest_tablet_proximity_out(dev); |
| 209 |
|
| 210 |
litest_assert_empty_queue(li); |
| 211 |
|
| 212 |
/* no event from resuming */ |
| 213 |
status = libinput_device_config_send_events_set_mode( |
| 214 |
device, |
| 215 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 216 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 217 |
litest_assert_empty_queue(li); |
| 218 |
} |
| 219 |
END_TEST |
| 220 |
|
| 221 |
START_TEST(device_disable_touchpad) |
| 222 |
{ |
| 223 |
struct litest_device *dev = litest_current_device(); |
| 224 |
struct libinput *li = dev->libinput; |
| 225 |
struct libinput_device *device; |
| 226 |
enum libinput_config_status status; |
| 227 |
|
| 228 |
device = dev->libinput_device; |
| 229 |
|
| 230 |
litest_drain_events(li); |
| 231 |
|
| 232 |
status = libinput_device_config_send_events_set_mode( |
| 233 |
device, |
| 234 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 235 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 236 |
|
| 237 |
/* no event from disabling */ |
| 238 |
litest_assert_empty_queue(li); |
| 239 |
|
| 240 |
litest_touch_down(dev, 0, 50, 50); |
| 241 |
litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); |
| 242 |
litest_touch_up(dev, 0); |
| 243 |
|
| 244 |
litest_assert_empty_queue(li); |
| 245 |
|
| 246 |
/* no event from resuming */ |
| 247 |
status = libinput_device_config_send_events_set_mode( |
| 248 |
device, |
| 249 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 250 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 251 |
litest_assert_empty_queue(li); |
| 252 |
} |
| 253 |
END_TEST |
| 254 |
|
| 255 |
START_TEST(device_disable_touch) |
| 256 |
{ |
| 257 |
struct litest_device *dev = litest_current_device(); |
| 258 |
struct libinput *li = dev->libinput; |
| 259 |
struct libinput_device *device; |
| 260 |
enum libinput_config_status status; |
| 261 |
|
| 262 |
device = dev->libinput_device; |
| 263 |
|
| 264 |
litest_drain_events(li); |
| 265 |
|
| 266 |
status = libinput_device_config_send_events_set_mode( |
| 267 |
device, |
| 268 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 269 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 270 |
|
| 271 |
/* no event from disabling */ |
| 272 |
litest_assert_empty_queue(li); |
| 273 |
|
| 274 |
litest_touch_down(dev, 0, 50, 50); |
| 275 |
litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); |
| 276 |
litest_touch_up(dev, 0); |
| 277 |
|
| 278 |
litest_assert_empty_queue(li); |
| 279 |
|
| 280 |
/* no event from resuming */ |
| 281 |
status = libinput_device_config_send_events_set_mode( |
| 282 |
device, |
| 283 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 284 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 285 |
litest_assert_empty_queue(li); |
| 286 |
} |
| 287 |
END_TEST |
| 288 |
|
| 289 |
START_TEST(device_disable_touch_during_touch) |
| 290 |
{ |
| 291 |
struct litest_device *dev = litest_current_device(); |
| 292 |
struct libinput *li = dev->libinput; |
| 293 |
struct libinput_device *device; |
| 294 |
enum libinput_config_status status; |
| 295 |
struct libinput_event *event; |
| 296 |
|
| 297 |
device = dev->libinput_device; |
| 298 |
|
| 299 |
litest_touch_down(dev, 0, 50, 50); |
| 300 |
litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); |
| 301 |
litest_drain_events(li); |
| 302 |
|
| 303 |
status = libinput_device_config_send_events_set_mode( |
| 304 |
device, |
| 305 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 306 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 307 |
|
| 308 |
/* after disabling sendevents we require a touch up */ |
| 309 |
litest_dispatch(li); |
| 310 |
event = libinput_get_event(li); |
| 311 |
litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_CANCEL); |
| 312 |
libinput_event_destroy(event); |
| 313 |
|
| 314 |
event = libinput_get_event(li); |
| 315 |
litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_FRAME); |
| 316 |
libinput_event_destroy(event); |
| 317 |
|
| 318 |
litest_assert_empty_queue(li); |
| 319 |
|
| 320 |
litest_touch_move_to(dev, 0, 90, 90, 50, 50, 10); |
| 321 |
litest_touch_up(dev, 0); |
| 322 |
|
| 323 |
litest_touch_down(dev, 0, 50, 50); |
| 324 |
litest_touch_move_to(dev, 0, 50, 50, 90, 90, 10); |
| 325 |
litest_touch_up(dev, 0); |
| 326 |
|
| 327 |
litest_assert_empty_queue(li); |
| 328 |
|
| 329 |
/* no event from resuming */ |
| 330 |
status = libinput_device_config_send_events_set_mode( |
| 331 |
device, |
| 332 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 333 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 334 |
litest_assert_empty_queue(li); |
| 335 |
} |
| 336 |
END_TEST |
| 337 |
|
| 338 |
START_TEST(device_disable_events_pending) |
| 339 |
{ |
| 340 |
struct litest_device *dev = litest_current_device(); |
| 341 |
struct libinput *li = dev->libinput; |
| 342 |
struct libinput_device *device; |
| 343 |
enum libinput_config_status status; |
| 344 |
struct libinput_event *event; |
| 345 |
int i; |
| 346 |
|
| 347 |
device = dev->libinput_device; |
| 348 |
|
| 349 |
litest_drain_events(li); |
| 350 |
|
| 351 |
/* put a couple of events in the queue, enough to |
| 352 |
feed the ptraccel trackers */ |
| 353 |
for (i = 0; i < 10; i++) { |
| 354 |
litest_event(dev, EV_REL, REL_X, 10); |
| 355 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 356 |
} |
| 357 |
litest_dispatch(li); |
| 358 |
|
| 359 |
status = libinput_device_config_send_events_set_mode( |
| 360 |
device, |
| 361 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 362 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 363 |
|
| 364 |
/* expect above events */ |
| 365 |
litest_wait_for_event(li); |
| 366 |
while ((event = libinput_get_event(li)) != NULL) { |
| 367 |
litest_assert_enum_eq(libinput_event_get_type(event), |
| 368 |
LIBINPUT_EVENT_POINTER_MOTION); |
| 369 |
libinput_event_destroy(event); |
| 370 |
} |
| 371 |
} |
| 372 |
END_TEST |
| 373 |
|
| 374 |
START_TEST(device_double_disable) |
| 375 |
{ |
| 376 |
struct litest_device *dev = litest_current_device(); |
| 377 |
struct libinput *li = dev->libinput; |
| 378 |
struct libinput_device *device; |
| 379 |
enum libinput_config_status status; |
| 380 |
|
| 381 |
device = dev->libinput_device; |
| 382 |
|
| 383 |
litest_drain_events(li); |
| 384 |
|
| 385 |
status = libinput_device_config_send_events_set_mode( |
| 386 |
device, |
| 387 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 388 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 389 |
|
| 390 |
status = libinput_device_config_send_events_set_mode( |
| 391 |
device, |
| 392 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 393 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 394 |
|
| 395 |
litest_assert_empty_queue(li); |
| 396 |
} |
| 397 |
END_TEST |
| 398 |
|
| 399 |
START_TEST(device_double_enable) |
| 400 |
{ |
| 401 |
struct litest_device *dev = litest_current_device(); |
| 402 |
struct libinput *li = dev->libinput; |
| 403 |
struct libinput_device *device; |
| 404 |
enum libinput_config_status status; |
| 405 |
|
| 406 |
device = dev->libinput_device; |
| 407 |
|
| 408 |
litest_drain_events(li); |
| 409 |
|
| 410 |
status = libinput_device_config_send_events_set_mode( |
| 411 |
device, |
| 412 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 413 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 414 |
|
| 415 |
status = libinput_device_config_send_events_set_mode( |
| 416 |
device, |
| 417 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 418 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 419 |
|
| 420 |
litest_assert_empty_queue(li); |
| 421 |
} |
| 422 |
END_TEST |
| 423 |
|
| 424 |
START_TEST(device_reenable_syspath_changed) |
| 425 |
{ |
| 426 |
struct litest_device *litest_device; |
| 427 |
struct libinput_device *device1; |
| 428 |
enum libinput_config_status status; |
| 429 |
struct libinput_event *event; |
| 430 |
|
| 431 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 432 |
litest_device = litest_add_device(li, LITEST_MOUSE); |
| 433 |
device1 = litest_device->libinput_device; |
| 434 |
|
| 435 |
libinput_device_ref(device1); |
| 436 |
status = libinput_device_config_send_events_set_mode( |
| 437 |
device1, |
| 438 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 439 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 440 |
|
| 441 |
litest_drain_events(li); |
| 442 |
|
| 443 |
litest_device_destroy(litest_device); |
| 444 |
litest_drain_events(li); |
| 445 |
|
| 446 |
litest_device = litest_add_device(li, LITEST_MOUSE); |
| 447 |
|
| 448 |
status = libinput_device_config_send_events_set_mode( |
| 449 |
device1, |
| 450 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 451 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 452 |
|
| 453 |
/* can't really check for much here, other than that if we pump |
| 454 |
events through libinput, none of them should be from the first |
| 455 |
device */ |
| 456 |
litest_event(litest_device, EV_REL, REL_X, 1); |
| 457 |
litest_event(litest_device, EV_REL, REL_Y, 1); |
| 458 |
litest_event(litest_device, EV_SYN, SYN_REPORT, 0); |
| 459 |
|
| 460 |
litest_dispatch(li); |
| 461 |
while ((event = libinput_get_event(li))) { |
| 462 |
litest_assert(libinput_event_get_device(event) != device1); |
| 463 |
libinput_event_destroy(event); |
| 464 |
} |
| 465 |
|
| 466 |
litest_device_destroy(litest_device); |
| 467 |
libinput_device_unref(device1); |
| 468 |
} |
| 469 |
END_TEST |
| 470 |
|
| 471 |
START_TEST(device_reenable_device_removed) |
| 472 |
{ |
| 473 |
struct litest_device *litest_device; |
| 474 |
struct libinput_device *device; |
| 475 |
enum libinput_config_status status; |
| 476 |
|
| 477 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 478 |
litest_device = litest_add_device(li, LITEST_MOUSE); |
| 479 |
device = litest_device->libinput_device; |
| 480 |
|
| 481 |
libinput_device_ref(device); |
| 482 |
status = libinput_device_config_send_events_set_mode( |
| 483 |
device, |
| 484 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 485 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 486 |
|
| 487 |
litest_drain_events(li); |
| 488 |
|
| 489 |
litest_device_destroy(litest_device); |
| 490 |
litest_drain_events(li); |
| 491 |
|
| 492 |
status = libinput_device_config_send_events_set_mode( |
| 493 |
device, |
| 494 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 495 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 496 |
|
| 497 |
/* can't really check for much here, this really just exercises the |
| 498 |
code path. */ |
| 499 |
litest_assert_empty_queue(li); |
| 500 |
|
| 501 |
libinput_device_unref(device); |
| 502 |
} |
| 503 |
END_TEST |
| 504 |
|
| 505 |
START_TEST(device_disable_release_buttons) |
| 506 |
{ |
| 507 |
struct litest_device *dev = litest_current_device(); |
| 508 |
struct libinput *li = dev->libinput; |
| 509 |
struct libinput_device *device; |
| 510 |
struct libinput_event *event; |
| 511 |
struct libinput_event_pointer *ptrevent; |
| 512 |
enum libinput_config_status status; |
| 513 |
|
| 514 |
device = dev->libinput_device; |
| 515 |
|
| 516 |
litest_button_click_debounced(dev, li, BTN_LEFT, true); |
| 517 |
litest_drain_events(li); |
| 518 |
|
| 519 |
status = libinput_device_config_send_events_set_mode( |
| 520 |
device, |
| 521 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 522 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 523 |
|
| 524 |
litest_wait_for_event(li); |
| 525 |
event = libinput_get_event(li); |
| 526 |
|
| 527 |
litest_assert_enum_eq(libinput_event_get_type(event), |
| 528 |
LIBINPUT_EVENT_POINTER_BUTTON); |
| 529 |
ptrevent = libinput_event_get_pointer_event(event); |
| 530 |
litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent), |
| 531 |
(unsigned int)BTN_LEFT); |
| 532 |
litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent), |
| 533 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 534 |
|
| 535 |
libinput_event_destroy(event); |
| 536 |
litest_assert_empty_queue(li); |
| 537 |
} |
| 538 |
END_TEST |
| 539 |
|
| 540 |
START_TEST(device_disable_release_keys) |
| 541 |
{ |
| 542 |
struct litest_device *dev = litest_current_device(); |
| 543 |
struct libinput *li = dev->libinput; |
| 544 |
struct libinput_device *device; |
| 545 |
struct libinput_event *event; |
| 546 |
struct libinput_event_keyboard *kbdevent; |
| 547 |
enum libinput_config_status status; |
| 548 |
|
| 549 |
device = dev->libinput_device; |
| 550 |
|
| 551 |
litest_keyboard_key(dev, KEY_A, true); |
| 552 |
litest_drain_events(li); |
| 553 |
|
| 554 |
status = libinput_device_config_send_events_set_mode( |
| 555 |
device, |
| 556 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 557 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 558 |
|
| 559 |
litest_wait_for_event(li); |
| 560 |
event = libinput_get_event(li); |
| 561 |
|
| 562 |
litest_assert_enum_eq(libinput_event_get_type(event), |
| 563 |
LIBINPUT_EVENT_KEYBOARD_KEY); |
| 564 |
kbdevent = libinput_event_get_keyboard_event(event); |
| 565 |
litest_assert_int_eq(libinput_event_keyboard_get_key(kbdevent), |
| 566 |
(unsigned int)KEY_A); |
| 567 |
litest_assert_enum_eq(libinput_event_keyboard_get_key_state(kbdevent), |
| 568 |
LIBINPUT_KEY_STATE_RELEASED); |
| 569 |
|
| 570 |
libinput_event_destroy(event); |
| 571 |
litest_assert_empty_queue(li); |
| 572 |
} |
| 573 |
END_TEST |
| 574 |
|
| 575 |
START_TEST(device_disable_release_tap) |
| 576 |
{ |
| 577 |
struct litest_device *dev = litest_current_device(); |
| 578 |
struct libinput *li = dev->libinput; |
| 579 |
struct libinput_device *device; |
| 580 |
enum libinput_config_status status; |
| 581 |
|
| 582 |
device = dev->libinput_device; |
| 583 |
|
| 584 |
libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED); |
| 585 |
|
| 586 |
litest_drain_events(li); |
| 587 |
|
| 588 |
litest_touch_down(dev, 0, 50, 50); |
| 589 |
litest_touch_up(dev, 0); |
| 590 |
|
| 591 |
litest_dispatch(li); |
| 592 |
|
| 593 |
status = libinput_device_config_send_events_set_mode( |
| 594 |
device, |
| 595 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 596 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 597 |
/* tap happened before suspending, so we still expect the event */ |
| 598 |
|
| 599 |
litest_timeout_tap(li); |
| 600 |
|
| 601 |
litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); |
| 602 |
litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); |
| 603 |
|
| 604 |
litest_assert_empty_queue(li); |
| 605 |
|
| 606 |
/* resume, make sure we don't get anything */ |
| 607 |
status = libinput_device_config_send_events_set_mode( |
| 608 |
device, |
| 609 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 610 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 611 |
litest_dispatch(li); |
| 612 |
litest_assert_empty_queue(li); |
| 613 |
} |
| 614 |
END_TEST |
| 615 |
|
| 616 |
START_TEST(device_disable_release_tap_n_drag) |
| 617 |
{ |
| 618 |
struct litest_device *dev = litest_current_device(); |
| 619 |
struct libinput *li = dev->libinput; |
| 620 |
struct libinput_device *device; |
| 621 |
enum libinput_config_status status; |
| 622 |
|
| 623 |
device = dev->libinput_device; |
| 624 |
|
| 625 |
libinput_device_config_tap_set_enabled(device, LIBINPUT_CONFIG_TAP_ENABLED); |
| 626 |
|
| 627 |
litest_drain_events(li); |
| 628 |
|
| 629 |
litest_touch_down(dev, 0, 50, 50); |
| 630 |
litest_touch_up(dev, 0); |
| 631 |
litest_touch_down(dev, 0, 50, 50); |
| 632 |
litest_timeout_tap(li); |
| 633 |
|
| 634 |
status = libinput_device_config_send_events_set_mode( |
| 635 |
device, |
| 636 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 637 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 638 |
|
| 639 |
litest_dispatch(li); |
| 640 |
litest_touch_up(dev, 0); |
| 641 |
|
| 642 |
litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED); |
| 643 |
litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED); |
| 644 |
|
| 645 |
litest_assert_empty_queue(li); |
| 646 |
} |
| 647 |
END_TEST |
| 648 |
|
| 649 |
START_TEST(device_disable_release_softbutton) |
| 650 |
{ |
| 651 |
struct litest_device *dev = litest_current_device(); |
| 652 |
struct libinput *li = dev->libinput; |
| 653 |
struct libinput_device *device; |
| 654 |
enum libinput_config_status status; |
| 655 |
|
| 656 |
device = dev->libinput_device; |
| 657 |
|
| 658 |
litest_drain_events(li); |
| 659 |
|
| 660 |
litest_touch_down(dev, 0, 90, 90); |
| 661 |
litest_button_click_debounced(dev, li, BTN_LEFT, true); |
| 662 |
|
| 663 |
/* make sure softbutton works */ |
| 664 |
litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED); |
| 665 |
/* disable */ |
| 666 |
status = libinput_device_config_send_events_set_mode( |
| 667 |
device, |
| 668 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 669 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 670 |
|
| 671 |
litest_assert_button_event(li, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED); |
| 672 |
|
| 673 |
litest_assert_empty_queue(li); |
| 674 |
|
| 675 |
litest_button_click_debounced(dev, li, BTN_LEFT, false); |
| 676 |
litest_touch_up(dev, 0); |
| 677 |
|
| 678 |
litest_assert_empty_queue(li); |
| 679 |
|
| 680 |
/* resume, make sure we don't get anything */ |
| 681 |
status = libinput_device_config_send_events_set_mode( |
| 682 |
device, |
| 683 |
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED); |
| 684 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 685 |
litest_dispatch(li); |
| 686 |
litest_assert_empty_queue(li); |
| 687 |
} |
| 688 |
END_TEST |
| 689 |
|
| 690 |
START_TEST(device_disable_topsoftbutton) |
| 691 |
{ |
| 692 |
struct litest_device *dev = litest_current_device(); |
| 693 |
struct litest_device *trackpoint; |
| 694 |
struct libinput *li = dev->libinput; |
| 695 |
struct libinput_device *device; |
| 696 |
enum libinput_config_status status; |
| 697 |
|
| 698 |
struct libinput_event *event; |
| 699 |
struct libinput_event_pointer *ptrevent; |
| 700 |
|
| 701 |
device = dev->libinput_device; |
| 702 |
|
| 703 |
trackpoint = litest_add_device(li, LITEST_TRACKPOINT); |
| 704 |
|
| 705 |
status = libinput_device_config_send_events_set_mode( |
| 706 |
device, |
| 707 |
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
| 708 |
litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); |
| 709 |
litest_drain_events(li); |
| 710 |
|
| 711 |
litest_touch_down(dev, 0, 90, 10); |
| 712 |
litest_button_click_debounced(dev, li, BTN_LEFT, true); |
| 713 |
litest_button_click_debounced(dev, li, BTN_LEFT, false); |
| 714 |
litest_touch_up(dev, 0); |
| 715 |
|
| 716 |
litest_wait_for_event(li); |
| 717 |
event = libinput_get_event(li); |
| 718 |
litest_assert_enum_eq(libinput_event_get_type(event), |
| 719 |
LIBINPUT_EVENT_POINTER_BUTTON); |
| 720 |
litest_assert_ptr_eq(libinput_event_get_device(event), |
| 721 |
trackpoint->libinput_device); |
| 722 |
ptrevent = libinput_event_get_pointer_event(event); |
| 723 |
litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent), |
| 724 |
(unsigned int)BTN_RIGHT); |
| 725 |
litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent), |
| 726 |
LIBINPUT_BUTTON_STATE_PRESSED); |
| 727 |
libinput_event_destroy(event); |
| 728 |
|
| 729 |
event = libinput_get_event(li); |
| 730 |
litest_assert_enum_eq(libinput_event_get_type(event), |
| 731 |
LIBINPUT_EVENT_POINTER_BUTTON); |
| 732 |
litest_assert_ptr_eq(libinput_event_get_device(event), |
| 733 |
trackpoint->libinput_device); |
| 734 |
ptrevent = libinput_event_get_pointer_event(event); |
| 735 |
litest_assert_int_eq(libinput_event_pointer_get_button(ptrevent), |
| 736 |
(unsigned int)BTN_RIGHT); |
| 737 |
litest_assert_enum_eq(libinput_event_pointer_get_button_state(ptrevent), |
| 738 |
LIBINPUT_BUTTON_STATE_RELEASED); |
| 739 |
libinput_event_destroy(event); |
| 740 |
|
| 741 |
litest_assert_empty_queue(li); |
| 742 |
|
| 743 |
litest_device_destroy(trackpoint); |
| 744 |
} |
| 745 |
END_TEST |
| 746 |
|
| 747 |
START_TEST(device_ids) |
| 748 |
{ |
| 749 |
struct litest_device *dev = litest_current_device(); |
| 750 |
const char *name; |
| 751 |
unsigned int bus, pid, vid; |
| 752 |
|
| 753 |
name = libevdev_get_name(dev->evdev); |
| 754 |
bus = libevdev_get_id_bustype(dev->evdev); |
| 755 |
pid = libevdev_get_id_product(dev->evdev); |
| 756 |
vid = libevdev_get_id_vendor(dev->evdev); |
| 757 |
|
| 758 |
litest_assert_str_eq(name, libinput_device_get_name(dev->libinput_device)); |
| 759 |
litest_assert_int_eq(bus, libinput_device_get_id_bustype(dev->libinput_device)); |
| 760 |
litest_assert_int_eq(pid, libinput_device_get_id_product(dev->libinput_device)); |
| 761 |
litest_assert_int_eq(vid, libinput_device_get_id_vendor(dev->libinput_device)); |
| 762 |
} |
| 763 |
END_TEST |
| 764 |
|
| 765 |
START_TEST(device_get_udev_handle) |
| 766 |
{ |
| 767 |
struct litest_device *dev = litest_current_device(); |
| 768 |
struct udev_device *udev_device; |
| 769 |
|
| 770 |
udev_device = libinput_device_get_udev_device(dev->libinput_device); |
| 771 |
litest_assert_notnull(udev_device); |
| 772 |
udev_device_unref(udev_device); |
| 773 |
} |
| 774 |
END_TEST |
| 775 |
|
| 776 |
START_TEST(device_context) |
| 777 |
{ |
| 778 |
struct litest_device *dev = litest_current_device(); |
| 779 |
struct libinput_seat *seat; |
| 780 |
|
| 781 |
litest_assert(dev->libinput == |
| 782 |
libinput_device_get_context(dev->libinput_device)); |
| 783 |
seat = libinput_device_get_seat(dev->libinput_device); |
| 784 |
litest_assert(dev->libinput == libinput_seat_get_context(seat)); |
| 785 |
} |
| 786 |
END_TEST |
| 787 |
|
| 788 |
START_TEST(device_user_data) |
| 789 |
{ |
| 790 |
struct litest_device *dev = litest_current_device(); |
| 791 |
struct libinput_device *device = dev->libinput_device; |
| 792 |
void *userdata = &dev; /* not referenced */ |
| 793 |
|
| 794 |
litest_assert(libinput_device_get_user_data(device) == NULL); |
| 795 |
libinput_device_set_user_data(device, userdata); |
| 796 |
litest_assert_ptr_eq(libinput_device_get_user_data(device), userdata); |
| 797 |
libinput_device_set_user_data(device, NULL); |
| 798 |
litest_assert(libinput_device_get_user_data(device) == NULL); |
| 799 |
} |
| 800 |
END_TEST |
| 801 |
|
| 802 |
START_TEST(device_group_get) |
| 803 |
{ |
| 804 |
struct litest_device *dev = litest_current_device(); |
| 805 |
struct libinput_device_group *group; |
| 806 |
|
| 807 |
int userdata = 10; |
| 808 |
|
| 809 |
group = libinput_device_get_device_group(dev->libinput_device); |
| 810 |
litest_assert_notnull(group); |
| 811 |
|
| 812 |
libinput_device_group_ref(group); |
| 813 |
|
| 814 |
libinput_device_group_set_user_data(group, &userdata); |
| 815 |
litest_assert_ptr_eq(&userdata, libinput_device_group_get_user_data(group)); |
| 816 |
|
| 817 |
libinput_device_group_unref(group); |
| 818 |
} |
| 819 |
END_TEST |
| 820 |
|
| 821 |
START_TEST(device_group_ref) |
| 822 |
{ |
| 823 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 824 |
struct litest_device *dev = litest_add_device(li, LITEST_MOUSE); |
| 825 |
struct libinput_device *device = dev->libinput_device; |
| 826 |
struct libinput_device_group *group; |
| 827 |
|
| 828 |
group = libinput_device_get_device_group(device); |
| 829 |
litest_assert_notnull(group); |
| 830 |
libinput_device_group_ref(group); |
| 831 |
|
| 832 |
libinput_device_ref(device); |
| 833 |
litest_drain_events(li); |
| 834 |
litest_device_destroy(dev); |
| 835 |
litest_drain_events(li); |
| 836 |
|
| 837 |
/* make sure the device is dead but the group is still around */ |
| 838 |
litest_assert(libinput_device_unref(device) == NULL); |
| 839 |
|
| 840 |
libinput_device_group_ref(group); |
| 841 |
litest_assert_notnull(libinput_device_group_unref(group)); |
| 842 |
litest_assert(libinput_device_group_unref(group) == NULL); |
| 843 |
} |
| 844 |
END_TEST |
| 845 |
|
| 846 |
START_TEST(device_group_leak) |
| 847 |
{ |
| 848 |
struct libinput_device *device; |
| 849 |
struct libevdev_uinput *uinput; |
| 850 |
struct libinput_device_group *group; |
| 851 |
|
| 852 |
/* clang-format off */ |
| 853 |
uinput = litest_create_uinput_device("test device", NULL, |
| 854 |
EV_KEY, BTN_LEFT, |
| 855 |
EV_KEY, BTN_RIGHT, |
| 856 |
EV_REL, REL_X, |
| 857 |
EV_REL, REL_Y, |
| 858 |
-1); |
| 859 |
/* clang-format on */ |
| 860 |
|
| 861 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 862 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 863 |
|
| 864 |
group = libinput_device_get_device_group(device); |
| 865 |
libinput_device_group_ref(group); |
| 866 |
|
| 867 |
libinput_path_remove_device(device); |
| 868 |
|
| 869 |
libevdev_uinput_destroy(uinput); |
| 870 |
|
| 871 |
/* the device group leaks, check valgrind */ |
| 872 |
} |
| 873 |
END_TEST |
| 874 |
|
| 875 |
START_TEST(abs_device_missing_one_abs) |
| 876 |
{ |
| 877 |
struct libevdev_uinput *uinput; |
| 878 |
struct libinput_device *device; |
| 879 |
|
| 880 |
int axis = litest_test_param_get_i32(test_env->params, "axis"); |
| 881 |
|
| 882 |
/* clang-format off */ |
| 883 |
uinput = litest_create_uinput_device("test device", NULL, |
| 884 |
EV_KEY, BTN_LEFT, |
| 885 |
EV_KEY, BTN_RIGHT, |
| 886 |
EV_ABS, axis, |
| 887 |
-1); |
| 888 |
/* clang-format on */ |
| 889 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 890 |
litest_disable_log_handler(li); |
| 891 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 892 |
litest_restore_log_handler(li); |
| 893 |
litest_assert(device == NULL); |
| 894 |
|
| 895 |
libevdev_uinput_destroy(uinput); |
| 896 |
} |
| 897 |
END_TEST |
| 898 |
|
| 899 |
START_TEST(abs_mt_device_missing_one_mt_abs) |
| 900 |
{ |
| 901 |
struct libevdev_uinput *uinput; |
| 902 |
struct libinput_device *device; |
| 903 |
int axis = litest_test_param_get_i32(test_env->params, "axis"); |
| 904 |
|
| 905 |
/* clang-format off */ |
| 906 |
uinput = litest_create_uinput_device("test device", NULL, |
| 907 |
EV_KEY, BTN_LEFT, |
| 908 |
EV_KEY, BTN_RIGHT, |
| 909 |
EV_ABS, ABS_X, |
| 910 |
EV_ABS, ABS_Y, |
| 911 |
EV_ABS, ABS_MT_SLOT, |
| 912 |
EV_ABS, axis, |
| 913 |
-1); |
| 914 |
/* clang-format on */ |
| 915 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 916 |
litest_disable_log_handler(li); |
| 917 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 918 |
litest_restore_log_handler(li); |
| 919 |
litest_assert(device == NULL); |
| 920 |
|
| 921 |
libevdev_uinput_destroy(uinput); |
| 922 |
} |
| 923 |
END_TEST |
| 924 |
|
| 925 |
static void |
| 926 |
assert_device_ignored(struct libinput *li, struct input_absinfo *absinfo) |
| 927 |
{ |
| 928 |
struct libevdev_uinput *uinput; |
| 929 |
struct libinput_device *device; |
| 930 |
|
| 931 |
/* clang-format off */ |
| 932 |
uinput = litest_create_uinput_abs_device("test device", NULL, |
| 933 |
absinfo, |
| 934 |
EV_KEY, BTN_LEFT, |
| 935 |
EV_KEY, BTN_RIGHT, |
| 936 |
-1); |
| 937 |
/* clang-format on */ |
| 938 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 939 |
litest_assert_ptr_null(device); |
| 940 |
libevdev_uinput_destroy(uinput); |
| 941 |
} |
| 942 |
|
| 943 |
START_TEST(abs_device_no_range) |
| 944 |
{ |
| 945 |
int code = _i; /* looped test */ |
| 946 |
/* set x/y so libinput doesn't just reject for missing axes */ |
| 947 |
struct input_absinfo absinfo[] = { |
| 948 |
{ ABS_X, 0, 10, 0, 0, 0 }, |
| 949 |
{ ABS_Y, 0, 10, 0, 0, 0 }, |
| 950 |
{ code, 0, 0, 0, 0, 0 }, |
| 951 |
{ -1, -1, -1, -1, -1, -1 }, |
| 952 |
}; |
| 953 |
|
| 954 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 955 |
litest_disable_log_handler(li); |
| 956 |
|
| 957 |
assert_device_ignored(li, absinfo); |
| 958 |
|
| 959 |
litest_restore_log_handler(li); |
| 960 |
} |
| 961 |
END_TEST |
| 962 |
|
| 963 |
START_TEST(abs_mt_device_no_range) |
| 964 |
{ |
| 965 |
int code = _i; /* looped test */ |
| 966 |
/* set x/y so libinput doesn't just reject for missing axes */ |
| 967 |
struct input_absinfo absinfo[] = { |
| 968 |
{ ABS_X, 0, 10, 0, 0, 0 }, |
| 969 |
{ ABS_Y, 0, 10, 0, 0, 0 }, |
| 970 |
{ ABS_MT_SLOT, 0, 10, 0, 0, 0 }, |
| 971 |
{ ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, |
| 972 |
{ ABS_MT_POSITION_X, 0, 10, 0, 0, 0 }, |
| 973 |
{ ABS_MT_POSITION_Y, 0, 10, 0, 0, 0 }, |
| 974 |
{ code, 0, 0, 0, 0, 0 }, |
| 975 |
{ -1, -1, -1, -1, -1, -1 }, |
| 976 |
}; |
| 977 |
|
| 978 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 979 |
litest_disable_log_handler(li); |
| 980 |
|
| 981 |
if (code != ABS_MT_TOOL_TYPE && |
| 982 |
code != ABS_MT_TRACKING_ID) /* kernel overrides it */ |
| 983 |
assert_device_ignored(li, absinfo); |
| 984 |
|
| 985 |
litest_restore_log_handler(li); |
| 986 |
} |
| 987 |
END_TEST |
| 988 |
|
| 989 |
START_TEST(abs_device_missing_res) |
| 990 |
{ |
| 991 |
struct input_absinfo absinfo[] = { |
| 992 |
{ ABS_X, 0, 10, 0, 0, 10 }, |
| 993 |
{ ABS_Y, 0, 10, 0, 0, 10 }, |
| 994 |
{ -1, -1, -1, -1, -1, -1 }, |
| 995 |
}; |
| 996 |
int axis = litest_test_param_get_i32(test_env->params, "axis"); |
| 997 |
|
| 998 |
switch (axis) { |
| 999 |
case ABS_X: |
| 1000 |
absinfo[0].resolution = 0; |
| 1001 |
break; |
| 1002 |
case ABS_Y: |
| 1003 |
absinfo[1].resolution = 0; |
| 1004 |
break; |
| 1005 |
default: |
| 1006 |
litest_abort_msg("Invalid test parameter %d", axis); |
| 1007 |
} |
| 1008 |
|
| 1009 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1010 |
litest_disable_log_handler(li); |
| 1011 |
|
| 1012 |
assert_device_ignored(li, absinfo); |
| 1013 |
|
| 1014 |
litest_restore_log_handler(li); |
| 1015 |
} |
| 1016 |
END_TEST |
| 1017 |
|
| 1018 |
START_TEST(abs_mt_device_missing_res) |
| 1019 |
{ |
| 1020 |
struct input_absinfo absinfo[] = { |
| 1021 |
{ ABS_X, 0, 10, 0, 0, 10 }, |
| 1022 |
{ ABS_Y, 0, 10, 0, 0, 10 }, |
| 1023 |
{ ABS_MT_SLOT, 0, 2, 0, 0, 0 }, |
| 1024 |
{ ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, |
| 1025 |
{ ABS_MT_POSITION_X, 0, 10, 0, 0, 10 }, |
| 1026 |
{ ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 }, |
| 1027 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1028 |
}; |
| 1029 |
|
| 1030 |
int axis = litest_test_param_get_i32(test_env->params, "axis"); |
| 1031 |
|
| 1032 |
switch (axis) { |
| 1033 |
case ABS_MT_POSITION_X: |
| 1034 |
absinfo[4].resolution = 0; |
| 1035 |
break; |
| 1036 |
case ABS_MT_POSITION_Y: |
| 1037 |
absinfo[5].resolution = 0; |
| 1038 |
break; |
| 1039 |
default: |
| 1040 |
litest_abort_msg("Invalid test parameter %d", axis); |
| 1041 |
} |
| 1042 |
|
| 1043 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1044 |
litest_disable_log_handler(li); |
| 1045 |
assert_device_ignored(li, absinfo); |
| 1046 |
|
| 1047 |
litest_restore_log_handler(li); |
| 1048 |
} |
| 1049 |
END_TEST |
| 1050 |
|
| 1051 |
START_TEST(ignore_joystick) |
| 1052 |
{ |
| 1053 |
struct libevdev_uinput *uinput; |
| 1054 |
struct libinput_device *device; |
| 1055 |
struct input_absinfo absinfo[] = { |
| 1056 |
{ ABS_X, 0, 10, 0, 0, 10 }, { ABS_Y, 0, 10, 0, 0, 10 }, |
| 1057 |
{ ABS_RX, 0, 10, 0, 0, 10 }, { ABS_RY, 0, 10, 0, 0, 10 }, |
| 1058 |
{ ABS_THROTTLE, 0, 2, 0, 0, 0 }, { ABS_RUDDER, 0, 255, 0, 0, 0 }, |
| 1059 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1060 |
}; |
| 1061 |
|
| 1062 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1063 |
litest_disable_log_handler(li); |
| 1064 |
litest_drain_events(li); |
| 1065 |
|
| 1066 |
/* clang-format off */ |
| 1067 |
uinput = litest_create_uinput_abs_device("joystick test device", NULL, |
| 1068 |
absinfo, |
| 1069 |
EV_KEY, BTN_TRIGGER, |
| 1070 |
EV_KEY, BTN_A, |
| 1071 |
-1); |
| 1072 |
/* clang-format on */ |
| 1073 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1074 |
litest_assert_ptr_null(device); |
| 1075 |
libevdev_uinput_destroy(uinput); |
| 1076 |
litest_restore_log_handler(li); |
| 1077 |
} |
| 1078 |
END_TEST |
| 1079 |
|
| 1080 |
START_TEST(device_wheel_only) |
| 1081 |
{ |
| 1082 |
struct litest_device *dev = litest_current_device(); |
| 1083 |
struct libinput_device *device = dev->libinput_device; |
| 1084 |
|
| 1085 |
litest_assert( |
| 1086 |
libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)); |
| 1087 |
} |
| 1088 |
END_TEST |
| 1089 |
|
| 1090 |
START_TEST(device_accelerometer) |
| 1091 |
{ |
| 1092 |
struct libevdev_uinput *uinput; |
| 1093 |
struct libinput_device *device; |
| 1094 |
|
| 1095 |
struct input_absinfo absinfo[] = { |
| 1096 |
{ ABS_X, 0, 10, 0, 0, 10 }, |
| 1097 |
{ ABS_Y, 0, 10, 0, 0, 10 }, |
| 1098 |
{ ABS_Z, 0, 10, 0, 0, 10 }, |
| 1099 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1100 |
}; |
| 1101 |
|
| 1102 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1103 |
litest_disable_log_handler(li); |
| 1104 |
|
| 1105 |
uinput = litest_create_uinput_abs_device("test device", NULL, absinfo, -1); |
| 1106 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1107 |
litest_assert_ptr_null(device); |
| 1108 |
libevdev_uinput_destroy(uinput); |
| 1109 |
litest_restore_log_handler(li); |
| 1110 |
} |
| 1111 |
END_TEST |
| 1112 |
|
| 1113 |
START_TEST(device_udev_tag_wacom_tablet) |
| 1114 |
{ |
| 1115 |
struct litest_device *dev = litest_current_device(); |
| 1116 |
struct libinput_device *device = dev->libinput_device; |
| 1117 |
struct udev_device *d; |
| 1118 |
const char *prop; |
| 1119 |
|
| 1120 |
d = libinput_device_get_udev_device(device); |
| 1121 |
prop = udev_device_get_property_value(d, "ID_INPUT_TABLET"); |
| 1122 |
|
| 1123 |
litest_assert_notnull(prop); |
| 1124 |
udev_device_unref(d); |
| 1125 |
} |
| 1126 |
END_TEST |
| 1127 |
|
| 1128 |
START_TEST(device_nonpointer_rel) |
| 1129 |
{ |
| 1130 |
struct libevdev_uinput *uinput; |
| 1131 |
struct libinput_device *device; |
| 1132 |
int i; |
| 1133 |
|
| 1134 |
/* clang-format off */ |
| 1135 |
uinput = litest_create_uinput_device("test device", |
| 1136 |
NULL, |
| 1137 |
EV_KEY, KEY_A, |
| 1138 |
EV_KEY, KEY_B, |
| 1139 |
EV_REL, REL_X, |
| 1140 |
EV_REL, REL_Y, |
| 1141 |
-1); |
| 1142 |
/* clang-format on */ |
| 1143 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1144 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1145 |
litest_assert_notnull(device); |
| 1146 |
|
| 1147 |
litest_disable_log_handler(li); |
| 1148 |
for (i = 0; i < 100; i++) { |
| 1149 |
libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); |
| 1150 |
libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); |
| 1151 |
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); |
| 1152 |
litest_dispatch(li); |
| 1153 |
} |
| 1154 |
litest_restore_log_handler(li); |
| 1155 |
|
| 1156 |
libevdev_uinput_destroy(uinput); |
| 1157 |
} |
| 1158 |
END_TEST |
| 1159 |
|
| 1160 |
START_TEST(device_touchpad_rel) |
| 1161 |
{ |
| 1162 |
struct libevdev_uinput *uinput; |
| 1163 |
struct libinput_device *device; |
| 1164 |
const struct input_absinfo abs[] = { |
| 1165 |
{ ABS_X, 0, 10, 0, 0, 10 }, |
| 1166 |
{ ABS_Y, 0, 10, 0, 0, 10 }, |
| 1167 |
{ ABS_MT_SLOT, 0, 2, 0, 0, 0 }, |
| 1168 |
{ ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, |
| 1169 |
{ ABS_MT_POSITION_X, 0, 10, 0, 0, 10 }, |
| 1170 |
{ ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 }, |
| 1171 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1172 |
}; |
| 1173 |
int i; |
| 1174 |
|
| 1175 |
/* clang-format off */ |
| 1176 |
uinput = litest_create_uinput_abs_device("test device", |
| 1177 |
NULL, abs, |
| 1178 |
EV_KEY, BTN_TOOL_FINGER, |
| 1179 |
EV_KEY, BTN_TOUCH, |
| 1180 |
EV_REL, REL_X, |
| 1181 |
EV_REL, REL_Y, |
| 1182 |
-1); |
| 1183 |
/* clang-format on */ |
| 1184 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1185 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1186 |
litest_assert_notnull(device); |
| 1187 |
|
| 1188 |
for (i = 0; i < 100; i++) { |
| 1189 |
libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); |
| 1190 |
libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); |
| 1191 |
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); |
| 1192 |
litest_dispatch(li); |
| 1193 |
} |
| 1194 |
|
| 1195 |
libevdev_uinput_destroy(uinput); |
| 1196 |
} |
| 1197 |
END_TEST |
| 1198 |
|
| 1199 |
START_TEST(device_touch_rel) |
| 1200 |
{ |
| 1201 |
struct libevdev_uinput *uinput; |
| 1202 |
struct libinput_device *device; |
| 1203 |
const struct input_absinfo abs[] = { |
| 1204 |
{ ABS_X, 0, 10, 0, 0, 10 }, |
| 1205 |
{ ABS_Y, 0, 10, 0, 0, 10 }, |
| 1206 |
{ ABS_MT_SLOT, 0, 2, 0, 0, 0 }, |
| 1207 |
{ ABS_MT_TRACKING_ID, 0, 255, 0, 0, 0 }, |
| 1208 |
{ ABS_MT_POSITION_X, 0, 10, 0, 0, 10 }, |
| 1209 |
{ ABS_MT_POSITION_Y, 0, 10, 0, 0, 10 }, |
| 1210 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1211 |
}; |
| 1212 |
int i; |
| 1213 |
|
| 1214 |
/* clang-format off */ |
| 1215 |
uinput = litest_create_uinput_abs_device("test device", |
| 1216 |
NULL, abs, |
| 1217 |
EV_KEY, BTN_TOUCH, |
| 1218 |
EV_REL, REL_X, |
| 1219 |
EV_REL, REL_Y, |
| 1220 |
-1); |
| 1221 |
/* clang-format on */ |
| 1222 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1223 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1224 |
litest_assert_notnull(device); |
| 1225 |
|
| 1226 |
litest_disable_log_handler(li); |
| 1227 |
for (i = 0; i < 100; i++) { |
| 1228 |
libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); |
| 1229 |
libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); |
| 1230 |
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); |
| 1231 |
litest_dispatch(li); |
| 1232 |
} |
| 1233 |
litest_restore_log_handler(li); |
| 1234 |
|
| 1235 |
libevdev_uinput_destroy(uinput); |
| 1236 |
} |
| 1237 |
END_TEST |
| 1238 |
|
| 1239 |
START_TEST(device_abs_rel) |
| 1240 |
{ |
| 1241 |
struct libevdev_uinput *uinput; |
| 1242 |
struct libinput_device *device; |
| 1243 |
const struct input_absinfo abs[] = { |
| 1244 |
{ ABS_X, 0, 10, 0, 0, 10 }, |
| 1245 |
{ ABS_Y, 0, 10, 0, 0, 10 }, |
| 1246 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1247 |
}; |
| 1248 |
int i; |
| 1249 |
|
| 1250 |
/* clang-format off */ |
| 1251 |
uinput = litest_create_uinput_abs_device("test device", |
| 1252 |
NULL, abs, |
| 1253 |
EV_KEY, BTN_TOUCH, |
| 1254 |
EV_KEY, BTN_LEFT, |
| 1255 |
EV_REL, REL_X, |
| 1256 |
EV_REL, REL_Y, |
| 1257 |
-1); |
| 1258 |
/* clang-format on */ |
| 1259 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1260 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1261 |
litest_assert_notnull(device); |
| 1262 |
|
| 1263 |
for (i = 0; i < 100; i++) { |
| 1264 |
libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1); |
| 1265 |
libevdev_uinput_write_event(uinput, EV_REL, REL_Y, -1); |
| 1266 |
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0); |
| 1267 |
litest_dispatch(li); |
| 1268 |
} |
| 1269 |
|
| 1270 |
libevdev_uinput_destroy(uinput); |
| 1271 |
} |
| 1272 |
END_TEST |
| 1273 |
|
| 1274 |
START_TEST(device_quirks_no_abs_mt_y) |
| 1275 |
{ |
| 1276 |
struct litest_device *dev = litest_current_device(); |
| 1277 |
struct libinput *li = dev->libinput; |
| 1278 |
struct libinput_event *event; |
| 1279 |
struct libinput_event_pointer *pev; |
| 1280 |
bool hi_res_event_found, low_res_event_found; |
| 1281 |
int code, i; |
| 1282 |
|
| 1283 |
hi_res_event_found = false; |
| 1284 |
low_res_event_found = false; |
| 1285 |
|
| 1286 |
litest_drain_events(li); |
| 1287 |
|
| 1288 |
litest_event(dev, EV_REL, REL_HWHEEL, 1); |
| 1289 |
litest_event(dev, EV_REL, REL_HWHEEL_HI_RES, 120); |
| 1290 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1291 |
litest_dispatch(li); |
| 1292 |
|
| 1293 |
/* both high and low scroll end events must be sent */ |
| 1294 |
for (i = 0; i < 2; i++) { |
| 1295 |
event = libinput_get_event(li); |
| 1296 |
pev = litest_is_axis_event(event, |
| 1297 |
LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, |
| 1298 |
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, |
| 1299 |
LIBINPUT_POINTER_AXIS_SOURCE_WHEEL); |
| 1300 |
|
| 1301 |
if (litest_is_high_res_axis_event(event)) { |
| 1302 |
litest_assert(!hi_res_event_found); |
| 1303 |
hi_res_event_found = true; |
| 1304 |
} else { |
| 1305 |
litest_assert(!low_res_event_found); |
| 1306 |
low_res_event_found = true; |
| 1307 |
} |
| 1308 |
|
| 1309 |
libinput_event_destroy(libinput_event_pointer_get_base_event(pev)); |
| 1310 |
} |
| 1311 |
|
| 1312 |
litest_assert(low_res_event_found); |
| 1313 |
litest_assert(hi_res_event_found); |
| 1314 |
|
| 1315 |
for (code = ABS_MISC + 1; code < ABS_MAX; code++) { |
| 1316 |
litest_event(dev, EV_ABS, code, 1); |
| 1317 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1318 |
litest_assert_empty_queue(li); |
| 1319 |
} |
| 1320 |
} |
| 1321 |
END_TEST |
| 1322 |
|
| 1323 |
START_TEST(device_quirks_cyborg_rat_mode_button) |
| 1324 |
{ |
| 1325 |
struct litest_device *dev = litest_current_device(); |
| 1326 |
struct libinput_device *device = dev->libinput_device; |
| 1327 |
struct libinput *li = dev->libinput; |
| 1328 |
|
| 1329 |
litest_assert(!libinput_device_pointer_has_button(device, 0x118)); |
| 1330 |
litest_assert(!libinput_device_pointer_has_button(device, 0x119)); |
| 1331 |
litest_assert(!libinput_device_pointer_has_button(device, 0x11a)); |
| 1332 |
|
| 1333 |
litest_drain_events(li); |
| 1334 |
|
| 1335 |
litest_event(dev, EV_KEY, 0x118, 0); |
| 1336 |
litest_event(dev, EV_KEY, 0x119, 1); |
| 1337 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1338 |
|
| 1339 |
litest_assert_empty_queue(li); |
| 1340 |
|
| 1341 |
litest_event(dev, EV_KEY, 0x119, 0); |
| 1342 |
litest_event(dev, EV_KEY, 0x11a, 1); |
| 1343 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1344 |
|
| 1345 |
litest_assert_empty_queue(li); |
| 1346 |
|
| 1347 |
litest_event(dev, EV_KEY, 0x11a, 0); |
| 1348 |
litest_event(dev, EV_KEY, 0x118, 1); |
| 1349 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1350 |
|
| 1351 |
litest_assert_empty_queue(li); |
| 1352 |
} |
| 1353 |
END_TEST |
| 1354 |
|
| 1355 |
START_TEST(device_quirks_apple_magicmouse) |
| 1356 |
{ |
| 1357 |
struct litest_device *dev = litest_current_device(); |
| 1358 |
struct libinput *li = dev->libinput; |
| 1359 |
|
| 1360 |
litest_drain_events(li); |
| 1361 |
|
| 1362 |
/* ensure we get no events from the touch */ |
| 1363 |
litest_touch_down(dev, 0, 50, 50); |
| 1364 |
litest_touch_move_to(dev, 0, 50, 50, 80, 80, 10); |
| 1365 |
litest_touch_up(dev, 0); |
| 1366 |
litest_assert_empty_queue(li); |
| 1367 |
} |
| 1368 |
END_TEST |
| 1369 |
|
| 1370 |
START_TEST(device_quirks_logitech_marble_mouse) |
| 1371 |
{ |
| 1372 |
struct litest_device *dev = litest_current_device(); |
| 1373 |
struct libinput *li = dev->libinput; |
| 1374 |
|
| 1375 |
litest_drain_events(li); |
| 1376 |
|
| 1377 |
litest_assert( |
| 1378 |
!libinput_device_pointer_has_button(dev->libinput_device, BTN_MIDDLE)); |
| 1379 |
} |
| 1380 |
END_TEST |
| 1381 |
|
| 1382 |
static char *debug_messages[64] = { NULL }; |
| 1383 |
|
| 1384 |
LIBINPUT_ATTRIBUTE_PRINTF(3, 0) |
| 1385 |
static void |
| 1386 |
debug_log_handler(struct libinput *libinput, |
| 1387 |
enum libinput_log_priority priority, |
| 1388 |
const char *format, |
| 1389 |
va_list args) |
| 1390 |
{ |
| 1391 |
char *message; |
| 1392 |
int n; |
| 1393 |
|
| 1394 |
if (priority != LIBINPUT_LOG_PRIORITY_DEBUG) |
| 1395 |
return; |
| 1396 |
|
| 1397 |
n = xvasprintf(&message, format, args); |
| 1398 |
litest_assert_int_gt(n, 0); |
| 1399 |
|
| 1400 |
ARRAY_FOR_EACH(debug_messages, dmsg) { |
| 1401 |
if (*dmsg == NULL) { |
| 1402 |
*dmsg = message; |
| 1403 |
return; |
| 1404 |
} |
| 1405 |
} |
| 1406 |
|
| 1407 |
litest_abort_msg("Out of space for debug messages"); |
| 1408 |
} |
| 1409 |
|
| 1410 |
START_TEST(device_quirks) |
| 1411 |
{ |
| 1412 |
struct litest_device *dev; |
| 1413 |
struct libinput_device *device; |
| 1414 |
char **message; |
| 1415 |
bool disable_key_f1 = false, enable_btn_left = false, |
| 1416 |
disable_pointingstick = false, enable_buttonpad = false, |
| 1417 |
enable_direct = false, disable_direct = false, enable_semi_mt = false, |
| 1418 |
disable_semi_mt = false; |
| 1419 |
|
| 1420 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1421 |
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG); |
| 1422 |
libinput_log_set_handler(li, debug_log_handler); |
| 1423 |
dev = litest_add_device(li, LITEST_KEYBOARD_QUIRKED); |
| 1424 |
device = dev->libinput_device; |
| 1425 |
|
| 1426 |
litest_assert(libinput_device_pointer_has_button(device, BTN_LEFT)); |
| 1427 |
litest_assert( |
| 1428 |
libinput_device_pointer_has_button(dev->libinput_device, BTN_RIGHT)); |
| 1429 |
litest_assert(!libinput_device_pointer_has_button(device, BTN_MIDDLE)); |
| 1430 |
litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F1)); |
| 1431 |
litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F2)); |
| 1432 |
litest_assert(!libinput_device_keyboard_has_key(dev->libinput_device, KEY_F3)); |
| 1433 |
|
| 1434 |
/* Scrape the debug messages for confirmation that our quirks are |
| 1435 |
* triggered, the above checks cannot work non-key codes */ |
| 1436 |
message = debug_messages; |
| 1437 |
while (*message) { |
| 1438 |
if (strstr(*message, "disabling EV_KEY KEY_F1")) |
| 1439 |
disable_key_f1 = true; |
| 1440 |
if (strstr(*message, "enabling EV_KEY BTN_LEFT")) |
| 1441 |
enable_btn_left = true; |
| 1442 |
if (strstr(*message, "enabling INPUT_PROP_BUTTONPAD")) |
| 1443 |
enable_buttonpad = true; |
| 1444 |
if (strstr(*message, "disabling INPUT_PROP_POINTING_STICK")) |
| 1445 |
disable_pointingstick = true; |
| 1446 |
if (strstr(*message, "enabling INPUT_PROP_DIRECT")) { |
| 1447 |
litest_assert(!disable_direct); |
| 1448 |
enable_direct = true; |
| 1449 |
} |
| 1450 |
if (strstr(*message, "disabling INPUT_PROP_DIRECT")) { |
| 1451 |
litest_assert(enable_direct); |
| 1452 |
disable_direct = true; |
| 1453 |
} |
| 1454 |
if (strstr(*message, "enabling INPUT_PROP_SEMI_MT")) { |
| 1455 |
litest_assert(disable_semi_mt); |
| 1456 |
enable_semi_mt = true; |
| 1457 |
} |
| 1458 |
if (strstr(*message, "disabling INPUT_PROP_SEMI_MT")) { |
| 1459 |
litest_assert(!enable_semi_mt); |
| 1460 |
disable_semi_mt = true; |
| 1461 |
} |
| 1462 |
free(*message); |
| 1463 |
message++; |
| 1464 |
} |
| 1465 |
|
| 1466 |
litest_assert(disable_key_f1); |
| 1467 |
litest_assert(enable_btn_left); |
| 1468 |
litest_assert(enable_buttonpad); |
| 1469 |
litest_assert(disable_pointingstick); |
| 1470 |
litest_assert(enable_direct); |
| 1471 |
litest_assert(disable_direct); |
| 1472 |
litest_assert(enable_semi_mt); |
| 1473 |
litest_assert(disable_semi_mt); |
| 1474 |
|
| 1475 |
litest_disable_log_handler(li); |
| 1476 |
|
| 1477 |
litest_device_destroy(dev); |
| 1478 |
} |
| 1479 |
END_TEST |
| 1480 |
|
| 1481 |
START_TEST(device_capability_at_least_one) |
| 1482 |
{ |
| 1483 |
struct litest_device *dev = litest_current_device(); |
| 1484 |
struct libinput_device *device = dev->libinput_device; |
| 1485 |
enum libinput_device_capability caps[] = { |
| 1486 |
LIBINPUT_DEVICE_CAP_KEYBOARD, LIBINPUT_DEVICE_CAP_POINTER, |
| 1487 |
LIBINPUT_DEVICE_CAP_TOUCH, LIBINPUT_DEVICE_CAP_TABLET_TOOL, |
| 1488 |
LIBINPUT_DEVICE_CAP_TABLET_PAD, LIBINPUT_DEVICE_CAP_GESTURE, |
| 1489 |
LIBINPUT_DEVICE_CAP_SWITCH, |
| 1490 |
}; |
| 1491 |
int ncaps = 0; |
| 1492 |
|
| 1493 |
ARRAY_FOR_EACH(caps, cap) { |
| 1494 |
if (libinput_device_has_capability(device, *cap)) |
| 1495 |
ncaps++; |
| 1496 |
} |
| 1497 |
litest_assert_int_gt(ncaps, 0); |
| 1498 |
} |
| 1499 |
END_TEST |
| 1500 |
|
| 1501 |
START_TEST(device_capability_check_invalid) |
| 1502 |
{ |
| 1503 |
struct litest_device *dev = litest_current_device(); |
| 1504 |
struct libinput_device *device = dev->libinput_device; |
| 1505 |
|
| 1506 |
litest_assert(!libinput_device_has_capability(device, -1)); |
| 1507 |
litest_assert(!libinput_device_has_capability(device, 7)); |
| 1508 |
litest_assert(!libinput_device_has_capability(device, 0xffff)); |
| 1509 |
} |
| 1510 |
END_TEST |
| 1511 |
|
| 1512 |
START_TEST(device_capability_nocaps_ignored) |
| 1513 |
{ |
| 1514 |
struct libevdev_uinput *uinput; |
| 1515 |
struct libinput_device *device; |
| 1516 |
|
| 1517 |
/* SW_PEN_INSERTED isn't handled in libinput so the device is |
| 1518 |
* processed but ends up without seat capabilities and is ignored. |
| 1519 |
*/ |
| 1520 |
/* clang-format off */ |
| 1521 |
uinput = litest_create_uinput_device("test device", NULL, |
| 1522 |
EV_SW, SW_PEN_INSERTED, |
| 1523 |
-1); |
| 1524 |
/* clang-format on */ |
| 1525 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1526 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1527 |
litest_assert_ptr_null(device); |
| 1528 |
|
| 1529 |
libevdev_uinput_destroy(uinput); |
| 1530 |
} |
| 1531 |
END_TEST |
| 1532 |
|
| 1533 |
START_TEST(device_has_size) |
| 1534 |
{ |
| 1535 |
struct litest_device *dev = litest_current_device(); |
| 1536 |
struct libinput_device *device = dev->libinput_device; |
| 1537 |
double w, h; |
| 1538 |
int rc; |
| 1539 |
|
| 1540 |
rc = libinput_device_get_size(device, &w, &h); |
| 1541 |
litest_assert_int_eq(rc, 0); |
| 1542 |
/* This matches the current set of test devices but may fail if |
| 1543 |
* newer ones are added */ |
| 1544 |
litest_assert_double_gt(w, 30); |
| 1545 |
litest_assert_double_gt(h, 20); |
| 1546 |
} |
| 1547 |
END_TEST |
| 1548 |
|
| 1549 |
START_TEST(device_has_no_size) |
| 1550 |
{ |
| 1551 |
struct litest_device *dev = litest_current_device(); |
| 1552 |
struct libinput_device *device = dev->libinput_device; |
| 1553 |
double w = 45, h = 67; |
| 1554 |
int rc; |
| 1555 |
|
| 1556 |
rc = libinput_device_get_size(device, &w, &h); |
| 1557 |
litest_assert_int_eq(rc, -1); |
| 1558 |
litest_assert_double_eq(w, 45); |
| 1559 |
litest_assert_double_eq(h, 67); |
| 1560 |
} |
| 1561 |
END_TEST |
| 1562 |
|
| 1563 |
START_TEST(device_get_output) |
| 1564 |
{ |
| 1565 |
struct litest_device *dev = litest_current_device(); |
| 1566 |
struct libinput_device *device = dev->libinput_device; |
| 1567 |
const char *output_name; |
| 1568 |
|
| 1569 |
output_name = libinput_device_get_output_name(device); |
| 1570 |
litest_assert_str_eq(output_name, "myOutput"); |
| 1571 |
} |
| 1572 |
END_TEST |
| 1573 |
|
| 1574 |
START_TEST(device_no_output) |
| 1575 |
{ |
| 1576 |
struct litest_device *dev = litest_current_device(); |
| 1577 |
struct libinput_device *device = dev->libinput_device; |
| 1578 |
const char *output_name; |
| 1579 |
|
| 1580 |
output_name = libinput_device_get_output_name(device); |
| 1581 |
litest_assert(output_name == NULL); |
| 1582 |
} |
| 1583 |
END_TEST |
| 1584 |
|
| 1585 |
START_TEST(device_seat_phys_name) |
| 1586 |
{ |
| 1587 |
struct litest_device *dev = litest_current_device(); |
| 1588 |
struct libinput_device *device = dev->libinput_device; |
| 1589 |
struct libinput_seat *seat = libinput_device_get_seat(device); |
| 1590 |
const char *seat_name; |
| 1591 |
|
| 1592 |
seat_name = libinput_seat_get_physical_name(seat); |
| 1593 |
litest_assert(streq(seat_name, "seat0")); |
| 1594 |
} |
| 1595 |
END_TEST |
| 1596 |
|
| 1597 |
START_TEST(device_button_down_remove) |
| 1598 |
{ |
| 1599 |
struct litest_device *lidev = litest_current_device(); |
| 1600 |
struct litest_device *dev; |
| 1601 |
|
| 1602 |
for (int code = 0; code < KEY_MAX; code++) { |
| 1603 |
struct libinput_event *event; |
| 1604 |
struct libinput_event_pointer *p; |
| 1605 |
bool have_down = false, have_up = false; |
| 1606 |
const char *keyname; |
| 1607 |
int button_down = 0, button_up = 0; |
| 1608 |
|
| 1609 |
keyname = libevdev_event_code_get_name(EV_KEY, code); |
| 1610 |
if (!keyname || !strstartswith(keyname, "BTN_") || |
| 1611 |
strstartswith(keyname, "BTN_TOOL_")) |
| 1612 |
continue; |
| 1613 |
|
| 1614 |
if (!libevdev_has_event_code(lidev->evdev, EV_KEY, code)) |
| 1615 |
continue; |
| 1616 |
|
| 1617 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1618 |
dev = litest_add_device(li, lidev->which); |
| 1619 |
litest_drain_events(li); |
| 1620 |
|
| 1621 |
/* Clickpads require a touch down to trigger the button |
| 1622 |
* press */ |
| 1623 |
if (libevdev_has_property(lidev->evdev, INPUT_PROP_BUTTONPAD)) { |
| 1624 |
litest_touch_down(dev, 0, 20, 90); |
| 1625 |
litest_dispatch(li); |
| 1626 |
} |
| 1627 |
|
| 1628 |
litest_event(dev, EV_KEY, code, 1); |
| 1629 |
litest_event(dev, EV_SYN, SYN_REPORT, 0); |
| 1630 |
litest_dispatch(li); |
| 1631 |
|
| 1632 |
litest_device_destroy(dev); |
| 1633 |
litest_dispatch(li); |
| 1634 |
|
| 1635 |
while ((event = libinput_get_event(li))) { |
| 1636 |
if (libinput_event_get_type(event) != |
| 1637 |
LIBINPUT_EVENT_POINTER_BUTTON) { |
| 1638 |
libinput_event_destroy(event); |
| 1639 |
continue; |
| 1640 |
} |
| 1641 |
|
| 1642 |
p = libinput_event_get_pointer_event(event); |
| 1643 |
if (libinput_event_pointer_get_button_state(p)) { |
| 1644 |
litest_assert(button_down == 0); |
| 1645 |
button_down = libinput_event_pointer_get_button(p); |
| 1646 |
} else { |
| 1647 |
litest_assert(button_up == 0); |
| 1648 |
button_up = libinput_event_pointer_get_button(p); |
| 1649 |
litest_assert_int_eq(button_down, button_up); |
| 1650 |
} |
| 1651 |
libinput_event_destroy(event); |
| 1652 |
} |
| 1653 |
|
| 1654 |
litest_assert_int_eq(have_down, have_up); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
END_TEST |
| 1658 |
|
| 1659 |
enum extreme_axis_range_idx { |
| 1660 |
EXTREME_RANGE_0_TO_INT32MAX, |
| 1661 |
EXTREME_RANGE_INT32MIN_TO_0, |
| 1662 |
EXTREME_RANGE_NEGHALF_TO_POSHALF, |
| 1663 |
}; |
| 1664 |
|
| 1665 |
START_TEST(abs_device_extreme_axis_range) |
| 1666 |
{ |
| 1667 |
struct libevdev_uinput *uinput; |
| 1668 |
struct libinput_device *device; |
| 1669 |
int idx = litest_test_param_get_i32(test_env->params, "range"); |
| 1670 |
/* All ranges exceed INT32_MAX/2, device should be rejected */ |
| 1671 |
const struct { |
| 1672 |
int32_t min, max; |
| 1673 |
} ranges[] = { |
| 1674 |
[EXTREME_RANGE_0_TO_INT32MAX] = { 0, INT32_MAX }, |
| 1675 |
[EXTREME_RANGE_INT32MIN_TO_0] = { INT32_MIN, 0 }, |
| 1676 |
[EXTREME_RANGE_NEGHALF_TO_POSHALF] = { -(INT32_MAX / 2), |
| 1677 |
INT32_MAX / 2 }, |
| 1678 |
}; |
| 1679 |
struct input_absinfo absinfo[] = { |
| 1680 |
{ ABS_X, ranges[idx].min, ranges[idx].max, 0, 0, 0 }, |
| 1681 |
{ ABS_Y, 0, 1000, 0, 0, 0 }, |
| 1682 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1683 |
}; |
| 1684 |
|
| 1685 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1686 |
litest_disable_log_handler(li); |
| 1687 |
/* clang-format off */ |
| 1688 |
uinput = litest_create_uinput_abs_device("test device", NULL, |
| 1689 |
absinfo, |
| 1690 |
EV_KEY, BTN_LEFT, |
| 1691 |
EV_KEY, BTN_RIGHT, |
| 1692 |
-1); |
| 1693 |
/* clang-format on */ |
| 1694 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1695 |
litest_restore_log_handler(li); |
| 1696 |
litest_assert_ptr_null(device); |
| 1697 |
|
| 1698 |
libevdev_uinput_destroy(uinput); |
| 1699 |
} |
| 1700 |
END_TEST |
| 1701 |
|
| 1702 |
START_TEST(abs_device_negative_resolution) |
| 1703 |
{ |
| 1704 |
struct libevdev_uinput *uinput; |
| 1705 |
struct libinput_device *device; |
| 1706 |
struct input_absinfo absinfo[] = { |
| 1707 |
{ ABS_X, 0, 1000, 0, 0, -1 }, /* negative resolution */ |
| 1708 |
{ ABS_Y, 0, 1000, 0, 0, -1 }, /* negative resolution */ |
| 1709 |
{ -1, -1, -1, -1, -1, -1 }, |
| 1710 |
}; |
| 1711 |
|
| 1712 |
_litest_context_destroy_ struct libinput *li = litest_create_context(); |
| 1713 |
litest_disable_log_handler(li); |
| 1714 |
/* clang-format off */ |
| 1715 |
uinput = litest_create_uinput_abs_device("test device", NULL, |
| 1716 |
absinfo, |
| 1717 |
EV_KEY, BTN_LEFT, |
| 1718 |
EV_KEY, BTN_RIGHT, |
| 1719 |
-1); |
| 1720 |
/* clang-format on */ |
| 1721 |
device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput)); |
| 1722 |
litest_restore_log_handler(li); |
| 1723 |
/* Device should be rejected */ |
| 1724 |
litest_assert_ptr_null(device); |
| 1725 |
|
| 1726 |
libevdev_uinput_destroy(uinput); |
| 1727 |
} |
| 1728 |
END_TEST |
| 1729 |
|
| 1730 |
TEST_COLLECTION(device) |
| 1731 |
{ |
| 1732 |
/* clang-format off */ |
| 1733 |
struct range abs_range = range_init_exclusive(0, ABS_MISC); |
| 1734 |
struct range abs_mt_range = range_init_exclusive(ABS_MT_SLOT + 1, ABS_CNT); |
| 1735 |
|
| 1736 |
litest_add(device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD|LITEST_TABLET); |
| 1737 |
litest_add(device_sendevents_config_invalid, LITEST_ANY, LITEST_TABLET); |
| 1738 |
litest_add(device_sendevents_config_touchpad, LITEST_TOUCHPAD, LITEST_TABLET); |
| 1739 |
litest_add(device_sendevents_config_touchpad_superset, LITEST_TOUCHPAD, LITEST_TABLET); |
| 1740 |
litest_add(device_sendevents_config_default, LITEST_ANY, LITEST_TABLET); |
| 1741 |
litest_add(device_disable, LITEST_RELATIVE, LITEST_TABLET); |
| 1742 |
litest_add(device_disable_tablet, LITEST_TABLET, LITEST_ANY); |
| 1743 |
litest_add(device_disable_touchpad, LITEST_TOUCHPAD, LITEST_TABLET); |
| 1744 |
litest_add(device_disable_touch, LITEST_TOUCH, LITEST_ANY); |
| 1745 |
litest_add(device_disable_touch_during_touch, LITEST_TOUCH, LITEST_ANY); |
| 1746 |
litest_add(device_disable_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); |
| 1747 |
litest_add(device_disable_touch_during_touch, LITEST_SINGLE_TOUCH, LITEST_TOUCHPAD); |
| 1748 |
litest_add(device_disable_events_pending, LITEST_RELATIVE, LITEST_TOUCHPAD|LITEST_TABLET); |
| 1749 |
litest_add(device_double_disable, LITEST_ANY, LITEST_TABLET); |
| 1750 |
litest_add(device_double_enable, LITEST_ANY, LITEST_TABLET); |
| 1751 |
litest_add_no_device(device_reenable_syspath_changed); |
| 1752 |
litest_add_no_device(device_reenable_device_removed); |
| 1753 |
litest_add_for_device(device_disable_release_buttons, LITEST_MOUSE); |
| 1754 |
litest_add_for_device(device_disable_release_keys, LITEST_KEYBOARD); |
| 1755 |
litest_add(device_disable_release_tap, LITEST_TOUCHPAD, LITEST_ANY); |
| 1756 |
litest_add(device_disable_release_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY); |
| 1757 |
litest_add(device_disable_release_softbutton, LITEST_CLICKPAD, LITEST_APPLE_CLICKPAD); |
| 1758 |
litest_add(device_disable_topsoftbutton, LITEST_TOPBUTTONPAD, LITEST_ANY); |
| 1759 |
litest_add(device_ids, LITEST_ANY, LITEST_ANY); |
| 1760 |
litest_add_for_device(device_context, LITEST_SYNAPTICS_CLICKPAD_X220); |
| 1761 |
litest_add_for_device(device_user_data, LITEST_SYNAPTICS_CLICKPAD_X220); |
| 1762 |
|
| 1763 |
litest_add(device_get_udev_handle, LITEST_ANY, LITEST_ANY); |
| 1764 |
|
| 1765 |
litest_add(device_group_get, LITEST_ANY, LITEST_ANY); |
| 1766 |
litest_add_no_device(device_group_ref); |
| 1767 |
litest_add_no_device(device_group_leak); |
| 1768 |
|
| 1769 |
litest_with_parameters(params, "axis", 'I', 2, |
| 1770 |
litest_named_i32(ABS_X), |
| 1771 |
litest_named_i32(ABS_Y)) { |
| 1772 |
litest_add_parametrized_no_device(abs_device_missing_one_abs, params); |
| 1773 |
litest_add_parametrized_no_device(abs_device_missing_res, params); |
| 1774 |
} |
| 1775 |
litest_with_parameters(params, "axis", 'I', 2, |
| 1776 |
litest_named_i32(ABS_MT_POSITION_X), |
| 1777 |
litest_named_i32(ABS_MT_POSITION_Y)) { |
| 1778 |
litest_add_parametrized_no_device(abs_mt_device_missing_one_mt_abs, params); |
| 1779 |
litest_add_parametrized_no_device(abs_mt_device_missing_res, params); |
| 1780 |
} |
| 1781 |
litest_add_ranged_no_device(abs_device_no_range, &abs_range); |
| 1782 |
litest_add_ranged_no_device(abs_mt_device_no_range, &abs_mt_range); |
| 1783 |
litest_add_no_device(ignore_joystick); |
| 1784 |
|
| 1785 |
litest_add(device_wheel_only, LITEST_WHEEL, LITEST_RELATIVE|LITEST_ABSOLUTE|LITEST_TABLET); |
| 1786 |
litest_add_no_device(device_accelerometer); |
| 1787 |
litest_with_parameters(params, "range", 'I', 3, |
| 1788 |
litest_named_i32(EXTREME_RANGE_0_TO_INT32MAX, "0-to-INT32MAX"), |
| 1789 |
litest_named_i32(EXTREME_RANGE_INT32MIN_TO_0, "INT32MIN-to-0"), |
| 1790 |
litest_named_i32(EXTREME_RANGE_NEGHALF_TO_POSHALF, "-INT32MAX/2-to-INT32MAX/2")) { |
| 1791 |
litest_add_parametrized_no_device(abs_device_extreme_axis_range, params); |
| 1792 |
} |
| 1793 |
litest_add_no_device(abs_device_negative_resolution); |
| 1794 |
|
| 1795 |
litest_add(device_udev_tag_wacom_tablet, LITEST_TABLET, LITEST_TOTEM); |
| 1796 |
|
| 1797 |
litest_add_no_device(device_nonpointer_rel); |
| 1798 |
litest_add_no_device(device_touchpad_rel); |
| 1799 |
litest_add_no_device(device_touch_rel); |
| 1800 |
litest_add_no_device(device_abs_rel); |
| 1801 |
|
| 1802 |
litest_add_for_device(device_quirks_no_abs_mt_y, LITEST_ANKER_MOUSE_KBD); |
| 1803 |
litest_add_for_device(device_quirks_cyborg_rat_mode_button, LITEST_CYBORG_RAT); |
| 1804 |
litest_add_for_device(device_quirks_apple_magicmouse, LITEST_MAGICMOUSE); |
| 1805 |
litest_add_for_device(device_quirks_logitech_marble_mouse, LITEST_LOGITECH_TRACKBALL); |
| 1806 |
litest_add_no_device(device_quirks); |
| 1807 |
|
| 1808 |
litest_add(device_capability_at_least_one, LITEST_ANY, LITEST_ANY); |
| 1809 |
litest_add(device_capability_check_invalid, LITEST_ANY, LITEST_ANY); |
| 1810 |
litest_add_no_device(device_capability_nocaps_ignored); |
| 1811 |
|
| 1812 |
litest_add(device_has_size, LITEST_TOUCHPAD, LITEST_ANY); |
| 1813 |
litest_add(device_has_size, LITEST_TABLET, LITEST_ANY); |
| 1814 |
litest_add(device_has_no_size, LITEST_ANY, |
| 1815 |
LITEST_TOUCHPAD|LITEST_TABLET|LITEST_TOUCH|LITEST_ABSOLUTE|LITEST_SINGLE_TOUCH|LITEST_TOTEM); |
| 1816 |
|
| 1817 |
litest_add_for_device(device_get_output, LITEST_CALIBRATED_TOUCHSCREEN); |
| 1818 |
litest_add(device_no_output, LITEST_RELATIVE, LITEST_ANY); |
| 1819 |
litest_add(device_no_output, LITEST_KEYS, LITEST_ANY); |
| 1820 |
|
| 1821 |
litest_add(device_seat_phys_name, LITEST_ANY, LITEST_ANY); |
| 1822 |
|
| 1823 |
litest_add(device_button_down_remove, LITEST_BUTTON, LITEST_ANY); |
| 1824 |
|
| 1825 |
/* clang-format off */ |
| 1826 |
} |