[PATCH libinput 20/23] test: Add proximity-in-out and proximity-out-clear-buttons tests

Peter Hutterer peter.hutterer at who-t.net
Sun Jun 15 22:45:17 PDT 2014


On Thu, Jun 12, 2014 at 11:28:41PM -0400, Stephen Chandler Paul wrote:
> This tests to make sure proximity events actually work, that they don't output
> cooirdinate events after they occur, and that they make sure to release all of
> the buttons and clear the values of all the axes
> 
> Based off the patch originally written by Carlos Garnacho
> 
> Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
> ---
>  test/Makefile.am |   6 ++
>  test/tablet.c    | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 235 insertions(+)
>  create mode 100644 test/tablet.c
> 
> diff --git a/test/Makefile.am b/test/Makefile.am
> index b6b3a51..0b86d35 100644
> --- a/test/Makefile.am
> +++ b/test/Makefile.am
> @@ -34,6 +34,7 @@ run_tests = \
>  	test-pointer \
>  	test-touch \
>  	test-log \
> +	test-tablet \
>  	test-touchpad \
>  	test-misc \
>  	test-keyboard
> @@ -68,6 +69,11 @@ test_log_SOURCES = log.c
>  test_log_LDADD = $(TEST_LIBS)
>  test_log_LDFLAGS = -static
>  
> +test_tablet_SOURCES = tablet.c
> +test_tablet_CFLAGS = $(AM_CPPFLAGS)
> +test_tablet_LDADD = $(TEST_LIBS)
> +test_tablet_LDFLAGS = -static
> +
>  test_touchpad_SOURCES = touchpad.c
>  test_touchpad_LDADD = $(TEST_LIBS)
>  test_touchpad_LDFLAGS = -static
> diff --git a/test/tablet.c b/test/tablet.c
> new file mode 100644
> index 0000000..9c5397f
> --- /dev/null
> +++ b/test/tablet.c
> @@ -0,0 +1,229 @@
> +/*
> + * Copyright © 2014 Red Hat, Inc.
> + * Copyright © 2014 Stephen Chandler "Lyude" Paul
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and
> + * its documentation for any purpose is hereby granted without fee, provided
> + * that the above copyright notice appear in all copies and that both that
> + * copyright notice and this permission notice appear in supporting
> + * documentation, and that the name of the copyright holders not be used in
> + * advertising or publicity pertaining to distribution of the software
> + * without specific, written prior permission.  The copyright holders make
> + * no representations about the suitability of this software for any
> + * purpose.  It is provided "as is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
> + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
> + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
> + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
> + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
> + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
> + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <config.h>
> +
> +#include <check.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <libinput.h>
> +#include <unistd.h>
> +#include <stdbool.h>
> +
> +#include "libinput-util.h"
> +#include "evdev-tablet.h"
> +#include "litest.h"
> +
> +START_TEST(proximity_in_out)
> +{
> +	struct litest_device *dev = litest_current_device();
> +	struct libinput *li = dev->libinput;
> +	struct libinput_event_tablet *tablet_event;
> +	struct libinput_event *event;
> +	bool have_tool_update = false,
> +	     have_proximity_out = false;
> +	uint32_t *axis;
> +
> +	struct axis_replacement axes[] = {
> +		{ ABS_DISTANCE, 10 },
> +		{ -1, -1 }
> +	};
> +
> +	uint32_t test_axes[] = {
> +		ABS_X,
> +		ABS_Y,
> +		ABS_DISTANCE,
> +		ABS_PRESSURE,
> +		ABS_TILT_X,
> +		ABS_TILT_Y
> +	};
> +
> +	litest_drain_events(dev->libinput);
> +
> +	litest_tablet_proximity_in(dev, 10, 10, axes);
> +	libinput_dispatch(li);
> +
> +	while ((event = libinput_get_event(li))) {
> +		if (libinput_event_get_type(event) ==
> +		    LIBINPUT_EVENT_TABLET_TOOL_UPDATE) {
> +			struct libinput_tool * tool;
> +
> +			have_tool_update++;
> +			tablet_event = libinput_event_get_tablet_event(event);
> +			tool = libinput_event_tablet_get_tool(tablet_event);
> +			ck_assert_int_eq(libinput_tool_get_type(tool),
> +					 LIBINPUT_TOOL_PEN);
> +		}
> +		libinput_event_destroy(event);
> +	}
> +	ck_assert(have_tool_update);
> +
> +	litest_tablet_proximity_out(dev);
> +	libinput_dispatch(li);
> +
> +	while ((event = libinput_get_event(li))) {
> +		if (libinput_event_get_type(event) ==
> +		    LIBINPUT_EVENT_TABLET_PROXIMITY_OUT)
> +			have_proximity_out = true;
> +
> +		libinput_event_destroy(event);
> +	}
> +	ck_assert(have_proximity_out);

just finish the first test here.

as discussed below, the remainer here is testing for behaviour that's not
ideal. once we're out of proximity, we shouldn't get any further events from
libinput (that would be worth a test btw). and we need to make sure that
libinput interally keeps updating axes so we always have the right value
once the tool comes into proximity. Drop this loop from the test, leave the
rest in place.

> +
> +	/* Make sure every axis gets cleared during a proximity out event */
> +	ARRAY_FOR_EACH(test_axes, axis) {
> +		uint32_t *abs_code;
> +		enum libinput_tablet_axis li_axis;
> +		int a;
> +
> +		litest_tablet_proximity_in(dev, 10, 10, axes);
> +		ARRAY_FOR_EACH(test_axes, abs_code) {
> +			litest_event(dev, EV_ABS, *abs_code, 10);
> +		}
> +		litest_tablet_proximity_out(dev);
> +
> +		/* We need to trigger at least one axis event, otherwise we
> +		 * can't check the value of the other axes
> +		 */
> +		litest_event(dev, EV_ABS, *axis, 10);
> +		litest_event(dev, EV_SYN, SYN_REPORT, 0);
> +
> +		libinput_dispatch(li);
> +
> +		/* Skip to after the proximity out event */
> +		while (libinput_next_event_type(li) !=
> +		       LIBINPUT_EVENT_TABLET_PROXIMITY_OUT)
> +			libinput_event_destroy(libinput_get_event(li));
> +
> +		/* Check to make sure all of the other axes were cleared */
> +		li_axis = evcode_to_axis(*axis);
> +		while ((event = libinput_get_event(li))) {
> +			if (libinput_event_get_type(event) !=
> +			    LIBINPUT_EVENT_TABLET_AXIS) {
> +				libinput_event_destroy(event);
> +				continue;
> +			}
> +
> +			tablet_event = libinput_event_get_tablet_event(event);
> +
> +			for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) {
> +				int has_changed;
> +				double value;
> +
> +				has_changed = libinput_event_tablet_axis_has_changed(
> +				    tablet_event, a);
> +				value = libinput_event_tablet_get_axis_value(
> +				    tablet_event, a);
> +
> +				if (a == li_axis) {
> +					ck_assert(has_changed);
> +					litest_assert_double_ne(value, 0);
> +				} else {
> +					ck_assert(!has_changed);
> +					litest_assert_double_eq(value, 0);
> +				}
> +			}
> +
> +			libinput_event_destroy(event);
> +		}
> +	}
> +
> +	/* Proximity out must not emit axis events */
> +	litest_tablet_proximity_out(dev);
> +	libinput_dispatch(li);
> +
> +	while ((event = libinput_get_event(li))) {
> +		tablet_event = libinput_event_get_tablet_event(event);

tablet_event is unused here

> +		enum libinput_event_type type = libinput_event_get_type(event);
> +
> +		ck_assert(type != LIBINPUT_EVENT_TABLET_AXIS);
> +
> +		libinput_event_destroy(event);
> +	}
> +}
> +END_TEST
> +
> +START_TEST(proximity_out_clear_buttons)
> +{
> +	struct litest_device *dev = litest_current_device();
> +	struct libinput *li = dev->libinput;
> +	struct libinput_event_tablet *tablet_event;
> +	struct libinput_event *event;
> +	unsigned int button;
> +
> +	struct axis_replacement axes[] = {
> +		{ ABS_DISTANCE, 10 },
> +		{ -1, -1 }
> +	};
> +
> +	litest_drain_events(dev->libinput);
> +
> +	/* Test that proximity out events send button releases for any currently
> +	 * pressed stylus buttons
> +	 */
> +	for (button = BTN_TOUCH; button <= BTN_STYLUS2; button++) {
> +		bool button_released = false;
> +		unsigned int event_button;

use uint32_t, that's what the API wants.

> +		enum libinput_button_state state;
> +
> +		litest_tablet_proximity_in(dev, 10, 10, axes);
> +		litest_event(dev, EV_KEY, button, 1);
> +		litest_event(dev, EV_SYN, SYN_REPORT, 0);
> +		litest_tablet_proximity_out(dev);
> +
> +		libinput_dispatch(li);
> +
> +		while ((event = libinput_get_event(li))) {
> +			tablet_event = libinput_event_get_tablet_event(event);
> +
> +			if (libinput_event_get_type(event) ==
> +			    LIBINPUT_EVENT_TABLET_BUTTON) {
> +
> +				event_button = libinput_event_tablet_get_button(
> +				    tablet_event);
> +				state = libinput_event_tablet_get_button_state(
> +				    tablet_event);

not a big fan of the line-break here, I'd rather have this go over the 80
chars for readability.

> +
> +				if (event_button == button &&
> +				    state == LIBINPUT_BUTTON_STATE_RELEASED)
> +					button_released = true;
> +			}
> +
> +			libinput_event_destroy(event);
> +		}
> +
> +		ck_assert_msg(button_released,
> +			      "Button %d was not released.",
> +			      event_button);
> +	}
> +}
> +END_TEST
> +
> +int
> +main(int argc, char **argv)
> +{
> +	litest_add("tablet:proximity-out-clear-buttons", proximity_out_clear_buttons, LITEST_TABLET, LITEST_ANY);
> +	litest_add("tablet:proximity-in-out", proximity_in_out, LITEST_TABLET, LITEST_ANY);

the part in the quotes is for grouping tests, "tablet:proximity" is enough
for both.

Cheers,
   Peter

> +
> +	return litest_run(argc, argv);
> +}
> -- 
> 1.8.5.5
> 


More information about the wayland-devel mailing list