test: auto-unref the litest devices

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
This commit is contained in:
Peter Hutterer 2025-04-07 15:31:46 +10:00
parent cefab21e42
commit d72df04e7d
4 changed files with 15 additions and 51 deletions

View file

@ -811,6 +811,8 @@ litest_ungrab_device(struct litest_device *d);
void
litest_device_destroy(struct litest_device *d);
DEFINE_DESTROY_CLEANUP_FUNC(litest_device);
const char *
litest_event_type_str(enum libinput_event_type type);

View file

@ -727,14 +727,12 @@ END_TEST
START_TEST(timer_flush)
{
struct litest_device *keyboard, *touchpad;
_litest_context_destroy_ struct libinput *li = litest_create_context();
touchpad = litest_add_device(li, LITEST_SYNAPTICS_TOUCHPAD);
_destroy_(litest_device) *touchpad = litest_add_device(li, LITEST_SYNAPTICS_TOUCHPAD);
litest_enable_tap(touchpad->libinput_device);
litest_dispatch(li);
keyboard = litest_add_device(li, LITEST_KEYBOARD);
_destroy_(litest_device) *keyboard = litest_add_device(li, LITEST_KEYBOARD);
litest_dispatch(li);
litest_drain_events(li);
@ -783,9 +781,6 @@ START_TEST(timer_flush)
LIBINPUT_BUTTON_STATE_PRESSED);
litest_assert_button_event(li, BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
litest_device_destroy(keyboard);
litest_device_destroy(touchpad);
}
END_TEST

View file

@ -175,7 +175,6 @@ END_TEST
START_TEST(trackpoint_topsoftbuttons_left_handed_trackpoint)
{
struct litest_device *touchpad = litest_current_device();
struct litest_device *trackpoint;
struct libinput *li = touchpad->libinput;
enum libinput_config_status status;
struct libinput_event *event;
@ -183,7 +182,7 @@ START_TEST(trackpoint_topsoftbuttons_left_handed_trackpoint)
litest_disable_hold_gestures(touchpad->libinput_device);
trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
_destroy_(litest_device) *trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
litest_drain_events(li);
/* touchpad right-handed, trackpoint left-handed */
status = libinput_device_config_left_handed_set(
@ -212,15 +211,12 @@ START_TEST(trackpoint_topsoftbuttons_left_handed_trackpoint)
device = libinput_event_get_device(event);
litest_assert(device == trackpoint->libinput_device);
libinput_event_destroy(event);
litest_device_destroy(trackpoint);
}
END_TEST
START_TEST(trackpoint_topsoftbuttons_left_handed_touchpad)
{
struct litest_device *touchpad = litest_current_device();
struct litest_device *trackpoint;
struct libinput *li = touchpad->libinput;
enum libinput_config_status status;
struct libinput_event *event;
@ -228,7 +224,7 @@ START_TEST(trackpoint_topsoftbuttons_left_handed_touchpad)
litest_disable_hold_gestures(touchpad->libinput_device);
trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
_destroy_(litest_device) *trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
litest_drain_events(li);
/* touchpad left-handed, trackpoint right-handed */
status = libinput_device_config_left_handed_set(
@ -255,15 +251,12 @@ START_TEST(trackpoint_topsoftbuttons_left_handed_touchpad)
device = libinput_event_get_device(event);
litest_assert(device == trackpoint->libinput_device);
libinput_event_destroy(event);
litest_device_destroy(trackpoint);
}
END_TEST
START_TEST(trackpoint_topsoftbuttons_left_handed_both)
{
struct litest_device *touchpad = litest_current_device();
struct litest_device *trackpoint;
struct libinput *li = touchpad->libinput;
enum libinput_config_status status;
struct libinput_event *event;
@ -271,7 +264,7 @@ START_TEST(trackpoint_topsoftbuttons_left_handed_both)
litest_disable_hold_gestures(touchpad->libinput_device);
trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
_destroy_(litest_device) *trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
litest_drain_events(li);
/* touchpad left-handed, trackpoint left-handed */
status = libinput_device_config_left_handed_set(
@ -303,8 +296,6 @@ START_TEST(trackpoint_topsoftbuttons_left_handed_both)
device = libinput_event_get_device(event);
litest_assert(device == trackpoint->libinput_device);
libinput_event_destroy(event);
litest_device_destroy(trackpoint);
}
END_TEST
@ -331,11 +322,10 @@ disable_dwtp(struct litest_device *dev)
START_TEST(trackpoint_palmdetect)
{
struct litest_device *trackpoint = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = trackpoint->libinput;
int i;
touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
_destroy_(litest_device) *touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
if (has_disable_while_trackpointing(touchpad))
enable_dwtp(touchpad);
@ -361,19 +351,16 @@ START_TEST(trackpoint_palmdetect)
litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
litest_touch_up(touchpad, 0);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
litest_device_destroy(touchpad);
}
END_TEST
START_TEST(trackpoint_palmdetect_dwtp_disabled)
{
struct litest_device *trackpoint = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = trackpoint->libinput;
int i;
touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
_destroy_(litest_device) *touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
if (has_disable_while_trackpointing(touchpad))
disable_dwtp(touchpad);
@ -392,19 +379,16 @@ START_TEST(trackpoint_palmdetect_dwtp_disabled)
litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
litest_touch_up(touchpad, 0);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
litest_device_destroy(touchpad);
}
END_TEST
START_TEST(trackpoint_palmdetect_resume_touch)
{
struct litest_device *trackpoint = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = trackpoint->libinput;
int i;
touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
_destroy_(litest_device) *touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
if (has_disable_while_trackpointing(touchpad))
enable_dwtp(touchpad);
@ -430,18 +414,15 @@ START_TEST(trackpoint_palmdetect_resume_touch)
litest_touch_move_to(touchpad, 0, 80, 80, 30, 30, 10);
litest_touch_up(touchpad, 0);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
litest_device_destroy(touchpad);
}
END_TEST
START_TEST(trackpoint_palmdetect_require_min_events)
{
struct litest_device *trackpoint = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = trackpoint->libinput;
touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
_destroy_(litest_device) *touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
if (has_disable_while_trackpointing(touchpad))
enable_dwtp(touchpad);
@ -460,18 +441,15 @@ START_TEST(trackpoint_palmdetect_require_min_events)
litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
litest_touch_up(touchpad, 0);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
litest_device_destroy(touchpad);
}
END_TEST
START_TEST(trackpoint_palmdetect_require_min_events_timeout)
{
struct litest_device *trackpoint = litest_current_device();
struct litest_device *touchpad;
struct libinput *li = trackpoint->libinput;
touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
_destroy_(litest_device) *touchpad = litest_add_device(li, LITEST_SYNAPTICS_I2C);
if (has_disable_while_trackpointing(touchpad))
enable_dwtp(touchpad);
@ -494,8 +472,6 @@ START_TEST(trackpoint_palmdetect_require_min_events_timeout)
litest_timeout_trackpoint(li);
}
litest_device_destroy(touchpad);
}
END_TEST

View file

@ -182,7 +182,6 @@ START_TEST(udev_added_seat_default)
struct libinput_device *device;
struct libinput_seat *seat;
const char *seat_name;
struct litest_device *dev;
udev = udev_new();
litest_assert_notnull(udev);
@ -198,7 +197,7 @@ START_TEST(udev_added_seat_default)
/* Now create our own device, it should be in the "default"
* logical seat. This test may fail if there is a local rule changing
* that, but it'll be fine for the 99% case. */
dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
_destroy_(litest_device) *dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
event = libinput_get_event(li);
device = libinput_event_get_device(event);
@ -211,8 +210,6 @@ START_TEST(udev_added_seat_default)
libinput_unref(li);
udev_unref(udev);
litest_device_destroy(dev);
}
END_TEST
@ -226,7 +223,6 @@ START_TEST(udev_change_seat)
const char *seat1_name;
const char *seat2_name = "new seat";
int rc;
struct litest_device *dev;
udev = udev_new();
litest_assert_notnull(udev);
@ -242,7 +238,7 @@ START_TEST(udev_change_seat)
/* Now create our own device, it should be in the "default"
* logical seat. This test may fail if there is a local rule changing
* that, but it'll be fine for the 99% case. */
dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
_unused_ _destroy_(litest_device) *dev = litest_create(LITEST_MOUSE, NULL, NULL, NULL, NULL);
litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
event = libinput_get_event(li);
device = libinput_event_get_device(event);
@ -286,8 +282,6 @@ START_TEST(udev_change_seat)
libinput_unref(li);
udev_unref(udev);
litest_device_destroy(dev);
}
END_TEST
@ -628,10 +622,9 @@ START_TEST(udev_ignore_device)
struct libinput *li;
struct libinput_device *device;
struct libinput_event *event;
struct litest_device *dev;
const char *devname;
dev = litest_create(LITEST_IGNORED_MOUSE, NULL, NULL, NULL, NULL);
_destroy_(litest_device) *dev = litest_create(LITEST_IGNORED_MOUSE, NULL, NULL, NULL, NULL);
devname = libevdev_get_name(dev->evdev);
udev = udev_new();
@ -662,8 +655,6 @@ START_TEST(udev_ignore_device)
libinput_unref(li);
udev_unref(udev);
litest_device_destroy(dev);
}
END_TEST