mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 05:50:05 +01:00
test: add wheel tilt tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
4bf8b8934d
commit
dbb376f74b
5 changed files with 111 additions and 3 deletions
|
|
@ -36,6 +36,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 \
|
||||
|
|
|
|||
76
test/litest-device-mouse-wheel-tilt.c
Normal file
76
test/litest-device-mouse-wheel-tilt.c
Normal file
|
|
@ -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,
|
||||
};
|
||||
|
|
@ -406,6 +406,7 @@ 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_acer_hawaii_keyboard_device;
|
||||
extern struct litest_test_device litest_acer_hawaii_touchpad_device;
|
||||
extern struct litest_test_device litest_mouse_wheel_tilt_device;
|
||||
|
||||
struct litest_test_device* devices[] = {
|
||||
&litest_synaptics_clickpad_device,
|
||||
|
|
@ -466,6 +467,7 @@ struct litest_test_device* devices[] = {
|
|||
&litest_calibrated_touchscreen_device,
|
||||
&litest_acer_hawaii_keyboard_device,
|
||||
&litest_acer_hawaii_touchpad_device,
|
||||
&litest_mouse_wheel_tilt_device,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -226,6 +226,7 @@ enum litest_device_type {
|
|||
LITEST_CALIBRATED_TOUCHSCREEN,
|
||||
LITEST_ACER_HAWAII_KEYBOARD,
|
||||
LITEST_ACER_HAWAII_TOUCHPAD,
|
||||
LITEST_MOUSE_WHEEL_TILT,
|
||||
};
|
||||
|
||||
enum litest_device_feature {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue