From: Peter Hutterer Date: Fri, 14 Jul 2023 02:57:58 +0000 (+1000) Subject: test: expand the tablet mode switch test to check for fake key releases X-Git-Tag: accepted/tizen/unified/20240105.013022~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a3239f2eef71cbc946595c2f3eb5b9ee870aacc6;p=platform%2Fupstream%2Flibinput.git test: expand the tablet mode switch test to check for fake key releases If a key is still down when the tablet mode switch goes on, make sure we release the key before the switch goes in effect. Signed-off-by: Peter Hutterer --- diff --git a/test/litest.c b/test/litest.c index 175d7f42..615a16f7 100644 --- a/test/litest.c +++ b/test/litest.c @@ -3995,6 +3995,21 @@ litest_is_switch_event(struct libinput_event *event, return swev; } +void +litest_assert_switch_event(struct libinput *li, + enum libinput_switch sw, + enum libinput_switch_state state) +{ + struct libinput_event *event; + + litest_wait_for_event(li); + event = libinput_get_event(li); + + litest_is_switch_event(event, sw, state); + + libinput_event_destroy(event); +} + void litest_assert_pad_button_event(struct libinput *li, unsigned int button, diff --git a/test/litest.h b/test/litest.h index a69217b7..5fa1477c 100644 --- a/test/litest.h +++ b/test/litest.h @@ -837,6 +837,11 @@ litest_assert_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state); +void +litest_assert_switch_event(struct libinput *li, + enum libinput_switch sw, + enum libinput_switch_state state); + void litest_assert_scroll(struct libinput *li, enum libinput_event_type axis_type, diff --git a/test/test-switch.c b/test/test-switch.c index f4f3402e..23fdb45a 100644 --- a/test/test-switch.c +++ b/test/test-switch.c @@ -1097,13 +1097,23 @@ START_TEST(tablet_mode_disable_keyboard) litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); - litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + litest_keyboard_key(keyboard, KEY_B, true); /* KEY_B down but not up */ + libinput_dispatch(li); + + litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED); + litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); + litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_PRESSED); /* KEY_B down but not up */ litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); - litest_drain_events(li); + /* The key currently down must be released */ + litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_RELEASED); + litest_assert_switch_event(li, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON); + litest_assert_empty_queue(li); + + litest_keyboard_key(keyboard, KEY_B, false); /* release the kernel device */ litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); litest_assert_empty_queue(li); @@ -1111,11 +1121,16 @@ START_TEST(tablet_mode_disable_keyboard) litest_switch_action(sw, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); - litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); + litest_assert_switch_event(li, LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF); litest_keyboard_key(keyboard, KEY_A, true); litest_keyboard_key(keyboard, KEY_A, false); - litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); + litest_keyboard_key(keyboard, KEY_B, true); + litest_keyboard_key(keyboard, KEY_B, false); + litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_PRESSED); + litest_assert_key_event(li, KEY_A, LIBINPUT_KEY_STATE_RELEASED); + litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_PRESSED); + litest_assert_key_event(li, KEY_B, LIBINPUT_KEY_STATE_RELEASED); litest_delete_device(keyboard); }