From 92a7810a2e6a3c36b860a341a2a60aec3f8c8f16 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 11 Jun 2014 21:25:37 -0400 Subject: [PATCH] test: Add test for bad distance events 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 Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/tablet.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 591fa4b8..a4809f89 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -239,11 +239,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); + litest_drain_events(dev->libinput); + + 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", 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); litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY); return litest_run(argc, argv);