summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2022-02-09 10:25:07 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2022-02-22 07:39:28 +1000
commit8a01c35b4cb8f86c996ab63baa589a3841449a11 (patch)
tree6b2dcca3ba025f8de3475525f879ea80f20fa3b5 /test
parent858bb568716f19fd3973088a2af237904584fea9 (diff)
downloadxf86-input-wacom-8a01c35b4cb8f86c996ab63baa589a3841449a11.tar.gz
test: add a test for the relative motion issue
Diffstat (limited to 'test')
-rw-r--r--test/test_wacom.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/test_wacom.py b/test/test_wacom.py
index 4274a5c..57942d3 100644
--- a/test/test_wacom.py
+++ b/test/test_wacom.py
@@ -70,3 +70,77 @@ def test_proximity(mainloop, opts):
assert isinstance(monitor.events[-1], Proximity)
assert not monitor.events[-1].is_prox_in
+
+
+@pytest.mark.parametrize("rotate", ["NONE", "CW", "CCW", "HALF"])
+def test_relative_motion(mainloop, opts, rotate):
+ """
+ Check relative motion works in the various rotations
+ """
+ opts["Mode"] = "Relative"
+ opts["Rotate"] = rotate
+ dev = Device.from_name("PTH660", "Pen")
+ monitor = Monitor.new_from_device(dev, opts)
+
+ prox_in = [
+ Sev("ABS_X", 50),
+ Sev("ABS_Y", 50),
+ Sev("BTN_TOOL_PEN", 1),
+ Sev("SYN_REPORT", 0),
+ ]
+
+ # Physical pen motion is center towards bottom right
+ motions = []
+ for i in range(20):
+ motions.extend(
+ [
+ Sev("ABS_X", 50 + i),
+ Sev("ABS_Y", 50 + i),
+ Sev("SYN_REPORT", 0),
+ ]
+ )
+
+ prox_out = [
+ Sev("ABS_X", 50),
+ Sev("ABS_Y", 50),
+ Sev("BTN_TOOL_PEN", 0),
+ Sev("SYN_REPORT", 0),
+ ]
+ monitor.write_events(prox_in)
+ monitor.write_events(motions)
+ monitor.write_events(prox_out)
+ mainloop.run()
+
+ # Now collect the events
+ xs = [e.axes.x for e in monitor.events]
+ ys = [e.axes.y for e in monitor.events]
+
+ print(f"Collected events: {list(zip(xs, ys))}")
+
+ # We're in relative mode, so we expect the first and last event (the
+ # proximity ones) to be 0/0
+ assert xs[0] == 0
+ assert ys[0] == 0
+ assert xs[-1] == 0
+ assert ys[-1] == 0
+
+ # There's some motion adjustment, so we skip the first five events, the
+ # rest should be exactly the same
+ motions = list(zip(xs[5:-1], ys[5:-1]))
+
+ print(f"Motion events to analyze: {motions}")
+
+ # WARNING: the CW and CCW rotation seems swapped but that's what the
+ # driver does atm
+ if rotate == "NONE":
+ assert all([x > 0 and y > 0 for x, y in motions])
+ elif rotate == "HALF":
+ assert all([x < 0 and y < 0 for x, y in motions])
+ elif rotate == "CCW":
+ assert all([x < 0 and y > 0 for x, y in motions])
+ elif rotate == "CW":
+ assert all([x > 0 and y < 0 for x, y in motions])
+ else:
+ pytest.fail("Invalid rotation mode")
+
+ assert all([m == motions[0] for m in motions])