test: add another helper to discard specific events

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-02-12 11:59:09 +10:00
parent 067b5be144
commit 19aac0e4be
3 changed files with 46 additions and 5 deletions

View file

@ -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)
{

View file

@ -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);

View file

@ -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);