[PATCH libinput 1/3] test: add litest_drain_typed_events

Jonas Ådahl jadahl at gmail.com
Mon Jan 26 22:29:56 PST 2015


On Tue, Jan 27, 2015 at 03:45:56PM +1000, Peter Hutterer wrote:
> For the case where we don't care about a specific set of events in the queue
> and want to jump over them.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Reviewed-by: Jonas Ådahl <jadahl at gmail.com>

> ---
>  test/litest.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  test/litest.h |  2 ++
>  2 files changed, 47 insertions(+)
> 
> diff --git a/test/litest.c b/test/litest.c
> index 7d48278..643c168 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -899,6 +899,51 @@ litest_drain_events(struct libinput *li)
>  	}
>  }
>  
> +void
> +litest_drain_typed_events(struct libinput *li, ...)
> +{
> +	va_list args;
> +	enum libinput_event_type types[32] = {LIBINPUT_EVENT_NONE};
> +	size_t ntypes = 0;
> +	enum libinput_event_type type;
> +
> +
> +	va_start(args, li);
> +	type = va_arg(args, int);
> +	while ((int)type != -1) {
> +		assert(type > 0);
> +		assert(ntypes < ARRAY_LENGTH(types));
> +		types[ntypes++] = type;
> +		type = va_arg(args, int);
> +	}
> +	va_end(args);
> +
> +	libinput_dispatch(li);
> +
> +	while (1) {
> +		bool found;
> +		size_t i;
> +		struct libinput_event *event;
> +
> +		type = libinput_next_event_type(li);
> +		if (type == LIBINPUT_EVENT_NONE)
> +			break;
> +
> +		found = false;
> +		for (i = 0; i < ntypes; i++) {
> +			if (type == types[i]) {
> +				found = true;
> +				break;
> +			}
> +		}
> +		if (!found)
> +			break;
> +
> +		event = libinput_get_event(li);
> +		libinput_event_destroy(event);
> +	}
> +}
> +
>  static const char *
>  litest_event_type_str(struct libinput_event *event)
>  {
> diff --git a/test/litest.h b/test/litest.h
> index 2d4b4d8..f551bde 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -156,6 +156,8 @@ void litest_keyboard_key(struct litest_device *d,
>  void litest_wait_for_event(struct libinput *li);
>  void litest_wait_for_event_of_type(struct libinput *li, ...);
>  void litest_drain_events(struct libinput *li);
> +void litest_drain_typed_events(struct libinput *li,
> +			       ...);
>  void litest_assert_empty_queue(struct libinput *li);
>  void litest_assert_button_event(struct libinput *li,
>  				unsigned int button,
> -- 
> 2.1.0
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list