summaryrefslogtreecommitdiff
path: root/test/test-pad.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2017-08-28 09:16:53 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2017-08-28 09:19:54 +1000
commite3e6406c4f1026eee128d78c402675e6a473d08b (patch)
tree5cabd659cede9a385d6699435c964809cd5c1dd5 /test/test-pad.c
parent00272cfbb1e34c9179539fb4f874acfa4faf5ad6 (diff)
downloadlibinput-e3e6406c4f1026eee128d78c402675e6a473d08b.tar.gz
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>
Diffstat (limited to 'test/test-pad.c')
-rw-r--r--test/test-pad.c31
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