diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2017-08-28 09:16:53 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-10-03 18:14:19 +1000 |
commit | ed7ef90534572187ee23a5cb265a40de4d2b0d6c (patch) | |
tree | 56b8d933ad10cc247a437060c3c56390280d59cd | |
parent | 62a9db6ddf0ed73a9c342c05e2e2f5e9e1e61bd2 (diff) |
test: fix pad ring test for small pad ranges
The current tests worked because all rings had the same range, so our error
margin covered for that. With the upcoming MobileStudio Pro 16 pad device, the
range is half and our error margins don't work anymore. Switch to a more
reliable approach that tests every integer value the wheel can send, even
though it relies on kernel filtering.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit e3e6406c4f1026eee128d78c402675e6a473d08b)
-rw-r--r-- | test/test-pad.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/test/test-pad.c b/test/test-pad.c index 5bce7e06..5e4a66f5 100644 --- a/test/test-pad.c +++ b/test/test-pad.c @@ -270,6 +270,9 @@ START_TEST(pad_ring) struct libinput_event_tablet_pad *pev; int val; double degrees, expected; + int min, max; + int step_size; + int nevents = 0; litest_pad_ring_start(dev, 10); @@ -278,11 +281,28 @@ START_TEST(pad_ring) /* Wacom's 0 value is at 275 degrees */ expected = 270; - for (val = 0; val < 100; val += 10) { + min = libevdev_get_abs_minimum(dev->evdev, ABS_WHEEL); + max = libevdev_get_abs_maximum(dev->evdev, ABS_WHEEL); + step_size = 360/(max - min + 1); + + /* This is a bit strange because we rely on kernel filtering here. + The litest_*() functions take a percentage, but mapping this to + the pads 72 or 36 range pad ranges is lossy and a bit + unpredictable. So instead we increase by a small percentage, + expecting *most* events to be filtered by the kernel because they + resolve to the same integer value as the previous event. Whenever + an event gets through, we expect that to be the next integer + value in the range and thus the next step on the circle. + */ + for (val = 0; val < 100.0; val += 1) { litest_pad_ring_change(dev, val); libinput_dispatch(li); ev = libinput_get_event(li); + if (!ev) + continue; + + nevents++; pev = litest_is_pad_ring_event(ev, 0, LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER); @@ -291,15 +311,14 @@ START_TEST(pad_ring) ck_assert_double_ge(degrees, 0.0); ck_assert_double_lt(degrees, 360.0); - /* rounding errors, mostly caused by small physical range */ - ck_assert_double_ge(degrees, expected - 2); - ck_assert_double_le(degrees, expected + 2); + ck_assert_double_eq(degrees, expected); libinput_event_destroy(ev); - - expected = fmod(degrees + 36, 360); + expected = fmod(degrees + step_size, 360); } + ck_assert_int_eq(nevents, 360/step_size - 1); + litest_pad_ring_end(dev); } END_TEST |