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

Derek Foreman derekf at osg.samsung.com
Fri Apr 24 14:58:21 PDT 2015


On 23/04/15 08:04 PM, Peter Hutterer wrote:
> 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.

Sure, I figured it didn't matter since any non keyboard device is
immediately dismissed with a -1 before actually testing for the code.

I'll send a new patch with a loop similar to the existing test.

>> +}
>> +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
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 



More information about the wayland-devel mailing list