[PATCH v2 libinput 1/5] test: add litest helper functions for creating uinput devices

Hans de Goede hdegoede at redhat.com
Tue Apr 1 02:34:13 PDT 2014


Hi,

On 04/01/2014 05:47 AM, Peter Hutterer wrote:
> Both functions accept a series of event types/codes tuples, terminated by -1.
> For the even type INPUT_PROP_MAX (an invalid type otherwise) the code is used
> as a property to enable.
> 
> The _abs function als takes an array of absinfo, with absinfo.value
> determining the axis to change. If none are given, abs axes are initialized
> with default settings.
> 
> Both functions abort on failure, so the caller does not need to check the
> return value.
> 
> Example code for creating a rel device:
> 
> struct libevdev_uinput *uinput;
> struct input_id id = { ... };
> uinput = litest_create_uinput_device("foo", &id,
>                                      EV_REL, REL_X,
>                                      EV_REL, REL_Y,
>                                      EV_KEY, BTN_LEFT,
>                                      INPUT_PROP_MAX, INPUT_PROP_BUTTONPAD,
>                                      -1);
> libevdev_uinput_write_event(uinput, EV_REL, REL_X, -1);
> libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0);
> ...
> libevdev_uinput_destroy(uinput);
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Looks good:

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

Regards,

Hans

> ---
> Changes to v1:
> - make absinfo a -1-terminated list as well
> 
>  test/litest-bcm5974.c               |  45 +++-----
>  test/litest-generic-highres-touch.c |  34 +++---
>  test/litest-synaptics-st.c          |  37 +++----
>  test/litest-synaptics.c             |  45 +++-----
>  test/litest-trackpoint.c            |  32 +++---
>  test/litest-wacom-touch.c           |  33 ++----
>  test/litest.c                       |  88 +++++++++++++++
>  test/litest.h                       |   8 ++
>  test/path.c                         | 207 ++++++++++++------------------------
>  9 files changed, 244 insertions(+), 285 deletions(-)
> 
> diff --git a/test/litest-bcm5974.c b/test/litest-bcm5974.c
> index 5a8ce8a..6b7a22b 100644
> --- a/test/litest-bcm5974.c
> +++ b/test/litest-bcm5974.c
> @@ -95,7 +95,6 @@ static struct litest_device_interface interface = {
>  void
>  litest_create_bcm5974(struct litest_device *d)
>  {
> -	struct libevdev *dev;
>  	struct input_absinfo abs[] = {
>  		{ ABS_X, 1472, 5472, 75 },
>  		{ ABS_Y, 1408, 4448, 129 },
> @@ -105,36 +104,26 @@ litest_create_bcm5974(struct litest_device *d)
>  		{ ABS_MT_POSITION_X, 1472, 5472, 75 },
>  		{ ABS_MT_POSITION_Y, 1408, 4448, 129 },
>  		{ ABS_MT_TRACKING_ID, 0, 65535, 0 },
> -		{ ABS_MT_PRESSURE, 0, 255, 0 }
> +		{ ABS_MT_PRESSURE, 0, 255, 0 },
> +		{ .value = -1 },
> +	};
> +	struct input_id id = {
> +		.bustype = 0x3,
> +		.vendor = 0x5ac,
> +		.product = 0x249,
>  	};
> -	struct input_absinfo *a;
> -	int rc;
>  
>  	d->interface = &interface;
> -
> -	dev = libevdev_new();
> -	ck_assert(dev != NULL);
> -
> -	libevdev_set_name(dev, "bcm5974");
> -	libevdev_set_id_bustype(dev, 0x3);
> -	libevdev_set_id_vendor(dev, 0x5ac);
> -	libevdev_set_id_product(dev, 0x249);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_FINGER, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_QUINTTAP, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_DOUBLETAP, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_TRIPLETAP, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_QUADTAP, NULL);
> -
> -	ARRAY_FOR_EACH(abs, a)
> -		libevdev_enable_event_code(dev, EV_ABS, a->value, a);
> -
> -	rc = libevdev_uinput_create_from_device(dev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&d->uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(dev);
> +	d->uinput = litest_create_uinput_abs_device("bcm5974", &id,
> +						    abs,
> +						    EV_KEY, BTN_LEFT,
> +						    EV_KEY, BTN_TOOL_FINGER,
> +						    EV_KEY, BTN_TOOL_QUINTTAP,
> +						    EV_KEY, BTN_TOUCH,
> +						    EV_KEY, BTN_TOOL_DOUBLETAP,
> +						    EV_KEY, BTN_TOOL_TRIPLETAP,
> +						    EV_KEY, BTN_TOOL_QUADTAP,
> +						    -1, -1);
>  }
>  
>  struct litest_test_device litest_bcm5974_device = {
> diff --git a/test/litest-generic-highres-touch.c b/test/litest-generic-highres-touch.c
> index 68615c3..bb226d6 100644
> --- a/test/litest-generic-highres-touch.c
> +++ b/test/litest-generic-highres-touch.c
> @@ -94,9 +94,6 @@ static struct litest_device_interface interface = {
>  void
>  litest_create_generic_highres_touch(struct litest_device *d)
>  {
> -	struct libevdev *dev;
> -	int rc;
> -	struct input_absinfo *a;
>  	struct input_absinfo abs[] = {
>  		{ ABS_X, 0, 32767, 75 },
>  		{ ABS_Y, 0, 32767, 129 },
> @@ -104,28 +101,21 @@ litest_create_generic_highres_touch(struct litest_device *d)
>  		{ ABS_MT_POSITION_X, 0, 32767, 0, 0, 10 },
>  		{ ABS_MT_POSITION_Y, 0, 32767, 0, 0, 9 },
>  		{ ABS_MT_TRACKING_ID, 0, 65535, 0 },
> +		{ .value = -1 },
> +	};
> +	struct input_id id = {
> +		.bustype = 0x3,
> +		.vendor = 0xabcd, /* Some random vendor. */
> +		.product = 0x1234, /* Some random product id. */
>  	};
>  
>  	d->interface = &interface;
> -
> -	dev = libevdev_new();
> -	ck_assert(dev != NULL);
> -
> -	libevdev_set_name(dev, "Generic emulated highres touch device");
> -	libevdev_set_id_bustype(dev, 0x3);
> -	libevdev_set_id_vendor(dev, 0xabcd); /* Some random vendor. */
> -	libevdev_set_id_product(dev, 0x1234); /* Some random product id. */
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
> -	libevdev_enable_property(dev, INPUT_PROP_DIRECT);
> -
> -	ARRAY_FOR_EACH(abs, a)
> -		libevdev_enable_event_code(dev, EV_ABS, a->value, a);
> -
> -	rc = libevdev_uinput_create_from_device(dev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&d->uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(dev);
> +	d->uinput = litest_create_uinput_abs_device("Generic emulated highres touch device",
> +						    &id,
> +						    abs,
> +						    EV_KEY, BTN_TOUCH,
> +						    INPUT_PROP_MAX, INPUT_PROP_DIRECT,
> +						    -1, -1);
>  }
>  
>  struct litest_test_device litest_generic_highres_touch_device = {
> diff --git a/test/litest-synaptics-st.c b/test/litest-synaptics-st.c
> index 2c7d371..d13d9a2 100644
> --- a/test/litest-synaptics-st.c
> +++ b/test/litest-synaptics-st.c
> @@ -98,38 +98,27 @@ static struct litest_device_interface interface = {
>  void
>  litest_create_synaptics_touchpad(struct litest_device *d)
>  {
> -	struct libevdev *dev;
>  	struct input_absinfo abs[] = {
>  		{ ABS_X, 1472, 5472, 75 },
>  		{ ABS_Y, 1408, 4448, 129 },
>  		{ ABS_PRESSURE, 0, 255, 0 },
>  		{ ABS_TOOL_WIDTH, 0, 15, 0 },
> +		{ .value = -1 },
> +	};
> +	struct input_id id = {
> +		.bustype = 0x11,
> +		.vendor = 0x2,
> +		.product = 0x7,
>  	};
> -	struct input_absinfo *a;
> -	int rc;
>  
>  	d->interface = &interface;
> -
> -	dev = libevdev_new();
> -	ck_assert(dev != NULL);
> -
> -	libevdev_set_name(dev, "SynPS/2 Synaptics TouchPad");
> -	libevdev_set_id_bustype(dev, 0x11);
> -	libevdev_set_id_vendor(dev, 0x2);
> -	libevdev_set_id_product(dev, 0x7);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_FINGER, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
> -
> -	ARRAY_FOR_EACH(abs, a)
> -		libevdev_enable_event_code(dev, EV_ABS, a->value, a);
> -
> -	rc = libevdev_uinput_create_from_device(dev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&d->uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(dev);
> +	d->uinput = litest_create_uinput_abs_device("SynPS/2 Synaptics TouchPad", &id,
> +						    abs,
> +						    EV_KEY, BTN_LEFT,
> +						    EV_KEY, BTN_RIGHT,
> +						    EV_KEY, BTN_TOOL_FINGER,
> +						    EV_KEY, BTN_TOUCH,
> +						    -1, -1);
>  }
>  
>  struct litest_test_device litest_synaptics_touchpad_device = {
> diff --git a/test/litest-synaptics.c b/test/litest-synaptics.c
> index e4a4783..c960db2 100644
> --- a/test/litest-synaptics.c
> +++ b/test/litest-synaptics.c
> @@ -97,7 +97,6 @@ static struct litest_device_interface interface = {
>  void
>  litest_create_synaptics_clickpad(struct litest_device *d)
>  {
> -	struct libevdev *dev;
>  	struct input_absinfo abs[] = {
>  		{ ABS_X, 1472, 5472, 75 },
>  		{ ABS_Y, 1408, 4448, 129 },
> @@ -107,36 +106,26 @@ litest_create_synaptics_clickpad(struct litest_device *d)
>  		{ ABS_MT_POSITION_X, 1472, 5472, 75 },
>  		{ ABS_MT_POSITION_Y, 1408, 4448, 129 },
>  		{ ABS_MT_TRACKING_ID, 0, 65535, 0 },
> -		{ ABS_MT_PRESSURE, 0, 255, 0 }
> +		{ ABS_MT_PRESSURE, 0, 255, 0 },
> +		{ .value = -1 },
> +	};
> +	struct input_id id = {
> +		.bustype = 0x11,
> +		.vendor = 0x2,
> +		.product = 0x11,
>  	};
> -	struct input_absinfo *a;
> -	int rc;
>  
>  	d->interface = &interface;
> -
> -	dev = libevdev_new();
> -	ck_assert(dev != NULL);
> -
> -	libevdev_set_name(dev, "SynPS/2 Synaptics TouchPad");
> -	libevdev_set_id_bustype(dev, 0x11);
> -	libevdev_set_id_vendor(dev, 0x2);
> -	libevdev_set_id_product(dev, 0x11);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_FINGER, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_QUINTTAP, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_DOUBLETAP, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_TRIPLETAP, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_QUADTAP, NULL);
> -
> -	ARRAY_FOR_EACH(abs, a)
> -		libevdev_enable_event_code(dev, EV_ABS, a->value, a);
> -
> -	rc = libevdev_uinput_create_from_device(dev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&d->uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(dev);
> +	d->uinput = litest_create_uinput_abs_device("SynPS/2 Synaptics TouchPad", &id,
> +						    abs,
> +						    EV_KEY, BTN_LEFT,
> +						    EV_KEY, BTN_TOOL_FINGER,
> +						    EV_KEY, BTN_TOOL_QUINTTAP,
> +						    EV_KEY, BTN_TOUCH,
> +						    EV_KEY, BTN_TOOL_DOUBLETAP,
> +						    EV_KEY, BTN_TOOL_TRIPLETAP,
> +						    EV_KEY, BTN_TOOL_QUADTAP,
> +						    -1, -1);
>  }
>  
>  struct litest_test_device litest_synaptics_clickpad_device = {
> diff --git a/test/litest-trackpoint.c b/test/litest-trackpoint.c
> index 68d5834..e0b79c5 100644
> --- a/test/litest-trackpoint.c
> +++ b/test/litest-trackpoint.c
> @@ -40,28 +40,20 @@ static struct litest_device_interface interface = {
>  static void
>  litest_create_trackpoint(struct litest_device *d)
>  {
> -	struct libevdev *dev;
> -	int rc;
> +	struct input_id id = {
> +		.bustype = 0x11,
> +		.vendor = 0x2,
> +		.product = 0xa,
> +	};
>  
>  	d->interface = &interface;
> -	dev = libevdev_new();
> -	ck_assert(dev != NULL);
> -
> -	libevdev_set_name(dev, "TPPS/2 IBM TrackPoint");
> -	libevdev_set_id_bustype(dev, 0x11);
> -	libevdev_set_id_vendor(dev, 0x2);
> -	libevdev_set_id_product(dev, 0xa);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_MIDDLE, NULL);
> -	libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(dev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&d->uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(dev);
> +	d->uinput = litest_create_uinput_device("TPPS/2 IBM TrackPoint", &id,
> +						EV_KEY, BTN_LEFT,
> +						EV_KEY, BTN_RIGHT,
> +						EV_KEY, BTN_MIDDLE,
> +						EV_REL, REL_X,
> +						EV_REL, REL_Y,
> +						-1, -1);
>  }
>  
>  struct litest_test_device litest_trackpoint_device = {
> diff --git a/test/litest-wacom-touch.c b/test/litest-wacom-touch.c
> index 464d541..01a5a5d 100644
> --- a/test/litest-wacom-touch.c
> +++ b/test/litest-wacom-touch.c
> @@ -94,7 +94,6 @@ static struct litest_device_interface interface = {
>  void
>  litest_create_wacom_touch(struct litest_device *d)
>  {
> -	struct libevdev *dev;
>  	struct input_absinfo abs[] = {
>  		{ ABS_X, 0, 2776, 75 },
>  		{ ABS_Y, 0, 1569, 129 },
> @@ -102,30 +101,20 @@ litest_create_wacom_touch(struct litest_device *d)
>  		{ ABS_MT_POSITION_X, 0, 2776, 0, 0, 10 },
>  		{ ABS_MT_POSITION_Y, 0, 1569, 0, 0, 9 },
>  		{ ABS_MT_TRACKING_ID, 0, 65535, 0 },
> +		{ .value = -1 },
> +	};
> +	struct input_id id = {
> +		.bustype = 0x3,
> +		.vendor = 0x56a,
> +		.product = 0xe6,
>  	};
> -	struct input_absinfo *a;
> -	int rc;
>  
>  	d->interface = &interface;
> -
> -	dev = libevdev_new();
> -	ck_assert(dev != NULL);
> -
> -	libevdev_set_name(dev, "Wacom ISDv4 E6 Finger");
> -	libevdev_set_id_bustype(dev, 0x3);
> -	libevdev_set_id_vendor(dev, 0x56a);
> -	libevdev_set_id_product(dev, 0xe6);
> -	libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
> -	libevdev_enable_property(dev, INPUT_PROP_DIRECT);
> -
> -	ARRAY_FOR_EACH(abs, a)
> -		libevdev_enable_event_code(dev, EV_ABS, a->value, a);
> -
> -	rc = libevdev_uinput_create_from_device(dev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&d->uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(dev);
> +	d->uinput = litest_create_uinput_abs_device("Wacom ISDv4 E6 Finger", &id,
> +						    abs,
> +						    EV_KEY, BTN_TOUCH,
> +						    INPUT_PROP_MAX, INPUT_PROP_DIRECT,
> +						    -1, -1);
>  }
>  
>  struct litest_test_device litest_wacom_touch_device = {
> diff --git a/test/litest.c b/test/litest.c
> index 9241623..f7fe24e 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -490,3 +490,91 @@ litest_drain_events(struct libinput *li)
>  		libinput_dispatch(li);
>  	}
>  }
> +
> +static struct libevdev_uinput *
> +litest_create_uinput_abs_device_v(const char *name,
> +				  struct input_id *id,
> +				  const struct input_absinfo *abs,
> +				  va_list args)
> +{
> +	struct libevdev_uinput *uinput;
> +	struct libevdev *dev;
> +	int type, code;
> +	int rc;
> +	const struct input_absinfo default_abs = {
> +		.value = 0,
> +		.minimum = 0,
> +		.maximum = 0xffff,
> +		.fuzz = 0,
> +		.flat = 0,
> +		.resolution = 100
> +	};
> +
> +	dev = libevdev_new();
> +	ck_assert(dev != NULL);
> +
> +	libevdev_set_name(dev, name);
> +	if (id) {
> +		libevdev_set_id_bustype(dev, id->bustype);
> +		libevdev_set_id_vendor(dev, id->vendor);
> +		libevdev_set_id_product(dev, id->product);
> +	}
> +
> +	while (abs && abs->value != -1) {
> +		rc = libevdev_enable_event_code(dev, EV_ABS,
> +						abs->value, abs);
> +		ck_assert_int_eq(rc, 0);
> +		abs++;
> +	}
> +
> +	while ((type = va_arg(args, int)) != -1 &&
> +	       (code = va_arg(args, int)) != -1) {
> +		if (type == INPUT_PROP_MAX) {
> +			rc = libevdev_enable_property(dev, code);
> +		} else {
> +			if (type != EV_SYN)
> +				ck_assert(!libevdev_has_event_code(dev, type, code));
> +			rc = libevdev_enable_event_code(dev, type, code,
> +							type == EV_ABS ? &default_abs : NULL);
> +		}
> +		ck_assert_int_eq(rc, 0);
> +	}
> +
> +	rc = libevdev_uinput_create_from_device(dev,
> +					        LIBEVDEV_UINPUT_OPEN_MANAGED,
> +						&uinput);
> +	ck_assert_int_eq(rc, 0);
> +
> +	libevdev_free(dev);
> +
> +	return uinput;
> +}
> +
> +struct libevdev_uinput *
> +litest_create_uinput_abs_device(const char *name,
> +				struct input_id *id,
> +				const struct input_absinfo *abs,
> +				...)
> +{
> +	struct libevdev_uinput *uinput;
> +	va_list args;
> +
> +	va_start(args, abs);
> +	uinput = litest_create_uinput_abs_device_v(name, id, abs, args);
> +	va_end(args);
> +
> +	return uinput;
> +}
> +
> +struct libevdev_uinput *
> +litest_create_uinput_device(const char *name, struct input_id *id, ...)
> +{
> +	struct libevdev_uinput *uinput;
> +	va_list args;
> +
> +	va_start(args, id);
> +	uinput = litest_create_uinput_abs_device_v(name, id, NULL, args);
> +	va_end(args);
> +
> +	return uinput;
> +}
> diff --git a/test/litest.h b/test/litest.h
> index 9f0f614..75c517c 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -100,4 +100,12 @@ void litest_button_click(struct litest_device *d,
>  			 bool is_press);
>  void litest_drain_events(struct libinput *li);
>  
> +struct libevdev_uinput * litest_create_uinput_device(const char *name,
> +						     struct input_id *id,
> +						     ...);
> +struct libevdev_uinput * litest_create_uinput_abs_device(const char *name,
> +							 struct input_id *id,
> +							 const struct input_absinfo *abs,
> +							 ...);
> +
>  #endif /* LITEST_H */
> diff --git a/test/path.c b/test/path.c
> index 41ee5c6..e9f80cb 100644
> --- a/test/path.c
> +++ b/test/path.c
> @@ -105,25 +105,16 @@ START_TEST(path_create_destroy)
>  {
>  	struct libinput *li;
>  	struct libinput_device *device;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput;
>  	int rc;
>  	void *userdata = &rc;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(evdev);
> +	uinput = litest_create_uinput_device("test device", NULL,
> +					     EV_KEY, BTN_LEFT,
> +					     EV_KEY, BTN_RIGHT,
> +					     EV_REL, REL_X,
> +					     EV_REL, REL_Y,
> +					     -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> @@ -360,25 +351,16 @@ START_TEST(path_suspend)
>  {
>  	struct libinput *li;
>  	struct libinput_device *device;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput;
>  	int rc;
>  	void *userdata = &rc;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(evdev);
> +	uinput = litest_create_uinput_device("test device", NULL,
> +					     EV_KEY, BTN_LEFT,
> +					     EV_KEY, BTN_RIGHT,
> +					     EV_REL, REL_X,
> +					     EV_REL, REL_Y,
> +					     -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> @@ -402,25 +384,16 @@ START_TEST(path_double_suspend)
>  {
>  	struct libinput *li;
>  	struct libinput_device *device;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput;
>  	int rc;
>  	void *userdata = &rc;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(evdev);
> +	uinput = litest_create_uinput_device("test device", NULL,
> +					     EV_KEY, BTN_LEFT,
> +					     EV_KEY, BTN_RIGHT,
> +					     EV_REL, REL_X,
> +					     EV_REL, REL_Y,
> +					     -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> @@ -445,25 +418,16 @@ START_TEST(path_double_resume)
>  {
>  	struct libinput *li;
>  	struct libinput_device *device;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput;
>  	int rc;
>  	void *userdata = &rc;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(evdev);
> +	uinput = litest_create_uinput_device("test device", NULL,
> +					     EV_KEY, BTN_LEFT,
> +					     EV_KEY, BTN_RIGHT,
> +					     EV_REL, REL_X,
> +					     EV_REL, REL_Y,
> +					     -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> @@ -489,33 +453,23 @@ START_TEST(path_add_device_suspend_resume)
>  	struct libinput *li;
>  	struct libinput_device *device;
>  	struct libinput_event *event;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput1, *uinput2;
>  	int rc;
>  	int nevents;
>  	void *userdata = &rc;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput1);
> -	ck_assert_int_eq(rc, 0);
> -
> -	libevdev_set_name(evdev, "test device 2");
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput2);
> -	ck_assert_int_eq(rc, 0);
> -
> -	libevdev_free(evdev);
> +	uinput1 = litest_create_uinput_device("test device", NULL,
> +					      EV_KEY, BTN_LEFT,
> +					      EV_KEY, BTN_RIGHT,
> +					      EV_REL, REL_X,
> +					      EV_REL, REL_Y,
> +					      -1);
> +	uinput2 = litest_create_uinput_device("test device 2", NULL,
> +					      EV_KEY, BTN_LEFT,
> +					      EV_KEY, BTN_RIGHT,
> +					      EV_REL, REL_X,
> +					      EV_REL, REL_Y,
> +					      -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> @@ -582,33 +536,23 @@ START_TEST(path_add_device_suspend_resume_fail)
>  	struct libinput *li;
>  	struct libinput_device *device;
>  	struct libinput_event *event;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput1, *uinput2;
>  	int rc;
>  	int nevents;
>  	void *userdata = &rc;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput1);
> -	ck_assert_int_eq(rc, 0);
> -
> -	libevdev_set_name(evdev, "test device 2");
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput2);
> -	ck_assert_int_eq(rc, 0);
> -
> -	libevdev_free(evdev);
> +	uinput1 = litest_create_uinput_device("test device", NULL,
> +					      EV_KEY, BTN_LEFT,
> +					      EV_KEY, BTN_RIGHT,
> +					      EV_REL, REL_X,
> +					      EV_REL, REL_Y,
> +					      -1);
> +	uinput2 = litest_create_uinput_device("test device 2", NULL,
> +					      EV_KEY, BTN_LEFT,
> +					      EV_KEY, BTN_RIGHT,
> +					      EV_REL, REL_X,
> +					      EV_REL, REL_Y,
> +					      -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> @@ -683,33 +627,23 @@ START_TEST(path_add_device_suspend_resume_remove_device)
>  	struct libinput *li;
>  	struct libinput_device *device;
>  	struct libinput_event *event;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput1, *uinput2;
>  	int rc;
>  	int nevents;
>  	void *userdata = &rc;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput1);
> -	ck_assert_int_eq(rc, 0);
> -
> -	libevdev_set_name(evdev, "test device 2");
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput2);
> -	ck_assert_int_eq(rc, 0);
> -
> -	libevdev_free(evdev);
> +	uinput1 = litest_create_uinput_device("test device", NULL,
> +					      EV_KEY, BTN_LEFT,
> +					      EV_KEY, BTN_RIGHT,
> +					      EV_REL, REL_X,
> +					      EV_REL, REL_Y,
> +					      -1);
> +	uinput2 = litest_create_uinput_device("test device 2", NULL,
> +					      EV_KEY, BTN_LEFT,
> +					      EV_KEY, BTN_RIGHT,
> +					      EV_REL, REL_X,
> +					      EV_REL, REL_Y,
> +					      -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> @@ -781,7 +715,6 @@ END_TEST
>  START_TEST(path_seat_recycle)
>  {
>  	struct libinput *li;
> -	struct libevdev *evdev;
>  	struct libevdev_uinput *uinput;
>  	int rc;
>  	void *userdata = &rc;
> @@ -793,20 +726,12 @@ START_TEST(path_seat_recycle)
>  	int found = 0;
>  	void *user_data;
>  
> -	evdev = libevdev_new();
> -	ck_assert(evdev != NULL);
> -
> -	libevdev_set_name(evdev, "test device");
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_LEFT, NULL);
> -	libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL);
> -	libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL);
> -
> -	rc = libevdev_uinput_create_from_device(evdev,
> -						LIBEVDEV_UINPUT_OPEN_MANAGED,
> -						&uinput);
> -	ck_assert_int_eq(rc, 0);
> -	libevdev_free(evdev);
> +	uinput = litest_create_uinput_device("test device", NULL,
> +					     EV_KEY, BTN_LEFT,
> +					     EV_KEY, BTN_RIGHT,
> +					     EV_REL, REL_X,
> +					     EV_REL, REL_Y,
> +					     -1);
>  
>  	li = libinput_path_create_context(&simple_interface, userdata);
>  	ck_assert(li != NULL);
> 


More information about the wayland-devel mailing list