[PATCH libinput 4/4] test: add the MS surface touch cover device and fake-mt tests

Peter Hutterer peter.hutterer at who-t.net
Tue Nov 4 20:44:26 PST 2014


In the device description, define the interfaces for touch down/move even
though we technically don't have those interfaces. Makes it easier to test.

The fake-mt tests make sure the device shows up correctly and that no touch
events are being sent for touch events.
This device is a pointer device too, the pointer tests will test it for
correct functionality of the REL_X/Y bits, no special test needed.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/Makefile.am               |   1 +
 test/litest-ms-surface-cover.c | 386 +++++++++++++++++++++++++++++++++++++++++
 test/litest.h                  |   2 +
 test/touch.c                   |  46 +++++
 4 files changed, 435 insertions(+)
 create mode 100644 test/litest-ms-surface-cover.c

diff --git a/test/Makefile.am b/test/Makefile.am
index 6a68982..d932961 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,6 +20,7 @@ liblitest_la_SOURCES = \
 	litest-generic-singletouch.c \
 	litest-keyboard.c \
 	litest-mouse.c \
+	litest-ms-surface-cover.c \
 	litest-synaptics.c \
 	litest-synaptics-st.c \
 	litest-synaptics-t440.c \
diff --git a/test/litest-ms-surface-cover.c b/test/litest-ms-surface-cover.c
new file mode 100644
index 0000000..bd8b1a1
--- /dev/null
+++ b/test/litest-ms-surface-cover.c
@@ -0,0 +1,386 @@
+/*
+ * Copyright © 2014 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_ms_surface_cover_setup(void)
+{
+	struct litest_device *d = litest_create_device(LITEST_MS_SURFACE_COVER);
+	litest_set_current_device(d);
+}
+
+static struct input_event down[] = {
+	{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
+	{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .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_REPORT, .value = 0 },
+	{ .type = -1, .code = -1 },
+};
+
+static struct input_event move[] = {
+	{ .type = EV_ABS, .code = ABS_MT_SLOT, .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_REPORT, .value = 0 },
+	{ .type = -1, .code = -1 },
+};
+
+/* We define down/move so that we can emulate fake touches on this device,
+   to make sure nothing crashes. */
+static struct litest_device_interface interface = {
+	.touch_down_events = down,
+	.touch_move_events = move,
+};
+
+static struct input_absinfo absinfo[] = {
+	{ ABS_VOLUME, 0, 1023, 0, 0, 0 },
+	{ ABS_MISC, 0, 255, 0, 0, 0 },
+	{ 41, 0, 255, 0, 0, 0 },
+	{ 42, -127, 127, 0, 0, 0 },
+	{ 43, -127, 127, 0, 0, 0 },
+	{ 44, -127, 127, 0, 0, 0 },
+	{ 45, -127, 127, 0, 0, 0 },
+	{ 46, -127, 127, 0, 0, 0 },
+	{ 47, -127, 127, 0, 0, 0 },
+	/* ABS_MT range overlap starts here */
+	{ 48, -127, 127, 0, 0, 0 }, /* ABS_MT_SLOT */
+	{ 49, -127, 127, 0, 0, 0 },
+	{ 50, -127, 127, 0, 0, 0 },
+	{ 51, -127, 127, 0, 0, 0 },
+	{ 52, -127, 127, 0, 0, 0 },
+	{ 53, -127, 127, 0, 0, 0 },
+	{ 54, -127, 127, 0, 0, 0 },
+	{ 55, -127, 127, 0, 0, 0 },
+	{ 56, -127, 127, 0, 0, 0 },
+	{ 57, -127, 127, 0, 0, 0 },
+	{ 58, -127, 127, 0, 0, 0 },
+	{ 59, -127, 127, 0, 0, 0 },
+	{ 60, -127, 127, 0, 0, 0 },
+	{ 61, -127, 127, 0, 0, 0 }, /* ABS_MT_TOOL_Y */
+	{ 62, -127, 127, 0, 0, 0 },
+	{ .value = -1 },
+};
+
+static struct input_id input_id = {
+	.bustype = 0x3,
+	.vendor = 0x45e,
+	.product = 0x7a9,
+};
+
+static int events[] = {
+	EV_REL, REL_X,
+	EV_REL, REL_Y,
+	EV_REL, REL_HWHEEL,
+	EV_REL, REL_DIAL,
+	EV_REL, REL_WHEEL,
+	EV_KEY, KEY_ESC,
+	EV_KEY, KEY_1,
+	EV_KEY, KEY_2,
+	EV_KEY, KEY_3,
+	EV_KEY, KEY_4,
+	EV_KEY, KEY_5,
+	EV_KEY, KEY_6,
+	EV_KEY, KEY_7,
+	EV_KEY, KEY_8,
+	EV_KEY, KEY_9,
+	EV_KEY, KEY_0,
+	EV_KEY, KEY_MINUS,
+	EV_KEY, KEY_EQUAL,
+	EV_KEY, KEY_BACKSPACE,
+	EV_KEY, KEY_TAB,
+	E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_NEXT,
+	EV_KEY, KEY_RESTART,
+	EV_KEY, KEY_SLOW,
+	EV_KEY, KEY_SHUFFLE,
+	EV_KEY, KEY_PREVIOUS,
+	EV_KEY, KEY_VIDEOPHONE,
+	EV_KEY, KEY_GAMES,
+	EV_KEY, KEY_ZOOMIN,
+	EV_KEY, KEY_ZOOMOUT,
+	EV_KEY, KEY_ZOOMRESET,
+	EV_KEY, KEY_WORDPROCESSOR,
+	EV_KEY, KEY_EDITOR,
+	EV_KEY, KEY_SPREADSHEET,
+	EV_KEY, KEY_GRAPHICSEDITOR,
+	EV_KEY, KEY_PRESENTATION,
+	EV_KEY, KEY_DATABASE,
+	EV_KEY, KEY_NEWS,
+	EV_KEY, KEY_VOICEMAIL,
+	EV_KEY, KEY_ADDRESSBOOK,
+	EV_KEY, KEY_MESSENGER,
+	EV_KEY, KEY_DISPLAYTOGGLE,
+	EV_KEY, KEY_SPELLCHECK,
+	EV_KEY, KEY_LOGOFF,
+	EV_KEY, KEY_MEDIA_REPEAT,
+	EV_KEY, KEY_IMAGES,
+	EV_KEY, 576,
+	EV_KEY, 577,
+	EV_KEY, 578,
+	EV_KEY, 579,
+	EV_KEY, 580,
+	EV_KEY, 581,
+	EV_KEY, 582,
+	EV_KEY, 592,
+	EV_KEY, 593,
+	EV_KEY, 608,
+	EV_KEY, 609,
+	EV_KEY, 610,
+	EV_KEY, 611,
+	EV_KEY, 612,
+	EV_KEY, 613,
+	EV_LED, LED_NUML,
+	EV_LED, LED_CAPSL,
+	EV_LED, LED_SCROLLL,
+	EV_REP, REP_DELAY,
+	-1, -1,
+};
+
+struct litest_test_device litest_ms_surface_cover_device = {
+	.type = LITEST_MS_SURFACE_COVER,
+	.features = LITEST_KEYBOARD | LITEST_POINTER | LITEST_FAKE_MT,
+	.shortname = "MS surface cover",
+	.setup = litest_ms_surface_cover_setup,
+	.interface = &interface,
+
+	.name = "MICROSOFT SAM",
+	.id = &input_id,
+	.events = events,
+	.absinfo = absinfo,
+};
diff --git a/test/litest.h b/test/litest.h
index 26b3040..11de7cc 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -45,6 +45,7 @@ enum litest_device_type {
 	LITEST_WACOM_TOUCH = -9,
 	LITEST_ALPS_SEMI_MT = -10,
 	LITEST_GENERIC_SINGLETOUCH = -11,
+	LITEST_MS_SURFACE_COVER = -12,
 };
 
 enum litest_device_feature {
@@ -62,6 +63,7 @@ enum litest_device_feature {
 	LITEST_TOPBUTTONPAD = 1 << 9,
 	LITEST_SEMI_MT = 1 << 10,
 	LITEST_POINTINGSTICK = 1 << 11,
+	LITEST_FAKE_MT = 1 << 12,
 };
 
 struct litest_device {
diff --git a/test/touch.c b/test/touch.c
index e51b85e..168e2aa 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -422,6 +422,49 @@ START_TEST(touch_no_left_handed)
 }
 END_TEST
 
+START_TEST(fake_mt_exists)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_device *device;
+
+	litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1);
+	event = libinput_get_event(li);
+	device = libinput_event_get_device(event);
+
+	ck_assert(!libinput_device_has_capability(device,
+						  LIBINPUT_DEVICE_CAP_TOUCH));
+
+	/* This test may need fixing if we add other fake-mt devices that
+	 * have different capabilities */
+	ck_assert(libinput_device_has_capability(device,
+						 LIBINPUT_DEVICE_CAP_POINTER));
+}
+END_TEST
+
+START_TEST(fake_mt_no_touch_events)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_move_to(dev, 0, 50, 50, 70, 70, 5);
+	litest_touch_up(dev, 0);
+
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_down(dev, 1, 70, 70);
+	litest_touch_move_to(dev, 0, 50, 50, 90, 40, 10);
+	litest_touch_move_to(dev, 0, 70, 70, 40, 50, 10);
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
 int
 main(int argc, char **argv)
 {
@@ -438,5 +481,8 @@ main(int argc, char **argv)
 
 	litest_add("touch:left-handed", touch_no_left_handed, LITEST_TOUCH, LITEST_ANY);
 
+	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);
+
 	return litest_run(argc, argv);
 }
-- 
2.1.0



More information about the wayland-devel mailing list