[PATCH v2 libinput 27/26] test: add tablet wheel test

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 25 20:33:23 PST 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
New patch, I had to re-do the test because it never actually triggered. So
rather than complicated rebasing, this is the final test with everything
including discrete values.

New test sends more than one wheel event and then a couple of axis events
after to make sure we rest the wheel correctly.

 test/tablet.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)

diff --git a/test/tablet.c b/test/tablet.c
index 1eb91c6..519b067 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -1334,6 +1334,105 @@ START_TEST(mouse_rotation)
 }
 END_TEST
 
+START_TEST(mouse_wheel)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_tablet *tev;
+	struct libinput_tool *tool;
+	const struct input_absinfo *abs;
+	double val;
+	int i;
+
+	if (!libevdev_has_event_code(dev->evdev,
+				     EV_REL,
+				     REL_WHEEL))
+		return;
+
+	litest_drain_events(li);
+
+	litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1);
+	litest_event(dev, EV_ABS, ABS_MISC, 0x806); /* 5-button mouse tool_id */
+	litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	litest_wait_for_event_of_type(li,
+				      LIBINPUT_EVENT_TABLET_PROXIMITY,
+				      -1);
+	event = libinput_get_event(li);
+	tev = libinput_event_get_tablet_event(event);
+	tool = libinput_event_tablet_get_tool(tev);
+	ck_assert_notnull(tool);
+	libinput_tool_ref(tool);
+
+	libinput_event_destroy(event);
+
+	ck_assert(libinput_tool_has_axis(tool,
+					 LIBINPUT_TABLET_AXIS_REL_WHEEL));
+
+	for (i = 0; i < 3; i++) {
+		litest_event(dev, EV_REL, REL_WHEEL, -1);
+		litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+		litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
+
+		event = libinput_get_event(li);
+		tev = libinput_event_get_tablet_event(event);
+		ck_assert(libinput_event_tablet_axis_has_changed(tev,
+						LIBINPUT_TABLET_AXIS_REL_WHEEL));
+		val = libinput_event_tablet_get_axis_value(tev,
+						LIBINPUT_TABLET_AXIS_REL_WHEEL);
+		ck_assert_int_eq(val, 0);
+
+		val = libinput_event_tablet_get_axis_delta(tev,
+						LIBINPUT_TABLET_AXIS_REL_WHEEL);
+		ck_assert_int_eq(val, 15);
+
+		val = libinput_event_tablet_get_axis_delta_discrete(tev,
+						LIBINPUT_TABLET_AXIS_REL_WHEEL);
+		ck_assert_int_eq(val, 1);
+
+		libinput_event_destroy(event);
+
+		litest_assert_empty_queue(li);
+	}
+
+	for (i = 2; i < 5; i++) {
+		/* send  x/y events to make sure we reset the wheel */
+		abs = libevdev_get_abs_info(dev->evdev, ABS_X);
+		litest_event(dev, EV_ABS, ABS_X, (abs->maximum - abs->minimum)/i);
+		abs = libevdev_get_abs_info(dev->evdev, ABS_Y);
+		litest_event(dev, EV_ABS, ABS_Y, (abs->maximum - abs->minimum)/i);
+		litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+		litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
+
+		event = libinput_get_event(li);
+		tev = libinput_event_get_tablet_event(event);
+		ck_assert(!libinput_event_tablet_axis_has_changed(tev,
+						LIBINPUT_TABLET_AXIS_REL_WHEEL));
+		val = libinput_event_tablet_get_axis_value(tev,
+						LIBINPUT_TABLET_AXIS_REL_WHEEL);
+		ck_assert_int_eq(val, 0);
+
+		val = libinput_event_tablet_get_axis_delta(tev,
+						LIBINPUT_TABLET_AXIS_REL_WHEEL);
+		ck_assert_int_eq(val, 0);
+
+		val = libinput_event_tablet_get_axis_delta_discrete(tev,
+						LIBINPUT_TABLET_AXIS_ROTATION_Z);
+		ck_assert_int_eq(val, 0);
+
+		libinput_event_destroy(event);
+
+		litest_assert_empty_queue(li);
+	}
+
+	libinput_tool_unref(tool);
+}
+END_TEST
+
 START_TEST(airbrush_tool)
 {
 	struct litest_device *dev = litest_current_device();
@@ -1542,6 +1641,7 @@ main(int argc, char **argv)
 	litest_add("tablet:mouse", mouse_tool, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:mouse", mouse_buttons, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:mouse", mouse_rotation, LITEST_TABLET, LITEST_ANY);
+	litest_add("tablet:mouse", mouse_wheel, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:airbrush", airbrush_tool, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:airbrush", airbrush_wheel, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:artpen", artpen_tool, LITEST_TABLET, LITEST_ANY);
-- 
2.1.0



More information about the wayland-devel mailing list