[PATCH libinput 21/23] test: Add motion event test for tablets

Stephen Chandler Paul thatslyude at gmail.com
Thu Jun 12 20:28:42 PDT 2014


Based off the patch originally written by Carlos Garnacho

Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
---
 test/tablet.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/test/tablet.c b/test/tablet.c
index 9c5397f..80a70c8 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -130,7 +130,8 @@ START_TEST(proximity_in_out)
 				int has_changed;
 				double value;
 
-				has_changed = libinput_event_tablet_axis_has_changed(
+				has_changed =
+				libinput_event_tablet_axis_has_changed(
 				    tablet_event, a);
 				value = libinput_event_tablet_get_axis_value(
 				    tablet_event, a);
@@ -219,11 +220,73 @@ START_TEST(proximity_out_clear_buttons)
 }
 END_TEST
 
+START_TEST(motion)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event_tablet *tablet_event;
+	struct libinput_event *event;
+	double x1, x2, y1, y2;
+	bool have_motion = false;
+	enum libinput_event_type type;
+	struct axis_replacement axes[] = {
+		{ ABS_DISTANCE, 10 },
+		{ -1, -1 }
+	};
+
+	litest_drain_events(dev->libinput);
+
+	litest_tablet_proximity_in(dev, 10, 10, axes);
+	libinput_dispatch(li);
+
+	while ((event = libinput_get_event(li))) {
+		tablet_event = libinput_event_get_tablet_event(event);
+		type = libinput_event_get_type(event);
+
+		if (type == LIBINPUT_EVENT_TABLET_AXIS &&
+		    libinput_event_tablet_axis_has_changed(tablet_event,
+							   LIBINPUT_TABLET_AXIS_X) &&
+		    libinput_event_tablet_axis_has_changed(tablet_event,
+							   LIBINPUT_TABLET_AXIS_Y)) {
+			x1 = libinput_event_tablet_get_axis_value(
+			    tablet_event, LIBINPUT_TABLET_AXIS_X);
+			y1 = libinput_event_tablet_get_axis_value(
+			    tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+			have_motion = true;
+		}
+
+		libinput_event_destroy(event);
+	}
+	ck_assert(have_motion);
+
+	litest_tablet_motion(dev, 20, 20, axes);
+	libinput_dispatch(li);
+
+	while ((event = libinput_get_event(li))) {
+		tablet_event = libinput_event_get_tablet_event(event);
+		type = libinput_event_get_type(event);
+
+		if (type == LIBINPUT_EVENT_TABLET_AXIS) {
+			x2 = libinput_event_tablet_get_axis_value(
+			    tablet_event, LIBINPUT_TABLET_AXIS_X);
+			y2 = libinput_event_tablet_get_axis_value(
+			    tablet_event, LIBINPUT_TABLET_AXIS_Y);
+		}
+
+		libinput_event_destroy(event);
+	}
+	litest_assert_double_lt(x1, x2);
+	litest_assert_double_lt(y1, y2);
+}
+END_TEST
+
 int
 main(int argc, char **argv)
 {
 	litest_add("tablet:proximity-out-clear-buttons", proximity_out_clear_buttons, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:proximity-in-out", proximity_in_out, LITEST_TABLET, LITEST_ANY);
+	litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY);
 
 	return litest_run(argc, argv);
 }
-- 
1.8.5.5



More information about the wayland-devel mailing list