mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-24 15:50:08 +01:00
test: add uinput prop bits and the test for it
Turns out I was looking at an old header file, UI_SET_PROPBIT has existed for quite a while. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
9e64f40f61
commit
76a03e5326
3 changed files with 44 additions and 7 deletions
|
|
@ -185,7 +185,7 @@ inotify_setup()
|
|||
int
|
||||
uinput_device_create(struct uinput_device* d)
|
||||
{
|
||||
int type, code;
|
||||
int type, code, prop;
|
||||
struct uinput_user_dev dev;
|
||||
int rc;
|
||||
int fd;
|
||||
|
|
@ -252,6 +252,15 @@ uinput_device_create(struct uinput_device* d)
|
|||
|
||||
}
|
||||
|
||||
for (prop = 0; prop < INPUT_PROP_MAX; prop++) {
|
||||
if (!bit_is_set(d->d.props, prop))
|
||||
continue;
|
||||
|
||||
rc = ioctl(fd, UI_SET_PROPBIT, prop);
|
||||
if (rc == -1)
|
||||
goto error;
|
||||
}
|
||||
|
||||
rc = write(fd, &dev, sizeof(dev));
|
||||
if (rc < 0)
|
||||
goto error;
|
||||
|
|
@ -334,6 +343,19 @@ uinput_device_set_bit(struct uinput_device* dev, unsigned int bit)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
uinput_device_set_prop(struct uinput_device *dev, unsigned int prop)
|
||||
{
|
||||
if (!dev)
|
||||
return -EINVAL;
|
||||
|
||||
if (prop > INPUT_PROP_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
set_bit(dev->d.props, prop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
uinput_device_set_event_bit(struct uinput_device* dev, unsigned int type, unsigned int code)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ int uinput_device_create(struct uinput_device* dev);
|
|||
int uinput_device_set_name(struct uinput_device* dev, const char *name);
|
||||
int uinput_device_set_ids(struct uinput_device* dev, const struct input_id *ids);
|
||||
int uinput_device_set_bit(struct uinput_device* dev, unsigned int bit);
|
||||
int uinput_device_set_prop(struct uinput_device *dev, unsigned int prop);
|
||||
int uinput_device_set_event_bit(struct uinput_device* dev, unsigned int type, unsigned int code);
|
||||
int uinput_device_set_event_bits(struct uinput_device* dev, ...);
|
||||
int uinput_device_set_event_bits_v(struct uinput_device* dev, va_list args);
|
||||
|
|
|
|||
|
|
@ -212,17 +212,31 @@ START_TEST(test_input_props)
|
|||
{
|
||||
struct uinput_device* uidev;
|
||||
struct libevdev *dev;
|
||||
int rc;
|
||||
int rc, i;
|
||||
|
||||
rc = test_create_device(&uidev, &dev,
|
||||
EV_ABS, ABS_X,
|
||||
-1);
|
||||
uidev = uinput_device_new(TEST_DEVICE_NAME);
|
||||
rc = uinput_device_set_event_bits(uidev,
|
||||
EV_ABS, ABS_X,
|
||||
-1);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
uinput_device_set_prop(uidev, INPUT_PROP_DIRECT);
|
||||
uinput_device_set_prop(uidev, INPUT_PROP_BUTTONPAD);
|
||||
rc = uinput_device_create(uidev);
|
||||
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
||||
|
||||
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev);
|
||||
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
||||
|
||||
|
||||
for (i = 0; i < INPUT_PROP_MAX; i++) {
|
||||
if (i == INPUT_PROP_DIRECT || i == INPUT_PROP_BUTTONPAD)
|
||||
ck_assert_int_eq(libevdev_has_property(dev, i), 1);
|
||||
else
|
||||
ck_assert_int_eq(libevdev_has_property(dev, i), 0);
|
||||
}
|
||||
|
||||
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_MAX + 1), 0);
|
||||
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_MAX), 0);
|
||||
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_BUTTONPAD), 0);
|
||||
/* FIXME: no idea how to set props on uinput devices */
|
||||
|
||||
uinput_device_free(uidev);
|
||||
libevdev_free(dev);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue