test: add litest_assert_event_type_not_one_of

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1059>
This commit is contained in:
Peter Hutterer 2024-10-14 18:58:24 +10:00
parent 67061c1af0
commit 3ed70e864f
3 changed files with 41 additions and 2 deletions

View file

@ -3410,6 +3410,40 @@ litest_assert_event_type(struct libinput_event *event,
litest_assert_event_type_is_one_of(event, want);
}
#define litest_assert_event_type_not_one_of(...) \
_litest_assert_event_type_not_one_of(__VA_ARGS__, -1)
void
_litest_assert_event_type_not_one_of(struct libinput_event *event, ...)
{
va_list args;
enum libinput_event_type not_expected_type;
enum libinput_event_type actual_type = libinput_event_get_type(event);
bool match = false;
va_start(args, event);
not_expected_type = va_arg(args, int);
while ((int)not_expected_type != -1 && !match) {
match = (actual_type == not_expected_type);
not_expected_type = va_arg(args, int);
}
va_end(args);
if (!match)
return;
fprintf(stderr,
"FAILED EVENT TYPE: %s: have %s (%d) but didn't want that\n",
libinput_device_get_name(libinput_event_get_device(event)),
litest_event_get_type_str(event),
libinput_event_get_type(event));
fprintf(stderr, "\nWrong event is: ");
litest_print_event(event);
litest_backtrace();
abort();
}
void
_litest_assert_empty_queue(struct libinput *li,
const char *func,

View file

@ -798,6 +798,12 @@ void
litest_assert_event_type(struct libinput_event *event,
enum libinput_event_type want);
#define litest_assert_event_type_not_one_of(...) \
_litest_assert_event_type_not_one_of(__VA_ARGS__, -1)
void
_litest_assert_event_type_not_one_of(struct libinput_event *event, ...);
#define litest_assert_empty_queue(li_) \
_litest_assert_empty_queue(li_, __func__, __LINE__)

View file

@ -2699,8 +2699,7 @@ START_TEST(touchpad_no_first_fg_tap_after_move)
litest_dispatch(dev->libinput);
while ((event = libinput_get_event(li))) {
ck_assert_int_ne(libinput_event_get_type(event),
LIBINPUT_EVENT_POINTER_BUTTON);
litest_assert_event_type_not_one_of(event, LIBINPUT_EVENT_POINTER_BUTTON);
libinput_event_destroy(event);
}
}