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

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 23 18:04:29 PDT 2015


On Thu, Apr 23, 2015 at 05:05:49PM -0500, Derek Foreman wrote:
> Ensure we get a -1 return for non-keyboard devices.
> 
> Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
> ---
>  test/keyboard.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/test/keyboard.c b/test/keyboard.c
> index a477cfb..e098dc0 100644
> --- a/test/keyboard.c
> +++ b/test/keyboard.c
> @@ -309,6 +309,20 @@ 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;
> +
> +	if (libinput_device_has_capability(device,
> +					    LIBINPUT_DEVICE_CAP_KEYBOARD))
> +		return;
> +
> +	ck_assert_int_eq(libinput_device_keyboard_has_key(device, KEY_A),
> +			 -1);

shouldn't we be running through the whole key range here? at least up to
BTN_MISC and then again from KEY_OK.

otherwise we don't catch devices that have e.g. KEY_POWER, never set up the
capability but still send the event.

> +}
> +END_TEST
> +
>  int
>  main(int argc, char **argv)
>  {
> @@ -316,6 +330,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 bad device", keyboard_keys_bad_device, LITEST_ANY, LITEST_ANY);

use "keyboard:keys" as suite name please, they don't need to be different
for each key. the suite name is for grouping (e.g. touchpad:scroll,
touchpad:tap)

Cheers,
   Peter

>  
>  	return litest_run(argc, argv);
>  }
> -- 
> 2.1.4


More information about the wayland-devel mailing list