diff options
author | José Expósito <jose.exposito89@gmail.com> | 2021-07-24 13:54:24 +0200 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-08-31 14:42:15 +1000 |
commit | 427c855d21b442620bf6472c2a0585ddca9673e0 (patch) | |
tree | da9b1879c1111c8debdcbd9a35b45ff43e28ece5 | |
parent | a1566e3492ae0f62901349c746421676630de1e4 (diff) | |
download | libinput-427c855d21b442620bf6472c2a0585ddca9673e0.tar.gz |
test: refactor litest_assert_event_type logic
Extract the logic in litest_assert_event_type to a generic function,
litest_assert_event_type_is_one_of, that takes a variable number of
expected event types.
Refactor, no functional changes.
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
-rw-r--r-- | test/litest.c | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/test/litest.c b/test/litest.c index 54278bfa..b000fe8b 100644 --- a/test/litest.c +++ b/test/litest.c @@ -3268,27 +3268,61 @@ litest_print_event(struct libinput_event *event) fprintf(stderr, "\n"); } -void -litest_assert_event_type(struct libinput_event *event, - enum libinput_event_type want) +#define litest_assert_event_type_is_one_of(...) \ + _litest_assert_event_type_is_one_of(__VA_ARGS__, -1) + +static void +_litest_assert_event_type_is_one_of(struct libinput_event *event, ...) { - if (libinput_event_get_type(event) == want) + va_list args; + enum libinput_event_type expected_type; + enum libinput_event_type actual_type = libinput_event_get_type(event); + bool match = false; + + va_start(args, event); + expected_type = va_arg(args, int); + while ((int)expected_type != -1 && !match) { + match = (actual_type == expected_type); + expected_type = va_arg(args, int); + } + va_end(args); + + if (match) return; fprintf(stderr, - "FAILED EVENT TYPE: %s: have %s (%d) but want %s (%d)\n", + "FAILED EVENT TYPE: %s: have %s (%d) but want ", libinput_device_get_name(libinput_event_get_device(event)), litest_event_get_type_str(event), - libinput_event_get_type(event), - litest_event_type_str(want), - want); - fprintf(stderr, "Wrong event is: "); + libinput_event_get_type(event)); + + va_start(args, event); + expected_type = va_arg(args, int); + while ((int)expected_type != -1) { + fprintf(stderr, + "%s (%d)", + litest_event_type_str(expected_type), + expected_type); + expected_type = va_arg(args, int); + + if ((int)expected_type != -1) + fprintf(stderr, " || "); + } + + fprintf(stderr, "\nWrong event is: "); litest_print_event(event); litest_backtrace(); abort(); } void +litest_assert_event_type(struct libinput_event *event, + enum libinput_event_type want) +{ + litest_assert_event_type_is_one_of(event, want); +} + +void litest_assert_empty_queue(struct libinput *li) { bool empty_queue = true; |