From aeca8739c7c2e852bc84998ab1f85162d74e9454 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 21 Apr 2017 16:33:02 +1000 Subject: [PATCH] test: make the lid action helper function a generic switch action helper Signed-off-by: Peter Hutterer --- test/litest.c | 17 ++++++++-- test/litest.h | 5 +-- test/test-misc.c | 8 +++-- test/test-switch.c | 84 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 86 insertions(+), 28 deletions(-) diff --git a/test/litest.c b/test/litest.c index d63b4d7a..82ca14db 100644 --- a/test/litest.c +++ b/test/litest.c @@ -2179,10 +2179,21 @@ litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press) } void -litest_lid_action(struct litest_device *dev, - enum libinput_switch_state state) +litest_switch_action(struct litest_device *dev, + enum libinput_switch sw, + enum libinput_switch_state state) { - litest_event(dev, EV_SW, SW_LID, state); + unsigned int code; + + switch (sw) { + case LIBINPUT_SWITCH_LID: + code = SW_LID; + break; + default: + litest_abort_msg("Invalid switch %d", sw); + break; + } + litest_event(dev, EV_SW, code, state); litest_event(dev, EV_SYN, SYN_REPORT, 0); } diff --git a/test/litest.h b/test/litest.h index f33c05fa..39aa882b 100644 --- a/test/litest.h +++ b/test/litest.h @@ -579,8 +579,9 @@ litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press); -void litest_lid_action(struct litest_device *d, - enum libinput_switch_state state); +void litest_switch_action(struct litest_device *d, + enum libinput_switch sw, + enum libinput_switch_state state); void litest_wait_for_event(struct libinput *li); diff --git a/test/test-misc.c b/test/test-misc.c index 2173910b..1b85e9c9 100644 --- a/test/test-misc.c +++ b/test/test-misc.c @@ -502,8 +502,12 @@ START_TEST(event_conversion_switch) struct libinput_event *event; int sw = 0; - litest_lid_action(dev, LIBINPUT_SWITCH_STATE_ON); - litest_lid_action(dev, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(dev, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(dev, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); libinput_dispatch(li); while ((event = libinput_get_event(li))) { diff --git a/test/test-switch.c b/test/test-switch.c index b5d3d586..4623e55b 100644 --- a/test/test-switch.c +++ b/test/test-switch.c @@ -38,7 +38,9 @@ START_TEST(lid_switch) litest_drain_events(li); /* lid closed */ - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); libinput_dispatch(li); event = libinput_get_event(li); @@ -48,7 +50,9 @@ START_TEST(lid_switch) libinput_event_destroy(event); /* lid opened */ - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); libinput_dispatch(li); event = libinput_get_event(li); @@ -69,7 +73,9 @@ START_TEST(lid_switch_double) litest_drain_events(li); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); libinput_dispatch(li); event = libinput_get_event(li); @@ -80,7 +86,9 @@ START_TEST(lid_switch_double) /* This will be filtered by the kernel, so this test is a bit * useless */ - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); libinput_dispatch(li); litest_assert_empty_queue(li); @@ -113,7 +121,9 @@ START_TEST(lid_switch_down_on_init) if (!lid_switch_is_reliable(sw)) return; - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); /* need separate context to test */ li = litest_create_context(); @@ -134,7 +144,9 @@ START_TEST(lid_switch_down_on_init) libinput_event_destroy(event); } - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); libinput_dispatch(li); event = libinput_get_event(li); litest_is_switch_event(event, @@ -157,7 +169,9 @@ START_TEST(lid_switch_not_down_on_init) if (lid_switch_is_reliable(sw)) return; - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); /* need separate context to test */ li = litest_create_context(); @@ -171,7 +185,9 @@ START_TEST(lid_switch_not_down_on_init) libinput_event_destroy(event); } - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); litest_assert_empty_queue(li); libinput_unref(li); } @@ -196,7 +212,9 @@ START_TEST(lid_disable_touchpad) litest_drain_events(li); /* lid is down - no events */ - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); @@ -205,7 +223,9 @@ START_TEST(lid_disable_touchpad) litest_assert_empty_queue(li); /* lid is up - motion events */ - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 50, 50); @@ -231,7 +251,9 @@ START_TEST(lid_disable_touchpad_during_touch) litest_touch_move_to(touchpad, 0, 50, 50, 70, 50, 5, 1); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_move_to(touchpad, 0, 70, 50, 50, 50, 5, 1); @@ -253,7 +275,9 @@ START_TEST(lid_disable_touchpad_edge_scroll) litest_drain_events(li); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); litest_assert_only_typed_events(li, LIBINPUT_EVENT_SWITCH_TOGGLE); litest_touch_down(touchpad, 0, 99, 20); @@ -294,7 +318,9 @@ START_TEST(lid_disable_touchpad_edge_scroll_interrupt) libinput_dispatch(li); litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_AXIS); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); libinput_dispatch(li); event = libinput_get_event(li); @@ -330,7 +356,9 @@ START_TEST(lid_disable_touchpad_already_open) litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION); /* open lid - motion events */ - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); litest_assert_empty_queue(li); litest_touch_down(touchpad, 0, 50, 50); @@ -351,7 +379,9 @@ START_TEST(lid_open_on_key) keyboard = litest_add_device(li, LITEST_KEYBOARD); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_event(keyboard, EV_KEY, KEY_A, 1); @@ -367,7 +397,9 @@ START_TEST(lid_open_on_key) litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); litest_assert_empty_queue(li); libinput_event_destroy(event); @@ -384,7 +416,9 @@ START_TEST(lid_open_on_key_touchpad_enabled) keyboard = litest_add_device(li, LITEST_KEYBOARD); touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); litest_event(keyboard, EV_KEY, KEY_A, 1); @@ -420,9 +454,13 @@ START_TEST(lid_suspend_with_keyboard) keyboard = litest_add_device(li, LITEST_KEYBOARD); libinput_dispatch(li); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_OFF); litest_drain_events(li); litest_delete_device(keyboard); @@ -476,7 +514,9 @@ START_TEST(lid_update_hw_on_key) libevdev_uinput_get_devnode(sw->uinput)); litest_drain_events(li2); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); litest_drain_events(li); libinput_dispatch(li2); @@ -513,7 +553,9 @@ START_TEST(lid_update_hw_on_key_closed_on_init) struct libevdev *evdev = sw->evdev; struct input_event ev; - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_switch_action(sw, + LIBINPUT_SWITCH_LID, + LIBINPUT_SWITCH_STATE_ON); /* Make sure kernel state is right */ libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_FORCE_SYNC, &ev);