[PATCH libinput 3/3] test: switch the touchpad multitap tests over to ranged tests

Peter Hutterer peter.hutterer at who-t.net
Tue May 5 17:17:08 PDT 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/touchpad.c | 396 +++++++++++++++++++++++++++-----------------------------
 1 file changed, 194 insertions(+), 202 deletions(-)

diff --git a/test/touchpad.c b/test/touchpad.c
index 576b2bd..96f1799 100644
--- a/test/touchpad.c
+++ b/test/touchpad.c
@@ -189,46 +189,44 @@ START_TEST(touchpad_1fg_multitap)
 	struct libinput_event_pointer *ptrev;
 	uint32_t oldtime = 0,
 		 curtime;
-	int i, ntaps;
+	int range = _i, /* looped test */
+	    ntaps;
 
 	libinput_device_config_tap_set_enabled(dev->libinput_device,
 					       LIBINPUT_CONFIG_TAP_ENABLED);
 
 	litest_drain_events(li);
 
-	for (i = 3; i < 8; i++) {
-
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			litest_touch_down(dev, 0, 50, 50);
-			litest_touch_up(dev, 0);
-			libinput_dispatch(li);
-			msleep(10);
-		}
-
-		litest_timeout_tap();
+	for (ntaps = 0; ntaps <= range; ntaps++) {
+		litest_touch_down(dev, 0, 50, 50);
+		litest_touch_up(dev, 0);
 		libinput_dispatch(li);
+		msleep(10);
+	}
+
+	litest_timeout_tap();
+	libinput_dispatch(li);
 
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_PRESSED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_gt(curtime, oldtime);
+	for (ntaps = 0; ntaps <= range; ntaps++) {
+		event = libinput_get_event(li);
+		ptrev = litest_is_button_event(event,
+					       BTN_LEFT,
+					       LIBINPUT_BUTTON_STATE_PRESSED);
+		curtime = libinput_event_pointer_get_time(ptrev);
+		libinput_event_destroy(event);
+		ck_assert_int_gt(curtime, oldtime);
 
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_RELEASED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_ge(curtime, oldtime);
-			oldtime = curtime;
-		}
-		litest_timeout_tap();
-		litest_assert_empty_queue(li);
+		event = libinput_get_event(li);
+		ptrev = litest_is_button_event(event,
+					       BTN_LEFT,
+					       LIBINPUT_BUTTON_STATE_RELEASED);
+		curtime = libinput_event_pointer_get_time(ptrev);
+		libinput_event_destroy(event);
+		ck_assert_int_ge(curtime, oldtime);
+		oldtime = curtime;
 	}
+	litest_timeout_tap();
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
@@ -240,46 +238,27 @@ START_TEST(touchpad_1fg_multitap_n_drag_move)
 	struct libinput_event_pointer *ptrev;
 	uint32_t oldtime = 0,
 		 curtime;
-	int i, ntaps;
+	int range = _i, /* looped test */
+	    ntaps;
 
 	libinput_device_config_tap_set_enabled(dev->libinput_device,
 					       LIBINPUT_CONFIG_TAP_ENABLED);
 
 	litest_drain_events(li);
 
-	for (i = 3; i < 8; i++) {
-
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			litest_touch_down(dev, 0, 50, 50);
-			litest_touch_up(dev, 0);
-			libinput_dispatch(li);
-			msleep(10);
-		}
-
-		libinput_dispatch(li);
+	for (ntaps = 0; ntaps <= range; ntaps++) {
 		litest_touch_down(dev, 0, 50, 50);
-		litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10, 4);
+		litest_touch_up(dev, 0);
 		libinput_dispatch(li);
+		msleep(10);
+	}
 
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_PRESSED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_gt(curtime, oldtime);
-
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_RELEASED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_ge(curtime, oldtime);
-			oldtime = curtime;
-		}
+	libinput_dispatch(li);
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10, 4);
+	libinput_dispatch(li);
 
+	for (ntaps = 0; ntaps <= range; ntaps++) {
 		event = libinput_get_event(li);
 		ptrev = litest_is_button_event(event,
 					       BTN_LEFT,
@@ -288,16 +267,33 @@ START_TEST(touchpad_1fg_multitap_n_drag_move)
 		libinput_event_destroy(event);
 		ck_assert_int_gt(curtime, oldtime);
 
-		litest_assert_only_typed_events(li,
-						LIBINPUT_EVENT_POINTER_MOTION);
-
-		litest_touch_up(dev, 0);
-		litest_assert_button_event(li,
-					   BTN_LEFT,
-					   LIBINPUT_BUTTON_STATE_RELEASED);
-
-		litest_assert_empty_queue(li);
+		event = libinput_get_event(li);
+		ptrev = litest_is_button_event(event,
+					       BTN_LEFT,
+					       LIBINPUT_BUTTON_STATE_RELEASED);
+		curtime = libinput_event_pointer_get_time(ptrev);
+		libinput_event_destroy(event);
+		ck_assert_int_ge(curtime, oldtime);
+		oldtime = curtime;
 	}
+
+	event = libinput_get_event(li);
+	ptrev = litest_is_button_event(event,
+				       BTN_LEFT,
+				       LIBINPUT_BUTTON_STATE_PRESSED);
+	curtime = libinput_event_pointer_get_time(ptrev);
+	libinput_event_destroy(event);
+	ck_assert_int_gt(curtime, oldtime);
+
+	litest_assert_only_typed_events(li,
+					LIBINPUT_EVENT_POINTER_MOTION);
+
+	litest_touch_up(dev, 0);
+	litest_assert_button_event(li,
+				   BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_RELEASED);
+
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
@@ -309,47 +305,28 @@ START_TEST(touchpad_1fg_multitap_n_drag_2fg)
 	struct libinput_event_pointer *ptrev;
 	uint32_t oldtime = 0,
 		 curtime;
-	int i, ntaps;
+	int range = _i,
+	    ntaps;
 
 	libinput_device_config_tap_set_enabled(dev->libinput_device,
 					       LIBINPUT_CONFIG_TAP_ENABLED);
 
 	litest_drain_events(li);
 
-	for (i = 3; i < 8; i++) {
-
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			litest_touch_down(dev, 0, 50, 50);
-			litest_touch_up(dev, 0);
-			libinput_dispatch(li);
-			msleep(10);
-		}
-
-		libinput_dispatch(li);
+	for (ntaps = 0; ntaps <= range; ntaps++) {
 		litest_touch_down(dev, 0, 50, 50);
+		litest_touch_up(dev, 0);
+		libinput_dispatch(li);
 		msleep(10);
-		litest_touch_down(dev, 1, 70, 50);
-		libinput_dispatch(li);
+	}
 
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_PRESSED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_gt(curtime, oldtime);
-
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_RELEASED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_ge(curtime, oldtime);
-			oldtime = curtime;
-		}
+	libinput_dispatch(li);
+	litest_touch_down(dev, 0, 50, 50);
+	msleep(10);
+	litest_touch_down(dev, 1, 70, 50);
+	libinput_dispatch(li);
 
+	for (ntaps = 0; ntaps <= range; ntaps++) {
 		event = libinput_get_event(li);
 		ptrev = litest_is_button_event(event,
 					       BTN_LEFT,
@@ -358,20 +335,37 @@ START_TEST(touchpad_1fg_multitap_n_drag_2fg)
 		libinput_event_destroy(event);
 		ck_assert_int_gt(curtime, oldtime);
 
-		litest_touch_move_to(dev, 1, 70, 50, 90, 50, 10, 4);
-
-		litest_assert_only_typed_events(li,
-						LIBINPUT_EVENT_POINTER_MOTION);
-
-		litest_touch_up(dev, 1);
-		litest_touch_up(dev, 0);
-		litest_timeout_tap();
-		litest_assert_button_event(li,
-					   BTN_LEFT,
-					   LIBINPUT_BUTTON_STATE_RELEASED);
-
-		litest_assert_empty_queue(li);
+		event = libinput_get_event(li);
+		ptrev = litest_is_button_event(event,
+					       BTN_LEFT,
+					       LIBINPUT_BUTTON_STATE_RELEASED);
+		curtime = libinput_event_pointer_get_time(ptrev);
+		libinput_event_destroy(event);
+		ck_assert_int_ge(curtime, oldtime);
+		oldtime = curtime;
 	}
+
+	event = libinput_get_event(li);
+	ptrev = litest_is_button_event(event,
+				       BTN_LEFT,
+				       LIBINPUT_BUTTON_STATE_PRESSED);
+	curtime = libinput_event_pointer_get_time(ptrev);
+	libinput_event_destroy(event);
+	ck_assert_int_gt(curtime, oldtime);
+
+	litest_touch_move_to(dev, 1, 70, 50, 90, 50, 10, 4);
+
+	litest_assert_only_typed_events(li,
+					LIBINPUT_EVENT_POINTER_MOTION);
+
+	litest_touch_up(dev, 1);
+	litest_touch_up(dev, 0);
+	litest_timeout_tap();
+	litest_assert_button_event(li,
+				   BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_RELEASED);
+
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
@@ -383,58 +377,56 @@ START_TEST(touchpad_1fg_multitap_n_drag_click)
 	struct libinput_event_pointer *ptrev;
 	uint32_t oldtime = 0,
 		 curtime;
-	int i, ntaps;
+	int range = _i, /* looped test */
+	    ntaps;
 
 	libinput_device_config_tap_set_enabled(dev->libinput_device,
 					       LIBINPUT_CONFIG_TAP_ENABLED);
 
 	litest_drain_events(li);
 
-	for (i = 3; i < 5; i++) {
-
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			litest_touch_down(dev, 0, 50, 50);
-			litest_touch_up(dev, 0);
-			libinput_dispatch(li);
-			msleep(10);
-		}
-
+	for (ntaps = 0; ntaps <= range; ntaps++) {
 		litest_touch_down(dev, 0, 50, 50);
-		libinput_dispatch(li);
-		litest_button_click(dev, BTN_LEFT, true);
-		litest_button_click(dev, BTN_LEFT, false);
-		libinput_dispatch(li);
-
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_PRESSED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_gt(curtime, oldtime);
-
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_RELEASED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_ge(curtime, oldtime);
-			oldtime = curtime;
-		}
-
-		litest_assert_button_event(li,
-					   BTN_LEFT,
-					   LIBINPUT_BUTTON_STATE_PRESSED);
-		litest_assert_button_event(li,
-					   BTN_LEFT,
-					   LIBINPUT_BUTTON_STATE_RELEASED);
 		litest_touch_up(dev, 0);
-		litest_timeout_tap();
+		libinput_dispatch(li);
+		msleep(10);
+	}
+
+	litest_touch_down(dev, 0, 50, 50);
+	libinput_dispatch(li);
+	litest_button_click(dev, BTN_LEFT, true);
+	litest_button_click(dev, BTN_LEFT, false);
+	libinput_dispatch(li);
+
+	for (ntaps = 0; ntaps <= range; ntaps++) {
+		event = libinput_get_event(li);
+		ptrev = litest_is_button_event(event,
+					       BTN_LEFT,
+					       LIBINPUT_BUTTON_STATE_PRESSED);
+		curtime = libinput_event_pointer_get_time(ptrev);
+		libinput_event_destroy(event);
+		ck_assert_int_gt(curtime, oldtime);
 
-		litest_assert_empty_queue(li);
+		event = libinput_get_event(li);
+		ptrev = litest_is_button_event(event,
+					       BTN_LEFT,
+					       LIBINPUT_BUTTON_STATE_RELEASED);
+		curtime = libinput_event_pointer_get_time(ptrev);
+		libinput_event_destroy(event);
+		ck_assert_int_ge(curtime, oldtime);
+		oldtime = curtime;
 	}
+
+	litest_assert_button_event(li,
+				   BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_PRESSED);
+	litest_assert_button_event(li,
+				   BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_RELEASED);
+	litest_touch_up(dev, 0);
+	litest_timeout_tap();
+
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
@@ -446,48 +438,29 @@ START_TEST(touchpad_1fg_multitap_n_drag_timeout)
 	struct libinput_event_pointer *ptrev;
 	uint32_t oldtime = 0,
 		 curtime;
-	int i, ntaps;
+	int range = _i, /* looped test */
+	    ntaps;
 
 	libinput_device_config_tap_set_enabled(dev->libinput_device,
 					       LIBINPUT_CONFIG_TAP_ENABLED);
 
 	litest_drain_events(li);
 
-	for (i = 3; i < 5; i++) {
-
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			litest_touch_down(dev, 0, 50, 50);
-			litest_touch_up(dev, 0);
-			libinput_dispatch(li);
-			msleep(10);
-		}
-
-		libinput_dispatch(li);
+	for (ntaps = 0; ntaps <= range; ntaps++) {
 		litest_touch_down(dev, 0, 50, 50);
+		litest_touch_up(dev, 0);
 		libinput_dispatch(li);
+		msleep(10);
+	}
 
-		litest_timeout_tap();
-		libinput_dispatch(li);
-
-		for (ntaps = 0; ntaps <= i; ntaps++) {
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_PRESSED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_gt(curtime, oldtime);
+	libinput_dispatch(li);
+	litest_touch_down(dev, 0, 50, 50);
+	libinput_dispatch(li);
 
-			event = libinput_get_event(li);
-			ptrev = litest_is_button_event(event,
-						       BTN_LEFT,
-						       LIBINPUT_BUTTON_STATE_RELEASED);
-			curtime = libinput_event_pointer_get_time(ptrev);
-			libinput_event_destroy(event);
-			ck_assert_int_ge(curtime, oldtime);
-			oldtime = curtime;
-		}
+	litest_timeout_tap();
+	libinput_dispatch(li);
 
+	for (ntaps = 0; ntaps <= range; ntaps++) {
 		event = libinput_get_event(li);
 		ptrev = litest_is_button_event(event,
 					       BTN_LEFT,
@@ -496,18 +469,35 @@ START_TEST(touchpad_1fg_multitap_n_drag_timeout)
 		libinput_event_destroy(event);
 		ck_assert_int_gt(curtime, oldtime);
 
-		litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10, 4);
-
-		litest_assert_only_typed_events(li,
-						LIBINPUT_EVENT_POINTER_MOTION);
-
-		litest_touch_up(dev, 0);
-		litest_assert_button_event(li,
-					   BTN_LEFT,
-					   LIBINPUT_BUTTON_STATE_RELEASED);
-
-		litest_assert_empty_queue(li);
+		event = libinput_get_event(li);
+		ptrev = litest_is_button_event(event,
+					       BTN_LEFT,
+					       LIBINPUT_BUTTON_STATE_RELEASED);
+		curtime = libinput_event_pointer_get_time(ptrev);
+		libinput_event_destroy(event);
+		ck_assert_int_ge(curtime, oldtime);
+		oldtime = curtime;
 	}
+
+	event = libinput_get_event(li);
+	ptrev = litest_is_button_event(event,
+				       BTN_LEFT,
+				       LIBINPUT_BUTTON_STATE_PRESSED);
+	curtime = libinput_event_pointer_get_time(ptrev);
+	libinput_event_destroy(event);
+	ck_assert_int_gt(curtime, oldtime);
+
+	litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10, 4);
+
+	litest_assert_only_typed_events(li,
+					LIBINPUT_EVENT_POINTER_MOTION);
+
+	litest_touch_up(dev, 0);
+	litest_assert_button_event(li,
+				   BTN_LEFT,
+				   LIBINPUT_BUTTON_STATE_RELEASED);
+
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
@@ -4119,16 +4109,18 @@ END_TEST
 
 int main(int argc, char **argv)
 {
+	struct range multitap_range = {3, 8};
+
 	litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
 	litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
 
 	litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
 	litest_add("touchpad:tap", touchpad_1fg_doubletap, LITEST_TOUCHPAD, LITEST_ANY);
-	litest_add("touchpad:tap", touchpad_1fg_multitap, LITEST_TOUCHPAD, LITEST_ANY);
-	litest_add("touchpad:tap", touchpad_1fg_multitap_n_drag_timeout, LITEST_TOUCHPAD, LITEST_ANY);
-	litest_add("touchpad:tap", touchpad_1fg_multitap_n_drag_move, LITEST_TOUCHPAD, LITEST_ANY);
-	litest_add("touchpad:tap", touchpad_1fg_multitap_n_drag_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
-	litest_add("touchpad:tap", touchpad_1fg_multitap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
+	litest_add_ranged("touchpad:tap", touchpad_1fg_multitap, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range);
+	litest_add_ranged("touchpad:tap", touchpad_1fg_multitap_n_drag_timeout, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range);
+	litest_add_ranged("touchpad:tap", touchpad_1fg_multitap_n_drag_move, LITEST_TOUCHPAD, LITEST_ANY, &multitap_range);
+	litest_add_ranged("touchpad:tap", touchpad_1fg_multitap_n_drag_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &multitap_range);
+	litest_add_ranged("touchpad:tap", touchpad_1fg_multitap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY, &multitap_range);
 	litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
 	litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_timeout, LITEST_TOUCHPAD, LITEST_ANY);
 	litest_add("touchpad:tap", touchpad_2fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
-- 
2.3.5



More information about the wayland-devel mailing list