test: wrap slot counting into a helper function
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 9 Jan 2020 01:13:18 +0000 (11:13 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 29 Jan 2020 05:58:49 +0000 (15:58 +1000)
This is prep work for future devices that announce a wrong slot count. For the
tests this can be a problem if we rely on the correct slot count to decided
whether to run a test or not.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/litest.h
test/test-gestures.c
test/test-touchpad-buttons.c
test/test-touchpad-tap.c

index ab66ff9e3de4f28a72832a34b101bd7cfa956505..ac32433f7e4383c9dc0d5058d8e49f5f2b8754d3 100644 (file)
@@ -1149,4 +1149,9 @@ litest_send_file(int sock, int fd)
        return write(sock, buf, n);
 }
 
+static inline int litest_slot_count(struct litest_device *dev)
+{
+       return libevdev_get_num_slots(dev->evdev);
+}
+
 #endif /* LITEST_H */
index 85fdc3218fa009838948b9fa883cc4a72bdcdc8d..d16175eddd810c8e3da8812dac9cccf38f63cabd 100644 (file)
@@ -77,7 +77,7 @@ START_TEST(gestures_swipe_3fg)
                { -30, 30 },
        };
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        dir_x = cardinals[cardinal][0];
@@ -176,7 +176,7 @@ START_TEST(gestures_swipe_3fg_btntool)
                { -30, 30 },
        };
 
-       if (libevdev_get_num_slots(dev->evdev) > 2 ||
+       if (litest_slot_count(dev) > 2 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) ||
            !libinput_device_has_capability(dev->libinput_device,
                                            LIBINPUT_DEVICE_CAP_GESTURE))
@@ -266,7 +266,7 @@ START_TEST(gestures_swipe_3fg_btntool_pinch_like)
        struct libinput_event *event;
        struct libinput_event_gesture *gevent;
 
-       if (libevdev_get_num_slots(dev->evdev) > 2 ||
+       if (litest_slot_count(dev) > 2 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) ||
            !libinput_device_has_capability(dev->libinput_device,
                                            LIBINPUT_DEVICE_CAP_GESTURE))
@@ -330,7 +330,7 @@ START_TEST(gestures_swipe_4fg)
        };
        int i;
 
-       if (libevdev_get_num_slots(dev->evdev) < 4)
+       if (litest_slot_count(dev) < 4)
                return;
 
        dir_x = cardinals[cardinal][0];
@@ -456,7 +456,7 @@ START_TEST(gestures_swipe_4fg_btntool)
                { -30, 30 },
        };
 
-       if (libevdev_get_num_slots(dev->evdev) > 2 ||
+       if (litest_slot_count(dev) > 2 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP) ||
            !libinput_device_has_capability(dev->libinput_device,
                                            LIBINPUT_DEVICE_CAP_GESTURE))
@@ -562,7 +562,7 @@ START_TEST(gestures_pinch)
                { -30, 30 },
        };
 
-       if (libevdev_get_num_slots(dev->evdev) < 2 ||
+       if (litest_slot_count(dev) < 2 ||
            !libinput_device_has_capability(dev->libinput_device,
                                            LIBINPUT_DEVICE_CAP_GESTURE))
                return;
@@ -674,7 +674,7 @@ START_TEST(gestures_pinch_3fg)
                { -30, 30 },
        };
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        dir_x = cardinals[cardinal][0];
@@ -779,7 +779,7 @@ START_TEST(gestures_pinch_4fg)
                { -30, 30 },
        };
 
-       if (libevdev_get_num_slots(dev->evdev) < 4)
+       if (litest_slot_count(dev) < 4)
                return;
 
        dir_x = cardinals[cardinal][0];
@@ -890,7 +890,7 @@ START_TEST(gestures_spread)
                { -30, 30 },
        };
 
-       if (libevdev_get_num_slots(dev->evdev) < 2 ||
+       if (litest_slot_count(dev) < 2 ||
            !libinput_device_has_capability(dev->libinput_device,
                                            LIBINPUT_DEVICE_CAP_GESTURE))
                return;
@@ -985,7 +985,7 @@ START_TEST(gestures_time_usec)
        struct libinput_event_gesture *gevent;
        uint64_t time_usec;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_drain_events(li);
@@ -1014,7 +1014,7 @@ START_TEST(gestures_3fg_buttonarea_scroll)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_enable_buttonareas(dev);
@@ -1040,7 +1040,7 @@ START_TEST(gestures_3fg_buttonarea_scroll_btntool)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) > 2)
+       if (litest_slot_count(dev) > 2)
                return;
 
        litest_enable_buttonareas(dev);
index c88ccbb5768369560ea845862b18afbf76b92b3e..d6a5cebeb0b70e984f0c175875e12285d8b66441 100644 (file)
@@ -219,7 +219,7 @@ START_TEST(touchpad_3fg_clickfinger)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_enable_clickfinger(dev);
@@ -253,7 +253,7 @@ START_TEST(touchpad_3fg_clickfinger_btntool)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) >= 3 ||
+       if (litest_slot_count(dev) >= 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -293,7 +293,7 @@ START_TEST(touchpad_4fg_clickfinger)
        struct libinput *li = dev->libinput;
        struct libinput_event *event;
 
-       if (libevdev_get_num_slots(dev->evdev) < 4)
+       if (litest_slot_count(dev) < 4)
                return;
 
        litest_enable_clickfinger(dev);
@@ -337,7 +337,7 @@ START_TEST(touchpad_4fg_clickfinger_btntool_2slots)
        struct libinput *li = dev->libinput;
        struct libinput_event *event;
 
-       if (libevdev_get_num_slots(dev->evdev) >= 3 ||
+       if (litest_slot_count(dev) >= 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP))
                return;
 
@@ -382,7 +382,7 @@ START_TEST(touchpad_4fg_clickfinger_btntool_3slots)
        struct libinput *li = dev->libinput;
        struct libinput_event *event;
 
-       if (libevdev_get_num_slots(dev->evdev) != 3 ||
+       if (litest_slot_count(dev) != 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -489,7 +489,7 @@ START_TEST(touchpad_3fg_clickfinger_distance)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_enable_clickfinger(dev);
@@ -522,7 +522,7 @@ START_TEST(touchpad_3fg_clickfinger_distance_btntool)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) > 2)
+       if (litest_slot_count(dev) > 2)
                return;
 
        litest_enable_clickfinger(dev);
@@ -963,7 +963,7 @@ START_TEST(touchpad_clickfinger_click_drag)
        struct libinput *li = dev->libinput;
        int nfingers = _i; /* ranged test */
        unsigned int button;
-       int nslots = libevdev_get_num_slots(dev->evdev);
+       int nslots = litest_slot_count(dev);
 
        litest_enable_clickfinger(dev);
        litest_drain_events(li);
index c0c67477502704dcb4b850fdb6768a5c2ac57e64..3d131a9b7874b73039e31d4fc8175f1996f3ae46 100644 (file)
@@ -936,7 +936,7 @@ START_TEST(touchpad_2fg_tap_n_drag_3fg_btntool)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) > 2 ||
+       if (litest_slot_count(dev) > 2 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -981,7 +981,7 @@ START_TEST(touchpad_2fg_tap_n_drag_3fg)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -1522,7 +1522,7 @@ START_TEST(touchpad_3fg_tap)
        unsigned int button = 0;
        int i;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -1584,7 +1584,7 @@ START_TEST(touchpad_3fg_tap_tap_again)
        struct libinput *li = dev->libinput;
        int i;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -1635,7 +1635,7 @@ START_TEST(touchpad_3fg_tap_quickrelease)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -1673,7 +1673,7 @@ START_TEST(touchpad_3fg_tap_pressure_btntool)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) >= 3 ||
+       if (litest_slot_count(dev) >= 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -1734,7 +1734,7 @@ START_TEST(touchpad_3fg_tap_hover_btntool)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) >= 3 ||
+       if (litest_slot_count(dev) >= 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -1788,7 +1788,7 @@ START_TEST(touchpad_3fg_tap_btntool)
        enum libinput_config_tap_button_map map = _i; /* ranged test */
        unsigned int button = 0;
 
-       if (libevdev_get_num_slots(dev->evdev) > 3 ||
+       if (litest_slot_count(dev) >= 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -1838,7 +1838,7 @@ START_TEST(touchpad_3fg_tap_btntool_inverted)
        enum libinput_config_tap_button_map map = _i; /* ranged test */
        unsigned int button = 0;
 
-       if (libevdev_get_num_slots(dev->evdev) > 3 ||
+       if (litest_slot_count(dev) > 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -1888,7 +1888,7 @@ START_TEST(touchpad_3fg_tap_btntool_pointerjump)
        enum libinput_config_tap_button_map map = _i; /* ranged test */
        unsigned int button = 0;
 
-       if (libevdev_get_num_slots(dev->evdev) > 3 ||
+       if (litest_slot_count(dev) > 3 ||
            !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP))
                return;
 
@@ -2031,7 +2031,7 @@ START_TEST(touchpad_3fg_tap_after_scroll)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) <= 3)
+       if (litest_slot_count(dev) <= 3)
                return;
 
        litest_enable_2fg_scroll(dev);
@@ -2067,7 +2067,7 @@ START_TEST(touchpad_4fg_tap)
        struct libinput *li = dev->libinput;
        int i;
 
-       if (libevdev_get_num_slots(dev->evdev) <= 4)
+       if (litest_slot_count(dev) <= 4)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -2098,7 +2098,7 @@ START_TEST(touchpad_4fg_tap_quickrelease)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) <= 4)
+       if (litest_slot_count(dev) <= 4)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -2135,7 +2135,7 @@ START_TEST(touchpad_move_after_touch)
        struct libinput *li = dev->libinput;
        int nfingers = _i; /* ranged test */
 
-       if (nfingers > libevdev_get_num_slots(dev->evdev))
+       if (nfingers > litest_slot_count(dev))
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -2207,7 +2207,7 @@ START_TEST(touchpad_5fg_tap)
        struct libinput *li = dev->libinput;
        int i;
 
-       if (libevdev_get_num_slots(dev->evdev) < 5)
+       if (litest_slot_count(dev) < 5)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -2240,7 +2240,7 @@ START_TEST(touchpad_5fg_tap_quickrelease)
        struct litest_device *dev = litest_current_device();
        struct libinput *li = dev->libinput;
 
-       if (libevdev_get_num_slots(dev->evdev) < 5)
+       if (litest_slot_count(dev) < 5)
                return;
 
        litest_enable_tap(dev->libinput_device);
@@ -3204,7 +3204,7 @@ START_TEST(touchpad_tap_palm_on_touch_3)
        int which = _i; /* ranged test */
        int this = which % 3;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        if (!touchpad_has_palm_pressure(dev))
@@ -3250,7 +3250,7 @@ START_TEST(touchpad_tap_palm_on_touch_3_retouch)
        int which = _i; /* ranged test */
        int this = which % 3;
 
-       if (libevdev_get_num_slots(dev->evdev) < 3)
+       if (litest_slot_count(dev) < 3)
                return;
 
        if (!touchpad_has_palm_pressure(dev))
@@ -3301,7 +3301,7 @@ START_TEST(touchpad_tap_palm_on_touch_4)
        int which = _i; /* ranged test */
        int this = which % 4;
 
-       if (libevdev_get_num_slots(dev->evdev) < 4)
+       if (litest_slot_count(dev) < 4)
                return;
 
        if (!touchpad_has_palm_pressure(dev))