[PATCH libinput 4/4] test: add wheel tilt tests
Peter Hutterer
peter.hutterer at who-t.net
Tue Nov 29 02:28:25 UTC 2016
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
test/Makefile.am | 1 +
test/litest-device-mouse-wheel-tilt.c | 76 +++++++++++++++++++++++++++++++++++
test/litest.c | 2 +
test/litest.h | 1 +
test/pointer.c | 34 ++++++++++++++--
5 files changed, 111 insertions(+), 3 deletions(-)
create mode 100644 test/litest-device-mouse-wheel-tilt.c
diff --git a/test/Makefile.am b/test/Makefile.am
index 5c25b58..ac74b3b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -33,6 +33,7 @@ liblitest_la_SOURCES = \
litest-device-nexus4-touch-screen.c \
litest-device-magic-trackpad.c \
litest-device-mouse.c \
+ litest-device-mouse-wheel-tilt.c \
litest-device-mouse-roccat.c \
litest-device-mouse-low-dpi.c \
litest-device-mouse-wheel-click-angle.c \
diff --git a/test/litest-device-mouse-wheel-tilt.c b/test/litest-device-mouse-wheel-tilt.c
new file mode 100644
index 0000000..44eefb2
--- /dev/null
+++ b/test/litest-device-mouse-wheel-tilt.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright © 2016 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_mouse_setup(void)
+{
+ struct litest_device *d = litest_create_device(LITEST_MOUSE_WHEEL_TILT);
+ litest_set_current_device(d);
+}
+
+static struct input_id input_id = {
+ .bustype = 0x3,
+ .vendor = 0x17ef,
+ .product = 0x6019,
+};
+
+static int events[] = {
+ EV_KEY, BTN_LEFT,
+ EV_KEY, BTN_RIGHT,
+ EV_KEY, BTN_MIDDLE,
+ EV_REL, REL_X,
+ EV_REL, REL_Y,
+ EV_REL, REL_WHEEL,
+ EV_REL, REL_HWHEEL,
+ -1 , -1,
+};
+
+static const char udev_rule[] =
+"ACTION==\"remove\", GOTO=\"wheel_wheel_tilt_end\"\n"
+"KERNEL!=\"event*\", GOTO=\"wheel_wheel_tilt_end\"\n"
+"\n"
+"ATTRS{name}==\"litest Wheel Tilt Mouse*\",\\\n"
+" ENV{MOUSE_WHEEL_TILT_HORIZONTAL}=\"1\",\n"
+" ENV{MOUSE_WHEEL_TILT_VERTICAL}=\"1\"\n"
+"\n"
+"LABEL=\"wheel_wheel_tilt_end\"";
+
+struct litest_test_device litest_mouse_wheel_tilt_device = {
+ .type = LITEST_MOUSE_WHEEL_TILT,
+ .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL,
+ .shortname = "mouse-wheel-tilt",
+ .setup = litest_mouse_setup,
+ .interface = NULL,
+
+ .name = "Wheel Tilt Mouse",
+ .id = &input_id,
+ .absinfo = NULL,
+ .events = events,
+ .udev_rule = udev_rule,
+};
diff --git a/test/litest.c b/test/litest.c
index 148dd86..d93ce95 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -406,6 +406,7 @@ extern struct litest_test_device litest_wacom_cintiq_13hdt_pad_device;
extern struct litest_test_device litest_wacom_hid4800_tablet_device;
extern struct litest_test_device litest_mouse_wheel_click_count_device;
extern struct litest_test_device litest_calibrated_touchscreen_device;
+extern struct litest_test_device litest_mouse_wheel_tilt_device;
struct litest_test_device* devices[] = {
&litest_synaptics_clickpad_device,
@@ -464,6 +465,7 @@ struct litest_test_device* devices[] = {
&litest_wacom_hid4800_tablet_device,
&litest_mouse_wheel_click_count_device,
&litest_calibrated_touchscreen_device,
+ &litest_mouse_wheel_tilt_device,
NULL,
};
diff --git a/test/litest.h b/test/litest.h
index 7728c02..e5d1adb 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -226,6 +226,7 @@ enum litest_device_type {
LITEST_WACOM_HID4800_PEN,
LITEST_MOUSE_WHEEL_CLICK_COUNT,
LITEST_CALIBRATED_TOUCHSCREEN,
+ LITEST_MOUSE_WHEEL_TILT,
};
enum litest_device_feature {
diff --git a/test/pointer.c b/test/pointer.c
index 4f33de5..e40df33 100644
--- a/test/pointer.c
+++ b/test/pointer.c
@@ -531,6 +531,33 @@ out:
return angle;
}
+static enum libinput_pointer_axis_source
+wheel_source(struct litest_device *dev, int which)
+{
+ struct udev_device *d;
+ bool is_tilt = false;
+
+ d = libinput_device_get_udev_device(dev->libinput_device);
+ litest_assert_ptr_notnull(d);
+
+ switch(which) {
+ case REL_WHEEL:
+ is_tilt = !!udev_device_get_property_value(d, "MOUSE_WHEEL_TILT_VERTICAL");
+ break;
+ case REL_HWHEEL:
+ is_tilt = !!udev_device_get_property_value(d, "MOUSE_WHEEL_TILT_HORIZONTAL");
+ break;
+ default:
+ litest_abort_msg("Invalid source axis %d\n", which);
+ break;
+ }
+
+ udev_device_unref(d);
+ return is_tilt ?
+ LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT :
+ LIBINPUT_POINTER_AXIS_SOURCE_WHEEL;
+}
+
static void
test_wheel_event(struct litest_device *dev, int which, int amount)
{
@@ -538,10 +565,12 @@ test_wheel_event(struct litest_device *dev, int which, int amount)
struct libinput_event *event;
struct libinput_event_pointer *ptrev;
enum libinput_pointer_axis axis;
+ enum libinput_pointer_axis_source source;
double scroll_step, expected, discrete;
scroll_step = wheel_click_angle(dev, which);
+ source = wheel_source(dev, which);
expected = amount * scroll_step;
discrete = amount;
@@ -561,10 +590,9 @@ test_wheel_event(struct litest_device *dev, int which, int amount)
axis = (which == REL_WHEEL) ?
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL :
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
+
event = libinput_get_event(li);
- ptrev = litest_is_axis_event(event,
- axis,
- LIBINPUT_POINTER_AXIS_SOURCE_WHEEL);
+ ptrev = litest_is_axis_event(event, axis, source);
litest_assert_double_eq(
libinput_event_pointer_get_axis_value(ptrev, axis),
--
2.9.3
More information about the wayland-devel
mailing list