test: add helper functions for the two timers we care about
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 16 Sep 2014 06:08:29 +0000 (16:08 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 23 Sep 2014 04:38:37 +0000 (14:38 +1000)
Rather than a random msleep() with a comment, use a helper function that
describes what we're waiting for. Also makes changing the timeouts easier in
the future.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
test/device.c
test/litest.c
test/litest.h
test/touchpad.c

index 33aae04..3061ebc 100644 (file)
@@ -404,7 +404,7 @@ START_TEST(device_disable_release_tap)
        ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
        /* tap happened before suspending, so we still expect the event */
 
-       msleep(300); /* tap-n-drag timeout */
+       litest_timeout_tap();
 
        litest_assert_button_event(li,
                                   BTN_LEFT,
@@ -443,7 +443,7 @@ START_TEST(device_disable_release_tap_n_drag)
        litest_touch_up(dev, 0);
        litest_touch_down(dev, 0, 50, 50);
        libinput_dispatch(li);
-       msleep(400); /* tap-n-drag timeout */
+       litest_timeout_tap();
        libinput_dispatch(li);
 
        status = libinput_device_config_send_events_set_mode(device,
index e5092b8..29820a7 100644 (file)
@@ -1123,3 +1123,15 @@ void litest_assert_scroll(struct libinput *li, unsigned int axis, int dir)
                next_event = libinput_get_event(li);
        }
 }
+
+void
+litest_timeout_tap(void)
+{
+       msleep(200);
+}
+
+void
+litest_timeout_softbuttons(void)
+{
+       msleep(300);
+}
index fca6acb..c40427d 100644 (file)
@@ -158,6 +158,9 @@ struct libevdev_uinput * litest_create_uinput_abs_device(const char *name,
                                                         const struct input_absinfo *abs,
                                                         ...);
 
+void litest_timeout_tap(void);
+void litest_timeout_softbuttons(void);
+
 #ifndef ck_assert_notnull
 #define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL)
 #endif
index 717cb69..c89a71c 100644 (file)
@@ -107,7 +107,7 @@ START_TEST(touchpad_1fg_tap)
 
        litest_assert_button_event(li, BTN_LEFT,
                                   LIBINPUT_BUTTON_STATE_PRESSED);
-       msleep(300); /* tap-n-drag timeout */
+       litest_timeout_tap();
        litest_assert_button_event(li, BTN_LEFT,
                                   LIBINPUT_BUTTON_STATE_RELEASED);
 
@@ -162,7 +162,7 @@ START_TEST(touchpad_1fg_tap_n_drag)
 
        ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
 
-       msleep(300); /* tap-n-drag timeout */
+       litest_timeout_tap();
 
        litest_assert_button_event(li, BTN_LEFT,
                                   LIBINPUT_BUTTON_STATE_RELEASED);
@@ -185,7 +185,7 @@ START_TEST(touchpad_1fg_tap_n_drag_timeout)
        litest_touch_up(dev, 0);
        litest_touch_down(dev, 0, 50, 50);
        libinput_dispatch(li);
-       msleep(300);
+       litest_timeout_tap();
 
        litest_assert_button_event(li, BTN_LEFT,
                                   LIBINPUT_BUTTON_STATE_PRESSED);
@@ -219,7 +219,7 @@ START_TEST(touchpad_2fg_tap)
 
        litest_assert_button_event(li, BTN_RIGHT,
                                   LIBINPUT_BUTTON_STATE_PRESSED);
-       msleep(300); /* tap-n-drag timeout */
+       litest_timeout_tap();
        litest_assert_button_event(li, BTN_RIGHT,
                                   LIBINPUT_BUTTON_STATE_RELEASED);
 
@@ -246,7 +246,7 @@ START_TEST(touchpad_2fg_tap_inverted)
 
        litest_assert_button_event(li, BTN_RIGHT,
                                   LIBINPUT_BUTTON_STATE_PRESSED);
-       msleep(300); /* tap-n-drag timeout */
+       litest_timeout_tap();
        litest_assert_button_event(li, BTN_RIGHT,
                                   LIBINPUT_BUTTON_STATE_RELEASED);
 
@@ -274,7 +274,7 @@ START_TEST(touchpad_1fg_tap_click)
        litest_event(dev, EV_KEY, BTN_LEFT, 0);
        litest_event(dev, EV_SYN, SYN_REPORT, 0);
        libinput_dispatch(li);
-       msleep(200);
+       litest_timeout_tap();
 
        libinput_dispatch(li);
 
@@ -423,7 +423,7 @@ START_TEST(touchpad_no_2fg_tap_after_timeout)
         */
        litest_touch_down(dev, 0, 50, 50);
        libinput_dispatch(dev->libinput);
-       msleep(300);
+       litest_timeout_tap();
        libinput_dispatch(dev->libinput);
        litest_drain_events(dev->libinput);
 
@@ -577,7 +577,7 @@ START_TEST(touchpad_3fg_tap)
 
                litest_assert_button_event(li, BTN_MIDDLE,
                                           LIBINPUT_BUTTON_STATE_PRESSED);
-               msleep(300); /* tap-n-drag timeout */
+               litest_timeout_tap();
                litest_assert_button_event(li, BTN_MIDDLE,
                                           LIBINPUT_BUTTON_STATE_RELEASED);
 
@@ -613,7 +613,7 @@ START_TEST(touchpad_3fg_tap_btntool)
 
        litest_assert_button_event(li, BTN_MIDDLE,
                                   LIBINPUT_BUTTON_STATE_PRESSED);
-       msleep(300); /* tap-n-drag timeout */
+       litest_timeout_tap();
        litest_assert_button_event(li, BTN_MIDDLE,
                                   LIBINPUT_BUTTON_STATE_RELEASED);
 
@@ -648,7 +648,7 @@ START_TEST(touchpad_3fg_tap_btntool_inverted)
 
        litest_assert_button_event(li, BTN_MIDDLE,
                                   LIBINPUT_BUTTON_STATE_PRESSED);
-       msleep(300); /* tap-n-drag timeout */
+       litest_timeout_tap();
        litest_assert_button_event(li, BTN_MIDDLE,
                                   LIBINPUT_BUTTON_STATE_RELEASED);
 
@@ -750,7 +750,7 @@ START_TEST(clickpad_1fg_tap_click)
        litest_event(dev, EV_SYN, SYN_REPORT, 0);
        litest_touch_up(dev, 0);
        libinput_dispatch(li);
-       msleep(200);
+       litest_timeout_tap();
 
        libinput_dispatch(li);
 
@@ -999,7 +999,7 @@ START_TEST(clickpad_softbutton_left_1st_fg_move)
        /* move out of the area, then wait for softbutton timer */
        litest_touch_move_to(dev, 0, 20, 90, 90, 20, 10);
        libinput_dispatch(li);
-       msleep(400);
+       litest_timeout_softbuttons();
        libinput_dispatch(li);
        litest_drain_events(li);
 
@@ -1302,13 +1302,13 @@ START_TEST(clickpad_topsoftbuttons_move_out_ignore)
 
        litest_touch_down(dev, 0, 50, 5);
        libinput_dispatch(li);
-       msleep(200);
+       litest_timeout_softbuttons();
        libinput_dispatch(li);
        litest_assert_empty_queue(li);
 
        litest_touch_move_to(dev, 0, 50, 5, 80, 90, 20);
        libinput_dispatch(li);
-       msleep(400);
+       litest_timeout_softbuttons();
        libinput_dispatch(li);
 
        litest_event(dev, EV_KEY, BTN_LEFT, 1);
@@ -1323,7 +1323,7 @@ START_TEST(clickpad_topsoftbuttons_move_out_ignore)
 END_TEST
 
 static void
-test_2fg_scroll(struct litest_device *dev, double dx, double dy, int sleep)
+test_2fg_scroll(struct litest_device *dev, double dx, double dy, int want_sleep)
 {
        struct libinput *li = dev->libinput;
 
@@ -1334,9 +1334,9 @@ test_2fg_scroll(struct litest_device *dev, double dx, double dy, int sleep)
        litest_touch_move_to(dev, 1, 53, 50, 53 + dx, 50 + dy, 5);
 
        /* Avoid a small scroll being seen as a tap */
-       if (sleep) {
+       if (want_sleep) {
                libinput_dispatch(li);
-               msleep(sleep);
+               litest_timeout_tap();
                libinput_dispatch(li);
        }