[PATCH libinput 2/3] litest: Add litest_assert_scroll() helper function

Peter Hutterer peter.hutterer at who-t.net
Wed Sep 17 18:29:03 PDT 2014


On Wed, Sep 17, 2014 at 03:35:31PM +0200, Hans de Goede wrote:
> Make check_2fg_scroll functionality available outside of touchpad.c ,
> no functional changes.
> 
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
>  test/litest.c   | 39 +++++++++++++++++++++++++++++++++++++++
>  test/litest.h   |  1 +
>  test/touchpad.c | 49 ++++---------------------------------------------
>  3 files changed, 44 insertions(+), 45 deletions(-)
> 
> diff --git a/test/litest.c b/test/litest.c
> index cf7e692..e5092b8 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -1084,3 +1084,42 @@ litest_assert_button_event(struct libinput *li, unsigned int button,
>  			 state);
>  	libinput_event_destroy(event);
>  }
> +
> +void litest_assert_scroll(struct libinput *li, unsigned int axis, int dir)
> +{
> +	struct libinput_event *event, *next_event;
> +	struct libinput_event_pointer *ptrev;
> +
> +	event = libinput_get_event(li);
> +	next_event = libinput_get_event(li);
> +	ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */

ck_assert_notnull(), not that it makes much difference.

> +
> +	while (event) {
> +		ck_assert_int_eq(libinput_event_get_type(event),
> +				 LIBINPUT_EVENT_POINTER_AXIS);
> +		ptrev = libinput_event_get_pointer_event(event);
> +		ck_assert(ptrev != NULL);
> +		ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
> +
> +		if (next_event) {
> +			/* Normal scroll event, check dir */
> +			if (dir > 0) {
> +				ck_assert_int_ge(
> +					libinput_event_pointer_get_axis_value(ptrev),
> +					dir);

if you use a temporary var for the axis values we can skip the
indentation/linewidth dance.

Ok, and now that I wrote this I see that's just moving the code around. so
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
for this one and I'll push the updates on top of it.

Cheers,
   Peter



> +			} else {
> +				ck_assert_int_le(
> +					libinput_event_pointer_get_axis_value(ptrev),
> +					dir);
> +			}
> +		} else {
> +			/* Last scroll event, must be 0 */
> +			ck_assert_int_eq(
> +				libinput_event_pointer_get_axis_value(ptrev),
> +				0);
> +		}
> +		libinput_event_destroy(event);
> +		event = next_event;
> +		next_event = libinput_get_event(li);
> +	}
> +}
> diff --git a/test/litest.h b/test/litest.h
> index dd1386c..fdf815f 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -147,6 +147,7 @@ void litest_assert_empty_queue(struct libinput *li);
>  void litest_assert_button_event(struct libinput *li,
>  				unsigned int button,
>  				enum libinput_button_state state);
> +void litest_assert_scroll(struct libinput *li, unsigned int axis, int dir);
>  
>  struct libevdev_uinput * litest_create_uinput_device(const char *name,
>  						     struct input_id *id,
> diff --git a/test/touchpad.c b/test/touchpad.c
> index 7ff3d14..522cee6 100644
> --- a/test/touchpad.c
> +++ b/test/touchpad.c
> @@ -1346,47 +1346,6 @@ test_2fg_scroll(struct litest_device *dev, double dx, double dy, int sleep)
>  	libinput_dispatch(li);
>  }
>  
> -static void
> -check_2fg_scroll(struct litest_device *dev, unsigned int axis, int dir)
> -{
> -	struct libinput *li = dev->libinput;
> -	struct libinput_event *event, *next_event;
> -	struct libinput_event_pointer *ptrev;
> -
> -	event = libinput_get_event(li);
> -	next_event = libinput_get_event(li);
> -	ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
> -
> -	while (event) {
> -		ck_assert_int_eq(libinput_event_get_type(event),
> -				 LIBINPUT_EVENT_POINTER_AXIS);
> -		ptrev = libinput_event_get_pointer_event(event);
> -		ck_assert(ptrev != NULL);
> -		ck_assert_int_eq(libinput_event_pointer_get_axis(ptrev), axis);
> -
> -		if (next_event) {
> -			/* Normal scroll event, check dir */
> -			if (dir > 0) {
> -				ck_assert_int_ge(
> -					libinput_event_pointer_get_axis_value(ptrev),
> -					dir);
> -			} else {
> -				ck_assert_int_le(
> -					libinput_event_pointer_get_axis_value(ptrev),
> -					dir);
> -			}
> -		} else {
> -			/* Last scroll event, must be 0 */
> -			ck_assert_int_eq(
> -				libinput_event_pointer_get_axis_value(ptrev),
> -				0);
> -		}
> -		libinput_event_destroy(event);
> -		event = next_event;
> -		next_event = libinput_get_event(li);
> -	}
> -}
> -
>  START_TEST(touchpad_2fg_scroll)
>  {
>  	struct litest_device *dev = litest_current_device();
> @@ -1395,13 +1354,13 @@ START_TEST(touchpad_2fg_scroll)
>  	litest_drain_events(li);
>  
>  	test_2fg_scroll(dev, 0.1, 40, 0);
> -	check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
> +	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 10);
>  	test_2fg_scroll(dev, 0.1, -40, 0);
> -	check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
> +	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -10);
>  	test_2fg_scroll(dev, 40, 0.1, 0);
> -	check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
> +	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 10);
>  	test_2fg_scroll(dev, -40, 0.1, 0);
> -	check_2fg_scroll(dev, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
> +	litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -10);
>  
>  	/* 2fg scroll smaller than the threshold should not generate events */
>  	test_2fg_scroll(dev, 0.1, 0.1, 200);
> -- 
> 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