From: Peter Hutterer Date: Tue, 12 Feb 2019 01:59:09 +0000 (+1000) Subject: test: add another helper to discard specific events X-Git-Tag: 1.12.901~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19aac0e4be7ee2f75e5343fd23577533bac32a48;p=platform%2Fupstream%2Flibinput.git test: add another helper to discard specific events Signed-off-by: Peter Hutterer --- diff --git a/test/litest.c b/test/litest.c index 7c988f49..046c7f10 100644 --- a/test/litest.c +++ b/test/litest.c @@ -2601,6 +2601,48 @@ litest_drain_events(struct libinput *li) } } + +void +litest_drain_events_of_type(struct libinput *li, ...) +{ + enum libinput_event_type type; + enum libinput_event_type types[32] = {LIBINPUT_EVENT_NONE}; + size_t ntypes = 0; + va_list args; + + va_start(args, li); + type = va_arg(args, int); + while ((int)type != -1) { + litest_assert(type > 0); + litest_assert(ntypes < ARRAY_LENGTH(types)); + types[ntypes++] = type; + type = va_arg(args, int); + } + va_end(args); + + libinput_dispatch(li); + type = libinput_next_event_type(li); + while (type != LIBINPUT_EVENT_NONE) { + struct libinput_event *event; + bool found = false; + + type = libinput_next_event_type(li); + + for (size_t i = 0; i < ntypes; i++) { + if (type == types[i]) { + found = true; + break; + } + } + if (!found) + return; + + event = libinput_get_event(li); + libinput_event_destroy(event); + libinput_dispatch(li); + } +} + static const char * litest_event_type_str(enum libinput_event_type type) { diff --git a/test/litest.h b/test/litest.h index 67788012..50171a82 100644 --- a/test/litest.h +++ b/test/litest.h @@ -675,6 +675,9 @@ litest_wait_for_event_of_type(struct libinput *li, ...); void litest_drain_events(struct libinput *li); +void +litest_drain_events_of_type(struct libinput *li, ...); + void litest_assert_event_type(struct libinput_event *event, enum libinput_event_type want); diff --git a/test/test-tablet.c b/test/test-tablet.c index ce2fe732..35c47c58 100644 --- a/test/test-tablet.c +++ b/test/test-tablet.c @@ -2642,11 +2642,7 @@ START_TEST(tool_in_prox_before_start) li = litest_create_context(); libinput_path_add_device(li, devnode); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_DEVICE_ADDED, - -1); - event = libinput_get_event(li); - libinput_event_destroy(event); + litest_drain_events_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1); litest_assert_empty_queue(li);