test: use __attribute__(cleanup) for the test libinput contexts

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
This commit is contained in:
Peter Hutterer 2025-04-07 13:15:28 +10:00
parent 34b3881d24
commit 6f6bba9588
14 changed files with 80 additions and 216 deletions

View file

@ -2103,15 +2103,15 @@ litest_create_context(void)
void
litest_destroy_context(struct libinput *li)
{
struct path *p;
_autofree_ struct litest_context *ctx;
if (li) {
_autofree_ struct litest_context *ctx = libinput_get_user_data(li);
litest_assert_ptr_notnull(ctx);
libinput_unref(li);
ctx = libinput_get_user_data(li);
litest_assert_ptr_notnull(ctx);
libinput_unref(li);
list_for_each_safe(p, &ctx->paths, link) {
litest_abort_msg("Device paths should be removed by now");
struct path *p;
list_for_each_safe(p, &ctx->paths, link) {
litest_abort_msg("Device paths should be removed by now");
}
}
}

View file

@ -598,6 +598,10 @@ litest_axis_set_value(struct axis_replacement *axes, int code, double value)
struct libinput *litest_create_context(void);
void litest_destroy_context(struct libinput *li);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct libinput *, litest_destroy_context);
#define _litest_context_destroy_ _cleanup_(litest_destroy_contextp)
void litest_disable_log_handler(struct libinput *libinput);
void litest_restore_log_handler(struct libinput *libinput);
void litest_set_log_handler_bug(struct libinput *libinput);

View file

@ -412,13 +412,12 @@ END_TEST
START_TEST(device_reenable_syspath_changed)
{
struct libinput *li;
struct litest_device *litest_device;
struct libinput_device *device1;
enum libinput_config_status status;
struct libinput_event *event;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_device = litest_add_device(li, LITEST_MOUSE);
device1 = litest_device->libinput_device;
@ -453,18 +452,16 @@ START_TEST(device_reenable_syspath_changed)
litest_delete_device(litest_device);
libinput_device_unref(device1);
litest_destroy_context(li);
}
END_TEST
START_TEST(device_reenable_device_removed)
{
struct libinput *li;
struct litest_device *litest_device;
struct libinput_device *device;
enum libinput_config_status status;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_device = litest_add_device(li, LITEST_MOUSE);
device = litest_device->libinput_device;
@ -487,7 +484,6 @@ START_TEST(device_reenable_device_removed)
litest_assert_empty_queue(li);
libinput_device_unref(device);
litest_destroy_context(li);
}
END_TEST
@ -821,7 +817,7 @@ END_TEST
START_TEST(device_group_ref)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev = litest_add_device(li,
LITEST_MOUSE);
struct libinput_device *device = dev->libinput_device;
@ -842,14 +838,11 @@ START_TEST(device_group_ref)
libinput_device_group_ref(group);
litest_assert_notnull(libinput_device_group_unref(group));
litest_assert(libinput_device_group_unref(group) == NULL);
litest_destroy_context(li);
}
END_TEST
START_TEST(device_group_leak)
{
struct libinput *li;
struct libinput_device *device;
struct libevdev_uinput *uinput;
struct libinput_device_group *group;
@ -861,7 +854,7 @@ START_TEST(device_group_leak)
EV_REL, REL_Y,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
@ -871,7 +864,6 @@ START_TEST(device_group_leak)
libinput_path_remove_device(device);
libevdev_uinput_destroy(uinput);
litest_destroy_context(li);
/* the device group leaks, check valgrind */
}
@ -880,7 +872,6 @@ END_TEST
START_TEST(abs_device_no_absx)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
uinput = litest_create_uinput_device("test device", NULL,
@ -888,13 +879,12 @@ START_TEST(abs_device_no_absx)
EV_KEY, BTN_RIGHT,
EV_ABS, ABS_Y,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_restore_log_handler(li);
litest_assert(device == NULL);
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
@ -903,7 +893,6 @@ END_TEST
START_TEST(abs_device_no_absy)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
uinput = litest_create_uinput_device("test device", NULL,
@ -911,13 +900,12 @@ START_TEST(abs_device_no_absy)
EV_KEY, BTN_RIGHT,
EV_ABS, ABS_X,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_restore_log_handler(li);
litest_assert(device == NULL);
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
@ -926,7 +914,6 @@ END_TEST
START_TEST(abs_mt_device_no_absy)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
uinput = litest_create_uinput_device("test device", NULL,
@ -937,13 +924,12 @@ START_TEST(abs_mt_device_no_absy)
EV_ABS, ABS_MT_SLOT,
EV_ABS, ABS_MT_POSITION_X,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_restore_log_handler(li);
litest_assert(device == NULL);
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
@ -952,7 +938,6 @@ END_TEST
START_TEST(abs_mt_device_no_absx)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
uinput = litest_create_uinput_device("test device", NULL,
@ -963,13 +948,12 @@ START_TEST(abs_mt_device_no_absx)
EV_ABS, ABS_MT_SLOT,
EV_ABS, ABS_MT_POSITION_Y,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_restore_log_handler(li);
litest_assert(device == NULL);
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
@ -994,7 +978,6 @@ assert_device_ignored(struct libinput *li, struct input_absinfo *absinfo)
START_TEST(abs_device_no_range)
{
struct libinput *li;
int code = _i; /* looped test */
/* set x/y so libinput doesn't just reject for missing axes */
struct input_absinfo absinfo[] = {
@ -1004,19 +987,17 @@ START_TEST(abs_device_no_range)
{ -1, -1, -1, -1, -1, -1 }
};
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
assert_device_ignored(li, absinfo);
litest_restore_log_handler(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(abs_mt_device_no_range)
{
struct libinput *li;
int code = _i; /* looped test */
/* set x/y so libinput doesn't just reject for missing axes */
struct input_absinfo absinfo[] = {
@ -1030,7 +1011,7 @@ START_TEST(abs_mt_device_no_range)
{ -1, -1, -1, -1, -1, -1 }
};
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
if (code != ABS_MT_TOOL_TYPE &&
@ -1038,20 +1019,18 @@ START_TEST(abs_mt_device_no_range)
assert_device_ignored(li, absinfo);
litest_restore_log_handler(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(abs_device_missing_res)
{
struct libinput *li;
struct input_absinfo absinfo[] = {
{ ABS_X, 0, 10, 0, 0, 10 },
{ ABS_Y, 0, 10, 0, 0, 0 },
{ -1, -1, -1, -1, -1, -1 }
};
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
assert_device_ignored(li, absinfo);
@ -1062,13 +1041,11 @@ START_TEST(abs_device_missing_res)
assert_device_ignored(li, absinfo);
litest_restore_log_handler(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(abs_mt_device_missing_res)
{
struct libinput *li;
struct input_absinfo absinfo[] = {
{ ABS_X, 0, 10, 0, 0, 10 },
{ ABS_Y, 0, 10, 0, 0, 10 },
@ -1079,7 +1056,7 @@ START_TEST(abs_mt_device_missing_res)
{ -1, -1, -1, -1, -1, -1 }
};
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
assert_device_ignored(li, absinfo);
@ -1089,14 +1066,12 @@ START_TEST(abs_mt_device_missing_res)
assert_device_ignored(li, absinfo);
litest_restore_log_handler(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(ignore_joystick)
{
struct libinput *li;
struct libevdev_uinput *uinput;
struct libinput_device *device;
struct input_absinfo absinfo[] = {
@ -1109,7 +1084,7 @@ START_TEST(ignore_joystick)
{ -1, -1, -1, -1, -1, -1 }
};
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
litest_drain_events(li);
@ -1123,7 +1098,6 @@ START_TEST(ignore_joystick)
litest_assert_ptr_null(device);
libevdev_uinput_destroy(uinput);
litest_restore_log_handler(li);
litest_destroy_context(li);
}
END_TEST
@ -1139,7 +1113,6 @@ END_TEST
START_TEST(device_accelerometer)
{
struct libinput *li;
struct libevdev_uinput *uinput;
struct libinput_device *device;
@ -1150,7 +1123,7 @@ START_TEST(device_accelerometer)
{ -1, -1, -1, -1, -1, -1 }
};
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
uinput = litest_create_uinput_abs_device("test device", NULL,
@ -1161,7 +1134,6 @@ START_TEST(device_accelerometer)
litest_assert_ptr_null(device);
libevdev_uinput_destroy(uinput);
litest_restore_log_handler(li);
litest_destroy_context(li);
}
END_TEST
@ -1184,7 +1156,6 @@ END_TEST
START_TEST(device_nonpointer_rel)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
int i;
@ -1195,7 +1166,7 @@ START_TEST(device_nonpointer_rel)
EV_REL, REL_X,
EV_REL, REL_Y,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_assert_notnull(device);
@ -1209,7 +1180,6 @@ START_TEST(device_nonpointer_rel)
}
litest_restore_log_handler(li);
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
END_TEST
@ -1217,7 +1187,6 @@ END_TEST
START_TEST(device_touchpad_rel)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
const struct input_absinfo abs[] = {
{ ABS_X, 0, 10, 0, 0, 10 },
@ -1237,7 +1206,7 @@ START_TEST(device_touchpad_rel)
EV_REL, REL_X,
EV_REL, REL_Y,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_assert_notnull(device);
@ -1249,7 +1218,6 @@ START_TEST(device_touchpad_rel)
litest_dispatch(li);
}
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
END_TEST
@ -1257,7 +1225,6 @@ END_TEST
START_TEST(device_touch_rel)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
const struct input_absinfo abs[] = {
{ ABS_X, 0, 10, 0, 0, 10 },
@ -1276,7 +1243,7 @@ START_TEST(device_touch_rel)
EV_REL, REL_X,
EV_REL, REL_Y,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_assert_notnull(device);
@ -1290,7 +1257,6 @@ START_TEST(device_touch_rel)
}
litest_restore_log_handler(li);
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
END_TEST
@ -1298,7 +1264,6 @@ END_TEST
START_TEST(device_abs_rel)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
const struct input_absinfo abs[] = {
{ ABS_X, 0, 10, 0, 0, 10 },
@ -1314,7 +1279,7 @@ START_TEST(device_abs_rel)
EV_REL, REL_X,
EV_REL, REL_Y,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_assert_notnull(device);
@ -1326,7 +1291,6 @@ START_TEST(device_abs_rel)
litest_dispatch(li);
}
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
END_TEST
@ -1468,7 +1432,6 @@ debug_log_handler(struct libinput *libinput,
START_TEST(device_quirks)
{
struct libinput *li;
struct litest_device *dev;
struct libinput_device *device;
char **message;
@ -1483,7 +1446,7 @@ START_TEST(device_quirks)
disable_semi_mt = false;
#endif
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(li, debug_log_handler);
dev = litest_add_device(li, LITEST_KEYBOARD_QUIRKED);
@ -1550,7 +1513,6 @@ START_TEST(device_quirks)
litest_disable_log_handler(li);
litest_delete_device(dev);
litest_destroy_context(li);
}
END_TEST
@ -1593,7 +1555,6 @@ END_TEST
START_TEST(device_capability_nocaps_ignored)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_device *device;
/* SW_PEN_INSERTED isn't handled in libinput so the device is
@ -1602,12 +1563,11 @@ START_TEST(device_capability_nocaps_ignored)
uinput = litest_create_uinput_device("test device", NULL,
EV_SW, SW_PEN_INSERTED,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
litest_assert_ptr_null(device);
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
}
END_TEST
@ -1680,7 +1640,6 @@ START_TEST(device_button_down_remove)
{
struct litest_device *lidev = litest_current_device();
struct litest_device *dev;
struct libinput *li;
for (int code = 0; code < KEY_MAX; code++) {
struct libinput_event *event;
@ -1699,7 +1658,7 @@ START_TEST(device_button_down_remove)
if (!libevdev_has_event_code(lidev->evdev, EV_KEY, code))
continue;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
dev = litest_add_device(li, lidev->which);
litest_drain_events(li);
@ -1736,7 +1695,6 @@ START_TEST(device_button_down_remove)
libinput_event_destroy(event);
}
litest_destroy_context(li);
litest_assert_int_eq(have_down, have_up);
}
}

View file

@ -32,7 +32,6 @@ START_TEST(keyboard_seat_key_count)
{
struct litest_device *devices[4];
const int num_devices = ARRAY_LENGTH(devices);
struct libinput *libinput;
struct libinput_event *ev;
struct libinput_event_keyboard *kev;
int i;
@ -40,7 +39,7 @@ START_TEST(keyboard_seat_key_count)
int expected_key_button_count = 0;
char device_name[255];
libinput = litest_create_context();
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
for (i = 0; i < num_devices; ++i) {
sprintf(device_name, "litest Generic keyboard (%d)", i);
devices[i] = litest_add_device_with_overrides(libinput,
@ -96,15 +95,12 @@ START_TEST(keyboard_seat_key_count)
for (i = 0; i < num_devices; ++i)
litest_delete_device(devices[i]);
litest_destroy_context(libinput);
}
END_TEST
START_TEST(keyboard_ignore_no_pressed_release)
{
struct litest_device *dev;
struct libinput *unused_libinput;
struct libinput *libinput;
struct libinput_event *event;
struct libinput_event_keyboard *kevent;
int events[] = {
@ -120,7 +116,7 @@ START_TEST(keyboard_ignore_no_pressed_release)
* as such non-symmetric events are dropped. Work-around this by first
* adding the test device to the tested context after having sent an
* initial pressed event. */
unused_libinput = litest_create_context();
_litest_context_destroy_ struct libinput *unused_libinput = litest_create_context();
dev = litest_add_device_with_overrides(unused_libinput,
LITEST_KEYBOARD,
"Generic keyboard",
@ -129,7 +125,7 @@ START_TEST(keyboard_ignore_no_pressed_release)
litest_keyboard_key(dev, KEY_A, true);
litest_drain_events(unused_libinput);
libinput = litest_create_context();
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
libinput_path_add_device(libinput,
libevdev_uinput_get_devnode(dev->uinput));
litest_drain_events(libinput);
@ -155,14 +151,11 @@ START_TEST(keyboard_ignore_no_pressed_release)
litest_assert_empty_queue(libinput);
litest_delete_device(dev);
litest_destroy_context(libinput);
litest_destroy_context(unused_libinput);
}
END_TEST
START_TEST(keyboard_key_auto_release)
{
struct libinput *libinput;
struct litest_device *dev;
struct libinput_event *event;
enum libinput_event_type type;
@ -194,7 +187,7 @@ START_TEST(keyboard_key_auto_release)
events[i++] = -1;
events[i++] = -1;
libinput = litest_create_context();
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
dev = litest_add_device_with_overrides(libinput,
LITEST_KEYBOARD,
"Generic keyboard",
@ -255,8 +248,6 @@ START_TEST(keyboard_key_auto_release)
for (i = 0; i < ARRAY_LENGTH(keys); ++i) {
litest_assert_int_eq(keys[i].released, 1);
}
litest_destroy_context(libinput);
}
END_TEST

View file

@ -65,25 +65,20 @@ static const struct libinput_interface simple_interface = {
START_TEST(log_default_priority)
{
enum libinput_log_priority pri;
struct libinput *li;
li = libinput_path_create_context(&simple_interface, NULL);
_unref_(libinput) *li = libinput_path_create_context(&simple_interface, NULL);
pri = libinput_log_get_priority(li);
litest_assert_enum_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
libinput_unref(li);
}
END_TEST
START_TEST(log_handler_invoked)
{
struct libinput *li;
log_handler_context = NULL;
log_handler_called = 0;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(li, simple_log_handler);
@ -93,8 +88,6 @@ START_TEST(log_handler_invoked)
litest_assert_int_gt(log_handler_called, 0);
litest_destroy_context(li);
log_handler_context = NULL;
log_handler_called = 0;
}
@ -102,11 +95,9 @@ END_TEST
START_TEST(log_handler_NULL)
{
struct libinput *li;
log_handler_called = 0;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(li, NULL);
@ -114,20 +105,16 @@ START_TEST(log_handler_NULL)
litest_assert_int_eq(log_handler_called, 0);
litest_destroy_context(li);
log_handler_called = 0;
}
END_TEST
START_TEST(log_priority)
{
struct libinput *li;
log_handler_context = NULL;
log_handler_called = 0;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_ERROR);
libinput_log_set_handler(li, simple_log_handler);
log_handler_context = li;
@ -142,8 +129,6 @@ START_TEST(log_priority)
libinput_path_add_device(li, "/dev/input/event0");
litest_assert_int_gt(log_handler_called, 1);
litest_destroy_context(li);
log_handler_context = NULL;
log_handler_called = 0;
}

View file

@ -93,7 +93,6 @@ create_simple_test_device(const char *name, ...)
START_TEST(event_conversion_device_notify)
{
struct libevdev_uinput *uinput;
struct libinput *li;
struct libinput_event *event;
int device_added = 0, device_removed = 0;
@ -104,7 +103,7 @@ START_TEST(event_conversion_device_notify)
EV_KEY, BTN_MIDDLE,
EV_KEY, BTN_LEFT,
-1, -1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_restore_log_handler(li); /* use the default litest handler */
libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput));
@ -143,7 +142,6 @@ START_TEST(event_conversion_device_notify)
libinput_event_destroy(event);
}
litest_destroy_context(li);
libevdev_uinput_destroy(uinput);
litest_assert_int_gt(device_added, 0);
@ -729,10 +727,9 @@ END_TEST
START_TEST(timer_flush)
{
struct libinput *li;
struct litest_device *keyboard, *touchpad;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
touchpad = litest_add_device(li, LITEST_SYNAPTICS_TOUCHPAD);
litest_enable_tap(touchpad->libinput_device);
@ -789,8 +786,6 @@ START_TEST(timer_flush)
litest_delete_device(keyboard);
litest_delete_device(touchpad);
litest_destroy_context(li);
}
END_TEST

View file

@ -437,10 +437,9 @@ END_TEST
START_TEST(path_add_invalid_path)
{
struct libinput *li;
struct libinput_device *device;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
litest_disable_log_handler(li);
device = libinput_path_add_device(li, "/tmp/");
@ -450,8 +449,6 @@ START_TEST(path_add_invalid_path)
litest_dispatch(li);
litest_assert_empty_queue(li);
litest_destroy_context(li);
}
END_TEST
@ -992,7 +989,6 @@ END_TEST
START_TEST(path_ignore_device)
{
struct litest_device *dev;
struct libinput *li;
struct libinput_device *device;
const char *path;
@ -1000,11 +996,10 @@ START_TEST(path_ignore_device)
path = libevdev_uinput_get_devnode(dev->uinput);
litest_assert_notnull(path);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li, path);
litest_assert(device == NULL);
litest_destroy_context(li);
litest_delete_device(dev);
}
END_TEST

View file

@ -283,7 +283,7 @@ END_TEST
START_TEST(pointer_absolute_initial_state)
{
struct litest_device *dev = litest_current_device();
struct libinput *libinput1, *libinput2;
struct libinput *libinput1;
struct libinput_event *ev1, *ev2;
struct libinput_event_pointer *p1, *p2;
int axis = litest_test_param_get_i32(test_env->params, "axis");
@ -295,7 +295,7 @@ START_TEST(pointer_absolute_initial_state)
/* device is now on some x/y value */
litest_drain_events(libinput1);
libinput2 = litest_create_context();
_litest_context_destroy_ struct libinput *libinput2 = litest_create_context();
libinput_path_add_device(libinput2,
libevdev_uinput_get_devnode(dev->uinput));
litest_drain_events(libinput2);
@ -329,8 +329,6 @@ START_TEST(pointer_absolute_initial_state)
libinput_event_destroy(ev1);
libinput_event_destroy(ev2);
}
litest_destroy_context(libinput2);
}
END_TEST
@ -425,7 +423,6 @@ END_TEST
START_TEST(pointer_button_auto_release)
{
struct libinput *libinput;
struct litest_device *dev;
struct libinput_event *event;
enum libinput_event_type type;
@ -456,7 +453,7 @@ START_TEST(pointer_button_auto_release)
events[i++] = -1;
events[i++] = -1;
libinput = litest_create_context();
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
dev = litest_add_device_with_overrides(libinput,
LITEST_MOUSE,
"Generic mouse",
@ -507,8 +504,6 @@ START_TEST(pointer_button_auto_release)
for (i = 0; i < ARRAY_LENGTH(buttons); ++i) {
litest_assert_int_eq(buttons[i].released, 1);
}
litest_destroy_context(libinput);
}
END_TEST
@ -1122,7 +1117,6 @@ START_TEST(pointer_seat_button_count)
{
struct litest_device *devices[4];
const int num_devices = ARRAY_LENGTH(devices);
struct libinput *libinput;
struct libinput_event *ev;
struct libinput_event_pointer *tev;
int i;
@ -1130,7 +1124,7 @@ START_TEST(pointer_seat_button_count)
int expected_seat_button_count = 0;
char device_name[255];
libinput = litest_create_context();
_litest_context_destroy_ struct libinput *libinput = litest_create_context();
for (i = 0; i < num_devices; ++i) {
sprintf(device_name, "litest Generic mouse (%d)", i);
devices[i] = litest_add_device_with_overrides(libinput,
@ -1207,7 +1201,6 @@ START_TEST(pointer_seat_button_count)
for (i = 0; i < num_devices; ++i)
litest_delete_device(devices[i]);
litest_destroy_context(libinput);
}
END_TEST
@ -1364,7 +1357,7 @@ END_TEST
START_TEST(pointer_left_handed_disable_with_button_down)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev = litest_add_device(li, LITEST_MOUSE);
enum libinput_config_status status;
@ -1389,8 +1382,6 @@ START_TEST(pointer_left_handed_disable_with_button_down)
litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED);
litest_assert_empty_queue(li);
libinput_event_destroy(event);
litest_destroy_context(li);
}
END_TEST
@ -1566,10 +1557,9 @@ END_TEST
START_TEST(pointer_scroll_button_device_remove_while_down)
{
struct libinput *li;
struct litest_device *dev;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
dev = litest_add_device(li, LITEST_MOUSE);
libinput_device_config_scroll_set_method(dev->libinput_device,
@ -1585,8 +1575,6 @@ START_TEST(pointer_scroll_button_device_remove_while_down)
/* delete the device while the timer is still active */
litest_delete_device(dev);
litest_dispatch(li);
litest_destroy_context(li);
}
END_TEST
@ -3660,10 +3648,9 @@ END_TEST
START_TEST(debounce_remove_device_button_up)
{
struct libinput *li;
struct litest_device *dev;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
dev = litest_add_device(li, LITEST_MOUSE);
litest_drain_events(li);
@ -3678,17 +3665,14 @@ START_TEST(debounce_remove_device_button_up)
litest_delete_device(dev);
litest_timeout_debounce(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(debounce_remove_device_button_down)
{
struct libinput *li;
struct litest_device *dev;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
dev = litest_add_device(li, LITEST_MOUSE);
litest_drain_events(li);
@ -3701,8 +3685,6 @@ START_TEST(debounce_remove_device_button_down)
litest_delete_device(dev);
litest_timeout_debounce(li);
litest_destroy_context(li);
}
END_TEST

View file

@ -188,7 +188,6 @@ lid_switch_is_reliable(struct litest_device *dev)
START_TEST(switch_down_on_init)
{
struct litest_device *dev = litest_current_device();
struct libinput *li;
struct libinput_event *event;
enum libinput_switch sw = litest_test_param_get_i32(test_env->params, "switch");
@ -203,7 +202,7 @@ START_TEST(switch_down_on_init)
litest_ungrab_device(dev);
/* need separate context to test */
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li,
libevdev_uinput_get_devnode(dev->uinput));
litest_dispatch(li);
@ -225,15 +224,12 @@ START_TEST(switch_down_on_init)
litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_OFF);
libinput_event_destroy(event);
litest_assert_empty_queue(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(switch_not_down_on_init)
{
struct litest_device *dev = litest_current_device();
struct libinput *li;
struct libinput_event *event;
enum libinput_switch sw = LIBINPUT_SWITCH_LID;
@ -248,7 +244,7 @@ START_TEST(switch_not_down_on_init)
litest_ungrab_device(dev);
/* need separate context to test */
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li,
libevdev_uinput_get_devnode(dev->uinput));
litest_dispatch(li);
@ -261,7 +257,6 @@ START_TEST(switch_not_down_on_init)
litest_switch_action(dev, sw, LIBINPUT_SWITCH_STATE_OFF);
litest_assert_empty_queue(li);
litest_destroy_context(li);
}
END_TEST
@ -628,11 +623,11 @@ END_TEST
START_TEST(switch_suspend_with_keyboard)
{
struct libinput *li;
struct litest_device *keyboard;
struct litest_device *sw;
enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch");
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
switch(which) {
case LIBINPUT_SWITCH_LID:
@ -662,17 +657,15 @@ START_TEST(switch_suspend_with_keyboard)
litest_delete_device(sw);
litest_dispatch(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(switch_suspend_with_touchpad)
{
struct libinput *li;
struct litest_device *touchpad, *sw;
enum libinput_switch which = litest_test_param_get_i32(test_env->params, "switch");
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
switch(which) {
case LIBINPUT_SWITCH_LID:
@ -701,8 +694,6 @@ START_TEST(switch_suspend_with_touchpad)
litest_drain_events(li);
litest_delete_device(touchpad);
litest_drain_events(li);
litest_destroy_context(li);
}
END_TEST
@ -761,7 +752,6 @@ END_TEST
START_TEST(lid_update_hw_on_key_closed_on_init)
{
struct litest_device *sw = litest_current_device();
struct libinput *li;
struct litest_device *keyboard;
_free_(libevdev) *evdev;
struct input_event event;
@ -783,7 +773,7 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
keyboard = litest_add_device(sw->libinput, LITEST_KEYBOARD);
/* separate context for the right state on init */
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li,
libevdev_uinput_get_devnode(sw->uinput));
libinput_path_add_device(li,
@ -818,7 +808,6 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
rc = libevdev_next_event(evdev, LIBEVDEV_READ_FLAG_NORMAL, &event);
litest_assert_int_eq(rc, -EAGAIN);
litest_destroy_context(li);
litest_delete_device(keyboard);
}
END_TEST

View file

@ -178,7 +178,7 @@ END_TEST
START_TEST(button_up_on_delete)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN);
struct libevdev *evdev = libevdev_new();
unsigned int code;
@ -212,7 +212,6 @@ START_TEST(button_up_on_delete)
litest_assert_tablet_proximity_event(li,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
libevdev_free(evdev);
litest_destroy_context(li);
}
END_TEST
@ -929,7 +928,7 @@ END_TEST
START_TEST(tip_up_on_delete)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN);
struct libinput_event *event;
struct libinput_event_tablet_tool *tablet_event;
@ -956,8 +955,6 @@ START_TEST(tip_up_on_delete)
litest_assert_enum_eq(libinput_event_tablet_tool_get_tip_state(tablet_event),
LIBINPUT_TABLET_TOOL_TIP_UP);
libinput_event_destroy(event);
litest_destroy_context(li);
}
END_TEST
@ -1708,7 +1705,7 @@ END_TEST
START_TEST(proximity_out_on_delete)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS5_PEN);
litest_tablet_proximity_in(dev, 10, 10, NULL);
@ -1719,7 +1716,6 @@ START_TEST(proximity_out_on_delete)
litest_assert_tablet_proximity_event(li,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
litest_destroy_context(li);
}
END_TEST
@ -2566,7 +2562,7 @@ END_TEST
START_TEST(tools_with_serials)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev[2];
struct libinput_tablet_tool *tool[2] = {0};
struct libinput_event *event;
@ -2601,13 +2597,12 @@ START_TEST(tools_with_serials)
litest_delete_device(dev[0]);
litest_delete_device(dev[1]);
litest_destroy_context(li);
}
END_TEST
START_TEST(tools_without_serials)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev[2];
struct libinput_tablet_tool *tool[2] = {0};
struct libinput_event *event;
@ -2645,7 +2640,6 @@ START_TEST(tools_without_serials)
litest_delete_device(dev[0]);
litest_delete_device(dev[1]);
litest_destroy_context(li);
}
END_TEST
@ -2748,7 +2742,7 @@ END_TEST
START_TEST(tool_capabilities)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *intuos;
struct litest_device *bamboo;
struct libinput_event *event;
@ -2794,7 +2788,6 @@ START_TEST(tool_capabilities)
litest_delete_device(bamboo);
litest_delete_device(intuos);
litest_destroy_context(li);
}
END_TEST
@ -2894,7 +2887,6 @@ END_TEST
START_TEST(tool_in_prox_before_start)
{
struct libinput *li;
struct litest_device *dev = litest_current_device();
struct libinput_event *event;
struct libinput_event_tablet_tool *tev;
@ -2913,7 +2905,7 @@ START_TEST(tool_in_prox_before_start)
/* for simplicity, we create a new litest context */
devnode = libevdev_uinput_get_devnode(dev->uinput);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li, devnode);
litest_drain_events_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
@ -2951,8 +2943,6 @@ START_TEST(tool_in_prox_before_start)
event = libinput_get_event(li);
litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
libinput_event_destroy(event);
litest_destroy_context(li);
}
END_TEST
@ -5114,7 +5104,7 @@ END_TEST
START_TEST(tablet_pressure_after_unplug)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev = litest_add_device(li, LITEST_WACOM_CINTIQ_PRO16_PEN);
struct axis_replacement axes[] = {
@ -5192,7 +5182,6 @@ START_TEST(tablet_pressure_after_unplug)
litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
litest_delete_device(dev);
litest_destroy_context(li);
}
END_TEST

View file

@ -133,7 +133,6 @@ END_TEST
START_TEST(totem_proximity_in_on_init)
{
struct litest_device *dev = litest_current_device();
struct libinput *li;
struct libinput_event *event;
struct libinput_event_tablet_tool *t;
const char *devnode;
@ -150,7 +149,7 @@ START_TEST(totem_proximity_in_on_init)
/* for simplicity, we create a new litest context */
devnode = libevdev_uinput_get_devnode(dev->uinput);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li, devnode);
litest_dispatch(li);
@ -189,22 +188,19 @@ START_TEST(totem_proximity_in_on_init)
libinput_event_destroy(event);
litest_assert_empty_queue(li);
litest_destroy_context(li);
}
END_TEST
START_TEST(totem_proximity_out_on_suspend)
{
struct litest_device *dev = litest_current_device();
struct libinput *li;
struct libinput_event *event;
struct libinput_event_tablet_tool *t;
const char *devnode;
/* for simplicity, we create a new litest context */
devnode = libevdev_uinput_get_devnode(dev->uinput);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li, devnode);
litest_tablet_proximity_in(dev, 50, 50, NULL);
@ -228,7 +224,6 @@ START_TEST(totem_proximity_out_on_suspend)
libinput_event_destroy(event);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
litest_destroy_context(li);
}
END_TEST
@ -399,7 +394,6 @@ END_TEST
START_TEST(totem_button_down_on_init)
{
struct litest_device *dev = litest_current_device();
struct libinput *li;
struct libinput_event *event;
struct libinput_event_tablet_tool *t;
const char *devnode;
@ -409,7 +403,7 @@ START_TEST(totem_button_down_on_init)
/* for simplicity, we create a new litest context */
devnode = libevdev_uinput_get_devnode(dev->uinput);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li, devnode);
litest_dispatch(li);
@ -447,14 +441,12 @@ START_TEST(totem_button_down_on_init)
litest_button_click(dev, BTN_0, false);
litest_dispatch(li);
litest_assert_tablet_button_event(li, BTN_0, LIBINPUT_BUTTON_STATE_RELEASED);
litest_destroy_context(li);
}
END_TEST
START_TEST(totem_button_up_on_delete)
{
struct libinput *li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
struct litest_device *dev = litest_add_device(li, LITEST_DELL_CANVAS_TOTEM);
litest_tablet_proximity_in(dev, 10, 10, NULL);
@ -473,7 +465,6 @@ START_TEST(totem_button_up_on_delete)
litest_assert_tablet_tip_event(li, LIBINPUT_TABLET_TOOL_TIP_UP);
litest_assert_tablet_proximity_event(li,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
litest_destroy_context(li);
}
END_TEST

View file

@ -809,7 +809,7 @@ END_TEST
START_TEST(touch_initial_state)
{
struct litest_device *dev;
struct libinput *libinput1, *libinput2;
struct libinput *libinput1;
struct libinput_event *ev1 = NULL;
struct libinput_event *ev2 = NULL;
struct libinput_event_touch *t1, *t2;
@ -828,7 +828,7 @@ START_TEST(touch_initial_state)
/* device is now on some x/y value */
litest_drain_events(libinput1);
libinput2 = litest_create_context();
_litest_context_destroy_ struct libinput *libinput2 = litest_create_context();
device2 = libinput_path_add_device(libinput2,
libevdev_uinput_get_devnode(
dev->uinput));
@ -872,8 +872,6 @@ START_TEST(touch_initial_state)
libinput_event_destroy(ev1);
libinput_event_destroy(ev2);
litest_destroy_context(libinput2);
}
END_TEST
@ -971,10 +969,9 @@ END_TEST
START_TEST(touch_release_on_unplug)
{
struct litest_device *dev;
struct libinput *li;
struct libinput_event *ev;
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
dev = litest_add_device(li, LITEST_GENERIC_MULTITOUCH_SCREEN);
litest_drain_events(li);
@ -997,8 +994,6 @@ START_TEST(touch_release_on_unplug)
ev = libinput_get_event(li);
litest_assert_event_type(ev, LIBINPUT_EVENT_DEVICE_REMOVED);
libinput_event_destroy(ev);
litest_destroy_context(li);
}
END_TEST

View file

@ -2188,7 +2188,6 @@ END_TEST
START_TEST(touchpad_non_clickpad_detection)
{
struct libinput *li;
struct libinput_device *device;
struct libevdev_uinput *uinput;
static struct input_absinfo absinfo[] = {
@ -2216,7 +2215,7 @@ START_TEST(touchpad_non_clickpad_detection)
EV_KEY, BTN_TOUCH,
-1);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
device = libinput_path_add_device(li,
libevdev_uinput_get_devnode(uinput));
@ -2226,7 +2225,6 @@ START_TEST(touchpad_non_clickpad_detection)
libinput_path_remove_device(device);
libevdev_uinput_destroy(uinput);
litest_destroy_context(li);
}
END_TEST

View file

@ -3561,7 +3561,7 @@ END_TEST
START_TEST(touchpad_initial_state)
{
struct litest_device *dev;
struct libinput *libinput1, *libinput2;
struct libinput *libinput1;
int x = 40, y = 60;
int axis = litest_test_param_get_i32(test_env->params, "axis");
@ -3577,7 +3577,7 @@ START_TEST(touchpad_initial_state)
/* device is now on some x/y value */
litest_drain_events(libinput1);
libinput2 = litest_create_context();
_litest_context_destroy_ struct libinput *libinput2 = litest_create_context();
libinput_path_add_device(libinput2,
libevdev_uinput_get_devnode(dev->uinput));
litest_drain_events(libinput2);
@ -3615,15 +3615,12 @@ START_TEST(touchpad_initial_state)
libinput_event_destroy(ev1);
libinput_event_destroy(ev2);
}
litest_destroy_context(libinput2);
}
END_TEST
START_TEST(touchpad_fingers_down_before_init)
{
struct litest_device *dev = litest_current_device();
struct libinput *li;
int finger_count = litest_test_param_get_i32(test_env->params, "fingers");
unsigned int map[] = {0, BTN_TOOL_PEN, BTN_TOOL_DOUBLETAP,
@ -3645,7 +3642,7 @@ START_TEST(touchpad_fingers_down_before_init)
litest_drain_events(dev->libinput);
/* create anew context that already has the fingers down */
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li,
libevdev_uinput_get_devnode(dev->uinput));
litest_drain_events(li);
@ -3671,8 +3668,6 @@ START_TEST(touchpad_fingers_down_before_init)
}
litest_assert_empty_queue(li);
litest_destroy_context(li);
}
END_TEST
@ -5791,13 +5786,12 @@ END_TEST
START_TEST(touchpad_finger_always_down)
{
struct litest_device *dev = litest_current_device();
struct libinput *li;
/* Set BTN_TOOL_FINGER before a new context is initialized */
litest_event(dev, EV_KEY, BTN_TOOL_FINGER, 1);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
li = litest_create_context();
_litest_context_destroy_ struct libinput *li = litest_create_context();
libinput_path_add_device(li,
libevdev_uinput_get_devnode(dev->uinput));
litest_drain_events(li);
@ -5806,8 +5800,6 @@ START_TEST(touchpad_finger_always_down)
litest_touch_move_to(dev, 0, 50, 50, 70, 50, 10);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
litest_destroy_context(li);
}
END_TEST