mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-04 05:50:26 +01: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 *
|
||||
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)
|
||||
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 *d;
|
||||
int fd;
|
||||
|
|
@ -477,9 +487,7 @@ litest_create_device_with_overrides(enum litest_device_type which,
|
|||
rc = libevdev_new_from_fd(fd, &d->evdev);
|
||||
ck_assert_int_eq(rc, 0);
|
||||
|
||||
d->libinput = libinput_path_create_context(&interface, NULL);
|
||||
ck_assert(d->libinput != NULL);
|
||||
|
||||
d->libinput = libinput;
|
||||
d->libinput_device = libinput_path_add_device(d->libinput, path);
|
||||
ck_assert(d->libinput_device != NULL);
|
||||
libinput_device_ref(d->libinput_device);
|
||||
|
|
@ -493,6 +501,24 @@ litest_create_device_with_overrides(enum litest_device_type which,
|
|||
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 *
|
||||
litest_create_device(enum litest_device_type which)
|
||||
{
|
||||
|
|
@ -520,7 +546,8 @@ litest_delete_device(struct litest_device *d)
|
|||
return;
|
||||
|
||||
libinput_device_unref(d->libinput_device);
|
||||
libinput_destroy(d->libinput);
|
||||
if (d->owns_context)
|
||||
libinput_destroy(d->libinput);
|
||||
libevdev_free(d->evdev);
|
||||
libevdev_uinput_destroy(d->uinput);
|
||||
memset(d,0, sizeof(*d));
|
||||
|
|
|
|||
|
|
@ -61,10 +61,13 @@ struct litest_device {
|
|||
struct libevdev *evdev;
|
||||
struct libevdev_uinput *uinput;
|
||||
struct libinput *libinput;
|
||||
bool owns_context;
|
||||
struct libinput_device *libinput_device;
|
||||
struct litest_device_interface *interface;
|
||||
};
|
||||
|
||||
struct libinput *litest_create_context(void);
|
||||
|
||||
void litest_add(const char *name, void *func,
|
||||
enum litest_device_feature required_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,
|
||||
const struct input_absinfo *abs_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);
|
||||
void litest_delete_device(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,
|
||||
...);
|
||||
|
||||
#ifndef ck_assert_notnull
|
||||
#define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL)
|
||||
#endif
|
||||
|
||||
#endif /* LITEST_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue