[PATCH libinput v2] tests: Add negative test for libinput_device_keyboard_has_key()

Derek Foreman derekf at osg.samsung.com
Fri Apr 24 15:21:18 PDT 2015


Ensure we get a -1 return for non-keyboard devices.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
 test/keyboard.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/test/keyboard.c b/test/keyboard.c
index a477cfb..cf56923 100644
--- a/test/keyboard.c
+++ b/test/keyboard.c
@@ -309,6 +309,22 @@ START_TEST(keyboard_has_key)
 }
 END_TEST
 
+START_TEST(keyboard_keys_bad_device)
+{
+	struct litest_device *dev = litest_current_device();
+	struct libinput_device *device = dev->libinput_device;
+	unsigned int code;
+
+	if (libinput_device_has_capability(device,
+					   LIBINPUT_DEVICE_CAP_KEYBOARD))
+		return;
+
+	for (code = 0; code < KEY_CNT; code++)
+		ck_assert_int_eq(
+			libinput_device_keyboard_has_key(device, code), -1);
+}
+END_TEST
+
 int
 main(int argc, char **argv)
 {
@@ -316,6 +332,7 @@ main(int argc, char **argv)
 	litest_add_no_device("keyboard:key counting", keyboard_ignore_no_pressed_release);
 	litest_add_no_device("keyboard:key counting", keyboard_key_auto_release);
 	litest_add("keyboard:keys", keyboard_has_key, LITEST_KEYS, LITEST_ANY);
+	litest_add("keyboard:keys", keyboard_keys_bad_device, LITEST_ANY, LITEST_ANY);
 
 	return litest_run(argc, argv);
 }
-- 
2.1.4



More information about the wayland-devel mailing list