2014-03-26 15:08:02 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Red Hat, Inc.
|
|
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2014-03-26 15:08:02 +10:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2014-03-26 15:08:02 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <libinput.h>
|
2014-05-16 09:06:41 +10:00
|
|
|
#include <libinput-util.h>
|
2014-03-26 15:08:02 +10:00
|
|
|
#include <unistd.h>
|
2017-12-01 09:31:07 +10:00
|
|
|
#include <stdarg.h>
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
#include "litest.h"
|
2014-05-21 21:52:57 -04:00
|
|
|
#include "libinput-util.h"
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
static int open_restricted(const char *path, int flags, void *data)
|
|
|
|
|
{
|
|
|
|
|
int fd = open(path, flags);
|
|
|
|
|
return fd < 0 ? -errno : fd;
|
|
|
|
|
}
|
|
|
|
|
static void close_restricted(int fd, void *data)
|
|
|
|
|
{
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 13:07:38 +10:00
|
|
|
static const struct libinput_interface simple_interface = {
|
2014-03-26 15:08:02 +10:00
|
|
|
.open_restricted = open_restricted,
|
|
|
|
|
.close_restricted = close_restricted,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct libevdev_uinput *
|
|
|
|
|
create_simple_test_device(const char *name, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
struct libevdev *evdev;
|
|
|
|
|
unsigned int type, code;
|
|
|
|
|
int rc;
|
|
|
|
|
struct input_absinfo abs = {
|
|
|
|
|
.value = -1,
|
|
|
|
|
.minimum = 0,
|
|
|
|
|
.maximum = 100,
|
|
|
|
|
.fuzz = 0,
|
|
|
|
|
.flat = 0,
|
|
|
|
|
.resolution = 100,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
evdev = libevdev_new();
|
2015-05-04 11:40:39 +10:00
|
|
|
litest_assert_notnull(evdev);
|
2014-03-26 15:08:02 +10:00
|
|
|
libevdev_set_name(evdev, name);
|
|
|
|
|
|
|
|
|
|
va_start(args, name);
|
|
|
|
|
|
2014-06-02 16:18:10 +10:00
|
|
|
while ((type = va_arg(args, unsigned int)) != (unsigned int)-1 &&
|
|
|
|
|
(code = va_arg(args, unsigned int)) != (unsigned int)-1) {
|
2014-03-26 15:08:02 +10:00
|
|
|
const struct input_absinfo *a = NULL;
|
|
|
|
|
if (type == EV_ABS)
|
|
|
|
|
a = &abs;
|
|
|
|
|
libevdev_enable_event_code(evdev, type, code, a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
rc = libevdev_uinput_create_from_device(evdev,
|
|
|
|
|
LIBEVDEV_UINPUT_OPEN_MANAGED,
|
|
|
|
|
&uinput);
|
2024-03-14 12:07:29 +10:00
|
|
|
litest_assert_neg_errno_success(rc);
|
2014-03-26 15:08:02 +10:00
|
|
|
libevdev_free(evdev);
|
|
|
|
|
|
|
|
|
|
return uinput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
START_TEST(event_conversion_device_notify)
|
|
|
|
|
{
|
|
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int device_added = 0, device_removed = 0;
|
|
|
|
|
|
2025-07-01 09:23:01 +10:00
|
|
|
/* clang-format off */
|
2014-07-04 07:55:51 +10:00
|
|
|
uinput = create_simple_test_device("litest test device",
|
2014-03-26 15:08:02 +10:00
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_MIDDLE,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
-1, -1);
|
2025-07-01 09:23:01 +10:00
|
|
|
/* clang-format on */
|
2025-04-07 13:15:28 +10:00
|
|
|
_litest_context_destroy_ struct libinput *li = litest_create_context();
|
2017-06-01 15:00:27 +10:00
|
|
|
litest_restore_log_handler(li); /* use the default litest handler */
|
2014-03-26 15:08:02 +10:00
|
|
|
libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_DEVICE_ADDED ||
|
|
|
|
|
type == LIBINPUT_EVENT_DEVICE_REMOVED) {
|
|
|
|
|
struct libinput_event_device_notify *dn;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
dn = libinput_event_get_device_notify_event(event);
|
|
|
|
|
base = libinput_event_device_notify_get_base_event(dn);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_DEVICE_ADDED)
|
|
|
|
|
device_added++;
|
|
|
|
|
else if (type == LIBINPUT_EVENT_DEVICE_REMOVED)
|
|
|
|
|
device_removed++;
|
|
|
|
|
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_pointer_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_gesture_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_tool_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_restore_log_handler(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput);
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(device_added, 0);
|
|
|
|
|
litest_assert_int_gt(device_removed, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(event_conversion_pointer)
|
|
|
|
|
{
|
2015-02-03 13:42:44 +10:00
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
2014-03-26 15:08:02 +10:00
|
|
|
struct libinput_event *event;
|
|
|
|
|
int motion = 0, button = 0;
|
|
|
|
|
|
2014-05-26 23:18:28 +02:00
|
|
|
/* Queue at least two relative motion events as the first one may
|
|
|
|
|
* be absorbed by the pointer acceleration filter. */
|
2015-02-03 13:42:44 +10:00
|
|
|
litest_event(dev, EV_REL, REL_X, -1);
|
|
|
|
|
litest_event(dev, EV_REL, REL_Y, -1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
litest_event(dev, EV_REL, REL_X, -1);
|
|
|
|
|
litest_event(dev, EV_REL, REL_Y, -1);
|
|
|
|
|
litest_event(dev, EV_KEY, BTN_LEFT, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_POINTER_MOTION ||
|
|
|
|
|
type == LIBINPUT_EVENT_POINTER_BUTTON) {
|
|
|
|
|
struct libinput_event_pointer *p;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
p = libinput_event_get_pointer_event(event);
|
|
|
|
|
base = libinput_event_pointer_get_base_event(p);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_POINTER_MOTION)
|
|
|
|
|
motion++;
|
|
|
|
|
else if (type == LIBINPUT_EVENT_POINTER_BUTTON)
|
|
|
|
|
button++;
|
|
|
|
|
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_gesture_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_tool_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_restore_log_handler(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(motion, 0);
|
|
|
|
|
litest_assert_int_gt(button, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(event_conversion_pointer_abs)
|
|
|
|
|
{
|
2015-02-03 13:42:44 +10:00
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
2014-03-26 15:08:02 +10:00
|
|
|
struct libinput_event *event;
|
|
|
|
|
int motion = 0, button = 0;
|
|
|
|
|
|
2015-02-03 13:42:44 +10:00
|
|
|
litest_event(dev, EV_ABS, ABS_X, 10);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_Y, 50);
|
|
|
|
|
litest_event(dev, EV_KEY, BTN_LEFT, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_X, 30);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_Y, 30);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE ||
|
|
|
|
|
type == LIBINPUT_EVENT_POINTER_BUTTON) {
|
|
|
|
|
struct libinput_event_pointer *p;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
p = libinput_event_get_pointer_event(event);
|
|
|
|
|
base = libinput_event_pointer_get_base_event(p);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE)
|
|
|
|
|
motion++;
|
|
|
|
|
else if (type == LIBINPUT_EVENT_POINTER_BUTTON)
|
|
|
|
|
button++;
|
|
|
|
|
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_gesture_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_tool_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_restore_log_handler(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(motion, 0);
|
|
|
|
|
litest_assert_int_gt(button, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(event_conversion_key)
|
|
|
|
|
{
|
2015-02-03 13:42:44 +10:00
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
2014-03-26 15:08:02 +10:00
|
|
|
struct libinput_event *event;
|
|
|
|
|
int key = 0;
|
|
|
|
|
|
2015-02-03 13:42:44 +10:00
|
|
|
litest_event(dev, EV_KEY, KEY_A, 1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
litest_event(dev, EV_KEY, KEY_A, 0);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_KEYBOARD_KEY) {
|
|
|
|
|
struct libinput_event_keyboard *k;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
k = libinput_event_get_keyboard_event(event);
|
|
|
|
|
base = libinput_event_keyboard_get_base_event(k);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
key++;
|
|
|
|
|
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_pointer_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_gesture_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_tool_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_restore_log_handler(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(key, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(event_conversion_touch)
|
|
|
|
|
{
|
2015-02-03 13:42:44 +10:00
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
2014-03-26 15:08:02 +10:00
|
|
|
struct libinput_event *event;
|
|
|
|
|
int touch = 0;
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
2015-02-03 13:42:44 +10:00
|
|
|
litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
|
|
|
|
|
litest_event(dev, EV_KEY, BTN_TOUCH, 1);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_X, 10);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_Y, 10);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_MT_SLOT, 0);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_MT_TRACKING_ID, 1);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_MT_POSITION_X, 10);
|
|
|
|
|
litest_event(dev, EV_ABS, ABS_MT_POSITION_Y, 10);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type >= LIBINPUT_EVENT_TOUCH_DOWN &&
|
|
|
|
|
type <= LIBINPUT_EVENT_TOUCH_FRAME) {
|
|
|
|
|
struct libinput_event_touch *t;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
t = libinput_event_get_touch_event(event);
|
|
|
|
|
base = libinput_event_touch_get_base_event(t);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2014-03-26 15:08:02 +10:00
|
|
|
|
|
|
|
|
touch++;
|
|
|
|
|
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_pointer_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_gesture_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_tool_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2015-03-13 09:32:37 +10:00
|
|
|
litest_restore_log_handler(li);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(touch, 0);
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2015-07-07 11:52:05 +10:00
|
|
|
START_TEST(event_conversion_gesture)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int gestures = 0;
|
|
|
|
|
int i;
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2015-07-07 11:52:05 +10:00
|
|
|
|
|
|
|
|
litest_touch_down(dev, 0, 70, 30);
|
|
|
|
|
litest_touch_down(dev, 1, 30, 70);
|
2025-04-01 09:23:10 +10:00
|
|
|
litest_timeout_gesture_hold(li);
|
2021-09-24 19:06:53 +02:00
|
|
|
|
2015-07-07 11:52:05 +10:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
|
litest_push_event_frame(dev);
|
|
|
|
|
litest_touch_move(dev, 0, 70 - i * 5, 30 + i * 5);
|
|
|
|
|
litest_touch_move(dev, 1, 30 + i * 5, 70 - i * 5);
|
|
|
|
|
litest_pop_event_frame(dev);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2015-07-07 11:52:05 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type >= LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN &&
|
2021-09-24 19:06:53 +02:00
|
|
|
type <= LIBINPUT_EVENT_GESTURE_HOLD_END) {
|
2015-07-07 11:52:05 +10:00
|
|
|
struct libinput_event_gesture *g;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
g = libinput_event_get_gesture_event(event);
|
|
|
|
|
base = libinput_event_gesture_get_base_event(g);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2015-07-07 11:52:05 +10:00
|
|
|
|
|
|
|
|
gestures++;
|
|
|
|
|
|
|
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_pointer_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2015-07-07 11:52:05 +10:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(gestures, 0);
|
2015-07-07 11:52:05 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2015-05-27 11:28:52 +10:00
|
|
|
START_TEST(event_conversion_tablet)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int events = 0;
|
|
|
|
|
struct axis_replacement axes[] = {
|
|
|
|
|
{ ABS_DISTANCE, 10 },
|
2025-07-01 09:37:25 +10:00
|
|
|
{ -1, -1 },
|
2015-05-27 11:28:52 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
litest_tablet_proximity_in(dev, 50, 50, axes);
|
|
|
|
|
litest_tablet_motion(dev, 60, 50, axes);
|
2017-11-20 10:49:08 +10:00
|
|
|
litest_button_click(dev, BTN_STYLUS, true);
|
|
|
|
|
litest_button_click(dev, BTN_STYLUS, false);
|
2015-05-27 11:28:52 +10:00
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2015-05-27 11:28:52 +10:00
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
2015-11-16 16:27:46 +10:00
|
|
|
if (type >= LIBINPUT_EVENT_TABLET_TOOL_AXIS &&
|
|
|
|
|
type <= LIBINPUT_EVENT_TABLET_TOOL_BUTTON) {
|
2015-11-16 16:28:55 +10:00
|
|
|
struct libinput_event_tablet_tool *t;
|
2015-05-27 11:28:52 +10:00
|
|
|
struct libinput_event *base;
|
2015-11-16 16:28:55 +10:00
|
|
|
t = libinput_event_get_tablet_tool_event(event);
|
|
|
|
|
base = libinput_event_tablet_tool_get_base_event(t);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2015-05-27 11:28:52 +10:00
|
|
|
|
|
|
|
|
events++;
|
|
|
|
|
|
|
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_pointer_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2016-02-05 10:57:37 +10:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(events, 0);
|
2016-02-05 10:57:37 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(event_conversion_tablet_pad)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int events = 0;
|
|
|
|
|
|
2017-11-20 10:49:08 +10:00
|
|
|
litest_button_click(dev, BTN_0, true);
|
2016-02-05 10:57:37 +10:00
|
|
|
litest_pad_ring_start(dev, 10);
|
|
|
|
|
litest_pad_ring_end(dev);
|
|
|
|
|
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2016-02-05 10:57:37 +10:00
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type >= LIBINPUT_EVENT_TABLET_PAD_BUTTON &&
|
|
|
|
|
type <= LIBINPUT_EVENT_TABLET_PAD_STRIP) {
|
|
|
|
|
struct libinput_event_tablet_pad *p;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
|
|
|
|
|
p = libinput_event_get_tablet_pad_event(event);
|
|
|
|
|
base = libinput_event_tablet_pad_get_base_event(p);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2016-02-05 10:57:37 +10:00
|
|
|
|
|
|
|
|
events++;
|
|
|
|
|
|
|
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_pointer_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_tool_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_switch_event(event) == NULL);
|
2015-05-27 11:28:52 +10:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(events, 0);
|
2015-05-27 11:28:52 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-01-20 16:54:16 +11:00
|
|
|
START_TEST(event_conversion_switch)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int sw = 0;
|
|
|
|
|
|
2017-04-21 16:33:02 +10:00
|
|
|
litest_switch_action(dev,
|
|
|
|
|
LIBINPUT_SWITCH_LID,
|
|
|
|
|
LIBINPUT_SWITCH_STATE_ON);
|
|
|
|
|
litest_switch_action(dev,
|
|
|
|
|
LIBINPUT_SWITCH_LID,
|
|
|
|
|
LIBINPUT_SWITCH_STATE_OFF);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-01-20 16:54:16 +11:00
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_SWITCH_TOGGLE) {
|
|
|
|
|
struct libinput_event_switch *s;
|
|
|
|
|
struct libinput_event *base;
|
|
|
|
|
s = libinput_event_get_switch_event(event);
|
|
|
|
|
base = libinput_event_switch_get_base_event(s);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(event == base);
|
2017-01-20 16:54:16 +11:00
|
|
|
|
|
|
|
|
sw++;
|
|
|
|
|
|
|
|
|
|
litest_disable_log_handler(li);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(libinput_event_get_device_notify_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_keyboard_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_pointer_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_touch_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_gesture_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_tool_event(event) == NULL);
|
|
|
|
|
litest_assert(libinput_event_get_tablet_pad_event(event) == NULL);
|
2017-01-20 16:54:16 +11:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(sw, 0);
|
2017-01-20 16:54:16 +11:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-06-25 00:06:59 +02:00
|
|
|
START_TEST(context_ref_counting)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
|
|
|
|
|
/* These tests rely on valgrind to detect memory leak and use after
|
|
|
|
|
* free errors. */
|
|
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, NULL);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_ptr_eq(libinput_unref(li), NULL);
|
2014-06-25 00:06:59 +02:00
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, NULL);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(li);
|
|
|
|
|
litest_assert_ptr_eq(libinput_ref(li), li);
|
|
|
|
|
litest_assert_ptr_eq(libinput_unref(li), li);
|
|
|
|
|
litest_assert_ptr_eq(libinput_unref(li), NULL);
|
2014-06-25 00:06:59 +02:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-05-16 09:06:41 +10:00
|
|
|
START_TEST(config_status_string)
|
|
|
|
|
{
|
|
|
|
|
const char *strs[3];
|
|
|
|
|
const char *invalid;
|
|
|
|
|
size_t i, j;
|
|
|
|
|
|
|
|
|
|
strs[0] = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_SUCCESS);
|
|
|
|
|
strs[1] = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
|
|
|
|
|
strs[2] = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_INVALID);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(strs) - 1; i++)
|
|
|
|
|
for (j = i + 1; j < ARRAY_LENGTH(strs); j++)
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_str_ne(strs[i], strs[j]);
|
2014-05-16 09:06:41 +10:00
|
|
|
|
|
|
|
|
invalid = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_INVALID + 1);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(invalid == NULL);
|
2014-05-16 09:06:41 +10:00
|
|
|
invalid = libinput_config_status_to_str(LIBINPUT_CONFIG_STATUS_SUCCESS - 1);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(invalid == NULL);
|
2014-05-16 09:06:41 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2015-12-16 10:48:39 +10:00
|
|
|
static int open_restricted_leak(const char *path, int flags, void *data)
|
|
|
|
|
{
|
|
|
|
|
return *(int*)data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void close_restricted_leak(int fd, void *data)
|
|
|
|
|
{
|
|
|
|
|
/* noop */
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-18 16:24:11 +01:00
|
|
|
static const struct libinput_interface leak_interface = {
|
2015-12-16 10:48:39 +10:00
|
|
|
.open_restricted = open_restricted_leak,
|
|
|
|
|
.close_restricted = close_restricted_leak,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
START_TEST(fd_no_event_leak)
|
|
|
|
|
{
|
|
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
int fd = -1;
|
|
|
|
|
const char *path;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
2025-07-01 09:23:01 +10:00
|
|
|
/* clang-format off */
|
2015-12-16 10:48:39 +10:00
|
|
|
uinput = create_simple_test_device("litest test device",
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_MIDDLE,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
-1, -1);
|
2025-07-01 09:23:01 +10:00
|
|
|
/* clang-format on */
|
2015-12-16 10:48:39 +10:00
|
|
|
path = libevdev_uinput_get_devnode(uinput);
|
|
|
|
|
|
|
|
|
|
fd = open(path, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_gt(fd, -1);
|
2015-12-16 10:48:39 +10:00
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&leak_interface, &fd);
|
2017-06-01 15:00:27 +10:00
|
|
|
litest_restore_log_handler(li); /* use the default litest handler */
|
2015-12-16 10:48:39 +10:00
|
|
|
|
|
|
|
|
/* Add the device, trigger an event, then remove it again.
|
|
|
|
|
* Without it, we get a SYN_DROPPED immediately and no events.
|
|
|
|
|
*/
|
|
|
|
|
device = libinput_path_add_device(li, path);
|
|
|
|
|
libevdev_uinput_write_event(uinput, EV_REL, REL_X, 1);
|
|
|
|
|
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
libinput_path_remove_device(device);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2015-12-16 10:48:39 +10:00
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
/* Device is removed, but fd is still open. Queue an event, add a
|
|
|
|
|
* new device with the same fd, the queued event must be discarded
|
|
|
|
|
* by libinput */
|
|
|
|
|
libevdev_uinput_write_event(uinput, EV_REL, REL_Y, 1);
|
|
|
|
|
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2015-12-16 10:48:39 +10:00
|
|
|
|
|
|
|
|
libinput_path_add_device(li, path);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2015-12-16 10:48:39 +10:00
|
|
|
event = libinput_get_event(li);
|
2024-09-18 14:44:38 +10:00
|
|
|
litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_ADDED);
|
2015-12-16 10:48:39 +10:00
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
libinput_unref(li);
|
|
|
|
|
libevdev_uinput_destroy(uinput);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-07-03 11:28:18 +10:00
|
|
|
static void timer_offset_warning(struct libinput *libinput,
|
|
|
|
|
enum libinput_log_priority priority,
|
|
|
|
|
const char *format,
|
|
|
|
|
va_list args)
|
|
|
|
|
{
|
2021-02-12 07:55:21 +10:00
|
|
|
struct litest_user_data *user_data = libinput_get_user_data(libinput);
|
|
|
|
|
int *warning_triggered = user_data->private;
|
2017-07-03 11:28:18 +10:00
|
|
|
|
|
|
|
|
if (priority == LIBINPUT_LOG_PRIORITY_ERROR &&
|
2020-01-31 12:23:01 +10:00
|
|
|
strstr(format, "scheduled expiry is in the past"))
|
2017-07-03 11:28:18 +10:00
|
|
|
(*warning_triggered)++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
START_TEST(timer_offset_bug_warning)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
int warning_triggered = 0;
|
2021-02-12 07:55:21 +10:00
|
|
|
struct litest_user_data *user_data = libinput_get_user_data(li);
|
2017-07-03 11:28:18 +10:00
|
|
|
|
|
|
|
|
litest_enable_tap(dev->libinput_device);
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
litest_touch_down(dev, 0, 50, 50);
|
|
|
|
|
litest_touch_up(dev, 0);
|
|
|
|
|
|
2025-04-01 09:23:10 +10:00
|
|
|
litest_timeout_tap(NULL);
|
2017-07-03 11:28:18 +10:00
|
|
|
|
2021-02-12 07:55:21 +10:00
|
|
|
user_data->private = &warning_triggered;
|
2017-07-03 11:28:18 +10:00
|
|
|
libinput_log_set_handler(li, timer_offset_warning);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-07-03 11:28:18 +10:00
|
|
|
|
|
|
|
|
/* triggered for touch down and touch up */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(warning_triggered, 2);
|
2017-07-03 11:28:18 +10:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2020-04-13 15:12:43 +10:00
|
|
|
static void timer_delay_warning(struct libinput *libinput,
|
|
|
|
|
enum libinput_log_priority priority,
|
|
|
|
|
const char *format,
|
|
|
|
|
va_list args)
|
|
|
|
|
{
|
2021-02-12 07:55:21 +10:00
|
|
|
struct litest_user_data *user_data = libinput_get_user_data(libinput);
|
|
|
|
|
int *warning_triggered = user_data->private;
|
2020-04-13 15:12:43 +10:00
|
|
|
|
|
|
|
|
if (priority == LIBINPUT_LOG_PRIORITY_ERROR &&
|
|
|
|
|
strstr(format, "event processing lagging behind by"))
|
|
|
|
|
(*warning_triggered)++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
START_TEST(timer_delay_bug_warning)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
int warning_triggered = 0;
|
2021-02-12 07:55:21 +10:00
|
|
|
struct litest_user_data *user_data = libinput_get_user_data(li);
|
2020-04-13 15:12:43 +10:00
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
2021-02-12 07:55:21 +10:00
|
|
|
user_data->private = &warning_triggered;
|
2021-02-11 15:31:12 +10:00
|
|
|
libinput_log_set_handler(li, timer_delay_warning);
|
|
|
|
|
|
2021-02-12 10:24:43 +10:00
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
|
litest_event(dev, EV_REL, REL_X, -1);
|
|
|
|
|
litest_event(dev, EV_SYN, SYN_REPORT, 0);
|
2021-12-07 11:18:07 +10:00
|
|
|
msleep(21);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2020-04-13 15:12:43 +10:00
|
|
|
}
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_ge(warning_triggered, 1);
|
2020-04-13 15:12:43 +10:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-09-19 15:51:09 +10:00
|
|
|
START_TEST(timer_flush)
|
|
|
|
|
{
|
2025-04-07 13:15:28 +10:00
|
|
|
_litest_context_destroy_ struct libinput *li = litest_create_context();
|
2017-09-19 15:51:09 +10:00
|
|
|
|
2025-04-07 15:31:46 +10:00
|
|
|
_destroy_(litest_device) *touchpad = litest_add_device(li, LITEST_SYNAPTICS_TOUCHPAD);
|
2017-09-19 15:51:09 +10:00
|
|
|
litest_enable_tap(touchpad->libinput_device);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2025-04-07 15:31:46 +10:00
|
|
|
_destroy_(litest_device) *keyboard = litest_add_device(li, LITEST_KEYBOARD);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-09-19 15:51:09 +10:00
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
/* make sure tapping works */
|
|
|
|
|
litest_touch_down(touchpad, 0, 50, 50);
|
|
|
|
|
litest_touch_up(touchpad, 0);
|
2025-04-01 09:23:10 +10:00
|
|
|
litest_timeout_tap(li);
|
2017-09-19 15:51:09 +10:00
|
|
|
|
|
|
|
|
litest_assert_button_event(li, BTN_LEFT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_PRESSED);
|
|
|
|
|
litest_assert_button_event(li, BTN_LEFT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
|
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
|
|
|
|
|
/* make sure dwt-tap is ignored */
|
|
|
|
|
litest_keyboard_key(keyboard, KEY_A, true);
|
|
|
|
|
litest_keyboard_key(keyboard, KEY_A, false);
|
2024-09-13 15:13:38 +10:00
|
|
|
litest_dispatch(li);
|
2017-09-19 15:51:09 +10:00
|
|
|
litest_touch_down(touchpad, 0, 50, 50);
|
|
|
|
|
litest_touch_up(touchpad, 0);
|
2025-04-01 09:23:10 +10:00
|
|
|
litest_timeout_tap(li);
|
2017-09-19 15:51:09 +10:00
|
|
|
litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
|
|
|
|
|
|
2020-08-27 19:52:34 +02:00
|
|
|
/* Ignore 'timer offset negative' warnings */
|
2017-09-19 15:51:09 +10:00
|
|
|
litest_disable_log_handler(li);
|
|
|
|
|
|
|
|
|
|
/* now mess with the timing
|
|
|
|
|
- send a key event
|
|
|
|
|
- expire dwt
|
|
|
|
|
- send a tap
|
2024-09-13 15:13:38 +10:00
|
|
|
and then call litest_dispatch(). libinput should notice that
|
2017-09-19 15:51:09 +10:00
|
|
|
the tap event came in after the timeout and thus acknowledge the
|
|
|
|
|
tap.
|
|
|
|
|
*/
|
|
|
|
|
litest_keyboard_key(keyboard, KEY_A, true);
|
|
|
|
|
litest_keyboard_key(keyboard, KEY_A, false);
|
2025-04-01 09:23:10 +10:00
|
|
|
litest_timeout_dwt_long(li);
|
2017-09-19 15:51:09 +10:00
|
|
|
litest_touch_down(touchpad, 0, 50, 50);
|
|
|
|
|
litest_touch_up(touchpad, 0);
|
2025-04-01 09:23:10 +10:00
|
|
|
litest_timeout_tap(li);
|
2017-09-19 15:51:09 +10:00
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
|
|
|
|
|
litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
|
|
|
|
|
litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED);
|
|
|
|
|
litest_assert_button_event(li, BTN_LEFT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_PRESSED);
|
|
|
|
|
litest_assert_button_event(li, BTN_LEFT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2020-02-12 18:04:41 +10:00
|
|
|
START_TEST(udev_absinfo_override)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libevdev *evdev = dev->evdev;
|
|
|
|
|
const struct input_absinfo *abs;
|
|
|
|
|
struct udev_device *ud;
|
|
|
|
|
struct udev_list_entry *entry;
|
|
|
|
|
bool found_x = false, found_y = false,
|
|
|
|
|
found_mt_x = false, found_mt_y = false;
|
|
|
|
|
|
|
|
|
|
ud = libinput_device_get_udev_device(dev->libinput_device);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_notnull(ud);
|
2020-02-12 18:04:41 +10:00
|
|
|
|
|
|
|
|
/* Custom checks for this special litest device only */
|
|
|
|
|
|
|
|
|
|
entry = udev_device_get_properties_list_entry(ud);
|
|
|
|
|
while (entry) {
|
|
|
|
|
const char *key, *value;
|
|
|
|
|
|
|
|
|
|
key = udev_list_entry_get_name(entry);
|
|
|
|
|
value = udev_list_entry_get_value(entry);
|
|
|
|
|
|
|
|
|
|
if (streq(key, "EVDEV_ABS_00")) {
|
|
|
|
|
found_x = true;
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(streq(value, "1:1000:100:10"));
|
2020-02-12 18:04:41 +10:00
|
|
|
}
|
|
|
|
|
if (streq(key, "EVDEV_ABS_01")) {
|
|
|
|
|
found_y = true;
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(streq(value, "2:2000:200:20"));
|
2020-02-12 18:04:41 +10:00
|
|
|
}
|
|
|
|
|
if (streq(key, "EVDEV_ABS_35")) {
|
|
|
|
|
found_mt_x = true;
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(streq(value, "3:3000:300:30"));
|
2020-02-12 18:04:41 +10:00
|
|
|
}
|
|
|
|
|
if (streq(key, "EVDEV_ABS_36")) {
|
|
|
|
|
found_mt_y = true;
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(streq(value, "4:4000:400:40"));
|
2020-02-12 18:04:41 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry = udev_list_entry_get_next(entry);
|
|
|
|
|
}
|
|
|
|
|
udev_device_unref(ud);
|
|
|
|
|
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert(found_x);
|
|
|
|
|
litest_assert(found_y);
|
|
|
|
|
litest_assert(found_mt_x);
|
|
|
|
|
litest_assert(found_mt_y);
|
2020-02-12 18:04:41 +10:00
|
|
|
|
|
|
|
|
abs = libevdev_get_abs_info(evdev, ABS_X);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->minimum, 1);
|
|
|
|
|
litest_assert_int_eq(abs->maximum, 1000);
|
|
|
|
|
litest_assert_int_eq(abs->resolution, 100);
|
2020-02-12 18:04:41 +10:00
|
|
|
/* if everything goes well, we override the fuzz to 0 */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->fuzz, 0);
|
2020-02-12 18:04:41 +10:00
|
|
|
|
|
|
|
|
abs = libevdev_get_abs_info(evdev, ABS_Y);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->minimum, 2);
|
|
|
|
|
litest_assert_int_eq(abs->maximum, 2000);
|
|
|
|
|
litest_assert_int_eq(abs->resolution, 200);
|
2020-02-12 18:04:41 +10:00
|
|
|
/* if everything goes well, we override the fuzz to 0 */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->fuzz, 0);
|
2020-02-12 18:04:41 +10:00
|
|
|
|
|
|
|
|
abs = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->minimum, 3);
|
|
|
|
|
litest_assert_int_eq(abs->maximum, 3000);
|
|
|
|
|
litest_assert_int_eq(abs->resolution, 300);
|
2020-02-12 18:04:41 +10:00
|
|
|
/* if everything goes well, we override the fuzz to 0 */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->fuzz, 0);
|
2020-02-12 18:04:41 +10:00
|
|
|
|
|
|
|
|
abs = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->minimum, 4);
|
|
|
|
|
litest_assert_int_eq(abs->maximum, 4000);
|
|
|
|
|
litest_assert_int_eq(abs->resolution, 400);
|
2020-02-12 18:04:41 +10:00
|
|
|
/* if everything goes well, we override the fuzz to 0 */
|
2024-09-16 16:20:26 +10:00
|
|
|
litest_assert_int_eq(abs->fuzz, 0);
|
2020-02-12 18:04:41 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2018-03-21 12:54:10 +10:00
|
|
|
TEST_COLLECTION(misc)
|
2015-05-01 11:41:12 +10:00
|
|
|
{
|
2025-07-01 11:30:59 +10:00
|
|
|
/* clang-format off */
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add_no_device(event_conversion_device_notify);
|
|
|
|
|
litest_add_for_device(event_conversion_pointer, LITEST_MOUSE);
|
|
|
|
|
litest_add_for_device(event_conversion_pointer_abs, LITEST_XEN_VIRTUAL_POINTER);
|
|
|
|
|
litest_add_for_device(event_conversion_key, LITEST_KEYBOARD);
|
2025-03-12 09:34:47 +10:00
|
|
|
litest_add_for_device(event_conversion_touch, LITEST_WACOM_ISDV4_E6_FINGER);
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add_for_device(event_conversion_gesture, LITEST_BCM5974);
|
2025-03-12 09:34:47 +10:00
|
|
|
litest_add_for_device(event_conversion_tablet, LITEST_WACOM_CINTIQ_12WX_PEN);
|
2021-02-05 14:51:02 +10:00
|
|
|
litest_add_for_device(event_conversion_tablet_pad, LITEST_WACOM_INTUOS5_PAD);
|
|
|
|
|
litest_add_for_device(event_conversion_switch, LITEST_LID_SWITCH);
|
|
|
|
|
|
|
|
|
|
litest_add_deviceless(context_ref_counting);
|
|
|
|
|
litest_add_deviceless(config_status_string);
|
|
|
|
|
|
|
|
|
|
litest_add_for_device(timer_offset_bug_warning, LITEST_SYNAPTICS_TOUCHPAD);
|
|
|
|
|
litest_add_for_device(timer_delay_bug_warning, LITEST_MOUSE);
|
|
|
|
|
litest_add_no_device(timer_flush);
|
|
|
|
|
|
|
|
|
|
litest_add_no_device(fd_no_event_leak);
|
|
|
|
|
|
|
|
|
|
litest_add_for_device(udev_absinfo_override, LITEST_ABSINFO_OVERRIDE);
|
2025-07-01 11:30:59 +10:00
|
|
|
/* clang-format on */
|
2014-03-26 15:08:02 +10:00
|
|
|
}
|