[PATCH libinput 3/6] test: add a bunch of test for click behavior on touchpads

Peter Hutterer peter.hutterer at who-t.net
Tue Jun 10 17:11:32 PDT 2014


Mainly testing the behaviour when clicking during a tap or tap-n-drag. Adds a
new "feature" to the litest system, Apple clickpads don't have software
buttons by default.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/litest-bcm5974.c |   3 +-
 test/litest.h         |   1 +
 test/touchpad.c       | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+), 1 deletion(-)

diff --git a/test/litest-bcm5974.c b/test/litest-bcm5974.c
index 33127d9..10a9eb4 100644
--- a/test/litest-bcm5974.c
+++ b/test/litest-bcm5974.c
@@ -97,7 +97,8 @@ static int events[] = {
 
 struct litest_test_device litest_bcm5974_device = {
 	.type = LITEST_BCM5974,
-	.features = LITEST_TOUCHPAD | LITEST_CLICKPAD | LITEST_BUTTON,
+	.features = LITEST_TOUCHPAD | LITEST_CLICKPAD |
+		    LITEST_BUTTON | LITEST_APPLE_CLICKPAD,
 	.shortname = "bcm5974",
 	.setup = litest_bcm5974_setup,
 	.interface = &interface,
diff --git a/test/litest.h b/test/litest.h
index 170c87c..ea7d299 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -55,6 +55,7 @@ enum litest_device_feature {
 	LITEST_WHEEL = 1 << 5,
 	LITEST_TOUCH = 1 << 6,
 	LITEST_SINGLE_TOUCH = 1 << 7,
+	LITEST_APPLE_CLICKPAD = 1 << 8,
 };
 
 struct litest_device {
diff --git a/test/touchpad.c b/test/touchpad.c
index ec412d3..f9e2820 100644
--- a/test/touchpad.c
+++ b/test/touchpad.c
@@ -210,6 +210,179 @@ START_TEST(touchpad_2fg_tap)
 }
 END_TEST
 
+START_TEST(touchpad_1fg_tap_click)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+
+	litest_drain_events(dev->libinput);
+
+	/* finger down, button click, finger up
+	   -> only one button left event pair */
+	litest_touch_down(dev, 0, 50, 50);
+	litest_event(dev, EV_KEY, BTN_LEFT, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_event(dev, EV_KEY, BTN_LEFT, 0);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_touch_up(dev, 0);
+
+	libinput_dispatch(li);
+
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_PRESSED);
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_RELEASED);
+
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
+START_TEST(touchpad_2fg_tap_click)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+
+	litest_drain_events(dev->libinput);
+
+	/* two fingers down, button click, fingers up
+	   -> only one button left event pair */
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_down(dev, 1, 70, 50);
+	litest_event(dev, EV_KEY, BTN_LEFT, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_event(dev, EV_KEY, BTN_LEFT, 0);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_touch_up(dev, 1);
+	litest_touch_up(dev, 0);
+
+	libinput_dispatch(li);
+
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_PRESSED);
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_RELEASED);
+
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
+START_TEST(touchpad_2fg_tap_click_apple)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+
+	litest_drain_events(dev->libinput);
+
+	/* two fingers down, button click, fingers up
+	   -> only one button right event pair
+	   (apple have clickfinger enabled by default) */
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_down(dev, 1, 70, 50);
+	litest_event(dev, EV_KEY, BTN_LEFT, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_event(dev, EV_KEY, BTN_LEFT, 0);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_touch_up(dev, 1);
+	litest_touch_up(dev, 0);
+
+	libinput_dispatch(li);
+
+	assert_button_event(li, BTN_RIGHT,
+			    LIBINPUT_BUTTON_STATE_PRESSED);
+	assert_button_event(li, BTN_RIGHT,
+			    LIBINPUT_BUTTON_STATE_RELEASED);
+
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
+START_TEST(touchpad_1fg_double_tap_click)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+
+	litest_drain_events(dev->libinput);
+
+	/* one finger down, up, down, button click, finger up
+	   -> two button left event pairs */
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_up(dev, 0);
+	litest_touch_down(dev, 0, 50, 50);
+	litest_event(dev, EV_KEY, BTN_LEFT, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_event(dev, EV_KEY, BTN_LEFT, 0);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_touch_up(dev, 0);
+
+	libinput_dispatch(li);
+
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_PRESSED);
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_RELEASED);
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_PRESSED);
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_RELEASED);
+
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
+START_TEST(touchpad_1fg_tap_n_drag_click)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_event *event;
+
+	litest_drain_events(dev->libinput);
+
+	/* one finger down, up, down, move, button click, finger up
+	   -> two button left event pairs, motion allowed */
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_up(dev, 0);
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_move_to(dev, 1, 50, 50, 80, 50, 5);
+
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_PRESSED);
+
+	libinput_dispatch(li);
+	while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
+		event = libinput_get_event(li);
+		libinput_event_destroy(event);
+		libinput_dispatch(li);
+	}
+
+	litest_event(dev, EV_KEY, BTN_LEFT, 1);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_RELEASED);
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_PRESSED);
+
+	litest_event(dev, EV_KEY, BTN_LEFT, 0);
+	litest_event(dev, EV_SYN, SYN_REPORT, 0);
+	litest_touch_up(dev, 0);
+
+	libinput_dispatch(li);
+
+	assert_button_event(li, BTN_LEFT,
+			    LIBINPUT_BUTTON_STATE_RELEASED);
+
+	libinput_dispatch(li);
+
+	while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
+		event = libinput_get_event(li);
+		libinput_event_destroy(event);
+		libinput_dispatch(li);
+	}
+
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
 START_TEST(touchpad_1fg_clickfinger)
 {
 	struct litest_device *dev = litest_create_device(LITEST_BCM5974);
@@ -352,6 +525,13 @@ int main(int argc, char **argv) {
 	litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
 	litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
 	litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
+	litest_add("touchpad:tap", touchpad_1fg_tap_click, LITEST_TOUCHPAD, LITEST_ANY);
+	litest_add("touchpad:tap", touchpad_2fg_tap_click, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD);
+	litest_add("touchpad:tap", touchpad_2fg_tap_click_apple, LITEST_APPLE_CLICKPAD, LITEST_ANY);
+	/* Real buttons don't interfere with tapping, so don't run those for
+	   pads with buttons */
+	litest_add("touchpad:tap", touchpad_1fg_double_tap_click, LITEST_CLICKPAD, LITEST_ANY);
+	litest_add("touchpad:tap", touchpad_1fg_tap_n_drag_click, LITEST_CLICKPAD, LITEST_ANY);
 
 	litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
 	litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);
-- 
1.9.3



More information about the wayland-devel mailing list