[PATCH libinput v2 10/11] test: Add litest_button_scroll helper function

Hans de Goede hdegoede at redhat.com
Mon Nov 10 02:59:21 PST 2014


Turn test_trackpoint_scroll into a generic helper function for testing
"button scrolling".

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 test/litest.c     | 34 ++++++++++++++++++++++++++++++++++
 test/litest.h     |  4 ++++
 test/trackpoint.c | 40 +++++++---------------------------------
 3 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/test/litest.c b/test/litest.c
index c64e665..fa5fb36 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -792,6 +792,34 @@ litest_button_click(struct litest_device *d, unsigned int button, bool is_press)
 }
 
 void
+litest_button_scroll(struct litest_device *dev,
+		     unsigned int button,
+		     double dx, double dy)
+{
+	struct libinput *li = dev->libinput;
+
+	litest_button_click(dev, button, 1);
+
+	libinput_dispatch(li);
+	litest_timeout_buttonscroll();
+	libinput_dispatch(li);
+
+	/* Send two deltas, as the first one may be eaten up by an
+	 * acceleration filter. */
+	litest_event(dev, EV_REL, REL_X, dx);
+	litest_event(dev, EV_REL, REL_Y, dy);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	litest_event(dev, EV_REL, REL_X, dx);
+	litest_event(dev, EV_REL, REL_Y, dy);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	litest_button_click(dev, button, 0);
+
+	libinput_dispatch(li);
+}
+
+void
 litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press)
 {
 	litest_button_click(d, key, is_press);
@@ -1151,6 +1179,12 @@ litest_timeout_softbuttons(void)
 }
 
 void
+litest_timeout_buttonscroll(void)
+{
+	msleep(300);
+}
+
+void
 litest_push_event_frame(struct litest_device *dev)
 {
 	assert(!dev->skip_ev_syn);
diff --git a/test/litest.h b/test/litest.h
index 5b0478b..78b4d51 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -142,6 +142,9 @@ void litest_touch_move_to(struct litest_device *d,
 void litest_button_click(struct litest_device *d,
 			 unsigned int button,
 			 bool is_press);
+void litest_button_scroll(struct litest_device *d,
+			 unsigned int button,
+			 double dx, double dy);
 void litest_keyboard_key(struct litest_device *d,
 			 unsigned int key,
 			 bool is_press);
@@ -166,6 +169,7 @@ struct libevdev_uinput * litest_create_uinput_abs_device(const char *name,
 
 void litest_timeout_tap(void);
 void litest_timeout_softbuttons(void);
+void litest_timeout_buttonscroll(void);
 
 void litest_push_event_frame(struct litest_device *dev);
 void litest_pop_event_frame(struct litest_device *dev);
diff --git a/test/trackpoint.c b/test/trackpoint.c
index 2e2caba..3d965d4 100644
--- a/test/trackpoint.c
+++ b/test/trackpoint.c
@@ -49,32 +49,6 @@ START_TEST(trackpoint_middlebutton)
 }
 END_TEST
 
-static void
-test_trackpoint_scroll(struct litest_device *dev, double dx, double dy)
-{
-	struct libinput *li = dev->libinput;
-
-	litest_button_click(dev, BTN_MIDDLE, 1);
-
-	libinput_dispatch(li);
-	msleep(300);
-	libinput_dispatch(li);
-
-	/* Send two deltas, as the first one may be eaten up by an
-	 * acceleration filter. */
-	litest_event(dev, EV_REL, REL_X, dx);
-	litest_event(dev, EV_REL, REL_Y, dy);
-	litest_event(dev, EV_SYN, SYN_REPORT, 0);
-
-	litest_event(dev, EV_REL, REL_X, dx);
-	litest_event(dev, EV_REL, REL_Y, dy);
-	litest_event(dev, EV_SYN, SYN_REPORT, 0);
-
-	litest_button_click(dev, BTN_MIDDLE, 0);
-
-	libinput_dispatch(li);
-}
-
 START_TEST(trackpoint_scroll)
 {
 	struct litest_device *dev = litest_current_device();
@@ -82,19 +56,19 @@ START_TEST(trackpoint_scroll)
 
 	litest_drain_events(li);
 
-	test_trackpoint_scroll(dev, 1, 6);
+	litest_button_scroll(dev, BTN_MIDDLE, 1, 6);
 	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6);
-	test_trackpoint_scroll(dev, 1, -7);
+	litest_button_scroll(dev, BTN_MIDDLE, 1, -7);
 	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7);
-	test_trackpoint_scroll(dev, 8, 1);
+	litest_button_scroll(dev, BTN_MIDDLE, 8, 1);
 	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8);
-	test_trackpoint_scroll(dev, -9, 1);
+	litest_button_scroll(dev, BTN_MIDDLE, -9, 1);
 	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9);
 
 	/* scroll smaller than the threshold should not generate events */
-	test_trackpoint_scroll(dev, 1, 1);
+	litest_button_scroll(dev, BTN_MIDDLE, 1, 1);
 	/* long middle press without movement should not generate events */
-	test_trackpoint_scroll(dev, 0, 0);
+	litest_button_scroll(dev, BTN_MIDDLE, 0, 0);
 
 	litest_assert_empty_queue(li);
 }
@@ -113,7 +87,7 @@ START_TEST(trackpoint_middlebutton_noscroll)
 	litest_drain_events(li);
 
 	/* A long middle button click + motion should get reported normally now */
-	test_trackpoint_scroll(dev, 0, 10);
+	litest_button_scroll(dev, BTN_MIDDLE, 0, 10);
 
 	litest_assert_button_event(li, BTN_MIDDLE, 1);
 
-- 
2.1.0



More information about the wayland-devel mailing list