[PATCH libinput 12/14] test: add more gesture tests

Peter Hutterer peter.hutterer at who-t.net
Thu Jan 7 20:11:16 PST 2016


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

diff --git a/test/gestures.c b/test/gestures.c
index c21a411..141686b 100644
--- a/test/gestures.c
+++ b/test/gestures.c
@@ -156,6 +156,345 @@ START_TEST(gestures_swipe_3fg)
 }
 END_TEST
 
+START_TEST(gestures_swipe_3fg_btntool)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_gesture *gevent;
+	double dx, dy;
+	int cardinal = _i; /* ranged test */
+	double dir_x, dir_y;
+	int cardinals[8][2] = {
+		{ 0, 30 },
+		{ 30, 30 },
+		{ 30, 0 },
+		{ 30, -30 },
+		{ 0, -30 },
+		{ -30, -30 },
+		{ -30, 0 },
+		{ -30, 30 },
+	};
+
+	if (libevdev_get_num_slots(dev->evdev) > 2 ||
+	    !libinput_device_has_capability(dev->libinput_device,
+					    LIBINPUT_DEVICE_CAP_GESTURE))
+		return;
+
+	dir_x = cardinals[cardinal][0];
+	dir_y = cardinals[cardinal][1];
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 40, 40);
+	litest_touch_down(dev, 1, 50, 40);
+	litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
+	litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	libinput_dispatch(li);
+	litest_touch_move_two_touches(dev,
+				      40, 40,
+				      50, 40,
+				      dir_x, dir_y,
+				      10, 2);
+	libinput_dispatch(li);
+
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
+					 3);
+	dx = libinput_event_gesture_get_dx(gevent);
+	dy = libinput_event_gesture_get_dy(gevent);
+	ck_assert(dx == 0.0);
+	ck_assert(dy == 0.0);
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) != NULL) {
+		gevent = litest_is_gesture_event(event,
+						 LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
+						 3);
+
+		dx = libinput_event_gesture_get_dx(gevent);
+		dy = libinput_event_gesture_get_dy(gevent);
+		if (dir_x == 0.0)
+			ck_assert(dx == 0.0);
+		else if (dir_x < 0.0)
+			ck_assert(dx < 0.0);
+		else if (dir_x > 0.0)
+			ck_assert(dx > 0.0);
+
+		if (dir_y == 0.0)
+			ck_assert(dy == 0.0);
+		else if (dir_y < 0.0)
+			ck_assert(dy < 0.0);
+		else if (dir_y > 0.0)
+			ck_assert(dy > 0.0);
+
+		dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
+		dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
+		if (dir_x == 0.0)
+			ck_assert(dx == 0.0);
+		else if (dir_x < 0.0)
+			ck_assert(dx < 0.0);
+		else if (dir_x > 0.0)
+			ck_assert(dx > 0.0);
+
+		if (dir_y == 0.0)
+			ck_assert(dy == 0.0);
+		else if (dir_y < 0.0)
+			ck_assert(dy < 0.0);
+		else if (dir_y > 0.0)
+			ck_assert(dy > 0.0);
+
+		libinput_event_destroy(event);
+	}
+
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_SWIPE_END,
+					 3);
+	ck_assert(!libinput_event_gesture_get_cancelled(gevent));
+	libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(gestures_swipe_4fg)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_gesture *gevent;
+	double dx, dy;
+	int cardinal = _i; /* ranged test */
+	double dir_x, dir_y;
+	int cardinals[8][2] = {
+		{ 0, 3 },
+		{ 3, 3 },
+		{ 3, 0 },
+		{ 3, -3 },
+		{ 0, -3 },
+		{ -3, -3 },
+		{ -3, 0 },
+		{ -3, 3 },
+	};
+	int i;
+
+	if (libevdev_get_num_slots(dev->evdev) < 4)
+		return;
+
+	dir_x = cardinals[cardinal][0];
+	dir_y = cardinals[cardinal][1];
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 40, 40);
+	litest_touch_down(dev, 1, 50, 40);
+	litest_touch_down(dev, 2, 60, 40);
+	litest_touch_down(dev, 3, 70, 40);
+	libinput_dispatch(li);
+
+	for (i = 0; i < 8; i++) {
+		litest_push_event_frame(dev);
+
+		dir_x += cardinals[cardinal][0];
+		dir_y += cardinals[cardinal][1];
+
+		litest_touch_move(dev,
+				  0,
+				  40 + dir_x,
+				  40 + dir_y);
+		litest_touch_move(dev,
+				  1,
+				  50 + dir_x,
+				  40 + dir_y);
+		litest_touch_move(dev,
+				  2,
+				  60 + dir_x,
+				  40 + dir_y);
+		litest_touch_move(dev,
+				  3,
+				  70 + dir_x,
+				  40 + dir_y);
+		litest_pop_event_frame(dev);
+		libinput_dispatch(li);
+	}
+
+	libinput_dispatch(li);
+
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
+					 4);
+	dx = libinput_event_gesture_get_dx(gevent);
+	dy = libinput_event_gesture_get_dy(gevent);
+	ck_assert(dx == 0.0);
+	ck_assert(dy == 0.0);
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) != NULL) {
+		gevent = litest_is_gesture_event(event,
+						 LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
+						 4);
+
+		dx = libinput_event_gesture_get_dx(gevent);
+		dy = libinput_event_gesture_get_dy(gevent);
+		if (dir_x == 0.0)
+			ck_assert(dx == 0.0);
+		else if (dir_x < 0.0)
+			ck_assert(dx < 0.0);
+		else if (dir_x > 0.0)
+			ck_assert(dx > 0.0);
+
+		if (dir_y == 0.0)
+			ck_assert(dy == 0.0);
+		else if (dir_y < 0.0)
+			ck_assert(dy < 0.0);
+		else if (dir_y > 0.0)
+			ck_assert(dy > 0.0);
+
+		dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
+		dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
+		if (dir_x == 0.0)
+			ck_assert(dx == 0.0);
+		else if (dir_x < 0.0)
+			ck_assert(dx < 0.0);
+		else if (dir_x > 0.0)
+			ck_assert(dx > 0.0);
+
+		if (dir_y == 0.0)
+			ck_assert(dy == 0.0);
+		else if (dir_y < 0.0)
+			ck_assert(dy < 0.0);
+		else if (dir_y > 0.0)
+			ck_assert(dy > 0.0);
+
+		libinput_event_destroy(event);
+	}
+
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	litest_touch_up(dev, 2);
+	litest_touch_up(dev, 3);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_SWIPE_END,
+					 4);
+	ck_assert(!libinput_event_gesture_get_cancelled(gevent));
+	libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(gestures_swipe_4fg_btntool)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_gesture *gevent;
+	double dx, dy;
+	int cardinal = _i; /* ranged test */
+	double dir_x, dir_y;
+	int cardinals[8][2] = {
+		{ 0, 30 },
+		{ 30, 30 },
+		{ 30, 0 },
+		{ 30, -30 },
+		{ 0, -30 },
+		{ -30, -30 },
+		{ -30, 0 },
+		{ -30, 30 },
+	};
+
+	if (libevdev_get_num_slots(dev->evdev) > 2 ||
+	    !libinput_device_has_capability(dev->libinput_device,
+					    LIBINPUT_DEVICE_CAP_GESTURE))
+		return;
+
+	dir_x = cardinals[cardinal][0];
+	dir_y = cardinals[cardinal][1];
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 40, 40);
+	litest_touch_down(dev, 1, 50, 40);
+	litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
+	litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	libinput_dispatch(li);
+	litest_touch_move_two_touches(dev,
+				      40, 40,
+				      50, 40,
+				      dir_x, dir_y,
+				      10, 2);
+	libinput_dispatch(li);
+
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
+					 4);
+	dx = libinput_event_gesture_get_dx(gevent);
+	dy = libinput_event_gesture_get_dy(gevent);
+	ck_assert(dx == 0.0);
+	ck_assert(dy == 0.0);
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) != NULL) {
+		gevent = litest_is_gesture_event(event,
+						 LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
+						 4);
+
+		dx = libinput_event_gesture_get_dx(gevent);
+		dy = libinput_event_gesture_get_dy(gevent);
+		if (dir_x == 0.0)
+			ck_assert(dx == 0.0);
+		else if (dir_x < 0.0)
+			ck_assert(dx < 0.0);
+		else if (dir_x > 0.0)
+			ck_assert(dx > 0.0);
+
+		if (dir_y == 0.0)
+			ck_assert(dy == 0.0);
+		else if (dir_y < 0.0)
+			ck_assert(dy < 0.0);
+		else if (dir_y > 0.0)
+			ck_assert(dy > 0.0);
+
+		dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
+		dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
+		if (dir_x == 0.0)
+			ck_assert(dx == 0.0);
+		else if (dir_x < 0.0)
+			ck_assert(dx < 0.0);
+		else if (dir_x > 0.0)
+			ck_assert(dx > 0.0);
+
+		if (dir_y == 0.0)
+			ck_assert(dy == 0.0);
+		else if (dir_y < 0.0)
+			ck_assert(dy < 0.0);
+		else if (dir_y > 0.0)
+			ck_assert(dy > 0.0);
+
+		libinput_event_destroy(event);
+	}
+
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_SWIPE_END,
+					 4);
+	ck_assert(!libinput_event_gesture_get_cancelled(gevent));
+	libinput_event_destroy(event);
+}
+END_TEST
+
 START_TEST(gestures_pinch)
 {
 	struct litest_device *dev = litest_current_device();
@@ -257,6 +596,430 @@ START_TEST(gestures_pinch)
 }
 END_TEST
 
+START_TEST(gestures_pinch_3fg)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_gesture *gevent;
+	double dx, dy;
+	int cardinal = _i; /* ranged test */
+	double dir_x, dir_y;
+	int i;
+	double scale, oldscale;
+	double angle;
+	int cardinals[8][2] = {
+		{ 0, 30 },
+		{ 30, 30 },
+		{ 30, 0 },
+		{ 30, -30 },
+		{ 0, -30 },
+		{ -30, -30 },
+		{ -30, 0 },
+		{ -30, 30 },
+	};
+
+	if (libevdev_get_num_slots(dev->evdev) < 3)
+		return;
+
+	dir_x = cardinals[cardinal][0];
+	dir_y = cardinals[cardinal][1];
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
+	litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
+	litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y);
+	libinput_dispatch(li);
+
+	for (i = 0; i < 8; i++) {
+		litest_push_event_frame(dev);
+		if (dir_x > 0.0)
+			dir_x -= 2;
+		else if (dir_x < 0.0)
+			dir_x += 2;
+		if (dir_y > 0.0)
+			dir_y -= 2;
+		else if (dir_y < 0.0)
+			dir_y += 2;
+		litest_touch_move(dev,
+				  0,
+				  50 + dir_x,
+				  50 + dir_y);
+		litest_touch_move(dev,
+				  1,
+				  50 - dir_x,
+				  50 - dir_y);
+		litest_touch_move(dev,
+				  2,
+				  51 - dir_x,
+				  51 - dir_y);
+		litest_pop_event_frame(dev);
+		libinput_dispatch(li);
+	}
+
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
+					 3);
+	dx = libinput_event_gesture_get_dx(gevent);
+	dy = libinput_event_gesture_get_dy(gevent);
+	scale = libinput_event_gesture_get_scale(gevent);
+	ck_assert(dx == 0.0);
+	ck_assert(dy == 0.0);
+	ck_assert(scale == 1.0);
+
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) != NULL) {
+		gevent = litest_is_gesture_event(event,
+						 LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+						 3);
+
+		oldscale = scale;
+		scale = libinput_event_gesture_get_scale(gevent);
+
+		ck_assert(scale < oldscale);
+
+		angle = libinput_event_gesture_get_angle_delta(gevent);
+		ck_assert_double_le(fabs(angle), 1.0);
+
+		libinput_event_destroy(event);
+		libinput_dispatch(li);
+	}
+
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	litest_touch_up(dev, 2);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_END,
+					 3);
+	ck_assert(!libinput_event_gesture_get_cancelled(gevent));
+	libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(gestures_pinch_3fg_btntool)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_gesture *gevent;
+	double dx, dy;
+	int cardinal = _i; /* ranged test */
+	double dir_x, dir_y;
+	int i;
+	double scale, oldscale;
+	double angle;
+	int cardinals[8][2] = {
+		{ 0, 30 },
+		{ 30, 30 },
+		{ 30, 0 },
+		{ 30, -30 },
+		{ 0, -30 },
+		{ -30, -30 },
+		{ -30, 0 },
+		{ -30, 30 },
+	};
+
+	if (libevdev_get_num_slots(dev->evdev) > 2 ||
+	    !libinput_device_has_capability(dev->libinput_device,
+					    LIBINPUT_DEVICE_CAP_GESTURE))
+		return;
+
+	dir_x = cardinals[cardinal][0];
+	dir_y = cardinals[cardinal][1];
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
+	litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
+	litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
+	litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	libinput_dispatch(li);
+
+	for (i = 0; i < 8; i++) {
+		litest_push_event_frame(dev);
+		if (dir_x > 0.0)
+			dir_x -= 2;
+		else if (dir_x < 0.0)
+			dir_x += 2;
+		if (dir_y > 0.0)
+			dir_y -= 2;
+		else if (dir_y < 0.0)
+			dir_y += 2;
+		litest_touch_move(dev,
+				  0,
+				  50 + dir_x,
+				  50 + dir_y);
+		litest_touch_move(dev,
+				  1,
+				  50 - dir_x,
+				  50 - dir_y);
+		litest_pop_event_frame(dev);
+		libinput_dispatch(li);
+	}
+
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
+					 3);
+	dx = libinput_event_gesture_get_dx(gevent);
+	dy = libinput_event_gesture_get_dy(gevent);
+	scale = libinput_event_gesture_get_scale(gevent);
+	ck_assert(dx == 0.0);
+	ck_assert(dy == 0.0);
+	ck_assert(scale == 1.0);
+
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) != NULL) {
+		gevent = litest_is_gesture_event(event,
+						 LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+						 3);
+
+		oldscale = scale;
+		scale = libinput_event_gesture_get_scale(gevent);
+
+		ck_assert(scale < oldscale);
+
+		angle = libinput_event_gesture_get_angle_delta(gevent);
+		ck_assert_double_le(fabs(angle), 1.0);
+
+		libinput_event_destroy(event);
+		libinput_dispatch(li);
+	}
+
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_END,
+					 3);
+	ck_assert(!libinput_event_gesture_get_cancelled(gevent));
+	libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(gestures_pinch_4fg)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_gesture *gevent;
+	double dx, dy;
+	int cardinal = _i; /* ranged test */
+	double dir_x, dir_y;
+	int i;
+	double scale, oldscale;
+	double angle;
+	int cardinals[8][2] = {
+		{ 0, 30 },
+		{ 30, 30 },
+		{ 30, 0 },
+		{ 30, -30 },
+		{ 0, -30 },
+		{ -30, -30 },
+		{ -30, 0 },
+		{ -30, 30 },
+	};
+
+	if (libevdev_get_num_slots(dev->evdev) < 4)
+		return;
+
+	dir_x = cardinals[cardinal][0];
+	dir_y = cardinals[cardinal][1];
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
+	litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
+	litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y);
+	litest_touch_down(dev, 3, 52 - dir_x, 52 - dir_y);
+	libinput_dispatch(li);
+
+	for (i = 0; i < 8; i++) {
+		litest_push_event_frame(dev);
+		if (dir_x > 0.0)
+			dir_x -= 2;
+		else if (dir_x < 0.0)
+			dir_x += 2;
+		if (dir_y > 0.0)
+			dir_y -= 2;
+		else if (dir_y < 0.0)
+			dir_y += 2;
+		litest_touch_move(dev,
+				  0,
+				  50 + dir_x,
+				  50 + dir_y);
+		litest_touch_move(dev,
+				  1,
+				  50 - dir_x,
+				  50 - dir_y);
+		litest_touch_move(dev,
+				  2,
+				  51 - dir_x,
+				  51 - dir_y);
+		litest_touch_move(dev,
+				  3,
+				  52 - dir_x,
+				  52 - dir_y);
+		litest_pop_event_frame(dev);
+		libinput_dispatch(li);
+	}
+
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
+					 4);
+	dx = libinput_event_gesture_get_dx(gevent);
+	dy = libinput_event_gesture_get_dy(gevent);
+	scale = libinput_event_gesture_get_scale(gevent);
+	ck_assert(dx == 0.0);
+	ck_assert(dy == 0.0);
+	ck_assert(scale == 1.0);
+
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) != NULL) {
+		gevent = litest_is_gesture_event(event,
+						 LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+						 4);
+
+		oldscale = scale;
+		scale = libinput_event_gesture_get_scale(gevent);
+
+		ck_assert(scale < oldscale);
+
+		angle = libinput_event_gesture_get_angle_delta(gevent);
+		ck_assert_double_le(fabs(angle), 1.0);
+
+		libinput_event_destroy(event);
+		libinput_dispatch(li);
+	}
+
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	litest_touch_up(dev, 2);
+	litest_touch_up(dev, 3);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_END,
+					 4);
+	ck_assert(!libinput_event_gesture_get_cancelled(gevent));
+	libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(gestures_pinch_4fg_btntool)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+	struct libinput_event_gesture *gevent;
+	double dx, dy;
+	int cardinal = _i; /* ranged test */
+	double dir_x, dir_y;
+	int i;
+	double scale, oldscale;
+	double angle;
+	int cardinals[8][2] = {
+		{ 0, 30 },
+		{ 30, 30 },
+		{ 30, 0 },
+		{ 30, -30 },
+		{ 0, -30 },
+		{ -30, -30 },
+		{ -30, 0 },
+		{ -30, 30 },
+	};
+
+	if (libevdev_get_num_slots(dev->evdev) > 2 ||
+	    !libinput_device_has_capability(dev->libinput_device,
+					    LIBINPUT_DEVICE_CAP_GESTURE))
+		return;
+
+	dir_x = cardinals[cardinal][0];
+	dir_y = cardinals[cardinal][1];
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
+	litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
+	litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
+	litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	libinput_dispatch(li);
+
+	for (i = 0; i < 8; i++) {
+		litest_push_event_frame(dev);
+		if (dir_x > 0.0)
+			dir_x -= 2;
+		else if (dir_x < 0.0)
+			dir_x += 2;
+		if (dir_y > 0.0)
+			dir_y -= 2;
+		else if (dir_y < 0.0)
+			dir_y += 2;
+		litest_touch_move(dev,
+				  0,
+				  50 + dir_x,
+				  50 + dir_y);
+		litest_touch_move(dev,
+				  1,
+				  50 - dir_x,
+				  50 - dir_y);
+		litest_pop_event_frame(dev);
+		libinput_dispatch(li);
+	}
+
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
+					 4);
+	dx = libinput_event_gesture_get_dx(gevent);
+	dy = libinput_event_gesture_get_dy(gevent);
+	scale = libinput_event_gesture_get_scale(gevent);
+	ck_assert(dx == 0.0);
+	ck_assert(dy == 0.0);
+	ck_assert(scale == 1.0);
+
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) != NULL) {
+		gevent = litest_is_gesture_event(event,
+						 LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+						 4);
+
+		oldscale = scale;
+		scale = libinput_event_gesture_get_scale(gevent);
+
+		ck_assert(scale < oldscale);
+
+		angle = libinput_event_gesture_get_angle_delta(gevent);
+		ck_assert_double_le(fabs(angle), 1.0);
+
+		libinput_event_destroy(event);
+		libinput_dispatch(li);
+	}
+
+	litest_touch_up(dev, 0);
+	litest_touch_up(dev, 1);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	gevent = litest_is_gesture_event(event,
+					 LIBINPUT_EVENT_GESTURE_PINCH_END,
+					 4);
+	ck_assert(!libinput_event_gesture_get_cancelled(gevent));
+	libinput_event_destroy(event);
+}
+END_TEST
+
 START_TEST(gestures_spread)
 {
 	struct litest_device *dev = litest_current_device();
@@ -400,7 +1163,14 @@ litest_setup_tests(void)
 	litest_add("gestures:cap", gestures_nocap, LITEST_ANY, LITEST_TOUCHPAD);
 
 	litest_add_ranged("gestures:swipe", gestures_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
+	litest_add_ranged("gestures:swipe", gestures_swipe_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
+	litest_add_ranged("gestures:swipe", gestures_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
+	litest_add_ranged("gestures:swipe", gestures_swipe_4fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
 	litest_add_ranged("gestures:pinch", gestures_pinch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
+	litest_add_ranged("gestures:pinch", gestures_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
+	litest_add_ranged("gestures:pinch", gestures_pinch_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
+	litest_add_ranged("gestures:pinch", gestures_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
+	litest_add_ranged("gestures:pinch", gestures_pinch_4fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
 	litest_add_ranged("gestures:pinch", gestures_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, &cardinals);
 
 	litest_add("gesture:time", gestures_time_usec, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
-- 
2.5.0



More information about the wayland-devel mailing list