[PATCH libinput 22/23] test: Add bad-distance-events test

Stephen Chandler Paul thatslyude at gmail.com
Thu Jun 12 20:28:43 PDT 2014


There's a special distance on wacom tablets where the stylus is close enough to
be (sort of) recongnized by the tablet, but not close enough to send any useful
data. When the pen's in this distance, it will send a distance event with the
value absinfo->maximum or absinfo->minimum, but no other events. Since that
gives the caller the false impression that the tablet is actually in useful
proximity of the tablet, we want to make sure we filter out any events like
this.

Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
---
 test/tablet.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/test/tablet.c b/test/tablet.c
index 80a70c8..e503124 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -281,12 +281,54 @@ START_TEST(motion)
 }
 END_TEST
 
+START_TEST(bad_distance_events)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event_tablet *tablet_event;
+	struct libinput_event *event;
+	bool bad_distance_event_received = false,
+	     axis_has_changed;
+	enum libinput_event_type type;
+	const struct input_absinfo *absinfo;
+
+	litest_drain_events(dev->libinput);
+
+	litest_tablet_proximity_out(dev);
+
+	absinfo = libevdev_get_abs_info(dev->evdev, ABS_DISTANCE);
+	ck_assert(absinfo != NULL);
+
+	litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->maximum);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->minimum);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	/* We shouldn't be able to see any of the bad distance events that got
+	 * sent
+	 */
+	while ((event = libinput_get_event(li))) {
+		tablet_event = libinput_event_get_tablet_event(event);
+		type = libinput_event_get_type(event);
+		axis_has_changed = libinput_event_tablet_axis_has_changed(
+		    tablet_event, LIBINPUT_TABLET_AXIS_DISTANCE);
+
+		if (type == LIBINPUT_EVENT_TABLET_AXIS && axis_has_changed)
+			bad_distance_event_received = true;
+
+		libinput_event_destroy(event);
+	}
+	ck_assert(!bad_distance_event_received);
+}
+END_TEST
+
 int
 main(int argc, char **argv)
 {
 	litest_add("tablet:proximity-out-clear-buttons", proximity_out_clear_buttons, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:proximity-in-out", proximity_in_out, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY);
+	litest_add("tablet:bad-distance-events", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY);
 
 	return litest_run(argc, argv);
 }
-- 
1.8.5.5



More information about the wayland-devel mailing list