mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-05 00:38:01 +02:00
test: add litest_assert_empty_queue helper function
Checks if the queue is empty and prints informatino about any events before failing. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
fc51daff73
commit
e0ce8a67ea
3 changed files with 64 additions and 7 deletions
|
|
@ -737,6 +737,67 @@ litest_drain_events(struct libinput *li)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
litest_print_event(struct libinput_event *event)
|
||||||
|
{
|
||||||
|
struct libinput_event_pointer *p;
|
||||||
|
struct libinput_device *dev;
|
||||||
|
enum libinput_event_type type;
|
||||||
|
double x, y;
|
||||||
|
|
||||||
|
dev = libinput_event_get_device(event);
|
||||||
|
type = libinput_event_get_type(event);
|
||||||
|
|
||||||
|
fprintf(stderr,
|
||||||
|
"device %s type %d ",
|
||||||
|
libinput_device_get_sysname(dev),
|
||||||
|
type);
|
||||||
|
switch (type) {
|
||||||
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
||||||
|
p = libinput_event_get_pointer_event(event);
|
||||||
|
x = libinput_event_pointer_get_dx(p);
|
||||||
|
y = libinput_event_pointer_get_dy(p);
|
||||||
|
fprintf(stderr, "motion: %.2f/%.2f", x, y);
|
||||||
|
break;
|
||||||
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
||||||
|
p = libinput_event_get_pointer_event(event);
|
||||||
|
x = libinput_event_pointer_get_absolute_x(p);
|
||||||
|
y = libinput_event_pointer_get_absolute_y(p);
|
||||||
|
fprintf(stderr, "motion: %.2f/%.2f", x, y);
|
||||||
|
break;
|
||||||
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
||||||
|
p = libinput_event_get_pointer_event(event);
|
||||||
|
fprintf(stderr,
|
||||||
|
"button: %d state %d",
|
||||||
|
libinput_event_pointer_get_button(p),
|
||||||
|
libinput_event_pointer_get_button_state(p));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
litest_assert_empty_queue(struct libinput *li)
|
||||||
|
{
|
||||||
|
bool empty_queue = true;
|
||||||
|
struct libinput_event *event;
|
||||||
|
|
||||||
|
libinput_dispatch(li);
|
||||||
|
while ((event = libinput_get_event(li))) {
|
||||||
|
empty_queue = false;
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unexpected event: ");
|
||||||
|
litest_print_event(event);
|
||||||
|
libinput_event_destroy(event);
|
||||||
|
libinput_dispatch(li);
|
||||||
|
}
|
||||||
|
|
||||||
|
ck_assert(empty_queue);
|
||||||
|
}
|
||||||
|
|
||||||
struct libevdev_uinput *
|
struct libevdev_uinput *
|
||||||
litest_create_uinput_device_from_description(const char *name,
|
litest_create_uinput_device_from_description(const char *name,
|
||||||
const struct input_id *id,
|
const struct input_id *id,
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ void litest_keyboard_key(struct litest_device *d,
|
||||||
unsigned int key,
|
unsigned int key,
|
||||||
bool is_press);
|
bool is_press);
|
||||||
void litest_drain_events(struct libinput *li);
|
void litest_drain_events(struct libinput *li);
|
||||||
|
void litest_assert_empty_queue(struct libinput *li);
|
||||||
|
|
||||||
struct libevdev_uinput * litest_create_uinput_device(const char *name,
|
struct libevdev_uinput * litest_create_uinput_device(const char *name,
|
||||||
struct input_id *id,
|
struct input_id *id,
|
||||||
|
|
|
||||||
|
|
@ -182,9 +182,7 @@ START_TEST(touchpad_1fg_tap_n_drag)
|
||||||
assert_button_event(li, BTN_LEFT,
|
assert_button_event(li, BTN_LEFT,
|
||||||
LIBINPUT_BUTTON_STATE_RELEASED);
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
||||||
|
|
||||||
libinput_dispatch(li);
|
litest_assert_empty_queue(li);
|
||||||
event = libinput_get_event(li);
|
|
||||||
ck_assert(event == NULL);
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
@ -192,7 +190,6 @@ START_TEST(touchpad_2fg_tap)
|
||||||
{
|
{
|
||||||
struct litest_device *dev = litest_current_device();
|
struct litest_device *dev = litest_current_device();
|
||||||
struct libinput *li = dev->libinput;
|
struct libinput *li = dev->libinput;
|
||||||
struct libinput_event *event;
|
|
||||||
|
|
||||||
litest_drain_events(dev->libinput);
|
litest_drain_events(dev->libinput);
|
||||||
|
|
||||||
|
|
@ -209,9 +206,7 @@ START_TEST(touchpad_2fg_tap)
|
||||||
assert_button_event(li, BTN_RIGHT,
|
assert_button_event(li, BTN_RIGHT,
|
||||||
LIBINPUT_BUTTON_STATE_RELEASED);
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
||||||
|
|
||||||
libinput_dispatch(li);
|
litest_assert_empty_queue(li);
|
||||||
event = libinput_get_event(li);
|
|
||||||
ck_assert(event == NULL);
|
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue