test: change switch tests to use parameters

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1119>
This commit is contained in:
Peter Hutterer 2025-01-08 09:13:47 +10:00
parent 812611ca2e
commit 4bbad8adf0

View file

@ -104,12 +104,26 @@ START_TEST(switch_has_tablet_mode_switch)
}
END_TEST
static enum libinput_switch
switch_param_lookup(const char *sw)
{
if (streq(sw, "lid"))
return LIBINPUT_SWITCH_LID;
if (streq(sw, "tablet_mode"))
return LIBINPUT_SWITCH_TABLET_MODE;
litest_abort_msg("Invalid switch parameter: %s", sw);
}
START_TEST(switch_toggle)
{
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_event *event;
enum libinput_switch sw = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch sw = switch_param_lookup(str);
litest_drain_events(li);
@ -144,7 +158,10 @@ START_TEST(switch_toggle_double)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_event *event;
enum libinput_switch sw = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch sw = switch_param_lookup(str);
if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
return LITEST_NOT_APPLICABLE;
@ -190,7 +207,10 @@ START_TEST(switch_down_on_init)
struct litest_device *dev = litest_current_device();
struct libinput *li;
struct libinput_event *event;
enum libinput_switch sw = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch sw = switch_param_lookup(str);
if (libinput_device_switch_has_switch(dev->libinput_device, sw) <= 0)
return LITEST_NOT_APPLICABLE;
@ -278,7 +298,10 @@ START_TEST(switch_disable_touchpad)
struct litest_device *sw = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = sw->libinput;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
return LITEST_NOT_APPLICABLE;
@ -318,7 +341,9 @@ START_TEST(switch_disable_touchpad_during_touch)
struct litest_device *sw = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = sw->libinput;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
return LITEST_NOT_APPLICABLE;
@ -350,7 +375,10 @@ START_TEST(switch_disable_touchpad_edge_scroll)
struct litest_device *sw = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = sw->libinput;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
return LITEST_NOT_APPLICABLE;
@ -390,7 +418,10 @@ START_TEST(switch_disable_touchpad_edge_scroll_interrupt)
struct litest_device *touchpad;
struct libinput *li = sw->libinput;
struct libinput_event *event;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
return LITEST_NOT_APPLICABLE;
@ -430,7 +461,10 @@ START_TEST(switch_disable_touchpad_already_open)
struct litest_device *sw = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = sw->libinput;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
return LITEST_NOT_APPLICABLE;
@ -465,7 +499,10 @@ START_TEST(switch_dont_resume_disabled_touchpad)
struct litest_device *sw = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = sw->libinput;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
return LITEST_NOT_APPLICABLE;
@ -506,7 +543,10 @@ START_TEST(switch_dont_resume_disabled_touchpad_external_mouse)
struct litest_device *sw = litest_current_device();
struct litest_device *touchpad, *mouse;
struct libinput *li = sw->libinput;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
if (libinput_device_switch_has_switch(sw->libinput_device, which) <= 0)
return LITEST_NOT_APPLICABLE;
@ -638,7 +678,10 @@ START_TEST(switch_suspend_with_keyboard)
struct libinput *li;
struct litest_device *keyboard;
struct litest_device *sw;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
li = litest_create_context();
@ -679,7 +722,10 @@ START_TEST(switch_suspend_with_touchpad)
{
struct libinput *li;
struct litest_device *touchpad, *sw;
enum libinput_switch which = _i; /* ranged test */
const char *str;
litest_test_param_fetch(test_env->params, "switch", &str);
enum libinput_switch which = switch_param_lookup(str);
li = litest_create_context();
@ -1392,26 +1438,30 @@ END_TEST
TEST_COLLECTION(switch)
{
struct range switches = { LIBINPUT_SWITCH_LID,
LIBINPUT_SWITCH_TABLET_MODE + 1};
litest_add(switch_has_cap, LITEST_SWITCH, LITEST_ANY);
litest_add(switch_has_lid_switch, LITEST_SWITCH, LITEST_ANY);
litest_add(switch_has_tablet_mode_switch, LITEST_SWITCH, LITEST_ANY);
litest_add_ranged(switch_toggle, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_toggle_double, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_down_on_init, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add(switch_not_down_on_init, LITEST_SWITCH, LITEST_ANY);
litest_add_ranged(switch_disable_touchpad, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_disable_touchpad_during_touch, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_disable_touchpad_edge_scroll, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_disable_touchpad_edge_scroll_interrupt, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_disable_touchpad_already_open, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_dont_resume_disabled_touchpad, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged(switch_dont_resume_disabled_touchpad_external_mouse, LITEST_SWITCH, LITEST_ANY, &switches);
litest_add_ranged_no_device(switch_suspend_with_keyboard, &switches);
litest_add_ranged_no_device(switch_suspend_with_touchpad, &switches);
{
struct litest_parameters *params = litest_parameters_new("switch", 's', 2, "lid", "tablet_mode");
litest_add_parametrized(switch_toggle, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_toggle_double, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_down_on_init, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_disable_touchpad, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_disable_touchpad_during_touch, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_disable_touchpad_edge_scroll, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_disable_touchpad_edge_scroll_interrupt, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_disable_touchpad_already_open, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_dont_resume_disabled_touchpad, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized(switch_dont_resume_disabled_touchpad_external_mouse, LITEST_SWITCH, LITEST_ANY, params);
litest_add_parametrized_no_device(switch_suspend_with_keyboard, params);
litest_add_parametrized_no_device(switch_suspend_with_touchpad, params);
litest_parameters_unref(params);
}
litest_add(lid_open_on_key, LITEST_SWITCH, LITEST_ANY);
litest_add(lid_open_on_key_touchpad_enabled, LITEST_SWITCH, LITEST_ANY);