mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-09 14:30:17 +01:00
litest: Add litest_assert_scroll() helper function
Make check_2fg_scroll functionality available outside of touchpad.c , no functional changes. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
d3ad8cf888
commit
faa8764921
3 changed files with 44 additions and 45 deletions
|
|
@ -1084,3 +1084,42 @@ litest_assert_button_event(struct libinput *li, unsigned int button,
|
|||
state);
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
|
||||
void litest_assert_scroll(struct libinput *li, unsigned int axis, int dir)
|
||||
{
|
||||
struct libinput_event *event, *next_event;
|
||||
struct libinput_event_pointer *ptrev;
|
||||
|
||||
event = libinput_get_event(li);
|
||||
next_event = libinput_get_event(li);
|
||||
ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
|
||||
|
||||
while (event) {
|
||||
ck_assert_int_eq(libinput_event_get_type(event),
|
||||
LIBINPUT_EVENT_POINTER_AXIS);
|
||||
ptrev = libinput_event_get_pointer_event(event);
|
||||
ck_assert(ptrev != NULL);
|
||||
ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
|
||||
|
||||
if (next_event) {
|
||||
/* Normal scroll event, check dir */
|
||||
if (dir > 0) {
|
||||
ck_assert_int_ge(
|
||||
libinput_event_pointer_get_axis_value(ptrev),
|
||||
dir);
|
||||
} else {
|
||||
ck_assert_int_le(
|
||||
libinput_event_pointer_get_axis_value(ptrev),
|
||||
dir);
|
||||
}
|
||||
} else {
|
||||
/* Last scroll event, must be 0 */
|
||||
ck_assert_int_eq(
|
||||
libinput_event_pointer_get_axis_value(ptrev),
|
||||
0);
|
||||
}
|
||||
libinput_event_destroy(event);
|
||||
event = next_event;
|
||||
next_event = libinput_get_event(li);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ void litest_assert_empty_queue(struct libinput *li);
|
|||
void litest_assert_button_event(struct libinput *li,
|
||||
unsigned int button,
|
||||
enum libinput_button_state state);
|
||||
void litest_assert_scroll(struct libinput *li, unsigned int axis, int dir);
|
||||
|
||||
struct libevdev_uinput * litest_create_uinput_device(const char *name,
|
||||
struct input_id *id,
|
||||
|
|
|
|||
|
|
@ -1346,47 +1346,6 @@ test_2fg_scroll(struct litest_device *dev, double dx, double dy, int sleep)
|
|||
libinput_dispatch(li);
|
||||
}
|
||||
|
||||
static void
|
||||
check_2fg_scroll(struct litest_device *dev, unsigned int axis, int dir)
|
||||
{
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event, *next_event;
|
||||
struct libinput_event_pointer *ptrev;
|
||||
|
||||
event = libinput_get_event(li);
|
||||
next_event = libinput_get_event(li);
|
||||
ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
|
||||
|
||||
while (event) {
|
||||
ck_assert_int_eq(libinput_event_get_type(event),
|
||||
LIBINPUT_EVENT_POINTER_AXIS);
|
||||
ptrev = libinput_event_get_pointer_event(event);
|
||||
ck_assert(ptrev != NULL);
|
||||
ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
|
||||
|
||||
if (next_event) {
|
||||
/* Normal scroll event, check dir */
|
||||
if (dir > 0) {
|
||||
ck_assert_int_ge(
|
||||
libinput_event_pointer_get_axis_value(ptrev),
|
||||
dir);
|
||||
} else {
|
||||
ck_assert_int_le(
|
||||
libinput_event_pointer_get_axis_value(ptrev),
|
||||
dir);
|
||||
}
|
||||
} else {
|
||||
/* Last scroll event, must be 0 */
|
||||
ck_assert_int_eq(
|
||||
libinput_event_pointer_get_axis_value(ptrev),
|
||||
0);
|
||||
}
|
||||
libinput_event_destroy(event);
|
||||
event = next_event;
|
||||
next_event = libinput_get_event(li);
|
||||
}
|
||||
}
|
||||
|
||||
START_TEST(touchpad_2fg_scroll)
|
||||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
|
|
@ -1395,13 +1354,13 @@ START_TEST(touchpad_2fg_scroll)
|
|||
litest_drain_events(li);
|
||||
|
||||
test_2fg_scroll(dev, 0.1, 40, 0);
|
||||
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
|
||||
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
|
||||
test_2fg_scroll(dev, 0.1, -40, 0);
|
||||
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
|
||||
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
|
||||
test_2fg_scroll(dev, 40, 0.1, 0);
|
||||
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
|
||||
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
|
||||
test_2fg_scroll(dev, -40, 0.1, 0);
|
||||
check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
|
||||
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
|
||||
|
||||
/* 2fg scroll smaller than the threshold should not generate events */
|
||||
test_2fg_scroll(dev, 0.1, 0.1, 200);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue