On Tue, Feb 18, 2014 at 08:13:58PM +0100, Jonas Ådahl wrote:
> Add a test case and test device that checks if the scale transform can
> handle high resolution devices and output monitor resolutions.
> 
> The test case is created in a way that it will fail if the coordinate
> transform expression will overflow if only 32 bit integer data
> containers are used.
> 
> Signed-off-by: Jonas Ådahl <jad...@gmail.com>
> ---
> 
> > fwiw, this is exactly the type of use-case where it would be simple and
> > worth it to knock up a test for a single device and make sure that the
> > coordinates are correct. which gives us a nice reproducer and prevents us
> > from errors like this in the future.
> 
> And here is such a test case. It will fail as is, but pass if either the
> expression uses 64 bit integers or doubles.
> 
> 
> Jonas
> 
> 
>  test/Makefile.am                    |   1 +
>  test/litest-generic-highres-touch.c | 139 
> ++++++++++++++++++++++++++++++++++++
>  test/litest.c                       |   2 +
>  test/litest.h                       |   1 +
>  test/touch.c                        |  40 ++++++++++-
>  5 files changed, 182 insertions(+), 1 deletion(-)
>  create mode 100644 test/litest-generic-highres-touch.c
> 
> diff --git a/test/Makefile.am b/test/Makefile.am
> index 59687f6..4b923aa 100644
> --- a/test/Makefile.am
> +++ b/test/Makefile.am
> @@ -14,6 +14,7 @@ liblitest_la_SOURCES = \
>       litest-synaptics.c \
>       litest-trackpoint.c \
>       litest-wacom-touch.c \
> +     litest-generic-highres-touch.c \
>       litest.c
>  
>  run_tests = test-udev test-path test-pointer test-touch
> diff --git a/test/litest-generic-highres-touch.c 
> b/test/litest-generic-highres-touch.c
> new file mode 100644
> index 0000000..bd326ce
> --- /dev/null
> +++ b/test/litest-generic-highres-touch.c
> @@ -0,0 +1,139 @@
> +/*
> + * Copyright © 2013 Red Hat, Inc.
> + * Copyright © 2014 Jonas Ådahl
> + *
> + * 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 "litest.h"
> +#include "litest-int.h"
> +#include "libinput-util.h"
> +
> +void litest_generic_highres_touch_setup(void)
> +{
> +     struct litest_device *d =
> +             litest_create_device(LITEST_GENERIC_HIGHRES_TOUCH);
> +     litest_set_current_device(d);
> +}
> +
> +void
> +litest_generic_highres_touch_touch_down(struct litest_device *d,
> +                                     unsigned int slot,
> +                                     int x, int y)
> +{
> +     static int tracking_id;
> +     struct input_event *ev;
> +     struct input_event down[] = {
> +             { .type = EV_ABS, .code = ABS_X, .value = x  },
> +             { .type = EV_ABS, .code = ABS_Y, .value = y },
> +             { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot },
> +             { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = 
> ++tracking_id },
> +             { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = x },
> +             { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = y },
> +             { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
> +             { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
> +     };
> +
> +     down[0].value = litest_scale(d, ABS_X, x);
> +     down[1].value = litest_scale(d, ABS_Y, y);
> +     down[4].value = litest_scale(d, ABS_X, x);
> +     down[5].value = litest_scale(d, ABS_Y, y);
> +
> +     ARRAY_FOR_EACH(down, ev)
> +             litest_event(d, ev->type, ev->code, ev->value);
> +}
> +
> +void
> +litest_generic_highres_touch_move(struct litest_device *d,
> +                               unsigned int slot,
> +                               int x, int y)
> +{
> +     struct input_event *ev;
> +     struct input_event move[] = {
> +             { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot },
> +             { .type = EV_ABS, .code = ABS_X, .value = x  },
> +             { .type = EV_ABS, .code = ABS_Y, .value = y },
> +             { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = x },
> +             { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = y },
> +             { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
> +             { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
> +     };
> +
> +     move[1].value = litest_scale(d, ABS_X, x);
> +     move[2].value = litest_scale(d, ABS_Y, y);
> +     move[3].value = litest_scale(d, ABS_X, x);
> +     move[4].value = litest_scale(d, ABS_Y, y);
> +
> +     ARRAY_FOR_EACH(move, ev)
> +             litest_event(d, ev->type, ev->code, ev->value);
> +}
> +
> +static struct litest_device_interface interface = {
> +     .touch_down = litest_generic_highres_touch_touch_down,
> +     .touch_move = litest_generic_highres_touch_move,
> +};
> +
> +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 },
> +             { ABS_MT_SLOT, 0, 1, 0 },
> +             { 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 },
> +     };
> +
> +     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);
> +}
> +
> +struct litest_test_device litest_generic_highres_touch_device = {
> +     .type = LITEST_GENERIC_HIGHRES_TOUCH,
> +     .features = LITEST_TOUCH,
> +     .shortname = "generic-highres-touch",
> +     .setup = litest_generic_highres_touch_setup,
> +     .teardown = litest_generic_device_teardown,
> +     .create = litest_create_generic_highres_touch,
> +};
> +
> diff --git a/test/litest.c b/test/litest.c
> index d64974a..78a0472 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -81,6 +81,7 @@ extern struct litest_test_device litest_trackpoint_device;
>  extern struct litest_test_device litest_bcm5974_device;
>  extern struct litest_test_device litest_mouse_device;
>  extern struct litest_test_device litest_wacom_touch_device;
> +extern struct litest_test_device litest_generic_highres_touch_device;
>  
>  struct litest_test_device* devices[] = {
>       &litest_synaptics_clickpad_device,
> @@ -89,6 +90,7 @@ struct litest_test_device* devices[] = {
>       &litest_bcm5974_device,
>       &litest_mouse_device,
>       &litest_wacom_touch_device,
> +     &litest_generic_highres_touch_device,
>       NULL,
>  };
>  
> diff --git a/test/litest.h b/test/litest.h
> index e3f599f..9cc0ff5 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -41,6 +41,7 @@ enum litest_device_type {
>       LITEST_TRACKPOINT,
>       LITEST_MOUSE,
>       LITEST_WACOM_TOUCH,
> +     LITEST_GENERIC_HIGHRES_TOUCH,
>  };
>  
>  enum litest_device_feature {
> diff --git a/test/touch.c b/test/touch.c
> index 2d9ce0a..d5ff36e 100644
> --- a/test/touch.c
> +++ b/test/touch.c
> @@ -62,9 +62,47 @@ START_TEST(touch_frame_events)
>  }
>  END_TEST
>  
> -int main (int argc, char **argv) {
> +START_TEST(touch_abs_transform)
> +{
> +     struct litest_device *dev = litest_current_device();
> +     struct libinput *libinput = dev->libinput;
> +     struct libinput_event *ev;
> +     struct libinput_event_touch *tev;
> +     li_fixed_t fx, fy;
> +     bool tested = false;
> +
> +     litest_touch_down(dev, 0, 100, 100);
> +
> +     libinput_dispatch(libinput);
> +
> +     while ((ev = libinput_get_event(libinput))) {
> +             if (libinput_event_get_type(ev) != LIBINPUT_EVENT_TOUCH_TOUCH)
> +                     continue;
> +
> +             tev = libinput_event_get_touch_event(ev);
> +             if (libinput_event_touch_get_touch_type(tev) !=
> +                 LIBINPUT_TOUCH_TYPE_DOWN)
> +                     continue;
> +
> +             fx = libinput_event_touch_get_x_transformed(tev, 1920);
> +             ck_assert_int_eq(li_fixed_to_int(fx), 1919);
> +             fx = libinput_event_touch_get_x_transformed(tev, 720);
> +             ck_assert_int_eq(li_fixed_to_int(fx), 719);

did you mean for this to test fx twice? I'm assuming this is a typo, I've
changed this locally to use y and will push the three patches once I get
benjamin's updated one.

Thanks for the test case!

Cheers,
   Peter

>  
> +             tested = true;
> +     }
> +
> +     ck_assert(tested);
> +}
> +END_TEST
> +
> +
> +int
> +main(int argc, char **argv)
> +{
>       litest_add("touch:frame", touch_frame_events, LITEST_TOUCH, LITEST_ANY);
> +     litest_add("touch:abs-transform", touch_abs_transform,
> +                LITEST_TOUCH, LITEST_ANY);
>  
>       return litest_run(argc, argv);
>  }
> -- 
> 1.8.3.2
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 
_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to