[PATCH libinput 2/2] test: add protocol A touch screen tests

Peter Hutterer peter.hutterer at who-t.net
Tue Feb 24 23:37:26 PST 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/Makefile.am                      |   1 +
 test/litest-protocol-a-touch-screen.c |  97 +++++++++++++++++++++++++++
 test/litest.c                         |   2 +
 test/litest.h                         |   2 +
 test/pointer.c                        |   2 +-
 test/touch.c                          | 122 ++++++++++++++++++++++++++++++++++
 test/valgrind.suppressions            |   6 ++
 7 files changed, 231 insertions(+), 1 deletion(-)
 create mode 100644 test/litest-protocol-a-touch-screen.c

diff --git a/test/Makefile.am b/test/Makefile.am
index 5743ca4..4bafe98 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -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 \
diff --git a/test/litest-protocol-a-touch-screen.c b/test/litest-protocol-a-touch-screen.c
new file mode 100644
index 0000000..2c93006
--- /dev/null
+++ b/test/litest-protocol-a-touch-screen.c
@@ -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,
+};
diff --git a/test/litest.c b/test/litest.c
index 16d9239..30f390a 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -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,
 };
 
diff --git a/test/litest.h b/test/litest.h
index 60ec458..c768cb0 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -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 {
diff --git a/test/pointer.c b/test/pointer.c
index 24ea726..23bf0d7 100644
--- a/test/pointer.c
+++ b/test/pointer.c
@@ -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);
diff --git a/test/touch.c b/test/touch.c
index 29890a4..2d918b2 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -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);
 }
diff --git a/test/valgrind.suppressions b/test/valgrind.suppressions
index 3ba7f29..5aef8a4 100644
--- a/test/valgrind.suppressions
+++ b/test/valgrind.suppressions
@@ -7,3 +7,9 @@
    fun:litest_run
    fun:main
 }
+{
+   mtdev:conditional_jumps_uninitialized_value
+   Memcheck:Cond
+   ...
+   fun:mtdev_put_event
+}
-- 
2.1.0



More information about the wayland-devel mailing list