[PATCH libevdev 5/6] test: add test for sending uinput events
David Herrmann
dh.herrmann at gmail.com
Wed Aug 14 06:28:03 PDT 2013
Hi
On Wed, Aug 14, 2013 at 3:21 PM, Benjamin Tissoires
<benjamin.tissoires at gmail.com> wrote:
> 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).
This would add a udev dependency. I think we don't have that yet, do
we? Besides, it's a pretty small helper and as mentioned on github,
real uinput drivers don't need it. It's only useful for uinput tests
as they need access to both, uinput and /dev/input/eventX.
Cheers
David
More information about the Input-tools
mailing list