[PATCH libinput 5/7] test: add litest_is_touch_event() helper function
Peter Hutterer
peter.hutterer at who-t.net
Mon May 4 22:43:07 PDT 2015
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
test/litest.c | 27 +++++++++++++++++++++++++++
test/litest.h | 3 +++
test/touch.c | 14 ++++----------
3 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/test/litest.c b/test/litest.c
index e7cf477..9677670 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -1403,6 +1403,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,
diff --git a/test/litest.h b/test/litest.h
index 8f58ad2..d34a2fc 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -184,6 +184,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);
diff --git a/test/touch.c b/test/touch.c
index a5eb553..d78deed 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -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);
--
2.3.5
More information about the wayland-devel
mailing list