2013-12-10 13:30:52 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 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:
|
2013-12-10 13:30:52 +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.
|
2013-12-10 13:30:52 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <check.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <libinput.h>
|
2016-03-03 08:33:22 +10:00
|
|
|
#include <stdio.h>
|
2016-04-01 09:37:18 +10:00
|
|
|
#include <sys/stat.h>
|
2013-12-10 13:30:52 +10:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "litest.h"
|
|
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
struct counter {
|
|
|
|
|
int open_func_count;
|
|
|
|
|
int close_func_count;
|
|
|
|
|
};
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
static int
|
|
|
|
|
open_restricted_count(const char *path, int flags, void *data)
|
2013-12-10 13:30:52 +10:00
|
|
|
{
|
2017-06-09 12:25:50 +10:00
|
|
|
struct counter *c = data;
|
2013-12-10 13:30:52 +10:00
|
|
|
int fd;
|
2017-06-09 12:25:50 +10:00
|
|
|
|
|
|
|
|
c->open_func_count++;
|
|
|
|
|
|
2013-12-10 13:30:52 +10:00
|
|
|
fd = open(path, flags);
|
|
|
|
|
return fd < 0 ? -errno : fd;
|
|
|
|
|
}
|
2017-06-09 12:25:50 +10:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
close_restricted_count(int fd, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct counter *c = data;
|
|
|
|
|
|
|
|
|
|
c->close_func_count++;
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct libinput_interface counting_interface = {
|
|
|
|
|
.open_restricted = open_restricted_count,
|
|
|
|
|
.close_restricted = close_restricted_count,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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)
|
2013-12-10 13:30:52 +10:00
|
|
|
{
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 13:07:38 +10:00
|
|
|
static const struct libinput_interface simple_interface = {
|
2013-12-10 13:30:52 +10:00
|
|
|
.open_restricted = open_restricted,
|
|
|
|
|
.close_restricted = close_restricted,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
START_TEST(path_create_NULL)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
2017-06-09 12:25:50 +10:00
|
|
|
struct counter counter;
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
counter.open_func_count = 0;
|
|
|
|
|
counter.close_func_count = 0;
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
li = libinput_path_create_context(NULL, NULL);
|
2013-12-10 13:30:52 +10:00
|
|
|
ck_assert(li == NULL);
|
2017-06-09 12:25:50 +10:00
|
|
|
li = libinput_path_create_context(&counting_interface, &counter);
|
2014-01-29 15:38:48 +10:00
|
|
|
ck_assert(li != NULL);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.open_func_count, 0);
|
|
|
|
|
ck_assert_int_eq(counter.close_func_count, 0);
|
2013-12-10 13:30:52 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(path_create_invalid)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
2014-01-29 15:38:48 +10:00
|
|
|
struct libinput_device *device;
|
2013-12-10 13:30:52 +10:00
|
|
|
const char *path = "/tmp";
|
2017-06-09 12:25:50 +10:00
|
|
|
struct counter counter;
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
counter.open_func_count = 0;
|
|
|
|
|
counter.close_func_count = 0;
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
li = libinput_path_create_context(&counting_interface, &counter);
|
2014-01-29 15:38:48 +10:00
|
|
|
ck_assert(li != NULL);
|
2017-06-01 15:00:27 +10:00
|
|
|
|
|
|
|
|
litest_disable_log_handler(li);
|
|
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
device = libinput_path_add_device(li, path);
|
|
|
|
|
ck_assert(device == NULL);
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.open_func_count, 0);
|
|
|
|
|
ck_assert_int_eq(counter.close_func_count, 0);
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-01 15:00:27 +10:00
|
|
|
litest_restore_log_handler(li);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.close_func_count, 0);
|
2013-12-10 13:30:52 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2016-03-03 08:33:22 +10:00
|
|
|
START_TEST(path_create_invalid_kerneldev)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
const char *path = "/dev/uinput";
|
2017-06-09 12:25:50 +10:00
|
|
|
struct counter counter;
|
2016-03-03 08:33:22 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
counter.open_func_count = 0;
|
|
|
|
|
counter.close_func_count = 0;
|
2016-03-03 08:33:22 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
li = libinput_path_create_context(&counting_interface, &counter);
|
2016-03-03 08:33:22 +10:00
|
|
|
ck_assert(li != NULL);
|
2017-06-01 15:00:27 +10:00
|
|
|
|
|
|
|
|
litest_disable_log_handler(li);
|
|
|
|
|
|
2016-03-03 08:33:22 +10:00
|
|
|
device = libinput_path_add_device(li, path);
|
|
|
|
|
ck_assert(device == NULL);
|
|
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.open_func_count, 1);
|
|
|
|
|
ck_assert_int_eq(counter.close_func_count, 1);
|
2016-03-03 08:33:22 +10:00
|
|
|
|
2017-06-01 15:00:27 +10:00
|
|
|
litest_restore_log_handler(li);
|
2016-03-03 08:33:22 +10:00
|
|
|
libinput_unref(li);
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.close_func_count, 1);
|
2016-03-03 08:33:22 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(path_create_invalid_file)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
char path[] = "/tmp/litest_path_XXXXXX";
|
|
|
|
|
int fd;
|
2017-06-09 12:25:50 +10:00
|
|
|
struct counter counter;
|
2016-03-03 08:33:22 +10:00
|
|
|
|
2016-04-01 09:37:18 +10:00
|
|
|
umask(002);
|
2016-03-03 08:33:22 +10:00
|
|
|
fd = mkstemp(path);
|
|
|
|
|
ck_assert_int_ge(fd, 0);
|
|
|
|
|
close(fd);
|
|
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
counter.open_func_count = 0;
|
|
|
|
|
counter.close_func_count = 0;
|
2016-03-03 08:33:22 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
li = libinput_path_create_context(&counting_interface, &counter);
|
2016-03-03 08:33:22 +10:00
|
|
|
unlink(path);
|
|
|
|
|
|
2017-06-01 15:00:27 +10:00
|
|
|
litest_disable_log_handler(li);
|
|
|
|
|
|
2016-03-03 08:33:22 +10:00
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
device = libinput_path_add_device(li, path);
|
|
|
|
|
ck_assert(device == NULL);
|
|
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.open_func_count, 0);
|
|
|
|
|
ck_assert_int_eq(counter.close_func_count, 0);
|
2016-03-03 08:33:22 +10:00
|
|
|
|
2017-06-01 15:00:27 +10:00
|
|
|
litest_restore_log_handler(li);
|
2016-03-03 08:33:22 +10:00
|
|
|
libinput_unref(li);
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.close_func_count, 0);
|
2016-03-03 08:33:22 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-12-10 13:30:52 +10:00
|
|
|
START_TEST(path_create_destroy)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
2014-01-29 15:38:48 +10:00
|
|
|
struct libinput_device *device;
|
2013-12-10 13:30:52 +10:00
|
|
|
struct libevdev_uinput *uinput;
|
2017-06-09 12:25:50 +10:00
|
|
|
struct counter counter;
|
|
|
|
|
|
|
|
|
|
counter.open_func_count = 0;
|
|
|
|
|
counter.close_func_count = 0;
|
2013-12-10 13:30:52 +10:00
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
li = libinput_path_create_context(&counting_interface, &counter);
|
2013-12-10 13:30:52 +10:00
|
|
|
ck_assert(li != NULL);
|
2017-06-01 15:00:27 +10:00
|
|
|
|
|
|
|
|
litest_disable_log_handler(li);
|
|
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert(libinput_get_user_data(li) == &counter);
|
2014-01-29 15:38:48 +10:00
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.open_func_count, 1);
|
2013-12-10 13:30:52 +10:00
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2017-06-09 12:25:50 +10:00
|
|
|
ck_assert_int_eq(counter.close_func_count, 1);
|
2013-12-10 13:30:52 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-01-13 15:57:45 +10:00
|
|
|
START_TEST(path_force_destroy)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, NULL);
|
|
|
|
|
ck_assert_notnull(li);
|
|
|
|
|
libinput_ref(li);
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(dev->uinput));
|
|
|
|
|
ck_assert_notnull(device);
|
|
|
|
|
|
|
|
|
|
while (libinput_unref(li) != NULL)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-12-23 13:37:28 +10:00
|
|
|
START_TEST(path_set_user_data)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
int data1, data2;
|
|
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, &data1);
|
|
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
ck_assert(libinput_get_user_data(li) == &data1);
|
|
|
|
|
libinput_set_user_data(li, &data2);
|
|
|
|
|
ck_assert(libinput_get_user_data(li) == &data2);
|
|
|
|
|
|
|
|
|
|
libinput_unref(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-12-10 13:30:52 +10:00
|
|
|
START_TEST(path_added_seat)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
2014-01-15 16:31:29 +10:00
|
|
|
struct libinput_device *device;
|
2013-12-10 13:30:52 +10:00
|
|
|
struct libinput_seat *seat;
|
|
|
|
|
const char *seat_name;
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert(event != NULL);
|
|
|
|
|
|
|
|
|
|
type = libinput_event_get_type(event);
|
2013-12-19 12:04:24 +10:00
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
2013-12-10 13:30:52 +10:00
|
|
|
|
2014-01-17 17:59:30 +10:00
|
|
|
device = libinput_event_get_device(event);
|
2014-01-15 16:31:29 +10:00
|
|
|
seat = libinput_device_get_seat(device);
|
2013-12-10 13:30:52 +10:00
|
|
|
ck_assert(seat != NULL);
|
|
|
|
|
|
2014-01-15 17:04:00 +10:00
|
|
|
seat_name = libinput_seat_get_logical_name(seat);
|
2014-06-11 08:35:56 +10:00
|
|
|
ck_assert_str_eq(seat_name, "default");
|
2013-12-10 13:30:52 +10:00
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-11-19 15:42:54 +10:00
|
|
|
START_TEST(path_seat_change)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_seat *seat1, *seat2;
|
|
|
|
|
const char *seat1_name;
|
|
|
|
|
const char *seat2_name = "new seat";
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert_int_eq(libinput_event_get_type(event),
|
|
|
|
|
LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
libinput_device_ref(device);
|
|
|
|
|
|
|
|
|
|
seat1 = libinput_device_get_seat(device);
|
|
|
|
|
libinput_seat_ref(seat1);
|
|
|
|
|
|
|
|
|
|
seat1_name = libinput_seat_get_logical_name(seat1);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
rc = libinput_device_set_seat_logical_name(device,
|
|
|
|
|
seat2_name);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert(event != NULL);
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libinput_event_get_type(event),
|
|
|
|
|
LIBINPUT_EVENT_DEVICE_REMOVED);
|
|
|
|
|
|
|
|
|
|
ck_assert(libinput_event_get_device(event) == device);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert(event != NULL);
|
|
|
|
|
ck_assert_int_eq(libinput_event_get_type(event),
|
|
|
|
|
LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
ck_assert(libinput_event_get_device(event) != device);
|
|
|
|
|
libinput_device_unref(device);
|
|
|
|
|
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
seat2 = libinput_device_get_seat(device);
|
|
|
|
|
|
|
|
|
|
ck_assert_str_ne(libinput_seat_get_logical_name(seat2),
|
|
|
|
|
seat1_name);
|
|
|
|
|
ck_assert_str_eq(libinput_seat_get_logical_name(seat2),
|
|
|
|
|
seat2_name);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
libinput_seat_unref(seat1);
|
|
|
|
|
|
|
|
|
|
/* litest: swap the new device in, so cleanup works */
|
|
|
|
|
libinput_device_unref(dev->libinput_device);
|
|
|
|
|
libinput_device_ref(device);
|
|
|
|
|
dev->libinput_device = device;
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-12-10 13:30:52 +10:00
|
|
|
START_TEST(path_added_device)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *device;
|
2017-01-05 20:15:56 +10:00
|
|
|
enum libinput_event_type type;
|
2013-12-10 13:30:52 +10:00
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert_notnull(event);
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
2014-01-17 17:59:30 +10:00
|
|
|
device = libinput_event_get_device(event);
|
2017-01-05 20:15:56 +10:00
|
|
|
ck_assert_notnull(device);
|
2013-12-10 13:30:52 +10:00
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-01-29 16:37:45 +10:00
|
|
|
START_TEST(path_add_device)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *device;
|
2017-01-05 20:15:56 +10:00
|
|
|
char *sysname1 = NULL, *sysname2 = NULL;
|
|
|
|
|
enum libinput_event_type type;
|
2014-01-29 16:37:45 +10:00
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert_notnull(event);
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert_notnull(device);
|
|
|
|
|
sysname1 = strdup(libinput_device_get_sysname(device));
|
|
|
|
|
libinput_event_destroy(event);
|
2014-01-29 16:37:45 +10:00
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
litest_assert_empty_queue(li);
|
2014-01-29 16:37:45 +10:00
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(dev->uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert_notnull(event);
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert_notnull(device);
|
|
|
|
|
sysname2 = strdup(libinput_device_get_sysname(device));
|
|
|
|
|
libinput_event_destroy(event);
|
2014-01-29 16:37:45 +10:00
|
|
|
|
2014-06-11 08:35:56 +10:00
|
|
|
ck_assert_str_eq(sysname1, sysname2);
|
2014-01-29 16:37:45 +10:00
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
free(sysname1);
|
|
|
|
|
free(sysname2);
|
2014-01-29 16:37:45 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-02-06 10:05:29 +10:00
|
|
|
START_TEST(path_add_invalid_path)
|
|
|
|
|
{
|
2014-07-16 21:14:51 +02:00
|
|
|
struct libinput *li;
|
2014-02-06 10:05:29 +10:00
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
|
2014-07-16 21:14:51 +02:00
|
|
|
li = litest_create_context();
|
2014-02-06 10:05:29 +10:00
|
|
|
|
2015-07-29 16:06:20 +10:00
|
|
|
litest_disable_log_handler(li);
|
2014-02-06 10:05:29 +10:00
|
|
|
device = libinput_path_add_device(li, "/tmp/");
|
2015-07-29 16:06:20 +10:00
|
|
|
litest_restore_log_handler(li);
|
2014-02-06 10:05:29 +10:00
|
|
|
ck_assert(device == NULL);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li)))
|
|
|
|
|
ck_abort();
|
2014-07-16 21:14:51 +02:00
|
|
|
|
|
|
|
|
libinput_unref(li);
|
2014-02-06 10:05:29 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-01-28 15:54:34 +10:00
|
|
|
START_TEST(path_device_sysname)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput_event *ev;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
const char *sysname;
|
2017-01-05 20:15:56 +10:00
|
|
|
enum libinput_event_type type;
|
2014-01-28 15:54:34 +10:00
|
|
|
|
|
|
|
|
libinput_dispatch(dev->libinput);
|
|
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
ev = libinput_get_event(dev->libinput);
|
|
|
|
|
ck_assert_notnull(ev);
|
|
|
|
|
type = libinput_event_get_type(ev);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
device = libinput_event_get_device(ev);
|
|
|
|
|
ck_assert_notnull(device);
|
|
|
|
|
sysname = libinput_device_get_sysname(device);
|
2014-01-28 15:54:34 +10:00
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
ck_assert(sysname != NULL && strlen(sysname) > 1);
|
|
|
|
|
ck_assert(strchr(sysname, '/') == NULL);
|
|
|
|
|
ck_assert_int_eq(strncmp(sysname, "event", 5), 0);
|
2014-02-03 14:23:38 +10:00
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
libinput_event_destroy(ev);
|
2014-01-28 15:54:34 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-01-29 16:37:45 +10:00
|
|
|
START_TEST(path_remove_device)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
int remove_event = 0;
|
|
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(dev->uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
libinput_path_remove_device(device);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_DEVICE_REMOVED)
|
|
|
|
|
remove_event++;
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(remove_event, 1);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(path_double_remove_device)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
int remove_event = 0;
|
|
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(dev->uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
libinput_path_remove_device(device);
|
|
|
|
|
libinput_path_remove_device(device);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_DEVICE_REMOVED)
|
|
|
|
|
remove_event++;
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(remove_event, 1);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-01-08 17:39:16 +10:00
|
|
|
START_TEST(path_suspend)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
2014-01-29 15:38:48 +10:00
|
|
|
struct libinput_device *device;
|
2014-01-08 17:39:16 +10:00
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
int rc;
|
|
|
|
|
void *userdata = &rc;
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2014-01-08 17:39:16 +10:00
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
li = libinput_path_create_context(&simple_interface, userdata);
|
2014-01-08 17:39:16 +10:00
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
2014-01-08 17:39:16 +10:00
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-01-08 17:39:16 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(path_double_suspend)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
2014-01-29 15:38:48 +10:00
|
|
|
struct libinput_device *device;
|
2014-01-08 17:39:16 +10:00
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
int rc;
|
|
|
|
|
void *userdata = &rc;
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2014-01-08 17:39:16 +10:00
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
li = libinput_path_create_context(&simple_interface, userdata);
|
2014-01-08 17:39:16 +10:00
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
2014-01-08 17:39:16 +10:00
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-01-08 17:39:16 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(path_double_resume)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
2014-01-29 15:38:48 +10:00
|
|
|
struct libinput_device *device;
|
2014-01-08 17:39:16 +10:00
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
int rc;
|
|
|
|
|
void *userdata = &rc;
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2014-01-08 17:39:16 +10:00
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
li = libinput_path_create_context(&simple_interface, userdata);
|
2014-01-08 17:39:16 +10:00
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
|
2014-01-29 15:38:48 +10:00
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
2014-01-08 17:39:16 +10:00
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-01-08 17:39:16 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-02-06 10:05:29 +10:00
|
|
|
START_TEST(path_add_device_suspend_resume)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libevdev_uinput *uinput1, *uinput2;
|
|
|
|
|
int rc;
|
|
|
|
|
int nevents;
|
|
|
|
|
void *userdata = &rc;
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput1 = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
|
|
|
|
uinput2 = litest_create_uinput_device("test device 2", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2014-02-06 10:05:29 +10:00
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, userdata);
|
|
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput1));
|
|
|
|
|
ck_assert(device != NULL);
|
2017-07-06 16:45:41 +10:00
|
|
|
libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput2));
|
2014-02-06 10:05:29 +10:00
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput1);
|
|
|
|
|
libevdev_uinput_destroy(uinput2);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-02-06 10:05:29 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(path_add_device_suspend_resume_fail)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libevdev_uinput *uinput1, *uinput2;
|
|
|
|
|
int rc;
|
|
|
|
|
int nevents;
|
|
|
|
|
void *userdata = &rc;
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput1 = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
|
|
|
|
uinput2 = litest_create_uinput_device("test device 2", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2014-02-06 10:05:29 +10:00
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, userdata);
|
|
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput1));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput2));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
/* now drop one of the devices */
|
|
|
|
|
libevdev_uinput_destroy(uinput1);
|
|
|
|
|
rc = libinput_resume(li);
|
|
|
|
|
ck_assert_int_eq(rc, -1);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
/* We expect one device being added, second one fails,
|
|
|
|
|
* causing a removed event for the first one */
|
|
|
|
|
if (type != LIBINPUT_EVENT_DEVICE_ADDED &&
|
|
|
|
|
type != LIBINPUT_EVENT_DEVICE_REMOVED)
|
|
|
|
|
ck_abort();
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput2);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-02-06 10:05:29 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(path_add_device_suspend_resume_remove_device)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libevdev_uinput *uinput1, *uinput2;
|
|
|
|
|
int rc;
|
|
|
|
|
int nevents;
|
|
|
|
|
void *userdata = &rc;
|
|
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput1 = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
|
|
|
|
uinput2 = litest_create_uinput_device("test device 2", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2014-02-06 10:05:29 +10:00
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, userdata);
|
|
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput1));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput2));
|
|
|
|
|
|
|
|
|
|
libinput_device_ref(device);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
libinput_suspend(li);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 2);
|
|
|
|
|
|
|
|
|
|
/* now drop and remove one of the devices */
|
|
|
|
|
libevdev_uinput_destroy(uinput2);
|
|
|
|
|
libinput_path_remove_device(device);
|
|
|
|
|
libinput_device_unref(device);
|
|
|
|
|
|
|
|
|
|
rc = libinput_resume(li);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
nevents = 0;
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
type = libinput_event_get_type(event);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
nevents++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(nevents, 1);
|
|
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput1);
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-02-06 10:05:29 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-02-10 11:40:55 +10:00
|
|
|
START_TEST(path_seat_recycle)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *li;
|
|
|
|
|
struct libevdev_uinput *uinput;
|
|
|
|
|
int rc;
|
|
|
|
|
void *userdata = &rc;
|
|
|
|
|
struct libinput_event *ev;
|
|
|
|
|
struct libinput_device *device;
|
|
|
|
|
struct libinput_seat *saved_seat = NULL;
|
|
|
|
|
struct libinput_seat *seat;
|
|
|
|
|
int data = 0;
|
|
|
|
|
int found = 0;
|
|
|
|
|
void *user_data;
|
2017-01-05 20:15:56 +10:00
|
|
|
enum libinput_event_type type;
|
2014-02-10 11:40:55 +10:00
|
|
|
|
test: add litest helper functions for creating uinput devices
Both functions accept a series of event types/codes tuples, terminated by -1.
For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
as a property to enable.
The _abs function als takes an array of absinfo, with absinfo.value
determining the axis to change. If none are given, abs axes are initialized
with default settings.
Both functions abort on failure, so the caller does not need to check the
return value.
Example code for creating a rel device:
struct libevdev_uinput *uinput;
struct input_id id = { ... };
uinput = litest_create_uinput_device("foo", &id,
EV_REL, REL_X,
EV_REL, REL_Y,
EV_KEY, BTN_LEFT,
INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
-1);
libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
...
libevdev_uinput_destroy(uinput);
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-03-26 20:09:42 +10:00
|
|
|
uinput = litest_create_uinput_device("test device", NULL,
|
|
|
|
|
EV_KEY, BTN_LEFT,
|
|
|
|
|
EV_KEY, BTN_RIGHT,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2014-02-10 11:40:55 +10:00
|
|
|
|
|
|
|
|
li = libinput_path_create_context(&simple_interface, userdata);
|
|
|
|
|
ck_assert(li != NULL);
|
|
|
|
|
|
|
|
|
|
device = libinput_path_add_device(li,
|
|
|
|
|
libevdev_uinput_get_devnode(uinput));
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
ev = libinput_get_event(li);
|
|
|
|
|
ck_assert_notnull(ev);
|
|
|
|
|
type = libinput_event_get_type(ev);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
device = libinput_event_get_device(ev);
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
saved_seat = libinput_device_get_seat(device);
|
|
|
|
|
libinput_seat_set_user_data(saved_seat, &data);
|
|
|
|
|
libinput_seat_ref(saved_seat);
|
|
|
|
|
libinput_event_destroy(ev);
|
2014-02-10 11:40:55 +10:00
|
|
|
ck_assert(saved_seat != NULL);
|
|
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
|
2014-02-10 11:40:55 +10:00
|
|
|
libinput_suspend(li);
|
|
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
libinput_resume(li);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(li);
|
2017-01-05 20:15:56 +10:00
|
|
|
ev = libinput_get_event(li);
|
|
|
|
|
ck_assert_notnull(ev);
|
|
|
|
|
type = libinput_event_get_type(ev);
|
|
|
|
|
ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED);
|
|
|
|
|
device = libinput_event_get_device(ev);
|
|
|
|
|
ck_assert(device != NULL);
|
|
|
|
|
|
|
|
|
|
seat = libinput_device_get_seat(device);
|
|
|
|
|
user_data = libinput_seat_get_user_data(seat);
|
|
|
|
|
if (user_data == &data) {
|
|
|
|
|
found = 1;
|
|
|
|
|
ck_assert(seat == saved_seat);
|
2014-02-10 11:40:55 +10:00
|
|
|
}
|
|
|
|
|
|
2017-01-05 20:15:56 +10:00
|
|
|
libinput_event_destroy(ev);
|
2014-02-10 11:40:55 +10:00
|
|
|
ck_assert(found == 1);
|
|
|
|
|
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput_unref(li);
|
2014-02-10 11:40:55 +10:00
|
|
|
|
|
|
|
|
libevdev_uinput_destroy(uinput);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2017-01-13 11:28:47 +10:00
|
|
|
START_TEST(path_udev_assign_seat)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
litest_set_log_handler_bug(li);
|
|
|
|
|
rc = libinput_udev_assign_seat(li, "foo");
|
|
|
|
|
ck_assert_int_eq(rc, -1);
|
|
|
|
|
litest_restore_log_handler(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2015-05-20 09:36:01 +10:00
|
|
|
void
|
2016-07-22 13:16:49 +10:00
|
|
|
litest_setup_tests_path(void)
|
2014-07-14 00:01:10 +02:00
|
|
|
{
|
2014-07-16 21:14:51 +02:00
|
|
|
litest_add_no_device("path:create", path_create_NULL);
|
|
|
|
|
litest_add_no_device("path:create", path_create_invalid);
|
2016-03-03 08:33:22 +10:00
|
|
|
litest_add_no_device("path:create", path_create_invalid_file);
|
|
|
|
|
litest_add_no_device("path:create", path_create_invalid_kerneldev);
|
2014-07-16 21:14:51 +02:00
|
|
|
litest_add_no_device("path:create", path_create_destroy);
|
2017-01-13 15:57:45 +10:00
|
|
|
litest_add("path:create", path_force_destroy, LITEST_ANY, LITEST_ANY);
|
2014-12-23 13:37:28 +10:00
|
|
|
litest_add_no_device("path:create", path_set_user_data);
|
2014-07-16 21:14:51 +02:00
|
|
|
litest_add_no_device("path:suspend", path_suspend);
|
|
|
|
|
litest_add_no_device("path:suspend", path_double_suspend);
|
|
|
|
|
litest_add_no_device("path:suspend", path_double_resume);
|
|
|
|
|
litest_add_no_device("path:suspend", path_add_device_suspend_resume);
|
|
|
|
|
litest_add_no_device("path:suspend", path_add_device_suspend_resume_fail);
|
|
|
|
|
litest_add_no_device("path:suspend", path_add_device_suspend_resume_remove_device);
|
2016-09-09 12:54:01 +10:00
|
|
|
litest_add_for_device("path:seat", path_added_seat, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device("path:seat", path_seat_change, LITEST_SYNAPTICS_CLICKPAD_X220);
|
2013-12-10 13:30:52 +10:00
|
|
|
litest_add("path:device events", path_added_device, LITEST_ANY, LITEST_ANY);
|
2014-01-28 15:54:34 +10:00
|
|
|
litest_add("path:device events", path_device_sysname, LITEST_ANY, LITEST_ANY);
|
2016-09-09 12:54:01 +10:00
|
|
|
litest_add_for_device("path:device events", path_add_device, LITEST_SYNAPTICS_CLICKPAD_X220);
|
2014-07-16 21:14:51 +02:00
|
|
|
litest_add_no_device("path:device events", path_add_invalid_path);
|
2016-09-09 12:54:01 +10:00
|
|
|
litest_add_for_device("path:device events", path_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220);
|
|
|
|
|
litest_add_for_device("path:device events", path_double_remove_device, LITEST_SYNAPTICS_CLICKPAD_X220);
|
2014-07-16 21:14:51 +02:00
|
|
|
litest_add_no_device("path:seat", path_seat_recycle);
|
2017-01-13 11:28:47 +10:00
|
|
|
litest_add_for_device("path:udev", path_udev_assign_seat, LITEST_SYNAPTICS_CLICKPAD_X220);
|
2013-12-10 13:30:52 +10:00
|
|
|
}
|