[PATCH libinput 8/8] test: test for release events on device suspend

Peter Hutterer peter.hutterer at who-t.net
Tue Aug 19 20:18:56 PDT 2014


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

diff --git a/test/device.c b/test/device.c
index 25e119e..2367fd6 100644
--- a/test/device.c
+++ b/test/device.c
@@ -30,6 +30,7 @@
 #include <unistd.h>
 
 #include "litest.h"
+#include "libinput-util.h"
 
 static int open_restricted(const char *path, int flags, void *data)
 {
@@ -238,6 +239,151 @@ START_TEST(device_resume_invalid_device_removed)
 }
 END_TEST
 
+START_TEST(device_suspend_release_buttons)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_device *device;
+	struct libinput_event *event;
+	struct libinput_event_pointer *ptrevent;
+
+	device = dev->libinput_device;
+
+	litest_button_click(dev, BTN_LEFT, true);
+	litest_drain_events(li);
+	litest_assert_empty_queue(li);
+
+	libinput_device_suspend(device);
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li)) == NULL)
+		libinput_dispatch(li);
+
+	ck_assert_int_eq(libinput_event_get_type(event),
+			 LIBINPUT_EVENT_POINTER_BUTTON);
+	ptrevent = libinput_event_get_pointer_event(event);
+	ck_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
+			 BTN_LEFT);
+	ck_assert_int_eq(libinput_event_pointer_get_button_state(ptrevent),
+			 LIBINPUT_BUTTON_STATE_RELEASED);
+
+	libinput_event_destroy(event);
+	litest_assert_empty_queue(li);
+
+	/* double-suspend for good measure, make sure we don't get
+	 * the button events again */
+	libinput_device_suspend(device);
+	libinput_dispatch(li);
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
+START_TEST(device_suspend_release_keys)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_device *device;
+	struct libinput_event *event;
+	struct libinput_event_keyboard *kbdevent;
+
+	device = dev->libinput_device;
+
+	litest_button_click(dev, KEY_A, true);
+	litest_drain_events(li);
+	litest_assert_empty_queue(li);
+
+	libinput_device_suspend(device);
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li)) == NULL)
+		libinput_dispatch(li);
+
+	ck_assert_int_eq(libinput_event_get_type(event),
+			 LIBINPUT_EVENT_KEYBOARD_KEY);
+	kbdevent = libinput_event_get_keyboard_event(event);
+	ck_assert_int_eq(libinput_event_keyboard_get_key(kbdevent),
+			 KEY_A);
+	ck_assert_int_eq(libinput_event_keyboard_get_key_state(kbdevent),
+			 LIBINPUT_KEY_STATE_RELEASED);
+
+	libinput_event_destroy(event);
+	litest_assert_empty_queue(li);
+
+	/* double-suspend for good measure, make sure we don't get
+	 * the key events again */
+	libinput_device_suspend(device);
+	libinput_dispatch(li);
+	litest_assert_empty_queue(li);
+}
+END_TEST
+
+START_TEST(device_suspend_release_tap)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput *li = dev->libinput;
+	struct libinput_device *device;
+	struct libinput_event *event;
+	struct libinput_event_pointer *ptrevent;
+
+	device = dev->libinput_device;
+
+	libinput_device_config_tap_set_enabled(device,
+					       LIBINPUT_CONFIG_TAP_ENABLED);
+
+	litest_drain_events(li);
+
+	litest_touch_down(dev, 0, 50, 50);
+	litest_touch_up(dev, 0);
+
+	libinput_dispatch(li);
+
+	libinput_device_suspend(device);
+	/* tap happened before suspending, so we still expect the event */
+
+	msleep(300); /* tap-n-drag timeout */
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li)) == NULL)
+		libinput_dispatch(li);
+
+	ck_assert_int_eq(libinput_event_get_type(event),
+			 LIBINPUT_EVENT_POINTER_BUTTON);
+	ptrevent = libinput_event_get_pointer_event(event);
+	ck_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
+			 BTN_LEFT);
+	ck_assert_int_eq(libinput_event_pointer_get_button_state(ptrevent),
+			 LIBINPUT_BUTTON_STATE_PRESSED);
+
+	libinput_event_destroy(event);
+
+	while ((event = libinput_get_event(li)) == NULL)
+		libinput_dispatch(li);
+
+	ck_assert_int_eq(libinput_event_get_type(event),
+			 LIBINPUT_EVENT_POINTER_BUTTON);
+	ptrevent = libinput_event_get_pointer_event(event);
+	ck_assert_int_eq(libinput_event_pointer_get_button(ptrevent),
+			 BTN_LEFT);
+	ck_assert_int_eq(libinput_event_pointer_get_button_state(ptrevent),
+			 LIBINPUT_BUTTON_STATE_RELEASED);
+
+	libinput_event_destroy(event);
+	litest_assert_empty_queue(li);
+
+	/* double-suspend for good measure, make sure we don't get
+	 * the button events again */
+	libinput_device_suspend(device);
+	libinput_dispatch(li);
+	litest_assert_empty_queue(li);
+
+	/* resume, make sure we don't get anything */
+	libinput_device_resume(device);
+	libinput_dispatch(li);
+	litest_assert_empty_queue(li);
+
+}
+END_TEST
+
 int main (int argc, char **argv)
 {
 	litest_add("device:suspend", device_suspend, LITEST_POINTER, LITEST_ANY);
@@ -245,6 +391,9 @@ int main (int argc, char **argv)
 	litest_add("device:suspend", device_double_resume, LITEST_ANY, LITEST_ANY);
 	litest_add_no_device("device:suspend", device_resume_invalid_syspath_changed);
 	litest_add_no_device("device:suspend", device_resume_invalid_device_removed);
+	litest_add_for_device("device:suspend", device_suspend_release_buttons, LITEST_MOUSE);
+	litest_add_for_device("device:suspend", device_suspend_release_keys, LITEST_KEYBOARD);
+	litest_add("device:suspend", device_suspend_release_tap, LITEST_TOUCHPAD, LITEST_ANY);
 
 	return litest_run(argc, argv);
 }
-- 
1.9.3



More information about the wayland-devel mailing list