mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 10:08:05 +02:00
test: Add ability to add test devices to existing libinput context
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
This commit is contained in:
parent
604f22eb79
commit
6207216702
2 changed files with 51 additions and 9 deletions
|
|
@ -451,12 +451,22 @@ litest_create(enum litest_device_type which,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct libinput *
|
||||||
|
litest_create_context(void)
|
||||||
|
{
|
||||||
|
struct libinput *libinput =
|
||||||
|
libinput_path_create_context(&interface, NULL);
|
||||||
|
ck_assert_notnull(libinput);
|
||||||
|
return libinput;
|
||||||
|
}
|
||||||
|
|
||||||
struct litest_device *
|
struct litest_device *
|
||||||
litest_create_device_with_overrides(enum litest_device_type which,
|
litest_add_device_with_overrides(struct libinput *libinput,
|
||||||
const char *name_override,
|
enum litest_device_type which,
|
||||||
struct input_id *id_override,
|
const char *name_override,
|
||||||
const struct input_absinfo *abs_override,
|
struct input_id *id_override,
|
||||||
const int *events_override)
|
const struct input_absinfo *abs_override,
|
||||||
|
const int *events_override)
|
||||||
{
|
{
|
||||||
struct litest_device *d;
|
struct litest_device *d;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
@ -477,9 +487,7 @@ litest_create_device_with_overrides(enum litest_device_type which,
|
||||||
rc = libevdev_new_from_fd(fd, &d->evdev);
|
rc = libevdev_new_from_fd(fd, &d->evdev);
|
||||||
ck_assert_int_eq(rc, 0);
|
ck_assert_int_eq(rc, 0);
|
||||||
|
|
||||||
d->libinput = libinput_path_create_context(&interface, NULL);
|
d->libinput = libinput;
|
||||||
ck_assert(d->libinput != NULL);
|
|
||||||
|
|
||||||
d->libinput_device = libinput_path_add_device(d->libinput, path);
|
d->libinput_device = libinput_path_add_device(d->libinput, path);
|
||||||
ck_assert(d->libinput_device != NULL);
|
ck_assert(d->libinput_device != NULL);
|
||||||
libinput_device_ref(d->libinput_device);
|
libinput_device_ref(d->libinput_device);
|
||||||
|
|
@ -493,6 +501,24 @@ litest_create_device_with_overrides(enum litest_device_type which,
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct litest_device *
|
||||||
|
litest_create_device_with_overrides(enum litest_device_type which,
|
||||||
|
const char *name_override,
|
||||||
|
struct input_id *id_override,
|
||||||
|
const struct input_absinfo *abs_override,
|
||||||
|
const int *events_override)
|
||||||
|
{
|
||||||
|
struct litest_device *dev =
|
||||||
|
litest_add_device_with_overrides(litest_create_context(),
|
||||||
|
which,
|
||||||
|
name_override,
|
||||||
|
id_override,
|
||||||
|
abs_override,
|
||||||
|
events_override);
|
||||||
|
dev->owns_context = true;
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
struct litest_device *
|
struct litest_device *
|
||||||
litest_create_device(enum litest_device_type which)
|
litest_create_device(enum litest_device_type which)
|
||||||
{
|
{
|
||||||
|
|
@ -520,7 +546,8 @@ litest_delete_device(struct litest_device *d)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
libinput_device_unref(d->libinput_device);
|
libinput_device_unref(d->libinput_device);
|
||||||
libinput_destroy(d->libinput);
|
if (d->owns_context)
|
||||||
|
libinput_destroy(d->libinput);
|
||||||
libevdev_free(d->evdev);
|
libevdev_free(d->evdev);
|
||||||
libevdev_uinput_destroy(d->uinput);
|
libevdev_uinput_destroy(d->uinput);
|
||||||
memset(d,0, sizeof(*d));
|
memset(d,0, sizeof(*d));
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,13 @@ struct litest_device {
|
||||||
struct libevdev *evdev;
|
struct libevdev *evdev;
|
||||||
struct libevdev_uinput *uinput;
|
struct libevdev_uinput *uinput;
|
||||||
struct libinput *libinput;
|
struct libinput *libinput;
|
||||||
|
bool owns_context;
|
||||||
struct libinput_device *libinput_device;
|
struct libinput_device *libinput_device;
|
||||||
struct litest_device_interface *interface;
|
struct litest_device_interface *interface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct libinput *litest_create_context(void);
|
||||||
|
|
||||||
void litest_add(const char *name, void *func,
|
void litest_add(const char *name, void *func,
|
||||||
enum litest_device_feature required_feature,
|
enum litest_device_feature required_feature,
|
||||||
enum litest_device_feature excluded_feature);
|
enum litest_device_feature excluded_feature);
|
||||||
|
|
@ -83,6 +86,14 @@ litest_create_device_with_overrides(enum litest_device_type which,
|
||||||
struct input_id *id_override,
|
struct input_id *id_override,
|
||||||
const struct input_absinfo *abs_override,
|
const struct input_absinfo *abs_override,
|
||||||
const int *events_override);
|
const int *events_override);
|
||||||
|
struct litest_device *
|
||||||
|
litest_add_device_with_overrides(struct libinput *libinput,
|
||||||
|
enum litest_device_type which,
|
||||||
|
const char *name_override,
|
||||||
|
struct input_id *id_override,
|
||||||
|
const struct input_absinfo *abs_override,
|
||||||
|
const int *events_override);
|
||||||
|
|
||||||
struct litest_device *litest_current_device(void);
|
struct litest_device *litest_current_device(void);
|
||||||
void litest_delete_device(struct litest_device *d);
|
void litest_delete_device(struct litest_device *d);
|
||||||
int litest_handle_events(struct litest_device *d);
|
int litest_handle_events(struct litest_device *d);
|
||||||
|
|
@ -118,4 +129,8 @@ struct libevdev_uinput * litest_create_uinput_abs_device(const char *name,
|
||||||
const struct input_absinfo *abs,
|
const struct input_absinfo *abs,
|
||||||
...);
|
...);
|
||||||
|
|
||||||
|
#ifndef ck_assert_notnull
|
||||||
|
#define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* LITEST_H */
|
#endif /* LITEST_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue