test: add litest_is_touch_event() helper function
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 4 May 2015 03:51:39 +0000 (13:51 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 7 May 2015 04:41:00 +0000 (14:41 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
test/litest.c
test/litest.h
test/touch.c

index ca996e4aa03ced9bdf8c8e8e24ba2c930f397f39..6506af082d7de0f14705cb837b5558cd8ed9ab4b 100644 (file)
@@ -1531,6 +1531,33 @@ litest_assert_button_event(struct libinput *li, unsigned int button,
        libinput_event_destroy(event);
 }
 
+struct libinput_event_touch *
+litest_is_touch_event(struct libinput_event *event,
+                     enum libinput_event_type type)
+{
+       struct libinput_event_touch *touch;
+
+       ck_assert(event != NULL);
+
+       if (type == 0)
+               type = libinput_event_get_type(event);
+
+       switch (type) {
+       case LIBINPUT_EVENT_TOUCH_DOWN:
+       case LIBINPUT_EVENT_TOUCH_UP:
+       case LIBINPUT_EVENT_TOUCH_MOTION:
+       case LIBINPUT_EVENT_TOUCH_FRAME:
+               ck_assert_int_eq(libinput_event_get_type(event), type);
+               break;
+       default:
+               ck_abort_msg("%s: invalid touch type %d\n", __func__, type);
+       }
+
+       touch = libinput_event_get_touch_event(event);
+
+       return touch;
+}
+
 void
 litest_assert_scroll(struct libinput *li,
                     enum libinput_pointer_axis axis,
index fa974958189e4ec5f0422b6040b437ac90881ee7..ebe2bea3b09c42bb8c14a2dfb29ddd6c8bd9debf 100644 (file)
@@ -206,6 +206,9 @@ struct libinput_event_pointer * litest_is_axis_event(
                       enum libinput_pointer_axis_source source);
 struct libinput_event_pointer * litest_is_motion_event(
                       struct libinput_event *event);
+struct libinput_event_touch * litest_is_touch_event(
+                      struct libinput_event *event,
+                      enum libinput_event_type type);
 void litest_assert_button_event(struct libinput *li,
                                unsigned int button,
                                enum libinput_button_state state);
index a5eb553d4a03d655b471ed91499568b8c624adc4..d78deedd07f6382770363c1c781d5b2bb4745537 100644 (file)
@@ -244,9 +244,7 @@ START_TEST(touch_calibration_scale)
 
                litest_wait_for_event(li);
                ev = libinput_get_event(li);
-               ck_assert_int_eq(libinput_event_get_type(ev),
-                                LIBINPUT_EVENT_TOUCH_DOWN);
-               tev = libinput_event_get_touch_event(ev);
+               tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
 
                x = libinput_event_touch_get_x_transformed(tev, width);
                y = libinput_event_touch_get_y_transformed(tev, height);
@@ -315,9 +313,7 @@ START_TEST(touch_calibration_rotation)
                litest_touch_up(dev, 0);
                litest_wait_for_event(li);
                ev = libinput_get_event(li);
-               ck_assert_int_eq(libinput_event_get_type(ev),
-                                LIBINPUT_EVENT_TOUCH_DOWN);
-               tev = libinput_event_get_touch_event(ev);
+               tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
 
                x = libinput_event_touch_get_x_transformed(tev, width);
                y = libinput_event_touch_get_y_transformed(tev, height);
@@ -381,9 +377,7 @@ START_TEST(touch_calibration_translation)
 
                litest_wait_for_event(li);
                ev = libinput_get_event(li);
-               ck_assert_int_eq(libinput_event_get_type(ev),
-                                LIBINPUT_EVENT_TOUCH_DOWN);
-               tev = libinput_event_get_touch_event(ev);
+               tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
 
                x = libinput_event_touch_get_x_transformed(tev, width);
                y = libinput_event_touch_get_y_transformed(tev, height);
@@ -499,7 +493,7 @@ START_TEST(touch_protocol_a_touch)
        litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TOUCH_DOWN, -1);
 
        ev = libinput_get_event(li);
-       tev = libinput_event_get_touch_event(ev);
+       tev = litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
 
        oldx = libinput_event_touch_get_x(tev);
        oldy = libinput_event_touch_get_y(tev);