test: add protocol A touch screen tests

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Peter Hutterer 2015-02-25 16:30:06 +10:00
parent bb78357f04
commit 72cc601007
7 changed files with 231 additions and 1 deletions

View file

@ -19,6 +19,7 @@ liblitest_la_SOURCES = \
litest-keyboard.c \
litest-mouse.c \
litest-ms-surface-cover.c \
litest-protocol-a-touch-screen.c \
litest-qemu-usb-tablet.c \
litest-synaptics.c \
litest-synaptics-hover.c \

View file

@ -0,0 +1,97 @@
/*
* Copyright © 2015 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include "litest.h"
#include "litest-int.h"
static void
litest_protocol_a_touch_setup(void)
{
struct litest_device *d = litest_create_device(LITEST_PROTOCOL_A_SCREEN);
litest_set_current_device(d);
}
static struct input_event down[] = {
{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_SYN, .code = SYN_MT_REPORT, .value = 0 },
{ .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
static struct input_event move[] = {
{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_SYN, .code = SYN_MT_REPORT, .value = 0 },
{ .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
static struct litest_device_interface interface = {
.touch_down_events = down,
.touch_move_events = move,
};
static struct input_absinfo absinfo[] = {
{ ABS_X, 0, 32767, 0, 0, 0 },
{ ABS_Y, 0, 32767, 0, 0, 0 },
{ ABS_MT_POSITION_X, 0, 32767, 0, 0, 0 },
{ ABS_MT_POSITION_Y, 0, 32767, 0, 0, 0 },
{ ABS_MT_PRESSURE, 0, 1, 0, 0, 0 },
{ .value = -1 },
};
static struct input_id input_id = {
.bustype = 0x18,
.vendor = 0xeef,
.product = 0x20,
};
static int events[] = {
EV_KEY, BTN_TOUCH,
INPUT_PROP_MAX, INPUT_PROP_DIRECT,
-1, -1,
};
struct litest_test_device litest_protocol_a_screen = {
.type = LITEST_PROTOCOL_A_SCREEN,
.features = LITEST_PROTOCOL_A,
.shortname = "protocol A",
.setup = litest_protocol_a_touch_setup,
.interface = &interface,
.name = "Protocol A touch screen",
.id = &input_id,
.events = events,
.absinfo = absinfo,
};

View file

@ -96,6 +96,7 @@ extern struct litest_test_device litest_xen_virtual_pointer_device;
extern struct litest_test_device litest_vmware_virtmouse_device;
extern struct litest_test_device litest_synaptics_hover_device;
extern struct litest_test_device litest_synaptics_carbon3rd_device;
extern struct litest_test_device litest_protocol_a_screen;
struct litest_test_device* devices[] = {
&litest_synaptics_clickpad_device,
@ -113,6 +114,7 @@ struct litest_test_device* devices[] = {
&litest_vmware_virtmouse_device,
&litest_synaptics_hover_device,
&litest_synaptics_carbon3rd_device,
&litest_protocol_a_screen,
NULL,
};

View file

@ -51,6 +51,7 @@ enum litest_device_type {
LITEST_VMWARE_VIRTMOUSE = -15,
LITEST_SYNAPTICS_HOVER_SEMI_MT = -16,
LITEST_SYNAPTICS_TRACKPOINT_BUTTONS = -17,
LITEST_PROTOCOL_A_SCREEN = -18,
};
enum litest_device_feature {
@ -70,6 +71,7 @@ enum litest_device_feature {
LITEST_POINTINGSTICK = 1 << 11,
LITEST_FAKE_MT = 1 << 12,
LITEST_ABSOLUTE = 1 << 13,
LITEST_PROTOCOL_A = 1 << 14,
};
struct litest_device {

View file

@ -826,7 +826,7 @@ int main (int argc, char **argv) {
litest_add("pointer:scroll", pointer_scroll_natural_wheel, LITEST_WHEEL, LITEST_ANY);
litest_add_no_device("pointer:seat button count", pointer_seat_button_count);
litest_add("pointer:calibration", pointer_no_calibration, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_ABSOLUTE);
litest_add("pointer:calibration", pointer_no_calibration, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_ABSOLUTE|LITEST_PROTOCOL_A);
/* tests touchpads too */
litest_add("pointer:left-handed", pointer_left_handed_defaults, LITEST_BUTTON, LITEST_ANY);

View file

@ -465,6 +465,124 @@ START_TEST(fake_mt_no_touch_events)
}
END_TEST
START_TEST(touch_protocol_a_init)
{
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_device *device = dev->libinput_device;
ck_assert_int_ne(libinput_next_event_type(li),
LIBINPUT_EVENT_NONE);
ck_assert(libinput_device_has_capability(device,
LIBINPUT_DEVICE_CAP_TOUCH));
}
END_TEST
START_TEST(touch_protocol_a_touch)
{
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_event *ev;
struct libinput_event_touch *tev;
double x, y, oldx, oldy;
litest_drain_events(li);
litest_touch_down(dev, 0, 5, 95);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_DOWN, -1);
ev = libinput_get_event(li);
tev = libinput_event_get_touch_event(ev);
oldx = libinput_event_touch_get_x(tev);
oldy = libinput_event_touch_get_y(tev);
libinput_event_destroy(ev);
litest_touch_move_to(dev, 0, 10, 90, 90, 10, 20, 1);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_MOTION, -1);
while ((ev = libinput_get_event(li))) {
if (libinput_event_get_type(ev) ==
LIBINPUT_EVENT_TOUCH_FRAME) {
libinput_event_destroy(ev);
continue;
}
ck_assert_int_eq(libinput_event_get_type(ev),
LIBINPUT_EVENT_TOUCH_MOTION);
tev = libinput_event_get_touch_event(ev);
x = libinput_event_touch_get_x(tev);
y = libinput_event_touch_get_y(tev);
ck_assert_int_gt(x, oldx);
ck_assert_int_lt(y, oldy);
oldx = x;
oldy = y;
libinput_event_destroy(ev);
}
litest_touch_up(dev, 0);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_UP, -1);
}
END_TEST
START_TEST(touch_protocol_a_2fg_touch)
{
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_event *ev;
struct libinput_event_touch *tev;
int pos;
litest_drain_events(li);
litest_push_event_frame(dev);
litest_touch_down(dev, 0, 5, 95);
litest_touch_down(dev, 0, 95, 5);
litest_pop_event_frame(dev);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_DOWN, -1);
ev = libinput_get_event(li);
libinput_event_destroy(ev);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_DOWN, -1);
ev = libinput_get_event(li);
libinput_event_destroy(ev);
for (pos = 10; pos < 100; pos += 10) {
litest_push_event_frame(dev);
litest_touch_move_to(dev, 0, pos, 100 - pos, pos, 100 - pos, 1, 1);
litest_touch_move_to(dev, 0, 100 - pos, pos, 100 - pos, pos, 1, 1);
litest_pop_event_frame(dev);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_MOTION, -1);
ev = libinput_get_event(li);
tev = libinput_event_get_touch_event(ev);
ck_assert_int_eq(libinput_event_touch_get_slot(tev),
0);
libinput_event_destroy(ev);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_MOTION, -1);
ev = libinput_get_event(li);
tev = libinput_event_get_touch_event(ev);
ck_assert_int_eq(libinput_event_touch_get_slot(tev),
1);
libinput_event_destroy(ev);
}
litest_event(dev, EV_SYN, SYN_MT_REPORT, 0);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_UP, -1);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_UP, -1);
}
END_TEST
int
main(int argc, char **argv)
{
@ -484,5 +602,9 @@ main(int argc, char **argv)
litest_add("touch:fake-mt", fake_mt_exists, LITEST_FAKE_MT, LITEST_ANY);
litest_add("touch:fake-mt", fake_mt_no_touch_events, LITEST_FAKE_MT, LITEST_ANY);
litest_add("touch:protocol a", touch_protocol_a_init, LITEST_PROTOCOL_A, LITEST_ANY);
litest_add("touch:protocol a", touch_protocol_a_touch, LITEST_PROTOCOL_A, LITEST_ANY);
litest_add("touch:protocol a", touch_protocol_a_2fg_touch, LITEST_PROTOCOL_A, LITEST_ANY);
return litest_run(argc, argv);
}

View file

@ -7,3 +7,9 @@
fun:litest_run
fun:main
}
{
mtdev:conditional_jumps_uninitialized_value
Memcheck:Cond
...
fun:mtdev_put_event
}