[PATCH libevdev 5/6] test: add test for sending uinput events

Benjamin Tissoires benjamin.tissoires at gmail.com
Wed Aug 14 06:21:17 PDT 2013


On Tue, Aug 13, 2013 at 12:39 PM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  test/test-uinput.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 64 insertions(+)
>
> diff --git a/test/test-uinput.c b/test/test-uinput.c
> index de5f3f8..c1ffc3a 100644
> --- a/test/test-uinput.c
> +++ b/test/test-uinput.c
> @@ -25,6 +25,7 @@
>  #include <linux/input.h>
>  #include <errno.h>
>  #include <unistd.h>
> +#include <stdlib.h>
>  #include <fcntl.h>
>  #include <libevdev/libevdev-uinput.h>
>
> @@ -161,6 +162,65 @@ START_TEST(test_uinput_check_syspath_name)
>  }
>  END_TEST
>
> +START_TEST(test_uinput_events)
> +{
> +       struct libevdev *dev;
> +       struct libevdev_uinput *uidev;
> +       int fd, fd2;
> +       int rc;
> +       char *devnode;
> +       int i;
> +       const int nevents = 5;
> +       struct input_event events[] = { {{0, 0}, EV_REL, REL_X, 1},
> +                                       {{0, 0}, EV_REL, REL_Y, -1},
> +                                       {{0, 0}, EV_SYN, SYN_REPORT, 0},
> +                                       {{0, 0}, EV_KEY, BTN_LEFT, 1},
> +                                       {{0, 0}, EV_SYN, SYN_REPORT, 0}};
> +       struct input_event events_read[nevents];
> +
> +       dev = libevdev_new();
> +       ck_assert(dev != NULL);
> +       libevdev_set_name(dev, TEST_DEVICE_NAME);
> +       libevdev_enable_event_type(dev, EV_SYN);
> +       libevdev_enable_event_type(dev, EV_REL);
> +       libevdev_enable_event_type(dev, EV_KEY);
> +       libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
> +       libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
> +       libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
> +
> +       fd = open(UINPUT_NODE, O_RDWR);
> +       ck_assert_int_gt(fd, -1);
> +
> +       rc = libevdev_uinput_create_from_device(dev, fd, &uidev);
> +       ck_assert_int_eq(rc, 0);
> +       ck_assert(uidev != NULL);
> +
> +       devnode = uinput_devnode_from_syspath(libevdev_uinput_get_syspath(uidev));

this makes me think that this function (retrieve the devnode of a
uinput device, should be in the libevdev_uinput API, rather than in
test-commons).

Other than that,
Reviewed-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>

Cheers,
Benjamin

> +       ck_assert(devnode != NULL);
> +
> +       fd2 = open(devnode, O_RDONLY);
> +
> +       for (i = 0; i < nevents; i++)
> +               libevdev_uinput_write_event(uidev, events[i].type, events[i].code, events[i].value);
> +
> +       rc = read(fd2, events_read, sizeof(events_read));
> +       ck_assert_int_eq(rc, sizeof(events_read));
> +
> +       for (i = 0; i < nevents; i++) {
> +               ck_assert_int_eq(events[i].type, events_read[i].type);
> +               ck_assert_int_eq(events[i].code, events_read[i].code);
> +               ck_assert_int_eq(events[i].value, events_read[i].value);
> +       }
> +
> +
> +       free(devnode);
> +       libevdev_free(dev);
> +       libevdev_uinput_destroy(uidev);
> +       close(fd);
> +       close(fd2);
> +}
> +END_TEST
> +
>  Suite *
>  uinput_suite(void)
>  {
> @@ -172,5 +232,9 @@ uinput_suite(void)
>         tcase_add_test(tc, test_uinput_check_syspath_name);
>         suite_add_tcase(s, tc);
>
> +       tc = tcase_create("device events");
> +       tcase_add_test(tc, test_uinput_events);
> +       suite_add_tcase(s, tc);
> +
>         return s;
>  }
> --
> 1.8.2.1
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/input-tools


More information about the Input-tools mailing list