[PATCH libinput 4/4] test: Add tests for serial numbers on tools

Stephen Chandler Paul thatslyude at gmail.com
Wed Jun 18 22:18:09 PDT 2014


These tests make sure that any tablets with the capability to report a tool's
serial number do so properly, that the tool changes when another tool of the
same type with a different serial number is used, and that libinput doesn't
change the current tool when -1 is reported as the serial number (-1 is used for
special purposes by the linuxwacom driver).

Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
---
 test/litest-wacom-cintiq-tablet.c |   2 +-
 test/litest-wacom-intuos-tablet.c |   2 +-
 test/litest.h                     |   1 +
 test/tablet.c                     | 113 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 116 insertions(+), 2 deletions(-)

diff --git a/test/litest-wacom-cintiq-tablet.c b/test/litest-wacom-cintiq-tablet.c
index 93cd2a8..0217f56 100644
--- a/test/litest-wacom-cintiq-tablet.c
+++ b/test/litest-wacom-cintiq-tablet.c
@@ -125,7 +125,7 @@ static int events[] = {
 
 struct litest_test_device litest_wacom_cintiq_tablet_device = {
 	.type = LITEST_WACOM_CINTIQ,
-	.features = LITEST_TABLET | LITEST_DISTANCE,
+	.features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL,
 	.shortname = "wacom-cintiq-tablet",
 	.setup = litest_wacom_cintiq_tablet_setup,
 	.interface = &interface,
diff --git a/test/litest-wacom-intuos-tablet.c b/test/litest-wacom-intuos-tablet.c
index 0cbb632..e30d606 100644
--- a/test/litest-wacom-intuos-tablet.c
+++ b/test/litest-wacom-intuos-tablet.c
@@ -123,7 +123,7 @@ static int events[] = {
 
 struct litest_test_device litest_wacom_intuos_tablet_device = {
 	.type = LITEST_WACOM_INTUOS,
-	.features = LITEST_TABLET | LITEST_DISTANCE,
+	.features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL,
 	.shortname = "wacom-intuos-tablet",
 	.setup = litest_wacom_intuos_tablet_setup,
 	.interface = &interface,
diff --git a/test/litest.h b/test/litest.h
index 5904805..9e159a3 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -64,6 +64,7 @@ enum litest_device_feature {
 	LITEST_TOPBUTTONPAD = 1 << 9,
 	LITEST_TABLET = 1 << 10,
 	LITEST_DISTANCE = 1 << 11,
+	LITEST_TOOL_SERIAL = 1 << 12,
 };
 
 struct litest_device {
diff --git a/test/tablet.c b/test/tablet.c
index 1121914..3bfbb6a 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -427,9 +427,122 @@ START_TEST(normalization)
 }
 END_TEST
 
+START_TEST(tool_serial)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event_tablet *tablet_event;
+	struct libinput_event *event;
+	struct libinput_tool *tool;
+
+	litest_drain_events(li);
+
+	litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+	litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li))) {
+		if (libinput_event_get_type(event) ==
+		    LIBINPUT_EVENT_TABLET_TOOL_UPDATE) {
+			tablet_event = libinput_event_get_tablet_event(event);
+			tool = libinput_event_tablet_get_tool(tablet_event);
+
+			ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000);
+		}
+
+		libinput_event_destroy(event);
+	}
+}
+END_TEST
+
+START_TEST(serial_changes_tool)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event_tablet *tablet_event;
+	struct libinput_event *event;
+	struct libinput_tool *tool;
+	bool tool_updated = false;
+
+	litest_drain_events(li);
+
+	litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+	litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	litest_drain_events(li);
+
+	litest_event(dev, EV_MSC, MSC_SERIAL, 2000);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li))) {
+		if (libinput_event_get_type(event) ==
+		    LIBINPUT_EVENT_TABLET_TOOL_UPDATE) {
+			tablet_event = libinput_event_get_tablet_event(event);
+			tool = libinput_event_tablet_get_tool(tablet_event);
+
+			ck_assert_uint_eq(libinput_tool_get_serial(tool), 2000);
+			tool_updated = true;
+		}
+
+		libinput_event_destroy(event);
+	}
+	ck_assert(tool_updated);
+}
+END_TEST
+
+START_TEST(invalid_serials)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	bool tool_updated = false;
+
+	litest_drain_events(li);
+
+	litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+	litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_drain_events(li);
+
+	litest_event(dev, EV_MSC, MSC_SERIAL, -1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li))) {
+		if (libinput_event_get_type(event) ==
+		    LIBINPUT_EVENT_TABLET_TOOL_UPDATE)
+			tool_updated = true;
+
+		libinput_event_destroy(event);
+	}
+	ck_assert(!tool_updated);
+
+	/* Make sure libinput doesn't report a tool update when the serial
+	 * number goes back from -1 to what it was previously */
+	litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li))) {
+		if (libinput_event_get_type(event) ==
+		    LIBINPUT_EVENT_TABLET_TOOL_UPDATE)
+			tool_updated = true;
+
+		libinput_event_destroy(event);
+	}
+	ck_assert(!tool_updated);
+}
+END_TEST
+
 int
 main(int argc, char **argv)
 {
+	litest_add("tablet:tool_serial", tool_serial, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY);
+	litest_add("tablet:tool_serial", serial_changes_tool, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY);
+	litest_add("tablet:tool_serial", invalid_serials, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY);
 	litest_add("tablet:proximity", proximity_out_clear_buttons, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:proximity", proximity_in_out, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:proximity", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY);
-- 
1.8.5.5



More information about the wayland-devel mailing list