test: make litest_wait_for_event_of_type auto-terminating
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 11 Sep 2024 06:23:08 +0000 (16:23 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 12 Sep 2024 02:37:55 +0000 (12:37 +1000)
Wrap this in a macro so we cannot forget to pass -1

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1048>

test/litest.c
test/litest.h
test/test-switch.c
test/test-totem.c
test/test-touchpad.c
test/test-trackpoint.c
test/test-udev.c

index d5aac9db3b0b21383a17ae5648aa3e0461aeab24..5ad0a77cbfd8baf557e9b998bd1c8fb0811782cf 100644 (file)
@@ -2991,7 +2991,7 @@ litest_wait_for_event(struct libinput *li)
 }
 
 void
-litest_wait_for_event_of_type(struct libinput *li, ...)
+_litest_wait_for_event_of_type(struct libinput *li, ...)
 {
        va_list args;
        enum libinput_event_type types[32] = {LIBINPUT_EVENT_NONE};
index d974497b46e688fdd1d1a423f49a85dfa5a10da0..f247f0afba37ce8bbf3d754c1b89c8952949a7ee 100644 (file)
@@ -764,7 +764,10 @@ void
 litest_wait_for_event(struct libinput *li);
 
 void
-litest_wait_for_event_of_type(struct libinput *li, ...);
+_litest_wait_for_event_of_type(struct libinput *li, ...);
+
+#define litest_wait_for_event_of_type(li_, ...) \
+       _litest_wait_for_event_of_type(li_, __VA_ARGS__, -1)
 
 void
 litest_drain_events(struct libinput *li);
index f58b9525460d8b17aa43e620fa6805c056205193..3e832e1f2f1d06ea92766053b199735bff0197ba 100644 (file)
@@ -209,7 +209,7 @@ START_TEST(switch_down_on_init)
                                 libevdev_uinput_get_devnode(dev->uinput));
        libinput_dispatch(li);
 
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_SWITCH_TOGGLE, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_SWITCH_TOGGLE);
        event = libinput_get_event(li);
        litest_is_switch_event(event, sw, LIBINPUT_SWITCH_STATE_ON);
        libinput_event_destroy(event);
index efe726cde1860cf2a040a82d1f7c5ae5444fb9ca..8bd70fcdfa04e82088887913aea4a35f77e38c90 100644 (file)
@@ -156,9 +156,7 @@ START_TEST(totem_proximity_in_on_init)
        libinput_path_add_device(li, devnode);
        libinput_dispatch(li);
 
-       litest_wait_for_event_of_type(li,
-                                     LIBINPUT_EVENT_DEVICE_ADDED,
-                                     -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
        event = libinput_get_event(li);
        libinput_event_destroy(event);
 
@@ -417,9 +415,7 @@ START_TEST(totem_button_down_on_init)
        libinput_path_add_device(li, devnode);
        libinput_dispatch(li);
 
-       litest_wait_for_event_of_type(li,
-                                     LIBINPUT_EVENT_DEVICE_ADDED,
-                                     -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
        event = libinput_get_event(li);
        libinput_event_destroy(event);
 
index 07353082581259dbbebed7d3116389c0cc2ca5b7..876bd9b72c507bf9bcaa300e96ec2ebfb0ef0f90 100644 (file)
@@ -201,9 +201,7 @@ START_TEST(touchpad_2fg_scroll_initially_diagonal)
        ydelta = 15 * ratio;
        litest_touch_move_two_touches(dev, 45, 30, 55, 30, 15, ydelta, 10);
        libinput_dispatch(li);
-       litest_wait_for_event_of_type(li,
-                                     LIBINPUT_EVENT_POINTER_AXIS,
-                                     -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
        litest_drain_events(li);
 
        /* get rid of any touch history still adding x deltas sideways */
@@ -351,9 +349,7 @@ START_TEST(touchpad_2fg_scroll_axis_lock_switch)
        /* Move roughly straight horizontally for >100ms to set axis lock */
        litest_touch_move_two_touches(dev, 20, 20, 25, 20, 55, 10, 15);
        libinput_dispatch(li);
-       litest_wait_for_event_of_type(li,
-                                     LIBINPUT_EVENT_POINTER_AXIS,
-                                     -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
 
        axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
        ck_assert(is_single_axis_2fg_scroll(dev, axis));
@@ -368,17 +364,13 @@ START_TEST(touchpad_2fg_scroll_axis_lock_switch)
         */
        litest_touch_move_two_touches(dev, 75, 30, 80, 30, 2, 20, 15);
        libinput_dispatch(li);
-       litest_wait_for_event_of_type(li,
-                                     LIBINPUT_EVENT_POINTER_AXIS,
-                                     -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
        litest_drain_events(li);
 
        /* Move some more, roughly vertically, and check new axis lock */
        litest_touch_move_two_touches(dev, 77, 50, 82, 50, 1, 40, 15);
        libinput_dispatch(li);
-       litest_wait_for_event_of_type(li,
-                                     LIBINPUT_EVENT_POINTER_AXIS,
-                                     -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
 
        axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
        ck_assert(is_single_axis_2fg_scroll(dev, axis));
@@ -387,9 +379,7 @@ START_TEST(touchpad_2fg_scroll_axis_lock_switch)
        /* Move in a clear diagonal direction to ensure the lock releases */
        litest_touch_move_two_touches(dev, 78, 90, 83, 90, -60, -60, 20);
        libinput_dispatch(li);
-       litest_wait_for_event_of_type(li,
-                                     LIBINPUT_EVENT_POINTER_AXIS,
-                                     -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
 
        axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
        ck_assert(!is_single_axis_2fg_scroll(dev, axis));
@@ -488,7 +478,7 @@ START_TEST(touchpad_2fg_scroll_source)
        litest_drain_events(li);
 
        test_2fg_scroll(dev, 0, 30, false);
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
 
        while ((event = libinput_get_event(li))) {
                litest_is_axis_event(event,
@@ -938,7 +928,7 @@ START_TEST(touchpad_edge_scroll_timeout)
        litest_touch_up(dev, 0);
        libinput_dispatch(li);
 
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
 
        while ((event = libinput_get_event(li))) {
                struct libinput_event_pointer *ptrev;
@@ -1022,7 +1012,7 @@ START_TEST(touchpad_edge_scroll_source)
        litest_touch_move_to(dev, 0, 99, 20, 99, 80, 10);
        litest_touch_up(dev, 0);
 
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
 
        while ((event = libinput_get_event(li))) {
                struct libinput_event_pointer *ptrev;
index 12bfc40911bc5cd8f93097172f9079707b0b76cb..a96e66053101caa38cec5f40bc8046fcf0203505 100644 (file)
@@ -160,7 +160,7 @@ START_TEST(trackpoint_scroll_source)
        litest_drain_events(li);
 
        litest_button_scroll(dev, BTN_MIDDLE, 0, 6);
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
 
        while ((event = libinput_get_event(li))) {
                ptrev = libinput_event_get_pointer_event(event);
index 0c46fea68152f332c8b241dede01bfdcad9bb50a..d903a74fcbe518ef96e88206ce90f9adf5235805 100644 (file)
@@ -200,7 +200,7 @@ START_TEST(udev_added_seat_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);
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
        event = libinput_get_event(li);
        device = libinput_event_get_device(event);
        seat = libinput_device_get_seat(device);
@@ -244,7 +244,7 @@ START_TEST(udev_change_seat)
         * 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);
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
        event = libinput_get_event(li);
        device = libinput_event_get_device(event);
        libinput_device_ref(device);
@@ -610,7 +610,7 @@ START_TEST(udev_path_remove_device)
        ck_assert_int_eq(libinput_udev_assign_seat(li, "seat0"), 0);
        libinput_dispatch(li);
 
-       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED, -1);
+       litest_wait_for_event_of_type(li, LIBINPUT_EVENT_DEVICE_ADDED);
        event = libinput_get_event(li);
        device = libinput_event_get_device(event);
        ck_assert_notnull(device);