[PATCH libinput 01/11] test: add helpers to wait for specific events

Hans de Goede hdegoede at redhat.com
Thu Aug 28 05:53:38 PDT 2014


Hi,

On 08/27/2014 06:31 AM, Peter Hutterer wrote:
> litest_wait_for_event() returns if any event is available.
> litest_wait_for_event_of_type(... type, type, type, -1) returns if any of the
> given event types is availble. All other events are discarded.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Looks good:

Reviewed-by: Hans de Goede <hdegoede at redhat.com>

Regards,

Hans

> ---
>  test/litest.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  test/litest.h |  2 ++
>  2 files changed, 48 insertions(+)
> 
> diff --git a/test/litest.c b/test/litest.c
> index 00db464..fcc8de1 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -781,6 +781,52 @@ litest_scale(const struct litest_device *d, unsigned int axis, double val)
>  }
>  
>  void
> +litest_wait_for_event(struct libinput *li)
> +{
> +	return litest_wait_for_event_of_type(li, -1);
> +}
> +
> +void
> +litest_wait_for_event_of_type(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;
> +	}
> +	va_end(args);
> +
> +	while (1) {
> +		size_t i;
> +		struct libinput_event *event;
> +
> +		while ((type = libinput_next_event_type(li)) == LIBINPUT_EVENT_NONE) {
> +			msleep(10);
> +			libinput_dispatch(li);
> +		}
> +
> +		/* no event mask means wait for any event */
> +		if (ntypes == 0)
> +			return;
> +
> +		for (i = 0; i < ntypes; i++) {
> +			if (type == types[i])
> +				return;
> +		}
> +
> +		event = libinput_get_event(li);
> +		libinput_event_destroy(event);
> +	}
> +}
> +
> +void
>  litest_drain_events(struct libinput *li)
>  {
>  	struct libinput_event *event;
> diff --git a/test/litest.h b/test/litest.h
> index 2dcb7b2..815a571 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -137,6 +137,8 @@ void litest_button_click(struct litest_device *d,
>  void litest_keyboard_key(struct litest_device *d,
>  			 unsigned int key,
>  			 bool is_press);
> +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_assert_empty_queue(struct libinput *li);
>  
> 


More information about the wayland-devel mailing list