mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-25 07:00:07 +01:00
test: add new helper function for absolute events
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
3ad61372c8
commit
3343076530
2 changed files with 43 additions and 0 deletions
|
|
@ -56,3 +56,41 @@ int test_create_device(struct uinput_device **uidev_return,
|
|||
return rc == 0 ? rc : -errno;
|
||||
}
|
||||
|
||||
int test_create_abs_device(struct uinput_device **uidev_return,
|
||||
struct libevdev **dev_return,
|
||||
int nabs,
|
||||
struct input_absinfo *abs,
|
||||
...)
|
||||
{
|
||||
int rc, fd;
|
||||
struct uinput_device *uidev;
|
||||
struct libevdev *dev;
|
||||
va_list args;
|
||||
|
||||
uidev = uinput_device_new("test device");
|
||||
ck_assert(uidev != NULL);
|
||||
|
||||
va_start(args, abs);
|
||||
rc = uinput_device_set_event_bits_v(uidev, args);
|
||||
va_end(args);
|
||||
|
||||
while (--nabs >= 0) {
|
||||
rc = uinput_device_set_abs_bit(uidev, abs[nabs].value, &abs[nabs]);
|
||||
ck_assert_msg(rc == 0, "for abs field %d\n", nabs);
|
||||
}
|
||||
|
||||
rc = uinput_device_create(uidev);
|
||||
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
||||
|
||||
fd = uinput_device_get_fd(uidev);
|
||||
|
||||
rc = libevdev_new_from_fd(fd, &dev);
|
||||
ck_assert_msg(rc == 0, "Failed to init device device: %s", strerror(-rc));
|
||||
rc = fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));
|
||||
|
||||
*uidev_return = uidev;
|
||||
*dev_return = dev;
|
||||
|
||||
return rc == 0 ? rc : -errno;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,5 +34,10 @@
|
|||
int test_create_device(struct uinput_device **uidev,
|
||||
struct libevdev **dev,
|
||||
...);
|
||||
int test_create_abs_device(struct uinput_device **uidev,
|
||||
struct libevdev **dev,
|
||||
int nabs,
|
||||
struct input_absinfo *abs,
|
||||
...);
|
||||
|
||||
#endif /* _TEST_COMMON_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue