mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-03 18:10:28 +01:00
test: simplify some checks in the path test
The first event is always a device added event, skip the loops that would paper over this. If we ever change this, the tests *should* fail. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
a9016f7e15
commit
9483a7a2c0
1 changed files with 64 additions and 86 deletions
150
test/test-path.c
150
test/test-path.c
|
|
@ -310,24 +310,16 @@ START_TEST(path_added_device)
|
|||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_device *device;
|
||||
enum libinput_event_type type;
|
||||
|
||||
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_ADDED) {
|
||||
break;
|
||||
}
|
||||
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
|
||||
ck_assert(event != NULL);
|
||||
|
||||
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(device != NULL);
|
||||
ck_assert_notnull(device);
|
||||
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
|
|
@ -339,23 +331,21 @@ START_TEST(path_add_device)
|
|||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_device *device;
|
||||
const char *sysname1 = NULL, *sysname2 = NULL;
|
||||
char *sysname1 = NULL, *sysname2 = NULL;
|
||||
enum libinput_event_type type;
|
||||
|
||||
libinput_dispatch(li);
|
||||
|
||||
while ((event = libinput_get_event(li))) {
|
||||
enum libinput_event_type type;
|
||||
type = libinput_event_get_type(event);
|
||||
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);
|
||||
|
||||
if (type == LIBINPUT_EVENT_DEVICE_ADDED) {
|
||||
ck_assert(sysname1 == NULL);
|
||||
device = libinput_event_get_device(event);
|
||||
ck_assert(device != NULL);
|
||||
sysname1 = libinput_device_get_sysname(device);
|
||||
}
|
||||
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
litest_assert_empty_queue(li);
|
||||
|
||||
device = libinput_path_add_device(li,
|
||||
libevdev_uinput_get_devnode(dev->uinput));
|
||||
|
|
@ -363,23 +353,19 @@ START_TEST(path_add_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_ADDED) {
|
||||
ck_assert(sysname2 == NULL);
|
||||
device = libinput_event_get_device(event);
|
||||
ck_assert(device != NULL);
|
||||
sysname2 = libinput_device_get_sysname(device);
|
||||
}
|
||||
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
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);
|
||||
|
||||
ck_assert_str_eq(sysname1, sysname2);
|
||||
|
||||
libinput_event_destroy(event);
|
||||
free(sysname1);
|
||||
free(sysname2);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
@ -411,21 +397,23 @@ START_TEST(path_device_sysname)
|
|||
struct libinput_event *ev;
|
||||
struct libinput_device *device;
|
||||
const char *sysname;
|
||||
enum libinput_event_type type;
|
||||
|
||||
libinput_dispatch(dev->libinput);
|
||||
|
||||
while ((ev = libinput_get_event(dev->libinput))) {
|
||||
if (libinput_event_get_type(ev) != LIBINPUT_EVENT_DEVICE_ADDED)
|
||||
continue;
|
||||
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);
|
||||
|
||||
device = libinput_event_get_device(ev);
|
||||
sysname = libinput_device_get_sysname(device);
|
||||
ck_assert(sysname != NULL && strlen(sysname) > 1);
|
||||
ck_assert(strchr(sysname, '/') == NULL);
|
||||
ck_assert_int_eq(strncmp(sysname, "event", 5), 0);
|
||||
ck_assert(sysname != NULL && strlen(sysname) > 1);
|
||||
ck_assert(strchr(sysname, '/') == NULL);
|
||||
ck_assert_int_eq(strncmp(sysname, "event", 5), 0);
|
||||
|
||||
libinput_event_destroy(ev);
|
||||
}
|
||||
libinput_event_destroy(ev);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
@ -865,6 +853,7 @@ START_TEST(path_seat_recycle)
|
|||
int data = 0;
|
||||
int found = 0;
|
||||
void *user_data;
|
||||
enum libinput_event_type type;
|
||||
|
||||
uinput = litest_create_uinput_device("test device", NULL,
|
||||
EV_KEY, BTN_LEFT,
|
||||
|
|
@ -881,27 +870,21 @@ START_TEST(path_seat_recycle)
|
|||
ck_assert(device != NULL);
|
||||
|
||||
libinput_dispatch(li);
|
||||
while ((ev = libinput_get_event(li))) {
|
||||
switch (libinput_event_get_type(ev)) {
|
||||
case LIBINPUT_EVENT_DEVICE_ADDED:
|
||||
if (saved_seat)
|
||||
break;
|
||||
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
libinput_event_destroy(ev);
|
||||
}
|
||||
|
||||
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);
|
||||
ck_assert(saved_seat != NULL);
|
||||
|
||||
litest_assert_empty_queue(li);
|
||||
|
||||
libinput_suspend(li);
|
||||
|
||||
litest_drain_events(li);
|
||||
|
|
@ -909,26 +892,21 @@ START_TEST(path_seat_recycle)
|
|||
libinput_resume(li);
|
||||
|
||||
libinput_dispatch(li);
|
||||
while ((ev = libinput_get_event(li))) {
|
||||
switch (libinput_event_get_type(ev)) {
|
||||
case LIBINPUT_EVENT_DEVICE_ADDED:
|
||||
device = libinput_event_get_device(ev);
|
||||
ck_assert(device != NULL);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
libinput_event_destroy(ev);
|
||||
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);
|
||||
}
|
||||
|
||||
libinput_event_destroy(ev);
|
||||
ck_assert(found == 1);
|
||||
|
||||
libinput_unref(li);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue