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