mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-05 13:28:04 +02:00
test: create devices for our udev seat checks
This way we can ensure that at least one device is available, and that it is the device we want. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
7265d1676f
commit
ca1c05ab44
1 changed files with 29 additions and 30 deletions
|
|
@ -175,10 +175,6 @@ START_TEST(udev_set_user_data)
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
/**
|
|
||||||
* This test only works if there's at least one device in the system that is
|
|
||||||
* assigned the default seat. Should cover the 99% case.
|
|
||||||
*/
|
|
||||||
START_TEST(udev_added_seat_default)
|
START_TEST(udev_added_seat_default)
|
||||||
{
|
{
|
||||||
struct libinput *li;
|
struct libinput *li;
|
||||||
|
|
@ -187,8 +183,7 @@ START_TEST(udev_added_seat_default)
|
||||||
struct libinput_device *device;
|
struct libinput_device *device;
|
||||||
struct libinput_seat *seat;
|
struct libinput_seat *seat;
|
||||||
const char *seat_name;
|
const char *seat_name;
|
||||||
enum libinput_event_type type;
|
struct litest_device *dev;
|
||||||
int default_seat_found = 0;
|
|
||||||
|
|
||||||
udev = udev_new();
|
udev = udev_new();
|
||||||
ck_assert_notnull(udev);
|
ck_assert_notnull(udev);
|
||||||
|
|
@ -198,33 +193,30 @@ START_TEST(udev_added_seat_default)
|
||||||
ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
while (!default_seat_found && (event = libinput_get_event(li))) {
|
/* Drop any events from other devices */
|
||||||
type = libinput_event_get_type(event);
|
litest_drain_events(li);
|
||||||
if (type != LIBINPUT_EVENT_DEVICE_ADDED) {
|
|
||||||
libinput_event_destroy(event);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
device = libinput_event_get_device(event);
|
/* Now create our own device, it should be in the "default"
|
||||||
seat = libinput_device_get_seat(device);
|
* logical seat. This test may fail if there is a local rule changing
|
||||||
ck_assert_notnull(seat);
|
* that, but it'll be fine for the 99% case. */
|
||||||
|
dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
|
||||||
|
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1);
|
||||||
|
event = libinput_get_event(li);
|
||||||
|
device = libinput_event_get_device(event);
|
||||||
|
seat = libinput_device_get_seat(device);
|
||||||
|
ck_assert_notnull(seat);
|
||||||
|
|
||||||
seat_name = libinput_seat_get_logical_name(seat);
|
seat_name = libinput_seat_get_logical_name(seat);
|
||||||
default_seat_found = streq(seat_name, "default");
|
ck_assert_str_eq(seat_name, "default");
|
||||||
libinput_event_destroy(event);
|
libinput_event_destroy(event);
|
||||||
}
|
|
||||||
|
|
||||||
ck_assert(default_seat_found);
|
|
||||||
|
|
||||||
libinput_unref(li);
|
libinput_unref(li);
|
||||||
udev_unref(udev);
|
udev_unref(udev);
|
||||||
|
|
||||||
|
litest_delete_device(dev);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
/**
|
|
||||||
* This test only works if there's at least one device in the system that is
|
|
||||||
* assigned the default seat. Should cover the 99% case.
|
|
||||||
*/
|
|
||||||
START_TEST(udev_change_seat)
|
START_TEST(udev_change_seat)
|
||||||
{
|
{
|
||||||
struct libinput *li;
|
struct libinput *li;
|
||||||
|
|
@ -235,6 +227,7 @@ START_TEST(udev_change_seat)
|
||||||
const char *seat1_name;
|
const char *seat1_name;
|
||||||
const char *seat2_name = "new seat";
|
const char *seat2_name = "new seat";
|
||||||
int rc;
|
int rc;
|
||||||
|
struct litest_device *dev;
|
||||||
|
|
||||||
udev = udev_new();
|
udev = udev_new();
|
||||||
ck_assert_notnull(udev);
|
ck_assert_notnull(udev);
|
||||||
|
|
@ -244,12 +237,15 @@ START_TEST(udev_change_seat)
|
||||||
ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
|
||||||
libinput_dispatch(li);
|
libinput_dispatch(li);
|
||||||
|
|
||||||
|
/* Drop any events from other devices */
|
||||||
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
/* Now create our own device, it should be in the "default"
|
||||||
|
* logical seat. This test may fail if there is a local rule changing
|
||||||
|
* that, but it'll be fine for the 99% case. */
|
||||||
|
dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
|
||||||
|
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1);
|
||||||
event = libinput_get_event(li);
|
event = libinput_get_event(li);
|
||||||
ck_assert_notnull(event);
|
|
||||||
|
|
||||||
ck_assert_int_eq(libinput_event_get_type(event),
|
|
||||||
LIBINPUT_EVENT_DEVICE_ADDED);
|
|
||||||
|
|
||||||
device = libinput_event_get_device(event);
|
device = libinput_event_get_device(event);
|
||||||
libinput_device_ref(device);
|
libinput_device_ref(device);
|
||||||
|
|
||||||
|
|
@ -261,6 +257,7 @@ START_TEST(udev_change_seat)
|
||||||
|
|
||||||
litest_drain_events(li);
|
litest_drain_events(li);
|
||||||
|
|
||||||
|
/* Changing the logical seat name will remove and re-add the device */
|
||||||
rc = libinput_device_set_seat_logical_name(device,
|
rc = libinput_device_set_seat_logical_name(device,
|
||||||
seat2_name);
|
seat2_name);
|
||||||
ck_assert_int_eq(rc, 0);
|
ck_assert_int_eq(rc, 0);
|
||||||
|
|
@ -293,6 +290,8 @@ START_TEST(udev_change_seat)
|
||||||
|
|
||||||
libinput_unref(li);
|
libinput_unref(li);
|
||||||
udev_unref(udev);
|
udev_unref(udev);
|
||||||
|
|
||||||
|
litest_delete_device(dev);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue