[PATCH libinput 6/7] test: add litest_is_keyboard_event() helper function

Peter Hutterer peter.hutterer at who-t.net
Mon May 4 22:43:08 PDT 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/keyboard.c | 45 ++++++++++++++-------------------------------
 test/litest.c   | 20 ++++++++++++++++++++
 test/litest.h   |  4 ++++
 3 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/test/keyboard.c b/test/keyboard.c
index 508362b..03d62dd 100644
--- a/test/keyboard.c
+++ b/test/keyboard.c
@@ -61,11 +61,9 @@ START_TEST(keyboard_seat_key_count)
 			continue;
 		}
 
-		kev = libinput_event_get_keyboard_event(ev);
-		ck_assert_notnull(kev);
-		ck_assert_int_eq(libinput_event_keyboard_get_key(kev), KEY_A);
-		ck_assert_int_eq(libinput_event_keyboard_get_key_state(kev),
-				 LIBINPUT_KEY_STATE_PRESSED);
+		kev = litest_is_keyboard_event(ev,
+					       KEY_A,
+					       LIBINPUT_KEY_STATE_PRESSED);
 
 		++expected_key_button_count;
 		seat_key_count =
@@ -175,31 +173,6 @@ START_TEST(keyboard_ignore_no_pressed_release)
 }
 END_TEST
 
-static void
-test_key_event(struct litest_device *dev, unsigned int key, int state)
-{
-	struct libinput *li = dev->libinput;
-	struct libinput_event *event;
-	struct libinput_event_keyboard *kevent;
-
-	litest_event(dev, EV_KEY, key, state);
-	litest_event(dev, EV_SYN, SYN_REPORT, 0);
-
-	libinput_dispatch(li);
-
-	event = libinput_get_event(li);
-	ck_assert(event != NULL);
-	ck_assert_int_eq(libinput_event_get_type(event), LIBINPUT_EVENT_KEYBOARD_KEY);
-
-	kevent = libinput_event_get_keyboard_event(event);
-	ck_assert(kevent != NULL);
-	ck_assert_int_eq(libinput_event_keyboard_get_key(kevent), key);
-	ck_assert_int_eq(libinput_event_keyboard_get_key_state(kevent),
-			 state ? LIBINPUT_KEY_STATE_PRESSED :
-				 LIBINPUT_KEY_STATE_RELEASED);
-	libinput_event_destroy(event);
-}
-
 START_TEST(keyboard_key_auto_release)
 {
 	struct libinput *libinput;
@@ -244,7 +217,17 @@ START_TEST(keyboard_key_auto_release)
 
 	/* Send pressed events, without releasing */
 	for (i = 0; i < ARRAY_LENGTH(keys); ++i) {
-		test_key_event(dev, keys[i].code, 1);
+		key = keys[i].code;
+		litest_event(dev, EV_KEY, key, 1);
+		litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+		libinput_dispatch(libinput);
+
+		event = libinput_get_event(libinput);
+		kevent = litest_is_keyboard_event(event,
+						  key,
+						  LIBINPUT_KEY_STATE_PRESSED);
+		libinput_event_destroy(event);
 	}
 
 	litest_drain_events(libinput);
diff --git a/test/litest.c b/test/litest.c
index 9677670..3aa0c0d 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -1430,6 +1430,26 @@ litest_is_touch_event(struct libinput_event *event,
 	return touch;
 }
 
+struct libinput_event_keyboard *
+litest_is_keyboard_event(struct libinput_event *event,
+			 unsigned int key,
+			 enum libinput_key_state state)
+{
+	struct libinput_event_keyboard *kevent;
+	enum libinput_event_type type = LIBINPUT_EVENT_KEYBOARD_KEY;
+
+	ck_assert_notnull(event);
+	ck_assert_int_eq(libinput_event_get_type(event), type);
+
+	kevent = libinput_event_get_keyboard_event(event);
+	ck_assert_notnull(kevent);
+
+	ck_assert_int_eq(libinput_event_keyboard_get_key(kevent), key);
+	ck_assert_int_eq(libinput_event_keyboard_get_key_state(kevent),
+			 state);
+	return kevent;
+}
+
 void
 litest_assert_scroll(struct libinput *li,
 		     enum libinput_pointer_axis axis,
diff --git a/test/litest.h b/test/litest.h
index d34a2fc..3ea4a1a 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -187,6 +187,10 @@ struct libinput_event_pointer * litest_is_motion_event(
 struct libinput_event_touch * litest_is_touch_event(
 		       struct libinput_event *event,
 		       enum libinput_event_type type);
+struct libinput_event_keyboard * litest_is_keyboard_event(
+		       struct libinput_event *event,
+		       unsigned int key,
+		       enum libinput_key_state state);
 void litest_assert_button_event(struct libinput *li,
 				unsigned int button,
 				enum libinput_button_state state);
-- 
2.3.5



More information about the wayland-devel mailing list