1c0abf9e6Sopenharmony_ci// SPDX-License-Identifier: MIT 2c0abf9e6Sopenharmony_ci/* 3c0abf9e6Sopenharmony_ci * Copyright © 2013 Red Hat, Inc. 4c0abf9e6Sopenharmony_ci */ 5c0abf9e6Sopenharmony_ci 6c0abf9e6Sopenharmony_ci#include "config.h" 7c0abf9e6Sopenharmony_ci#include <linux/input.h> 8c0abf9e6Sopenharmony_ci#include <errno.h> 9c0abf9e6Sopenharmony_ci#include <unistd.h> 10c0abf9e6Sopenharmony_ci#include <fcntl.h> 11c0abf9e6Sopenharmony_ci#include <stdio.h> 12c0abf9e6Sopenharmony_ci#include <libevdev/libevdev-util.h> 13c0abf9e6Sopenharmony_ci 14c0abf9e6Sopenharmony_ci#include "test-common.h" 15c0abf9e6Sopenharmony_ci 16c0abf9e6Sopenharmony_ciSTART_TEST(test_next_event) 17c0abf9e6Sopenharmony_ci{ 18c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 19c0abf9e6Sopenharmony_ci struct libevdev *dev; 20c0abf9e6Sopenharmony_ci int rc; 21c0abf9e6Sopenharmony_ci struct input_event ev; 22c0abf9e6Sopenharmony_ci 23c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 24c0abf9e6Sopenharmony_ci EV_REL, REL_X, 25c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 26c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 27c0abf9e6Sopenharmony_ci -1); 28c0abf9e6Sopenharmony_ci 29c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 30c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 31c0abf9e6Sopenharmony_ci 32c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1); 33c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 34c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 35c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 36c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_LEFT, 1); 37c0abf9e6Sopenharmony_ci 38c0abf9e6Sopenharmony_ci libevdev_free(dev); 39c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 40c0abf9e6Sopenharmony_ci 41c0abf9e6Sopenharmony_ci} 42c0abf9e6Sopenharmony_ciEND_TEST 43c0abf9e6Sopenharmony_ci 44c0abf9e6Sopenharmony_ciSTART_TEST(test_next_event_invalid_fd) 45c0abf9e6Sopenharmony_ci{ 46c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 47c0abf9e6Sopenharmony_ci struct libevdev *dev; 48c0abf9e6Sopenharmony_ci int rc; 49c0abf9e6Sopenharmony_ci struct input_event ev; 50c0abf9e6Sopenharmony_ci 51c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_ignore_error, NULL); 52c0abf9e6Sopenharmony_ci 53c0abf9e6Sopenharmony_ci dev = libevdev_new(); 54c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 55c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EBADF); 56c0abf9e6Sopenharmony_ci libevdev_free(dev); 57c0abf9e6Sopenharmony_ci 58c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 59c0abf9e6Sopenharmony_ci EV_REL, REL_X, 60c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 61c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 62c0abf9e6Sopenharmony_ci -1); 63c0abf9e6Sopenharmony_ci 64c0abf9e6Sopenharmony_ci /* invalid (missing) flag */ 65c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, 0x10, &ev); 66c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EINVAL); 67c0abf9e6Sopenharmony_ci 68c0abf9e6Sopenharmony_ci /* set an invalid fd */ 69c0abf9e6Sopenharmony_ci rc = libevdev_change_fd(dev, -3); 70c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, 0); 71c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 72c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EBADF); 73c0abf9e6Sopenharmony_ci 74c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_abort_on_error, NULL); 75c0abf9e6Sopenharmony_ci 76c0abf9e6Sopenharmony_ci libevdev_free(dev); 77c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 78c0abf9e6Sopenharmony_ci} 79c0abf9e6Sopenharmony_ciEND_TEST 80c0abf9e6Sopenharmony_ci 81c0abf9e6Sopenharmony_ciSTART_TEST(test_next_event_blocking) 82c0abf9e6Sopenharmony_ci{ 83c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 84c0abf9e6Sopenharmony_ci struct libevdev *dev; 85c0abf9e6Sopenharmony_ci int fd, flags; 86c0abf9e6Sopenharmony_ci int rc; 87c0abf9e6Sopenharmony_ci struct input_event ev; 88c0abf9e6Sopenharmony_ci 89c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 90c0abf9e6Sopenharmony_ci EV_REL, REL_X, 91c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 92c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 93c0abf9e6Sopenharmony_ci -1); 94c0abf9e6Sopenharmony_ci 95c0abf9e6Sopenharmony_ci fd = libevdev_get_fd(dev); 96c0abf9e6Sopenharmony_ci flags = fcntl(fd, F_GETFL) & ~O_NONBLOCK; 97c0abf9e6Sopenharmony_ci rc = fcntl(fd, F_SETFL, flags); 98c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, 0); 99c0abf9e6Sopenharmony_ci 100c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1); 101c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 102c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_BLOCKING, &ev); 103c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 104c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_LEFT, 1); 105c0abf9e6Sopenharmony_ci 106c0abf9e6Sopenharmony_ci libevdev_free(dev); 107c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 108c0abf9e6Sopenharmony_ci} 109c0abf9e6Sopenharmony_ciEND_TEST 110c0abf9e6Sopenharmony_ci 111c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_dropped_event) 112c0abf9e6Sopenharmony_ci{ 113c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 114c0abf9e6Sopenharmony_ci struct libevdev *dev; 115c0abf9e6Sopenharmony_ci int rc; 116c0abf9e6Sopenharmony_ci struct input_event ev; 117c0abf9e6Sopenharmony_ci int pipefd[2]; 118c0abf9e6Sopenharmony_ci 119c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 120c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 121c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 122c0abf9e6Sopenharmony_ci EV_REL, REL_X, 123c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 124c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 125c0abf9e6Sopenharmony_ci -1); 126c0abf9e6Sopenharmony_ci 127c0abf9e6Sopenharmony_ci /* This is a bit complicated: 128c0abf9e6Sopenharmony_ci we can't get SYN_DROPPED through uinput, so we push two events down 129c0abf9e6Sopenharmony_ci uinput, and process those. Then write a SYN_DROPPED on a pipe, 130c0abf9e6Sopenharmony_ci switch the fd and read one event off the wire. Switch back, so 131c0abf9e6Sopenharmony_ci that when we do read off the SYN_DROPPED we have the fd back on 132c0abf9e6Sopenharmony_ci the device and the ioctls work. 133c0abf9e6Sopenharmony_ci */ 134c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1); 135c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 136c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 137c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 138c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_LEFT, 1); 139c0abf9e6Sopenharmony_ci 140c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 141c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 142c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 143c0abf9e6Sopenharmony_ci 144c0abf9e6Sopenharmony_ci rc = pipe2(pipefd, O_NONBLOCK); 145c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, 0); 146c0abf9e6Sopenharmony_ci 147c0abf9e6Sopenharmony_ci libevdev_change_fd(dev, pipefd[0]); 148c0abf9e6Sopenharmony_ci ev.type = EV_SYN; 149c0abf9e6Sopenharmony_ci ev.code = SYN_DROPPED; 150c0abf9e6Sopenharmony_ci ev.value = 0; 151c0abf9e6Sopenharmony_ci rc = write(pipefd[1], &ev, sizeof(ev)); 152c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, sizeof(ev)); 153c0abf9e6Sopenharmony_ci 154c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 155c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 156c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_DROPPED, 0); 157c0abf9e6Sopenharmony_ci 158c0abf9e6Sopenharmony_ci libevdev_change_fd(dev, uinput_device_get_fd(uidev)); 159c0abf9e6Sopenharmony_ci /* only check for the rc, nothing actually changed on the device */ 160c0abf9e6Sopenharmony_ci 161c0abf9e6Sopenharmony_ci libevdev_free(dev); 162c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 163c0abf9e6Sopenharmony_ci 164c0abf9e6Sopenharmony_ci close(pipefd[0]); 165c0abf9e6Sopenharmony_ci close(pipefd[1]); 166c0abf9e6Sopenharmony_ci 167c0abf9e6Sopenharmony_ci} 168c0abf9e6Sopenharmony_ciEND_TEST 169c0abf9e6Sopenharmony_ci 170c0abf9e6Sopenharmony_ciSTART_TEST(test_event_type_filtered) 171c0abf9e6Sopenharmony_ci{ 172c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 173c0abf9e6Sopenharmony_ci struct libevdev *dev; 174c0abf9e6Sopenharmony_ci int rc; 175c0abf9e6Sopenharmony_ci struct input_event ev; 176c0abf9e6Sopenharmony_ci 177c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 178c0abf9e6Sopenharmony_ci EV_REL, REL_X, 179c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 180c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 181c0abf9e6Sopenharmony_ci -1); 182c0abf9e6Sopenharmony_ci 183c0abf9e6Sopenharmony_ci libevdev_disable_event_type(dev, EV_REL); 184c0abf9e6Sopenharmony_ci 185c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 186c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 187c0abf9e6Sopenharmony_ci 188c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_REL, REL_X, 1); 189c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, REL_Y, 1); 190c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 191c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 192c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 193c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 194c0abf9e6Sopenharmony_ci 195c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 196c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 197c0abf9e6Sopenharmony_ci 198c0abf9e6Sopenharmony_ci libevdev_free(dev); 199c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 200c0abf9e6Sopenharmony_ci 201c0abf9e6Sopenharmony_ci} 202c0abf9e6Sopenharmony_ciEND_TEST 203c0abf9e6Sopenharmony_ci 204c0abf9e6Sopenharmony_ciSTART_TEST(test_event_code_filtered) 205c0abf9e6Sopenharmony_ci{ 206c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 207c0abf9e6Sopenharmony_ci struct libevdev *dev; 208c0abf9e6Sopenharmony_ci int rc; 209c0abf9e6Sopenharmony_ci struct input_event ev; 210c0abf9e6Sopenharmony_ci 211c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 212c0abf9e6Sopenharmony_ci EV_REL, REL_X, 213c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 214c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 215c0abf9e6Sopenharmony_ci -1); 216c0abf9e6Sopenharmony_ci 217c0abf9e6Sopenharmony_ci libevdev_disable_event_code(dev, EV_REL, REL_X); 218c0abf9e6Sopenharmony_ci 219c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 220c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 221c0abf9e6Sopenharmony_ci 222c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_REL, REL_X, 1); 223c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_REL, REL_Y, 1); 224c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 225c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 226c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 227c0abf9e6Sopenharmony_ci assert_event(&ev, EV_REL, REL_Y, 1); 228c0abf9e6Sopenharmony_ci 229c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 230c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 231c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 232c0abf9e6Sopenharmony_ci 233c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 234c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 235c0abf9e6Sopenharmony_ci 236c0abf9e6Sopenharmony_ci libevdev_free(dev); 237c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 238c0abf9e6Sopenharmony_ci 239c0abf9e6Sopenharmony_ci} 240c0abf9e6Sopenharmony_ciEND_TEST 241c0abf9e6Sopenharmony_ci 242c0abf9e6Sopenharmony_ciSTART_TEST(test_has_event_pending) 243c0abf9e6Sopenharmony_ci{ 244c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 245c0abf9e6Sopenharmony_ci struct libevdev *dev; 246c0abf9e6Sopenharmony_ci int rc; 247c0abf9e6Sopenharmony_ci struct input_event ev; 248c0abf9e6Sopenharmony_ci 249c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 250c0abf9e6Sopenharmony_ci EV_REL, REL_X, 251c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 252c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 253c0abf9e6Sopenharmony_ci -1); 254c0abf9e6Sopenharmony_ci 255c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_pending(dev), 0); 256c0abf9e6Sopenharmony_ci 257c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_REL, REL_X, 1); 258c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_REL, REL_Y, 1); 259c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 260c0abf9e6Sopenharmony_ci 261c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_pending(dev), 1); 262c0abf9e6Sopenharmony_ci 263c0abf9e6Sopenharmony_ci libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 264c0abf9e6Sopenharmony_ci 265c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_pending(dev), 1); 266c0abf9e6Sopenharmony_ci 267c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev)) != -EAGAIN) 268c0abf9e6Sopenharmony_ci ; 269c0abf9e6Sopenharmony_ci 270c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_pending(dev), 0); 271c0abf9e6Sopenharmony_ci 272c0abf9e6Sopenharmony_ci libevdev_change_fd(dev, -1); 273c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_pending(dev), -EBADF); 274c0abf9e6Sopenharmony_ci 275c0abf9e6Sopenharmony_ci libevdev_free(dev); 276c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 277c0abf9e6Sopenharmony_ci 278c0abf9e6Sopenharmony_ci} 279c0abf9e6Sopenharmony_ciEND_TEST 280c0abf9e6Sopenharmony_ci 281c0abf9e6Sopenharmony_ciSTART_TEST(test_has_event_pending_invalid_fd) 282c0abf9e6Sopenharmony_ci{ 283c0abf9e6Sopenharmony_ci struct libevdev *dev; 284c0abf9e6Sopenharmony_ci int rc; 285c0abf9e6Sopenharmony_ci 286c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_ignore_error, NULL); 287c0abf9e6Sopenharmony_ci 288c0abf9e6Sopenharmony_ci dev = libevdev_new(); 289c0abf9e6Sopenharmony_ci rc = libevdev_has_event_pending(dev); 290c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EBADF); 291c0abf9e6Sopenharmony_ci 292c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_abort_on_error, NULL); 293c0abf9e6Sopenharmony_ci 294c0abf9e6Sopenharmony_ci libevdev_free(dev); 295c0abf9e6Sopenharmony_ci} 296c0abf9e6Sopenharmony_ciEND_TEST 297c0abf9e6Sopenharmony_ci 298c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_button) 299c0abf9e6Sopenharmony_ci{ 300c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 301c0abf9e6Sopenharmony_ci struct libevdev *dev; 302c0abf9e6Sopenharmony_ci int rc; 303c0abf9e6Sopenharmony_ci struct input_event ev; 304c0abf9e6Sopenharmony_ci 305c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 306c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 307c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 308c0abf9e6Sopenharmony_ci EV_REL, REL_X, 309c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 310c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 311c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 312c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 313c0abf9e6Sopenharmony_ci EV_KEY, KEY_MAX, 314c0abf9e6Sopenharmony_ci -1); 315c0abf9e6Sopenharmony_ci 316c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1); 317c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_RIGHT, 1); 318c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, KEY_MAX, 1); 319c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 320c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 321c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 322c0abf9e6Sopenharmony_ci 323c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 324c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 325c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_LEFT, 1); 326c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 327c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 328c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_RIGHT, 1); 329c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 330c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 331c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, KEY_MAX, 1); 332c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 333c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 334c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 335c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 336c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 337c0abf9e6Sopenharmony_ci 338c0abf9e6Sopenharmony_ci ck_assert(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT)); 339c0abf9e6Sopenharmony_ci ck_assert(libevdev_get_event_value(dev, EV_KEY, BTN_RIGHT)); 340c0abf9e6Sopenharmony_ci ck_assert(!libevdev_get_event_value(dev, EV_KEY, BTN_MIDDLE)); 341c0abf9e6Sopenharmony_ci ck_assert(libevdev_get_event_value(dev, EV_KEY, KEY_MAX)); 342c0abf9e6Sopenharmony_ci 343c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 344c0abf9e6Sopenharmony_ci libevdev_free(dev); 345c0abf9e6Sopenharmony_ci} 346c0abf9e6Sopenharmony_ciEND_TEST 347c0abf9e6Sopenharmony_ci 348c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_abs) 349c0abf9e6Sopenharmony_ci{ 350c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 351c0abf9e6Sopenharmony_ci struct libevdev *dev; 352c0abf9e6Sopenharmony_ci int rc; 353c0abf9e6Sopenharmony_ci struct input_event ev; 354c0abf9e6Sopenharmony_ci struct input_absinfo abs[3] = { 355c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 356c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 357c0abf9e6Sopenharmony_ci { .value = ABS_MAX, .maximum = 1000 }, 358c0abf9e6Sopenharmony_ci }; 359c0abf9e6Sopenharmony_ci 360c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 361c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 362c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 363c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 364c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 365c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 366c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 367c0abf9e6Sopenharmony_ci -1); 368c0abf9e6Sopenharmony_ci 369c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_X, 100); 370c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_Y, 500); 371c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MAX, 700); 372c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 373c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 374c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 375c0abf9e6Sopenharmony_ci 376c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 377c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 378c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_X, 100); 379c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 380c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 381c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_Y, 500); 382c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 383c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 384c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.type, EV_ABS); 385c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.code, ABS_MAX); 386c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 700); 387c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MAX, 700); 388c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 389c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 390c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 391c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 392c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 393c0abf9e6Sopenharmony_ci 394c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 395c0abf9e6Sopenharmony_ci libevdev_free(dev); 396c0abf9e6Sopenharmony_ci} 397c0abf9e6Sopenharmony_ciEND_TEST 398c0abf9e6Sopenharmony_ci 399c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_mt) 400c0abf9e6Sopenharmony_ci{ 401c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 402c0abf9e6Sopenharmony_ci struct libevdev *dev; 403c0abf9e6Sopenharmony_ci int rc; 404c0abf9e6Sopenharmony_ci struct input_event ev; 405c0abf9e6Sopenharmony_ci struct input_absinfo abs[6] = { 406c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 407c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 408c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 409c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 410c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 1 }, 411c0abf9e6Sopenharmony_ci { .value = ABS_MT_TRACKING_ID, .minimum = -1, .maximum = 2 }, 412c0abf9e6Sopenharmony_ci }; 413c0abf9e6Sopenharmony_ci 414c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 415c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 416c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 417c0abf9e6Sopenharmony_ci -1); 418c0abf9e6Sopenharmony_ci 419c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 420c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 421c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 100, 422c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 500, 423c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100, 424c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500, 425c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 1, 426c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 1, 427c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 1, 428c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 5, 429c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 1, 430c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 5, 431c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 2, 432c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 433c0abf9e6Sopenharmony_ci -1, -1); 434c0abf9e6Sopenharmony_ci 435c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 436c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 437c0abf9e6Sopenharmony_ci 438c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 0); 439c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 440c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 441c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_X, 1); 442c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 443c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 444c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_Y, 5); 445c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 446c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 447c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_SLOT, 0); 448c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 449c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 450c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_POSITION_X, 100); 451c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 452c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 453c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_POSITION_Y, 500); 454c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 455c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 456c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_TRACKING_ID, 1); 457c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 458c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 459c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_SLOT, 1); 460c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 1); 461c0abf9e6Sopenharmony_ci 462c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 463c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 464c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_POSITION_X, 1); 465c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 466c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 467c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_POSITION_Y, 5); 468c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 469c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 470c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_TRACKING_ID, 2); 471c0abf9e6Sopenharmony_ci 472c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 473c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 474c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 475c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 476c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 477c0abf9e6Sopenharmony_ci 478c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 479c0abf9e6Sopenharmony_ci libevdev_free(dev); 480c0abf9e6Sopenharmony_ci} 481c0abf9e6Sopenharmony_ciEND_TEST 482c0abf9e6Sopenharmony_ci 483c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_mt_reset_slot) 484c0abf9e6Sopenharmony_ci{ 485c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 486c0abf9e6Sopenharmony_ci struct libevdev *dev; 487c0abf9e6Sopenharmony_ci int rc; 488c0abf9e6Sopenharmony_ci struct input_event ev, 489c0abf9e6Sopenharmony_ci last_slot_event = { .type = 0}; 490c0abf9e6Sopenharmony_ci struct input_absinfo abs[6] = { 491c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 492c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 493c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 494c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 495c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 1 }, 496c0abf9e6Sopenharmony_ci { .value = ABS_MT_TRACKING_ID, .minimum = -1, .maximum = 2 }, 497c0abf9e6Sopenharmony_ci }; 498c0abf9e6Sopenharmony_ci 499c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 500c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 501c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 502c0abf9e6Sopenharmony_ci -1); 503c0abf9e6Sopenharmony_ci 504c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 505c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 1, 506c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100, 507c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500, 508c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 1, 509c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 510c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 1, 511c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 5, 512c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 2, 513c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 514c0abf9e6Sopenharmony_ci -1, -1); 515c0abf9e6Sopenharmony_ci 516c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 517c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 518c0abf9e6Sopenharmony_ci 519c0abf9e6Sopenharmony_ci do { 520c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 521c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_ABS, ABS_MT_SLOT)) 522c0abf9e6Sopenharmony_ci last_slot_event = ev; 523c0abf9e6Sopenharmony_ci } while (rc != -EAGAIN); 524c0abf9e6Sopenharmony_ci 525c0abf9e6Sopenharmony_ci ck_assert(libevdev_event_is_code(&last_slot_event, EV_ABS, ABS_MT_SLOT)); 526c0abf9e6Sopenharmony_ci ck_assert_int_eq(last_slot_event.value, 0); 527c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 0); 528c0abf9e6Sopenharmony_ci 529c0abf9e6Sopenharmony_ci last_slot_event.type = 0; 530c0abf9e6Sopenharmony_ci 531c0abf9e6Sopenharmony_ci /* same thing again, this time swap the numbers */ 532c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 533c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 534c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100, 535c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500, 536c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 1, 537c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 1, 538c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 1, 539c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 5, 540c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 2, 541c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 542c0abf9e6Sopenharmony_ci -1, -1); 543c0abf9e6Sopenharmony_ci 544c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 545c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 546c0abf9e6Sopenharmony_ci 547c0abf9e6Sopenharmony_ci do { 548c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 549c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_ABS, ABS_MT_SLOT)) 550c0abf9e6Sopenharmony_ci last_slot_event = ev; 551c0abf9e6Sopenharmony_ci } while (rc != -EAGAIN); 552c0abf9e6Sopenharmony_ci 553c0abf9e6Sopenharmony_ci ck_assert(libevdev_event_is_code(&last_slot_event, EV_ABS, ABS_MT_SLOT)); 554c0abf9e6Sopenharmony_ci ck_assert_int_eq(last_slot_event.value, 1); 555c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 1); 556c0abf9e6Sopenharmony_ci 557c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 558c0abf9e6Sopenharmony_ci libevdev_free(dev); 559c0abf9e6Sopenharmony_ci} 560c0abf9e6Sopenharmony_ciEND_TEST 561c0abf9e6Sopenharmony_ci 562c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_led) 563c0abf9e6Sopenharmony_ci{ 564c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 565c0abf9e6Sopenharmony_ci struct libevdev *dev; 566c0abf9e6Sopenharmony_ci int rc; 567c0abf9e6Sopenharmony_ci struct input_event ev; 568c0abf9e6Sopenharmony_ci 569c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 570c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 571c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 572c0abf9e6Sopenharmony_ci EV_LED, LED_NUML, 573c0abf9e6Sopenharmony_ci EV_LED, LED_CAPSL, 574c0abf9e6Sopenharmony_ci EV_LED, LED_MAX, 575c0abf9e6Sopenharmony_ci -1); 576c0abf9e6Sopenharmony_ci 577c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_LED, LED_NUML, 1); 578c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_LED, LED_CAPSL, 1); 579c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_LED, LED_MAX, 1); 580c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 581c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 582c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 583c0abf9e6Sopenharmony_ci 584c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 585c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 586c0abf9e6Sopenharmony_ci assert_event(&ev, EV_LED, LED_NUML, 1); 587c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 588c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 589c0abf9e6Sopenharmony_ci assert_event(&ev, EV_LED, LED_CAPSL, 1); 590c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 591c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 592c0abf9e6Sopenharmony_ci assert_event(&ev, EV_LED, LED_MAX, 1); 593c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 594c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 595c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 596c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 597c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 598c0abf9e6Sopenharmony_ci 599c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_LED, LED_NUML), 1); 600c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_LED, LED_CAPSL), 1); 601c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_LED, LED_MAX), 1); 602c0abf9e6Sopenharmony_ci 603c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 604c0abf9e6Sopenharmony_ci libevdev_free(dev); 605c0abf9e6Sopenharmony_ci} 606c0abf9e6Sopenharmony_ciEND_TEST 607c0abf9e6Sopenharmony_ci 608c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_sw) 609c0abf9e6Sopenharmony_ci{ 610c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 611c0abf9e6Sopenharmony_ci struct libevdev *dev; 612c0abf9e6Sopenharmony_ci int rc; 613c0abf9e6Sopenharmony_ci struct input_event ev; 614c0abf9e6Sopenharmony_ci 615c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 616c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 617c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 618c0abf9e6Sopenharmony_ci EV_SW, SW_HEADPHONE_INSERT, 619c0abf9e6Sopenharmony_ci EV_SW, SW_MICROPHONE_INSERT, 620c0abf9e6Sopenharmony_ci EV_SW, SW_MAX, 621c0abf9e6Sopenharmony_ci -1); 622c0abf9e6Sopenharmony_ci 623c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SW, SW_HEADPHONE_INSERT, 1); 624c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SW, SW_MICROPHONE_INSERT, 1); 625c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SW, SW_MAX, 1); 626c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 627c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 628c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 629c0abf9e6Sopenharmony_ci 630c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 631c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 632c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SW, SW_HEADPHONE_INSERT, 1); 633c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 634c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 635c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SW, SW_MICROPHONE_INSERT, 1); 636c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 637c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 638c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SW, SW_MAX, 1); 639c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 640c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 641c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 642c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 643c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 644c0abf9e6Sopenharmony_ci 645c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_SW, SW_HEADPHONE_INSERT), 1); 646c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_SW, SW_MICROPHONE_INSERT), 1); 647c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_SW, SW_MAX), 1); 648c0abf9e6Sopenharmony_ci 649c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 650c0abf9e6Sopenharmony_ci libevdev_free(dev); 651c0abf9e6Sopenharmony_ci} 652c0abf9e6Sopenharmony_ciEND_TEST 653c0abf9e6Sopenharmony_ci 654c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_tracking_ids) 655c0abf9e6Sopenharmony_ci{ 656c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 657c0abf9e6Sopenharmony_ci struct libevdev *dev; 658c0abf9e6Sopenharmony_ci int rc; 659c0abf9e6Sopenharmony_ci struct input_event ev; 660c0abf9e6Sopenharmony_ci int i; 661c0abf9e6Sopenharmony_ci const int num_slots = 15; 662c0abf9e6Sopenharmony_ci int slot = -1; 663c0abf9e6Sopenharmony_ci unsigned long terminated[NLONGS(num_slots)]; 664c0abf9e6Sopenharmony_ci unsigned long restarted[NLONGS(num_slots)]; 665c0abf9e6Sopenharmony_ci struct input_absinfo abs[6] = { 666c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 667c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 668c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 669c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 670c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = num_slots }, 671c0abf9e6Sopenharmony_ci { .value = ABS_MT_TRACKING_ID, .minimum = -1, .maximum = 0xff }, 672c0abf9e6Sopenharmony_ci }; 673c0abf9e6Sopenharmony_ci 674c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 675c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 676c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 677c0abf9e6Sopenharmony_ci -1); 678c0abf9e6Sopenharmony_ci 679c0abf9e6Sopenharmony_ci /* Test the sync process to make sure we get touches terminated when 680c0abf9e6Sopenharmony_ci * the tracking id changes: 681c0abf9e6Sopenharmony_ci * 1) start a bunch of touch points 682c0abf9e6Sopenharmony_ci * 2) read data into libevdev, make sure state is up-to-date 683c0abf9e6Sopenharmony_ci * 3) change touchpoints 684c0abf9e6Sopenharmony_ci * 3.1) change the tracking ID on some (indicating terminated and 685c0abf9e6Sopenharmony_ci * re-started touchpoint) 686c0abf9e6Sopenharmony_ci * 3.2) change the tracking ID to -1 on some (indicating termianted 687c0abf9e6Sopenharmony_ci * touchpoint) 688c0abf9e6Sopenharmony_ci * 3.3) just update the data on others 689c0abf9e6Sopenharmony_ci * 4) force a sync on the device 690c0abf9e6Sopenharmony_ci * 5) make sure we get the right tracking ID changes in the caller 691c0abf9e6Sopenharmony_ci */ 692c0abf9e6Sopenharmony_ci 693c0abf9e6Sopenharmony_ci /* Start a bunch of touch points */ 694c0abf9e6Sopenharmony_ci for (i = num_slots; i >= 0; i--) { 695c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 696c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, i, 697c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, i, 698c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 100 + i, 699c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 500 + i, 700c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100 + i, 701c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500 + i, 702c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 703c0abf9e6Sopenharmony_ci -1, -1); 704c0abf9e6Sopenharmony_ci do { 705c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 706c0abf9e6Sopenharmony_ci ck_assert_int_ne(rc, LIBEVDEV_READ_STATUS_SYNC); 707c0abf9e6Sopenharmony_ci } while (rc >= 0); 708c0abf9e6Sopenharmony_ci } 709c0abf9e6Sopenharmony_ci 710c0abf9e6Sopenharmony_ci /* we have a bunch of touches now, and libevdev knows it. Change all 711c0abf9e6Sopenharmony_ci * touches */ 712c0abf9e6Sopenharmony_ci for (i = num_slots; i >= 0; i--) { 713c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, i); 714c0abf9e6Sopenharmony_ci if (i % 3 == 0) { 715c0abf9e6Sopenharmony_ci /* change some slots with a new tracking id */ 716c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 717c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, num_slots + i, 718c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 200 + i, 719c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 700 + i, 720c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 200 + i, 721c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 700 + i, 722c0abf9e6Sopenharmony_ci -1, -1); 723c0abf9e6Sopenharmony_ci } else if (i % 3 == 1) { 724c0abf9e6Sopenharmony_ci /* stop others */ 725c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, -1); 726c0abf9e6Sopenharmony_ci } else { 727c0abf9e6Sopenharmony_ci /* just update */ 728c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 729c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 200 + i, 730c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 700 + i, 731c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 200 + i, 732c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 700 + i, 733c0abf9e6Sopenharmony_ci -1, -1); 734c0abf9e6Sopenharmony_ci } 735c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 736c0abf9e6Sopenharmony_ci } 737c0abf9e6Sopenharmony_ci 738c0abf9e6Sopenharmony_ci /* Force sync */ 739c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 740c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 741c0abf9e6Sopenharmony_ci 742c0abf9e6Sopenharmony_ci /* now check for the right tracking IDs */ 743c0abf9e6Sopenharmony_ci memset(terminated, 0, sizeof(terminated)); 744c0abf9e6Sopenharmony_ci memset(restarted, 0, sizeof(restarted)); 745c0abf9e6Sopenharmony_ci slot = -1; 746c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev)) != -EAGAIN) { 747c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_SYN, SYN_REPORT)) 748c0abf9e6Sopenharmony_ci continue; 749c0abf9e6Sopenharmony_ci 750c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_ABS, ABS_MT_SLOT)) { 751c0abf9e6Sopenharmony_ci slot = ev.value; 752c0abf9e6Sopenharmony_ci continue; 753c0abf9e6Sopenharmony_ci } 754c0abf9e6Sopenharmony_ci 755c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_ABS, ABS_X) || 756c0abf9e6Sopenharmony_ci libevdev_event_is_code(&ev, EV_ABS, ABS_Y)) 757c0abf9e6Sopenharmony_ci continue; 758c0abf9e6Sopenharmony_ci 759c0abf9e6Sopenharmony_ci ck_assert_int_ne(slot, -1); 760c0abf9e6Sopenharmony_ci 761c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_ABS, ABS_MT_TRACKING_ID)) { 762c0abf9e6Sopenharmony_ci if (slot % 3 == 0) { 763c0abf9e6Sopenharmony_ci if (!bit_is_set(terminated, slot)) { 764c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, -1); 765c0abf9e6Sopenharmony_ci set_bit(terminated, slot); 766c0abf9e6Sopenharmony_ci } else { 767c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, num_slots + slot); 768c0abf9e6Sopenharmony_ci set_bit(restarted, slot); 769c0abf9e6Sopenharmony_ci } 770c0abf9e6Sopenharmony_ci } else if (slot % 3 == 1) { 771c0abf9e6Sopenharmony_ci ck_assert(!bit_is_set(terminated, slot)); 772c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, -1); 773c0abf9e6Sopenharmony_ci set_bit(terminated, slot); 774c0abf9e6Sopenharmony_ci } else 775c0abf9e6Sopenharmony_ci ck_abort(); 776c0abf9e6Sopenharmony_ci 777c0abf9e6Sopenharmony_ci continue; 778c0abf9e6Sopenharmony_ci } 779c0abf9e6Sopenharmony_ci 780c0abf9e6Sopenharmony_ci switch(ev.code) { 781c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_X: 782c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 200 + slot); 783c0abf9e6Sopenharmony_ci break; 784c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_Y: 785c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 700 + slot); 786c0abf9e6Sopenharmony_ci break; 787c0abf9e6Sopenharmony_ci default: 788c0abf9e6Sopenharmony_ci ck_abort(); 789c0abf9e6Sopenharmony_ci } 790c0abf9e6Sopenharmony_ci } 791c0abf9e6Sopenharmony_ci 792c0abf9e6Sopenharmony_ci for (i = 0; i < num_slots; i++) { 793c0abf9e6Sopenharmony_ci if (i % 3 == 0) { 794c0abf9e6Sopenharmony_ci ck_assert(bit_is_set(terminated, i)); 795c0abf9e6Sopenharmony_ci ck_assert(bit_is_set(restarted, i)); 796c0abf9e6Sopenharmony_ci } else if (i % 3 == 1) { 797c0abf9e6Sopenharmony_ci ck_assert(bit_is_set(terminated, i)); 798c0abf9e6Sopenharmony_ci ck_assert(!bit_is_set(restarted, i)); 799c0abf9e6Sopenharmony_ci } else { 800c0abf9e6Sopenharmony_ci ck_assert(!bit_is_set(terminated, i)); 801c0abf9e6Sopenharmony_ci ck_assert(!bit_is_set(restarted, i)); 802c0abf9e6Sopenharmony_ci } 803c0abf9e6Sopenharmony_ci } 804c0abf9e6Sopenharmony_ci 805c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 806c0abf9e6Sopenharmony_ci libevdev_free(dev); 807c0abf9e6Sopenharmony_ci} 808c0abf9e6Sopenharmony_ciEND_TEST 809c0abf9e6Sopenharmony_ci 810c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_tracking_ids_btntool) 811c0abf9e6Sopenharmony_ci{ 812c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 813c0abf9e6Sopenharmony_ci struct libevdev *dev; 814c0abf9e6Sopenharmony_ci int rc; 815c0abf9e6Sopenharmony_ci struct input_event ev; 816c0abf9e6Sopenharmony_ci const int num_slots = 5; 817c0abf9e6Sopenharmony_ci struct input_absinfo abs[6] = { 818c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 819c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 820c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 821c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 822c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = num_slots }, 823c0abf9e6Sopenharmony_ci { .value = ABS_MT_TRACKING_ID, .minimum = -1, .maximum = 0xffff }, 824c0abf9e6Sopenharmony_ci }; 825c0abf9e6Sopenharmony_ci bool have_doubletap = false, 826c0abf9e6Sopenharmony_ci have_quadtap = false, 827c0abf9e6Sopenharmony_ci have_quinttap = false; 828c0abf9e6Sopenharmony_ci 829c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 830c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 831c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_FINGER, 832c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_DOUBLETAP, 833c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_TRIPLETAP, 834c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUADTAP, 835c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUINTTAP, 836c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 837c0abf9e6Sopenharmony_ci -1); 838c0abf9e6Sopenharmony_ci 839c0abf9e6Sopenharmony_ci /* Test the sync process to make sure we get the BTN_TOOL bits for 840c0abf9e6Sopenharmony_ci * touches adjusted correctly when the tracking id changes: 841c0abf9e6Sopenharmony_ci * 1) start a bunch of touch points 842c0abf9e6Sopenharmony_ci * 2) read data into libevdev, make sure state is up-to-date 843c0abf9e6Sopenharmony_ci * 3) change touchpoints 844c0abf9e6Sopenharmony_ci * 3.1) change the tracking ID on some (indicating terminated and 845c0abf9e6Sopenharmony_ci * re-started touchpoint) 846c0abf9e6Sopenharmony_ci * 3.2) change the tracking ID to -1 on some (indicating termianted 847c0abf9e6Sopenharmony_ci * touchpoint) 848c0abf9e6Sopenharmony_ci * 3.3) just update the data on others 849c0abf9e6Sopenharmony_ci * 4) force a sync on the device 850c0abf9e6Sopenharmony_ci * 5) make sure we get the right BTN_TOOL_ changes in the caller 851c0abf9e6Sopenharmony_ci */ 852c0abf9e6Sopenharmony_ci for (int i = 0; i < num_slots; i++) { 853c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 854c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, i, 855c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 111, 856c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 100 + 10 * i, 857c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 100 + 10 * i, 858c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100, 859c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 100, 860c0abf9e6Sopenharmony_ci -1, -1); 861c0abf9e6Sopenharmony_ci switch (i) { 862c0abf9e6Sopenharmony_ci case 0: 863c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_FINGER, 1); 864c0abf9e6Sopenharmony_ci break; 865c0abf9e6Sopenharmony_ci case 1: 866c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_FINGER, 0); 867c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); 868c0abf9e6Sopenharmony_ci break; 869c0abf9e6Sopenharmony_ci case 2: 870c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); 871c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_TRIPLETAP, 1); 872c0abf9e6Sopenharmony_ci break; 873c0abf9e6Sopenharmony_ci case 3: 874c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_TRIPLETAP, 0); 875c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_QUADTAP, 1); 876c0abf9e6Sopenharmony_ci break; 877c0abf9e6Sopenharmony_ci case 4: 878c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_QUADTAP, 0); 879c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_TOOL_QUINTTAP, 1); 880c0abf9e6Sopenharmony_ci break; 881c0abf9e6Sopenharmony_ci default: 882c0abf9e6Sopenharmony_ci ck_abort(); 883c0abf9e6Sopenharmony_ci } 884c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 885c0abf9e6Sopenharmony_ci } 886c0abf9e6Sopenharmony_ci 887c0abf9e6Sopenharmony_ci do { 888c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 889c0abf9e6Sopenharmony_ci ck_assert_int_ne(rc, LIBEVDEV_READ_STATUS_SYNC); 890c0abf9e6Sopenharmony_ci } while (rc >= 0); 891c0abf9e6Sopenharmony_ci 892c0abf9e6Sopenharmony_ci /* we have a bunch of touches now, and libevdev knows it. 893c0abf9e6Sopenharmony_ci * - stop touch 0 894c0abf9e6Sopenharmony_ci * - stop and restart touch 1 and 4 895c0abf9e6Sopenharmony_ci * - leave 2, 3 unchanged 896c0abf9e6Sopenharmony_ci */ 897c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 898c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 899c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, -1, 900c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUINTTAP, 0, 901c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUADTAP, 1, 902c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 903c0abf9e6Sopenharmony_ci -1, -1); 904c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 905c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 1, 906c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, -1, 907c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUADTAP, 0, 908c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_TRIPLETAP, 1, 909c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 910c0abf9e6Sopenharmony_ci -1, -1); 911c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 912c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 1, 913c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 666, 914c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 666, 915c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 666, 916c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 666, 917c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 666, 918c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_TRIPLETAP, 0, 919c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUADTAP, 1, 920c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 921c0abf9e6Sopenharmony_ci -1, -1); 922c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 923c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 4, 924c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, -1, 925c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUADTAP, 0, 926c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_TRIPLETAP, 1, 927c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 928c0abf9e6Sopenharmony_ci -1, -1); 929c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 930c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 4, 931c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 777, 932c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 777, 933c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 777, 934c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 777, 935c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 777, 936c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_QUADTAP, 1, 937c0abf9e6Sopenharmony_ci EV_KEY, BTN_TOOL_TRIPLETAP, 0, 938c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 939c0abf9e6Sopenharmony_ci -1, -1); 940c0abf9e6Sopenharmony_ci 941c0abf9e6Sopenharmony_ci /* Force sync */ 942c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 943c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 944c0abf9e6Sopenharmony_ci 945c0abf9e6Sopenharmony_ci /* In the first sync frame, we expect us to drop to 2 touches - we 946c0abf9e6Sopenharmony_ci * started with 5, 1 stopped, 2 stopped+restarted */ 947c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev)) != -EAGAIN) { 948c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_QUINTTAP)) { 949c0abf9e6Sopenharmony_ci ck_assert(!have_quinttap); 950c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_TOOL_QUINTTAP, 0); 951c0abf9e6Sopenharmony_ci have_quinttap = true; 952c0abf9e6Sopenharmony_ci } 953c0abf9e6Sopenharmony_ci 954c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_TRIPLETAP)) 955c0abf9e6Sopenharmony_ci ck_abort(); 956c0abf9e6Sopenharmony_ci 957c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_DOUBLETAP)) { 958c0abf9e6Sopenharmony_ci ck_assert(!have_doubletap); 959c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_TOOL_DOUBLETAP, 1); 960c0abf9e6Sopenharmony_ci have_doubletap = true; 961c0abf9e6Sopenharmony_ci } 962c0abf9e6Sopenharmony_ci 963c0abf9e6Sopenharmony_ci ck_assert(!libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_TRIPLETAP)); 964c0abf9e6Sopenharmony_ci ck_assert(!libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_QUADTAP)); 965c0abf9e6Sopenharmony_ci ck_assert(!libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_FINGER)); 966c0abf9e6Sopenharmony_ci 967c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_SYN, SYN_REPORT)) { 968c0abf9e6Sopenharmony_ci ck_assert(have_doubletap); 969c0abf9e6Sopenharmony_ci ck_assert(have_quinttap); 970c0abf9e6Sopenharmony_ci break; 971c0abf9e6Sopenharmony_ci } 972c0abf9e6Sopenharmony_ci } 973c0abf9e6Sopenharmony_ci 974c0abf9e6Sopenharmony_ci have_doubletap = false; 975c0abf9e6Sopenharmony_ci have_quadtap = false; 976c0abf9e6Sopenharmony_ci 977c0abf9e6Sopenharmony_ci /* In the second sync frame, we expect to go back to 4 touches, 978c0abf9e6Sopenharmony_ci * recovering the two stopped+started touches */ 979c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev)) != -EAGAIN) { 980c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_QUADTAP)) { 981c0abf9e6Sopenharmony_ci ck_assert(!have_quadtap); 982c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_TOOL_QUADTAP, 1); 983c0abf9e6Sopenharmony_ci have_quadtap = true; 984c0abf9e6Sopenharmony_ci } 985c0abf9e6Sopenharmony_ci 986c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_TRIPLETAP)) 987c0abf9e6Sopenharmony_ci ck_abort(); 988c0abf9e6Sopenharmony_ci 989c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_DOUBLETAP)) { 990c0abf9e6Sopenharmony_ci ck_assert(!have_doubletap); 991c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_TOOL_DOUBLETAP, 0); 992c0abf9e6Sopenharmony_ci have_doubletap = true; 993c0abf9e6Sopenharmony_ci } 994c0abf9e6Sopenharmony_ci 995c0abf9e6Sopenharmony_ci ck_assert(!libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_TRIPLETAP)); 996c0abf9e6Sopenharmony_ci ck_assert(!libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_QUINTTAP)); 997c0abf9e6Sopenharmony_ci ck_assert(!libevdev_event_is_code(&ev, EV_KEY, BTN_TOOL_FINGER)); 998c0abf9e6Sopenharmony_ci 999c0abf9e6Sopenharmony_ci if (libevdev_event_is_code(&ev, EV_SYN, SYN_REPORT)) { 1000c0abf9e6Sopenharmony_ci ck_assert(have_doubletap); 1001c0abf9e6Sopenharmony_ci ck_assert(have_quadtap); 1002c0abf9e6Sopenharmony_ci break; 1003c0abf9e6Sopenharmony_ci } 1004c0abf9e6Sopenharmony_ci } 1005c0abf9e6Sopenharmony_ci 1006c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1007c0abf9e6Sopenharmony_ci libevdev_free(dev); 1008c0abf9e6Sopenharmony_ci} 1009c0abf9e6Sopenharmony_ciEND_TEST 1010c0abf9e6Sopenharmony_ci 1011c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_late_sync) 1012c0abf9e6Sopenharmony_ci{ 1013c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1014c0abf9e6Sopenharmony_ci struct libevdev *dev; 1015c0abf9e6Sopenharmony_ci int rc; 1016c0abf9e6Sopenharmony_ci struct input_event ev; 1017c0abf9e6Sopenharmony_ci struct input_absinfo abs[6] = { 1018c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1019c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1020c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1021c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1022c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 1 }, 1023c0abf9e6Sopenharmony_ci { .value = ABS_MT_TRACKING_ID, .minimum = -1, .maximum = 0xff}, 1024c0abf9e6Sopenharmony_ci }; 1025c0abf9e6Sopenharmony_ci int i, slot; 1026c0abf9e6Sopenharmony_ci 1027c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1028c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1029c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1030c0abf9e6Sopenharmony_ci -1); 1031c0abf9e6Sopenharmony_ci 1032c0abf9e6Sopenharmony_ci /* emulate a touch down, make sure libevdev sees it */ 1033c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1034c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 1035c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 1, 1036c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 100, 1037c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 500, 1038c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100, 1039c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500, 1040c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1041c0abf9e6Sopenharmony_ci -1, -1); 1042c0abf9e6Sopenharmony_ci do { 1043c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1044c0abf9e6Sopenharmony_ci ck_assert_int_ne(rc, LIBEVDEV_READ_STATUS_SYNC); 1045c0abf9e6Sopenharmony_ci } while (rc >= 0); 1046c0abf9e6Sopenharmony_ci 1047c0abf9e6Sopenharmony_ci /* force enough events to trigger a SYN_DROPPED */ 1048c0abf9e6Sopenharmony_ci for (i = 0; i < 100; i++) { 1049c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1050c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 100 + i, 1051c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 500 + i, 1052c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100 + i, 1053c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500 + i, 1054c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1055c0abf9e6Sopenharmony_ci -1, -1); 1056c0abf9e6Sopenharmony_ci } 1057c0abf9e6Sopenharmony_ci 1058c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1059c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 1060c0abf9e6Sopenharmony_ci 1061c0abf9e6Sopenharmony_ci /* trigger the tracking ID change after getting the SYN_DROPPED */ 1062c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1063c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 1064c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, -1, 1065c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 200, 1066c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 600, 1067c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 200, 1068c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 600, 1069c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1070c0abf9e6Sopenharmony_ci -1, -1); 1071c0abf9e6Sopenharmony_ci 1072c0abf9e6Sopenharmony_ci slot = 0; 1073c0abf9e6Sopenharmony_ci 1074c0abf9e6Sopenharmony_ci /* Now sync the device, expect the data to be equal to the last event*/ 1075c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev)) != -EAGAIN) { 1076c0abf9e6Sopenharmony_ci if (ev.type == EV_SYN) 1077c0abf9e6Sopenharmony_ci continue; 1078c0abf9e6Sopenharmony_ci 1079c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.type, EV_ABS); 1080c0abf9e6Sopenharmony_ci switch(ev.code) { 1081c0abf9e6Sopenharmony_ci case ABS_MT_SLOT: 1082c0abf9e6Sopenharmony_ci slot = ev.value; 1083c0abf9e6Sopenharmony_ci break; 1084c0abf9e6Sopenharmony_ci case ABS_MT_TRACKING_ID: 1085c0abf9e6Sopenharmony_ci if (slot == 0) 1086c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, -1); 1087c0abf9e6Sopenharmony_ci break; 1088c0abf9e6Sopenharmony_ci case ABS_X: 1089c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_X: 1090c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 200); 1091c0abf9e6Sopenharmony_ci break; 1092c0abf9e6Sopenharmony_ci case ABS_Y: 1093c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_Y: 1094c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 600); 1095c0abf9e6Sopenharmony_ci break; 1096c0abf9e6Sopenharmony_ci } 1097c0abf9e6Sopenharmony_ci } 1098c0abf9e6Sopenharmony_ci 1099c0abf9e6Sopenharmony_ci /* And a new tracking ID */ 1100c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1101c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 1102c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 2, 1103c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 201, 1104c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 601, 1105c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 201, 1106c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 601, 1107c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1108c0abf9e6Sopenharmony_ci -1, -1); 1109c0abf9e6Sopenharmony_ci 1110c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev)) != -EAGAIN) { 1111c0abf9e6Sopenharmony_ci ck_assert_int_ne(rc, LIBEVDEV_READ_STATUS_SYNC); 1112c0abf9e6Sopenharmony_ci 1113c0abf9e6Sopenharmony_ci if (ev.type == EV_SYN) 1114c0abf9e6Sopenharmony_ci continue; 1115c0abf9e6Sopenharmony_ci 1116c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.type, EV_ABS); 1117c0abf9e6Sopenharmony_ci 1118c0abf9e6Sopenharmony_ci switch(ev.code) { 1119c0abf9e6Sopenharmony_ci case ABS_MT_SLOT: 1120c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 0); 1121c0abf9e6Sopenharmony_ci break; 1122c0abf9e6Sopenharmony_ci case ABS_MT_TRACKING_ID: 1123c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 2); 1124c0abf9e6Sopenharmony_ci break; 1125c0abf9e6Sopenharmony_ci case ABS_X: 1126c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_X: 1127c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 201); 1128c0abf9e6Sopenharmony_ci break; 1129c0abf9e6Sopenharmony_ci case ABS_Y: 1130c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_Y: 1131c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 601); 1132c0abf9e6Sopenharmony_ci break; 1133c0abf9e6Sopenharmony_ci } 1134c0abf9e6Sopenharmony_ci } 1135c0abf9e6Sopenharmony_ci 1136c0abf9e6Sopenharmony_ci /* Now we basically re-do the exact same test, just with the 1137c0abf9e6Sopenharmony_ci tracking ID order inverted */ 1138c0abf9e6Sopenharmony_ci 1139c0abf9e6Sopenharmony_ci /* drop the tracking ID, make sure libevdev sees it */ 1140c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 0); 1141c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, -1); 1142c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1143c0abf9e6Sopenharmony_ci do { 1144c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1145c0abf9e6Sopenharmony_ci ck_assert_int_ne(rc, LIBEVDEV_READ_STATUS_SYNC); 1146c0abf9e6Sopenharmony_ci } while (rc >= 0); 1147c0abf9e6Sopenharmony_ci 1148c0abf9e6Sopenharmony_ci /* force enough events to trigger a SYN_DROPPED */ 1149c0abf9e6Sopenharmony_ci for (i = 0; i < 100; i++) { 1150c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1151c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 100 + i, 1152c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 500 + i, 1153c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100 + i, 1154c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500 + i, 1155c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1156c0abf9e6Sopenharmony_ci -1, -1); 1157c0abf9e6Sopenharmony_ci } 1158c0abf9e6Sopenharmony_ci 1159c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1160c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 1161c0abf9e6Sopenharmony_ci 1162c0abf9e6Sopenharmony_ci /* trigger the new tracking ID after getting the SYN_DROPPED */ 1163c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1164c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 1165c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_TRACKING_ID, 5, 1166c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 200, 1167c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 600, 1168c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 200, 1169c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 600, 1170c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1171c0abf9e6Sopenharmony_ci -1, -1); 1172c0abf9e6Sopenharmony_ci 1173c0abf9e6Sopenharmony_ci slot = 0; 1174c0abf9e6Sopenharmony_ci 1175c0abf9e6Sopenharmony_ci /* Now sync the device, expect the data to be equal to the last event*/ 1176c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev)) != -EAGAIN) { 1177c0abf9e6Sopenharmony_ci if (ev.type == EV_SYN) 1178c0abf9e6Sopenharmony_ci continue; 1179c0abf9e6Sopenharmony_ci 1180c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.type, EV_ABS); 1181c0abf9e6Sopenharmony_ci switch(ev.code) { 1182c0abf9e6Sopenharmony_ci case ABS_MT_SLOT: 1183c0abf9e6Sopenharmony_ci slot = ev.value; 1184c0abf9e6Sopenharmony_ci break; 1185c0abf9e6Sopenharmony_ci case ABS_MT_TRACKING_ID: 1186c0abf9e6Sopenharmony_ci if (slot == 0) 1187c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 5); 1188c0abf9e6Sopenharmony_ci break; 1189c0abf9e6Sopenharmony_ci case ABS_X: 1190c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_X: 1191c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 200); 1192c0abf9e6Sopenharmony_ci break; 1193c0abf9e6Sopenharmony_ci case ABS_Y: 1194c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_Y: 1195c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 600); 1196c0abf9e6Sopenharmony_ci break; 1197c0abf9e6Sopenharmony_ci } 1198c0abf9e6Sopenharmony_ci } 1199c0abf9e6Sopenharmony_ci 1200c0abf9e6Sopenharmony_ci /* Drop the tracking ID */ 1201c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 0); 1202c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, -1); 1203c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1204c0abf9e6Sopenharmony_ci 1205c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev)) != -EAGAIN) { 1206c0abf9e6Sopenharmony_ci ck_assert_int_ne(rc, LIBEVDEV_READ_STATUS_SYNC); 1207c0abf9e6Sopenharmony_ci 1208c0abf9e6Sopenharmony_ci if (ev.type == EV_SYN) 1209c0abf9e6Sopenharmony_ci continue; 1210c0abf9e6Sopenharmony_ci 1211c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.type, EV_ABS); 1212c0abf9e6Sopenharmony_ci 1213c0abf9e6Sopenharmony_ci switch(ev.code) { 1214c0abf9e6Sopenharmony_ci case ABS_MT_SLOT: 1215c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, 0); 1216c0abf9e6Sopenharmony_ci break; 1217c0abf9e6Sopenharmony_ci case ABS_MT_TRACKING_ID: 1218c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev.value, -1); 1219c0abf9e6Sopenharmony_ci break; 1220c0abf9e6Sopenharmony_ci } 1221c0abf9e6Sopenharmony_ci } 1222c0abf9e6Sopenharmony_ci 1223c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1224c0abf9e6Sopenharmony_ci libevdev_free(dev); 1225c0abf9e6Sopenharmony_ci} 1226c0abf9e6Sopenharmony_ciEND_TEST 1227c0abf9e6Sopenharmony_ci 1228c0abf9e6Sopenharmony_ciSTART_TEST(test_syn_delta_fake_mt) 1229c0abf9e6Sopenharmony_ci{ 1230c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1231c0abf9e6Sopenharmony_ci struct libevdev *dev; 1232c0abf9e6Sopenharmony_ci int rc; 1233c0abf9e6Sopenharmony_ci struct input_event ev; 1234c0abf9e6Sopenharmony_ci struct input_absinfo abs[] = { 1235c0abf9e6Sopenharmony_ci { .value = ABS_X, .minimum = 0, .maximum = 1000 }, 1236c0abf9e6Sopenharmony_ci { .value = ABS_Y, .minimum = 0, .maximum = 1000 }, 1237c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .minimum = 0, .maximum = 1000 }, 1238c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .minimum = 0, .maximum = 1000 }, 1239c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT - 1, .minimum = 0, .maximum = 2 }}; 1240c0abf9e6Sopenharmony_ci /* don't set ABS_MT_SLOT here, otherwise uinput will init 1241c0abf9e6Sopenharmony_ci * slots and the behavior is different to real devices with 1242c0abf9e6Sopenharmony_ci * such events */ 1243c0abf9e6Sopenharmony_ci unsigned long received[NLONGS(ABS_CNT)] = {0}; 1244c0abf9e6Sopenharmony_ci 1245c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, ARRAY_LENGTH(abs), abs, -1); 1246c0abf9e6Sopenharmony_ci /* first set of events */ 1247c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1248c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 200, 1249c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 400, 1250c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100, 1251c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500, 1252c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT - 1, 1, 1253c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1254c0abf9e6Sopenharmony_ci -1, -1); 1255c0abf9e6Sopenharmony_ci 1256c0abf9e6Sopenharmony_ci /* second set of events */ 1257c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1258c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 201, 1259c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 401, 1260c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 101, 1261c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 501, 1262c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT - 1, 2, 1263c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1264c0abf9e6Sopenharmony_ci -1, -1); 1265c0abf9e6Sopenharmony_ci 1266c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 1267c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 1268c0abf9e6Sopenharmony_ci 1269c0abf9e6Sopenharmony_ci while ((rc = libevdev_next_event(dev, LIBEVDEV_READ_STATUS_SYNC, &ev)) != -EAGAIN) { 1270c0abf9e6Sopenharmony_ci if (ev.type != EV_ABS) 1271c0abf9e6Sopenharmony_ci continue; 1272c0abf9e6Sopenharmony_ci 1273c0abf9e6Sopenharmony_ci ck_assert(!bit_is_set(received, ev.code)); 1274c0abf9e6Sopenharmony_ci 1275c0abf9e6Sopenharmony_ci switch(ev.code) { 1276c0abf9e6Sopenharmony_ci /* see comment below for ABS_MT_POSITION_X 1277c0abf9e6Sopenharmony_ci * and ABS_MT_POSITION_Y */ 1278c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_X: 1279c0abf9e6Sopenharmony_ci case ABS_MT_POSITION_Y: 1280c0abf9e6Sopenharmony_ci ck_abort(); 1281c0abf9e6Sopenharmony_ci break; 1282c0abf9e6Sopenharmony_ci 1283c0abf9e6Sopenharmony_ci case ABS_MT_SLOT - 1: ck_assert_int_eq(ev.value, 2); break; 1284c0abf9e6Sopenharmony_ci case ABS_X: ck_assert_int_eq(ev.value, 201); break; 1285c0abf9e6Sopenharmony_ci case ABS_Y: ck_assert_int_eq(ev.value, 401); break; 1286c0abf9e6Sopenharmony_ci default: 1287c0abf9e6Sopenharmony_ci ck_abort(); 1288c0abf9e6Sopenharmony_ci } 1289c0abf9e6Sopenharmony_ci 1290c0abf9e6Sopenharmony_ci set_bit(received, ev.code); 1291c0abf9e6Sopenharmony_ci } 1292c0abf9e6Sopenharmony_ci 1293c0abf9e6Sopenharmony_ci /* Dont' expect ABS_MT values, they are ignored during the sync 1294c0abf9e6Sopenharmony_ci * process */ 1295c0abf9e6Sopenharmony_ci ck_assert(!bit_is_set(received, ABS_MT_POSITION_X)); 1296c0abf9e6Sopenharmony_ci ck_assert(!bit_is_set(received, ABS_MT_POSITION_Y)); 1297c0abf9e6Sopenharmony_ci ck_assert(bit_is_set(received, ABS_MT_SLOT - 1)); 1298c0abf9e6Sopenharmony_ci ck_assert(bit_is_set(received, ABS_X)); 1299c0abf9e6Sopenharmony_ci ck_assert(bit_is_set(received, ABS_Y)); 1300c0abf9e6Sopenharmony_ci 1301c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 201); 1302c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 401); 1303c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_SLOT - 1), 2); 1304c0abf9e6Sopenharmony_ci 1305c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1306c0abf9e6Sopenharmony_ci libevdev_free(dev); 1307c0abf9e6Sopenharmony_ci} 1308c0abf9e6Sopenharmony_ciEND_TEST 1309c0abf9e6Sopenharmony_ci 1310c0abf9e6Sopenharmony_ciSTART_TEST(test_skipped_sync) 1311c0abf9e6Sopenharmony_ci{ 1312c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1313c0abf9e6Sopenharmony_ci struct libevdev *dev; 1314c0abf9e6Sopenharmony_ci int rc; 1315c0abf9e6Sopenharmony_ci struct input_event ev; 1316c0abf9e6Sopenharmony_ci struct input_absinfo abs[2] = { 1317c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1318c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1319c0abf9e6Sopenharmony_ci }; 1320c0abf9e6Sopenharmony_ci 1321c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1322c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1323c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1324c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 1325c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1326c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 1327c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 1328c0abf9e6Sopenharmony_ci -1); 1329c0abf9e6Sopenharmony_ci 1330c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1); 1331c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_X, 100); 1332c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_Y, 500); 1333c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1334c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 1335c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 1336c0abf9e6Sopenharmony_ci 1337c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1338c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 1339c0abf9e6Sopenharmony_ci 1340c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 1); 1341c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 100); 1342c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 500); 1343c0abf9e6Sopenharmony_ci 1344c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1345c0abf9e6Sopenharmony_ci libevdev_free(dev); 1346c0abf9e6Sopenharmony_ci} 1347c0abf9e6Sopenharmony_ciEND_TEST 1348c0abf9e6Sopenharmony_ci 1349c0abf9e6Sopenharmony_ciSTART_TEST(test_incomplete_sync) 1350c0abf9e6Sopenharmony_ci{ 1351c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1352c0abf9e6Sopenharmony_ci struct libevdev *dev; 1353c0abf9e6Sopenharmony_ci int rc; 1354c0abf9e6Sopenharmony_ci struct input_event ev; 1355c0abf9e6Sopenharmony_ci struct input_absinfo abs[2] = { 1356c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1357c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1358c0abf9e6Sopenharmony_ci }; 1359c0abf9e6Sopenharmony_ci 1360c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1361c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1362c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1363c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 1364c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1365c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 1366c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 1367c0abf9e6Sopenharmony_ci -1); 1368c0abf9e6Sopenharmony_ci 1369c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1); 1370c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_X, 100); 1371c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_Y, 500); 1372c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1373c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 1374c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 1375c0abf9e6Sopenharmony_ci 1376c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 1377c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 1378c0abf9e6Sopenharmony_ci assert_event(&ev, EV_KEY, BTN_LEFT, 1); 1379c0abf9e6Sopenharmony_ci 1380c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1381c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 1382c0abf9e6Sopenharmony_ci 1383c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 1); 1384c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 100); 1385c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 500); 1386c0abf9e6Sopenharmony_ci 1387c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1388c0abf9e6Sopenharmony_ci libevdev_free(dev); 1389c0abf9e6Sopenharmony_ci} 1390c0abf9e6Sopenharmony_ciEND_TEST 1391c0abf9e6Sopenharmony_ci 1392c0abf9e6Sopenharmony_ciSTART_TEST(test_empty_sync) 1393c0abf9e6Sopenharmony_ci{ 1394c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1395c0abf9e6Sopenharmony_ci struct libevdev *dev; 1396c0abf9e6Sopenharmony_ci int rc; 1397c0abf9e6Sopenharmony_ci struct input_event ev; 1398c0abf9e6Sopenharmony_ci 1399c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 1400c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1401c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 1402c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1403c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 1404c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 1405c0abf9e6Sopenharmony_ci -1); 1406c0abf9e6Sopenharmony_ci 1407c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev); 1408c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC); 1409c0abf9e6Sopenharmony_ci 1410c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_SYNC, &ev); 1411c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 1412c0abf9e6Sopenharmony_ci 1413c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1414c0abf9e6Sopenharmony_ci libevdev_free(dev); 1415c0abf9e6Sopenharmony_ci} 1416c0abf9e6Sopenharmony_ciEND_TEST 1417c0abf9e6Sopenharmony_ci 1418c0abf9e6Sopenharmony_ciSTART_TEST(test_event_values) 1419c0abf9e6Sopenharmony_ci{ 1420c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1421c0abf9e6Sopenharmony_ci struct libevdev *dev; 1422c0abf9e6Sopenharmony_ci int rc; 1423c0abf9e6Sopenharmony_ci struct input_event ev; 1424c0abf9e6Sopenharmony_ci struct input_absinfo abs[2] = { 1425c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1426c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1427c0abf9e6Sopenharmony_ci }; 1428c0abf9e6Sopenharmony_ci int value; 1429c0abf9e6Sopenharmony_ci 1430c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1431c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1432c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1433c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 1434c0abf9e6Sopenharmony_ci EV_REL, REL_X, 1435c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 1436c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1437c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 1438c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 1439c0abf9e6Sopenharmony_ci -1); 1440c0abf9e6Sopenharmony_ci 1441c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1); 1442c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_X, 100); 1443c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_Y, 500); 1444c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1445c0abf9e6Sopenharmony_ci 1446c0abf9e6Sopenharmony_ci /* must still be on old values */ 1447c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 0); 1448c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 0); 1449c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 0); 1450c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_X), 0); 1451c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_Y), 0); 1452c0abf9e6Sopenharmony_ci 1453c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_event_value(dev, EV_KEY, BTN_LEFT, &value), 1); 1454c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 0); 1455c0abf9e6Sopenharmony_ci 1456c0abf9e6Sopenharmony_ci do { 1457c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1458c0abf9e6Sopenharmony_ci } while (rc == 0); 1459c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 1460c0abf9e6Sopenharmony_ci 1461c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 1); 1462c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 100); 1463c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 500); 1464c0abf9e6Sopenharmony_ci 1465c0abf9e6Sopenharmony_ci /* always 0 */ 1466c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_X), 0); 1467c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_Y), 0); 1468c0abf9e6Sopenharmony_ci 1469c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_event_value(dev, EV_KEY, BTN_LEFT, &value), 1); 1470c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 1); 1471c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_event_value(dev, EV_ABS, ABS_X, &value), 1); 1472c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 100); 1473c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_event_value(dev, EV_ABS, ABS_Y, &value), 1); 1474c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 500); 1475c0abf9e6Sopenharmony_ci 1476c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1477c0abf9e6Sopenharmony_ci libevdev_free(dev); 1478c0abf9e6Sopenharmony_ci 1479c0abf9e6Sopenharmony_ci} 1480c0abf9e6Sopenharmony_ciEND_TEST 1481c0abf9e6Sopenharmony_ci 1482c0abf9e6Sopenharmony_ciSTART_TEST(test_event_values_invalid) 1483c0abf9e6Sopenharmony_ci{ 1484c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1485c0abf9e6Sopenharmony_ci struct libevdev *dev; 1486c0abf9e6Sopenharmony_ci struct input_absinfo abs[2] = { 1487c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1488c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1489c0abf9e6Sopenharmony_ci }; 1490c0abf9e6Sopenharmony_ci int value; 1491c0abf9e6Sopenharmony_ci 1492c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1493c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1494c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1495c0abf9e6Sopenharmony_ci EV_SYN, SYN_DROPPED, 1496c0abf9e6Sopenharmony_ci EV_REL, REL_X, 1497c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 1498c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1499c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 1500c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 1501c0abf9e6Sopenharmony_ci -1); 1502c0abf9e6Sopenharmony_ci 1503c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_EXTRA), 0); 1504c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Z), 0); 1505c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_Z), 0); 1506c0abf9e6Sopenharmony_ci 1507c0abf9e6Sopenharmony_ci value = 0xab; 1508c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_event_value(dev, EV_KEY, BTN_EXTRA, &value), 0); 1509c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 0xab); 1510c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_event_value(dev, EV_ABS, ABS_Z, &value), 0); 1511c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 0xab); 1512c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_event_value(dev, EV_REL, REL_Z, &value), 0); 1513c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 0xab); 1514c0abf9e6Sopenharmony_ci 1515c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1516c0abf9e6Sopenharmony_ci libevdev_free(dev); 1517c0abf9e6Sopenharmony_ci 1518c0abf9e6Sopenharmony_ci} 1519c0abf9e6Sopenharmony_ciEND_TEST 1520c0abf9e6Sopenharmony_ci 1521c0abf9e6Sopenharmony_ciSTART_TEST(test_mt_event_values) 1522c0abf9e6Sopenharmony_ci{ 1523c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1524c0abf9e6Sopenharmony_ci struct libevdev *dev; 1525c0abf9e6Sopenharmony_ci int rc; 1526c0abf9e6Sopenharmony_ci struct input_event ev; 1527c0abf9e6Sopenharmony_ci struct input_absinfo abs[5] = { 1528c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1529c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1530c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1531c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1532c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 2 }, 1533c0abf9e6Sopenharmony_ci }; 1534c0abf9e6Sopenharmony_ci int value; 1535c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1536c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1537c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1538c0abf9e6Sopenharmony_ci -1); 1539c0abf9e6Sopenharmony_ci 1540c0abf9e6Sopenharmony_ci uinput_device_event_multiple(uidev, 1541c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 0, 1542c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 100, 1543c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 500, 1544c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 100, 1545c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 500, 1546c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_SLOT, 1, 1547c0abf9e6Sopenharmony_ci EV_ABS, ABS_X, 1, 1548c0abf9e6Sopenharmony_ci EV_ABS, ABS_Y, 5, 1549c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_X, 1, 1550c0abf9e6Sopenharmony_ci EV_ABS, ABS_MT_POSITION_Y, 5, 1551c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 0, 1552c0abf9e6Sopenharmony_ci -1, -1); 1553c0abf9e6Sopenharmony_ci 1554c0abf9e6Sopenharmony_ci /* must still be on old values */ 1555c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 0); 1556c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 0); 1557c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_Y), 0); 1558c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 0); 1559c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_Y), 0); 1560c0abf9e6Sopenharmony_ci 1561c0abf9e6Sopenharmony_ci do { 1562c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1563c0abf9e6Sopenharmony_ci } while (rc == LIBEVDEV_READ_STATUS_SUCCESS); 1564c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 1565c0abf9e6Sopenharmony_ci 1566c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 1); 1567c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 100); 1568c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_Y), 500); 1569c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 1); 1570c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_Y), 5); 1571c0abf9e6Sopenharmony_ci 1572c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_slot_value(dev, 0, ABS_MT_POSITION_X, &value), 1); 1573c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 100); 1574c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_slot_value(dev, 0, ABS_MT_POSITION_Y, &value), 1); 1575c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 500); 1576c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_slot_value(dev, 1, ABS_MT_POSITION_X, &value), 1); 1577c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 1); 1578c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_slot_value(dev, 1, ABS_MT_POSITION_Y, &value), 1); 1579c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 5); 1580c0abf9e6Sopenharmony_ci 1581c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1582c0abf9e6Sopenharmony_ci libevdev_free(dev); 1583c0abf9e6Sopenharmony_ci 1584c0abf9e6Sopenharmony_ci} 1585c0abf9e6Sopenharmony_ciEND_TEST 1586c0abf9e6Sopenharmony_ci 1587c0abf9e6Sopenharmony_ciSTART_TEST(test_mt_event_values_invalid) 1588c0abf9e6Sopenharmony_ci{ 1589c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1590c0abf9e6Sopenharmony_ci struct libevdev *dev; 1591c0abf9e6Sopenharmony_ci struct input_absinfo abs[5] = { 1592c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1593c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1594c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1595c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1596c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 2 }, 1597c0abf9e6Sopenharmony_ci }; 1598c0abf9e6Sopenharmony_ci int value; 1599c0abf9e6Sopenharmony_ci 1600c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1601c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1602c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1603c0abf9e6Sopenharmony_ci -1); 1604c0abf9e6Sopenharmony_ci 1605c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 0); 1606c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_TOUCH_MINOR), 0); 1607c0abf9e6Sopenharmony_ci value = 0xab; 1608c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_fetch_slot_value(dev, 0, ABS_MT_TOUCH_MINOR, &value), 0); 1609c0abf9e6Sopenharmony_ci ck_assert_int_eq(value, 0xab); 1610c0abf9e6Sopenharmony_ci 1611c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 10, ABS_MT_POSITION_X), 0); 1612c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_X), 0); 1613c0abf9e6Sopenharmony_ci 1614c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1615c0abf9e6Sopenharmony_ci libevdev_free(dev); 1616c0abf9e6Sopenharmony_ci} 1617c0abf9e6Sopenharmony_ciEND_TEST 1618c0abf9e6Sopenharmony_ci 1619c0abf9e6Sopenharmony_ciSTART_TEST(test_mt_slot_ranges_invalid) 1620c0abf9e6Sopenharmony_ci{ 1621c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1622c0abf9e6Sopenharmony_ci struct libevdev *dev; 1623c0abf9e6Sopenharmony_ci struct input_event ev[2]; 1624c0abf9e6Sopenharmony_ci int rc; 1625c0abf9e6Sopenharmony_ci int num_slots = 2; 1626c0abf9e6Sopenharmony_ci struct input_absinfo abs[5] = { 1627c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1628c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1629c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1630c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1631c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = num_slots - 1 }, 1632c0abf9e6Sopenharmony_ci }; 1633c0abf9e6Sopenharmony_ci int pipefd[2]; 1634c0abf9e6Sopenharmony_ci 1635c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1636c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1637c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1638c0abf9e6Sopenharmony_ci -1); 1639c0abf9e6Sopenharmony_ci 1640c0abf9e6Sopenharmony_ci rc = pipe2(pipefd, O_NONBLOCK); 1641c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, 0); 1642c0abf9e6Sopenharmony_ci libevdev_change_fd(dev, pipefd[0]); 1643c0abf9e6Sopenharmony_ci 1644c0abf9e6Sopenharmony_ci memset(ev, 0, sizeof(ev)); 1645c0abf9e6Sopenharmony_ci ev[0].type = EV_ABS; 1646c0abf9e6Sopenharmony_ci ev[0].code = ABS_MT_SLOT; 1647c0abf9e6Sopenharmony_ci ev[0].value = num_slots; 1648c0abf9e6Sopenharmony_ci ev[1].type = EV_SYN; 1649c0abf9e6Sopenharmony_ci ev[1].code = SYN_REPORT; 1650c0abf9e6Sopenharmony_ci ev[1].value = 0; 1651c0abf9e6Sopenharmony_ci rc = write(pipefd[1], ev, sizeof(ev)); 1652c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, sizeof(ev)); 1653c0abf9e6Sopenharmony_ci 1654c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_ignore_error, NULL); 1655c0abf9e6Sopenharmony_ci 1656c0abf9e6Sopenharmony_ci libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, ev); 1657c0abf9e6Sopenharmony_ci ck_assert(libevdev_event_is_code(ev, EV_ABS, ABS_MT_SLOT)); 1658c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev[0].value, num_slots - 1); 1659c0abf9e6Sopenharmony_ci 1660c0abf9e6Sopenharmony_ci /* drain the EV_SYN */ 1661c0abf9e6Sopenharmony_ci libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, ev); 1662c0abf9e6Sopenharmony_ci 1663c0abf9e6Sopenharmony_ci ev[0].type = EV_ABS; 1664c0abf9e6Sopenharmony_ci ev[0].code = ABS_MT_SLOT; 1665c0abf9e6Sopenharmony_ci ev[0].value = -1; 1666c0abf9e6Sopenharmony_ci ev[1].type = EV_SYN; 1667c0abf9e6Sopenharmony_ci ev[1].code = SYN_REPORT; 1668c0abf9e6Sopenharmony_ci ev[1].value = 0; 1669c0abf9e6Sopenharmony_ci rc = write(pipefd[1], ev, sizeof(ev)); 1670c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, sizeof(ev)); 1671c0abf9e6Sopenharmony_ci 1672c0abf9e6Sopenharmony_ci libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, ev); 1673c0abf9e6Sopenharmony_ci ck_assert(libevdev_event_is_code(ev, EV_ABS, ABS_MT_SLOT)); 1674c0abf9e6Sopenharmony_ci ck_assert_int_eq(ev[0].value, num_slots - 1); 1675c0abf9e6Sopenharmony_ci 1676c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), num_slots - 1); 1677c0abf9e6Sopenharmony_ci 1678c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_SLOT, num_slots), -1); 1679c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_SLOT, -1), -1); 1680c0abf9e6Sopenharmony_ci 1681c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_abort_on_error, NULL); 1682c0abf9e6Sopenharmony_ci 1683c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1684c0abf9e6Sopenharmony_ci libevdev_free(dev); 1685c0abf9e6Sopenharmony_ci} 1686c0abf9e6Sopenharmony_ciEND_TEST 1687c0abf9e6Sopenharmony_ci 1688c0abf9e6Sopenharmony_ciSTART_TEST(test_mt_tracking_id_discard) 1689c0abf9e6Sopenharmony_ci{ 1690c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1691c0abf9e6Sopenharmony_ci struct libevdev *dev; 1692c0abf9e6Sopenharmony_ci int rc; 1693c0abf9e6Sopenharmony_ci struct input_event ev; 1694c0abf9e6Sopenharmony_ci struct input_absinfo abs[6] = { 1695c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1696c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1697c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1698c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1699c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 10 }, 1700c0abf9e6Sopenharmony_ci { .value = ABS_MT_TRACKING_ID, .minimum = -1, .maximum = 500 }, 1701c0abf9e6Sopenharmony_ci }; 1702c0abf9e6Sopenharmony_ci 1703c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1704c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1705c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1706c0abf9e6Sopenharmony_ci -1); 1707c0abf9e6Sopenharmony_ci 1708c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 1); 1709c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 1); 1710c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1711c0abf9e6Sopenharmony_ci 1712c0abf9e6Sopenharmony_ci /* second tracking ID on same slot */ 1713c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 2); 1714c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1715c0abf9e6Sopenharmony_ci 1716c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_ignore_error, NULL); 1717c0abf9e6Sopenharmony_ci 1718c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1719c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 1720c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_SLOT, 1); 1721c0abf9e6Sopenharmony_ci 1722c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1723c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 1724c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_TRACKING_ID, 1); 1725c0abf9e6Sopenharmony_ci 1726c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1727c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 1728c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 1729c0abf9e6Sopenharmony_ci 1730c0abf9e6Sopenharmony_ci /* expect tracking ID discarded */ 1731c0abf9e6Sopenharmony_ci 1732c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1733c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 1734c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 1735c0abf9e6Sopenharmony_ci 1736c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1737c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 1738c0abf9e6Sopenharmony_ci 1739c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_abort_on_error, NULL); 1740c0abf9e6Sopenharmony_ci 1741c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1742c0abf9e6Sopenharmony_ci libevdev_free(dev); 1743c0abf9e6Sopenharmony_ci} 1744c0abf9e6Sopenharmony_ciEND_TEST 1745c0abf9e6Sopenharmony_ci 1746c0abf9e6Sopenharmony_ciSTART_TEST(test_mt_tracking_id_discard_neg_1) 1747c0abf9e6Sopenharmony_ci{ 1748c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1749c0abf9e6Sopenharmony_ci struct libevdev *dev; 1750c0abf9e6Sopenharmony_ci int rc; 1751c0abf9e6Sopenharmony_ci struct input_event ev; 1752c0abf9e6Sopenharmony_ci struct input_absinfo abs[6] = { 1753c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1754c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1755c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1756c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1757c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 10 }, 1758c0abf9e6Sopenharmony_ci { .value = ABS_MT_TRACKING_ID, .minimum = -1, .maximum = 500 }, 1759c0abf9e6Sopenharmony_ci }; 1760c0abf9e6Sopenharmony_ci int pipefd[2]; 1761c0abf9e6Sopenharmony_ci struct input_event events[] = { 1762c0abf9e6Sopenharmony_ci { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = -1 }, 1763c0abf9e6Sopenharmony_ci { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, 1764c0abf9e6Sopenharmony_ci }; 1765c0abf9e6Sopenharmony_ci 1766c0abf9e6Sopenharmony_ci rc = pipe2(pipefd, O_NONBLOCK); 1767c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, 0); 1768c0abf9e6Sopenharmony_ci 1769c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1770c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1771c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1772c0abf9e6Sopenharmony_ci -1); 1773c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 1); 1774c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 1); 1775c0abf9e6Sopenharmony_ci uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0); 1776c0abf9e6Sopenharmony_ci 1777c0abf9e6Sopenharmony_ci while (libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev) != -EAGAIN) 1778c0abf9e6Sopenharmony_ci ; 1779c0abf9e6Sopenharmony_ci 1780c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_ignore_error, NULL); 1781c0abf9e6Sopenharmony_ci 1782c0abf9e6Sopenharmony_ci /* two -1 tracking ids, need to use the pipe here, the kernel will 1783c0abf9e6Sopenharmony_ci filter it otherwise */ 1784c0abf9e6Sopenharmony_ci libevdev_change_fd(dev, pipefd[0]); 1785c0abf9e6Sopenharmony_ci 1786c0abf9e6Sopenharmony_ci rc = write(pipefd[1], events, sizeof(events)); 1787c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, sizeof(events)); 1788c0abf9e6Sopenharmony_ci rc = write(pipefd[1], events, sizeof(events)); 1789c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, sizeof(events)); 1790c0abf9e6Sopenharmony_ci 1791c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1792c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 1793c0abf9e6Sopenharmony_ci assert_event(&ev, EV_ABS, ABS_MT_TRACKING_ID, -1); 1794c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1795c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 1796c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 1797c0abf9e6Sopenharmony_ci 1798c0abf9e6Sopenharmony_ci /* expect second tracking ID discarded */ 1799c0abf9e6Sopenharmony_ci 1800c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1801c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS); 1802c0abf9e6Sopenharmony_ci assert_event(&ev, EV_SYN, SYN_REPORT, 0); 1803c0abf9e6Sopenharmony_ci 1804c0abf9e6Sopenharmony_ci rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); 1805c0abf9e6Sopenharmony_ci ck_assert_int_eq(rc, -EAGAIN); 1806c0abf9e6Sopenharmony_ci 1807c0abf9e6Sopenharmony_ci libevdev_set_log_function(test_logfunc_abort_on_error, NULL); 1808c0abf9e6Sopenharmony_ci 1809c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1810c0abf9e6Sopenharmony_ci libevdev_free(dev); 1811c0abf9e6Sopenharmony_ci} 1812c0abf9e6Sopenharmony_ciEND_TEST 1813c0abf9e6Sopenharmony_ci 1814c0abf9e6Sopenharmony_ciSTART_TEST(test_ev_rep_values) 1815c0abf9e6Sopenharmony_ci{ 1816c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1817c0abf9e6Sopenharmony_ci struct libevdev *dev; 1818c0abf9e6Sopenharmony_ci int delay = 500, period = 200; 1819c0abf9e6Sopenharmony_ci test_create_device(&uidev, &dev, 1820c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1821c0abf9e6Sopenharmony_ci EV_REL, REL_X, 1822c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 1823c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1824c0abf9e6Sopenharmony_ci -1); 1825c0abf9e6Sopenharmony_ci 1826c0abf9e6Sopenharmony_ci libevdev_enable_event_code(dev, EV_REP, REP_DELAY, &delay); 1827c0abf9e6Sopenharmony_ci libevdev_enable_event_code(dev, EV_REP, REP_PERIOD, &period); 1828c0abf9e6Sopenharmony_ci 1829c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_type(dev, EV_REP), 1); 1830c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_code(dev, EV_REP, REP_DELAY), 1); 1831c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_has_event_code(dev, EV_REP, REP_PERIOD), 1); 1832c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REP, REP_DELAY), 500); 1833c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REP, REP_PERIOD), 200); 1834c0abf9e6Sopenharmony_ci 1835c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1836c0abf9e6Sopenharmony_ci libevdev_free(dev); 1837c0abf9e6Sopenharmony_ci} 1838c0abf9e6Sopenharmony_ciEND_TEST 1839c0abf9e6Sopenharmony_ci 1840c0abf9e6Sopenharmony_ciSTART_TEST(test_event_value_setters) 1841c0abf9e6Sopenharmony_ci{ 1842c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1843c0abf9e6Sopenharmony_ci struct libevdev *dev; 1844c0abf9e6Sopenharmony_ci struct input_absinfo abs[2] = { 1845c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1846c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1847c0abf9e6Sopenharmony_ci }; 1848c0abf9e6Sopenharmony_ci 1849c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1850c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1851c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1852c0abf9e6Sopenharmony_ci EV_REL, REL_X, 1853c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 1854c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1855c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 1856c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 1857c0abf9e6Sopenharmony_ci EV_LED, LED_NUML, 1858c0abf9e6Sopenharmony_ci EV_LED, LED_CAPSL, 1859c0abf9e6Sopenharmony_ci EV_SW, SW_HEADPHONE_INSERT, 1860c0abf9e6Sopenharmony_ci EV_SW, SW_TABLET_MODE, 1861c0abf9e6Sopenharmony_ci -1); 1862c0abf9e6Sopenharmony_ci 1863c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 0); 1864c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 0); 1865c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 0); 1866c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_X), 0); 1867c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_Y), 0); 1868c0abf9e6Sopenharmony_ci 1869c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_KEY, BTN_LEFT, 1), 0); 1870c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_KEY, BTN_RIGHT, 1), 0); 1871c0abf9e6Sopenharmony_ci 1872c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 1); 1873c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_RIGHT), 1); 1874c0abf9e6Sopenharmony_ci 1875c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_X, 10), 0); 1876c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_Y, 20), 0); 1877c0abf9e6Sopenharmony_ci 1878c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 10); 1879c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 20); 1880c0abf9e6Sopenharmony_ci 1881c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_LED, LED_NUML, 1), 0); 1882c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_LED, LED_CAPSL, 1), 0); 1883c0abf9e6Sopenharmony_ci 1884c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_LED, LED_NUML), 1); 1885c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_LED, LED_CAPSL), 1); 1886c0abf9e6Sopenharmony_ci 1887c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_SW, SW_HEADPHONE_INSERT, 1), 0); 1888c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_SW, SW_TABLET_MODE, 1), 0); 1889c0abf9e6Sopenharmony_ci 1890c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_SW, SW_HEADPHONE_INSERT), 1); 1891c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_SW, SW_TABLET_MODE), 1); 1892c0abf9e6Sopenharmony_ci 1893c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1894c0abf9e6Sopenharmony_ci libevdev_free(dev); 1895c0abf9e6Sopenharmony_ci 1896c0abf9e6Sopenharmony_ci} 1897c0abf9e6Sopenharmony_ciEND_TEST 1898c0abf9e6Sopenharmony_ci 1899c0abf9e6Sopenharmony_ciSTART_TEST(test_event_value_setters_invalid) 1900c0abf9e6Sopenharmony_ci{ 1901c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1902c0abf9e6Sopenharmony_ci struct libevdev *dev; 1903c0abf9e6Sopenharmony_ci struct input_absinfo abs[2] = { 1904c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1905c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1906c0abf9e6Sopenharmony_ci }; 1907c0abf9e6Sopenharmony_ci 1908c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1909c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1910c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1911c0abf9e6Sopenharmony_ci EV_REL, REL_X, 1912c0abf9e6Sopenharmony_ci EV_REL, REL_Y, 1913c0abf9e6Sopenharmony_ci EV_KEY, BTN_LEFT, 1914c0abf9e6Sopenharmony_ci EV_KEY, BTN_MIDDLE, 1915c0abf9e6Sopenharmony_ci EV_KEY, BTN_RIGHT, 1916c0abf9e6Sopenharmony_ci -1); 1917c0abf9e6Sopenharmony_ci 1918c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_REL, REL_X, 1), -1); 1919c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_SW, SW_DOCK, 1), -1); 1920c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_Z, 1), -1); 1921c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_MAX + 1, 0, 1), -1); 1922c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_SYN, SYN_REPORT, 0), -1); 1923c0abf9e6Sopenharmony_ci 1924c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1925c0abf9e6Sopenharmony_ci libevdev_free(dev); 1926c0abf9e6Sopenharmony_ci 1927c0abf9e6Sopenharmony_ci} 1928c0abf9e6Sopenharmony_ciEND_TEST 1929c0abf9e6Sopenharmony_ci 1930c0abf9e6Sopenharmony_ciSTART_TEST(test_event_mt_value_setters) 1931c0abf9e6Sopenharmony_ci{ 1932c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1933c0abf9e6Sopenharmony_ci struct libevdev *dev; 1934c0abf9e6Sopenharmony_ci struct input_absinfo abs[5] = { 1935c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1936c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1937c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1938c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1939c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 2 }, 1940c0abf9e6Sopenharmony_ci }; 1941c0abf9e6Sopenharmony_ci 1942c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1943c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1944c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1945c0abf9e6Sopenharmony_ci -1); 1946c0abf9e6Sopenharmony_ci 1947c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_POSITION_X, 1), 0); 1948c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_POSITION_Y, 2), 0); 1949c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 0, ABS_MT_POSITION_X, 3), 0); 1950c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 0, ABS_MT_POSITION_Y, 4), 0); 1951c0abf9e6Sopenharmony_ci 1952c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 1); 1953c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_Y), 2); 1954c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 3); 1955c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_Y), 4); 1956c0abf9e6Sopenharmony_ci 1957c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_SLOT, 1), 0); 1958c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_SLOT), 1); 1959c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 1); 1960c0abf9e6Sopenharmony_ci 1961c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1962c0abf9e6Sopenharmony_ci libevdev_free(dev); 1963c0abf9e6Sopenharmony_ci} 1964c0abf9e6Sopenharmony_ciEND_TEST 1965c0abf9e6Sopenharmony_ci 1966c0abf9e6Sopenharmony_ciSTART_TEST(test_event_mt_value_setters_invalid) 1967c0abf9e6Sopenharmony_ci{ 1968c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 1969c0abf9e6Sopenharmony_ci struct libevdev *dev; 1970c0abf9e6Sopenharmony_ci struct input_absinfo abs[5] = { 1971c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 1972c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 1973c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 1974c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 1975c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 2 }, 1976c0abf9e6Sopenharmony_ci }; 1977c0abf9e6Sopenharmony_ci 1978c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 1979c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 1980c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 1981c0abf9e6Sopenharmony_ci -1); 1982c0abf9e6Sopenharmony_ci 1983c0abf9e6Sopenharmony_ci /* invalid axis */ 1984c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_Z, 1), -1); 1985c0abf9e6Sopenharmony_ci /* valid, but non-mt axis */ 1986c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_X, 1), -1); 1987c0abf9e6Sopenharmony_ci /* invalid mt axis */ 1988c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_PRESSURE, 1), -1); 1989c0abf9e6Sopenharmony_ci /* invalid slot no */ 1990c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 4, ABS_X, 1), -1); 1991c0abf9e6Sopenharmony_ci 1992c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 1993c0abf9e6Sopenharmony_ci libevdev_free(dev); 1994c0abf9e6Sopenharmony_ci} 1995c0abf9e6Sopenharmony_ciEND_TEST 1996c0abf9e6Sopenharmony_ci 1997c0abf9e6Sopenharmony_ciSTART_TEST(test_event_mt_value_setters_current_slot) 1998c0abf9e6Sopenharmony_ci{ 1999c0abf9e6Sopenharmony_ci struct uinput_device* uidev; 2000c0abf9e6Sopenharmony_ci struct libevdev *dev; 2001c0abf9e6Sopenharmony_ci struct input_absinfo abs[5] = { 2002c0abf9e6Sopenharmony_ci { .value = ABS_X, .maximum = 1000 }, 2003c0abf9e6Sopenharmony_ci { .value = ABS_Y, .maximum = 1000 }, 2004c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_X, .maximum = 1000 }, 2005c0abf9e6Sopenharmony_ci { .value = ABS_MT_POSITION_Y, .maximum = 1000 }, 2006c0abf9e6Sopenharmony_ci { .value = ABS_MT_SLOT, .maximum = 2 }, 2007c0abf9e6Sopenharmony_ci }; 2008c0abf9e6Sopenharmony_ci 2009c0abf9e6Sopenharmony_ci test_create_abs_device(&uidev, &dev, 2010c0abf9e6Sopenharmony_ci ARRAY_LENGTH(abs), abs, 2011c0abf9e6Sopenharmony_ci EV_SYN, SYN_REPORT, 2012c0abf9e6Sopenharmony_ci -1); 2013c0abf9e6Sopenharmony_ci 2014c0abf9e6Sopenharmony_ci /* set_event_value/get_event_value works on the current slot */ 2015c0abf9e6Sopenharmony_ci 2016c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 0); 2017c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_POSITION_X, 1), 0); 2018c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 1); 2019c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 1); 2020c0abf9e6Sopenharmony_ci 2021c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_SLOT, 1), 0); 2022c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 1); 2023c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_POSITION_X, 2), 0); 2024c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 2); 2025c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 2); 2026c0abf9e6Sopenharmony_ci 2027c0abf9e6Sopenharmony_ci /* set slot 0, but current is still slot 1 */ 2028c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_slot_value(dev, 0, ABS_MT_POSITION_X, 3), 0); 2029c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 2); 2030c0abf9e6Sopenharmony_ci 2031c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_SLOT, 0), 0); 2032c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_current_slot(dev), 0); 2033c0abf9e6Sopenharmony_ci ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 3); 2034c0abf9e6Sopenharmony_ci 2035c0abf9e6Sopenharmony_ci uinput_device_free(uidev); 2036c0abf9e6Sopenharmony_ci libevdev_free(dev); 2037c0abf9e6Sopenharmony_ci} 2038c0abf9e6Sopenharmony_ciEND_TEST 2039c0abf9e6Sopenharmony_ci 2040c0abf9e6Sopenharmony_ciTEST_SUITE_ROOT_PRIVILEGES(libevdev_events) 2041c0abf9e6Sopenharmony_ci{ 2042c0abf9e6Sopenharmony_ci Suite *s = suite_create("libevdev event tests"); 2043c0abf9e6Sopenharmony_ci 2044c0abf9e6Sopenharmony_ci add_test(s, test_next_event); 2045c0abf9e6Sopenharmony_ci add_test(s, test_next_event_invalid_fd); 2046c0abf9e6Sopenharmony_ci add_test(s, test_next_event_blocking); 2047c0abf9e6Sopenharmony_ci add_test(s, test_syn_dropped_event); 2048c0abf9e6Sopenharmony_ci add_test(s, test_event_type_filtered); 2049c0abf9e6Sopenharmony_ci add_test(s, test_event_code_filtered); 2050c0abf9e6Sopenharmony_ci add_test(s, test_has_event_pending); 2051c0abf9e6Sopenharmony_ci add_test(s, test_has_event_pending_invalid_fd); 2052c0abf9e6Sopenharmony_ci 2053c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_button); 2054c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_abs); 2055c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_mt); 2056c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_mt_reset_slot); 2057c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_led); 2058c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_sw); 2059c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_fake_mt); 2060c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_late_sync); 2061c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_tracking_ids); 2062c0abf9e6Sopenharmony_ci add_test(s, test_syn_delta_tracking_ids_btntool); 2063c0abf9e6Sopenharmony_ci 2064c0abf9e6Sopenharmony_ci add_test(s, test_skipped_sync); 2065c0abf9e6Sopenharmony_ci add_test(s, test_incomplete_sync); 2066c0abf9e6Sopenharmony_ci add_test(s, test_empty_sync); 2067c0abf9e6Sopenharmony_ci 2068c0abf9e6Sopenharmony_ci add_test(s, test_event_values); 2069c0abf9e6Sopenharmony_ci add_test(s, test_event_values_invalid); 2070c0abf9e6Sopenharmony_ci add_test(s, test_mt_event_values); 2071c0abf9e6Sopenharmony_ci add_test(s, test_mt_event_values_invalid); 2072c0abf9e6Sopenharmony_ci add_test(s, test_mt_slot_ranges_invalid); 2073c0abf9e6Sopenharmony_ci add_test(s, test_mt_tracking_id_discard); 2074c0abf9e6Sopenharmony_ci add_test(s, test_mt_tracking_id_discard_neg_1); 2075c0abf9e6Sopenharmony_ci add_test(s, test_ev_rep_values); 2076c0abf9e6Sopenharmony_ci 2077c0abf9e6Sopenharmony_ci add_test(s, test_event_value_setters); 2078c0abf9e6Sopenharmony_ci add_test(s, test_event_value_setters_invalid); 2079c0abf9e6Sopenharmony_ci add_test(s, test_event_mt_value_setters); 2080c0abf9e6Sopenharmony_ci add_test(s, test_event_mt_value_setters_invalid); 2081c0abf9e6Sopenharmony_ci add_test(s, test_event_mt_value_setters_current_slot); 2082c0abf9e6Sopenharmony_ci 2083c0abf9e6Sopenharmony_ci return s; 2084c0abf9e6Sopenharmony_ci} 2085