[PATCH libinput 3/7] test: add litest_is_axis_event() helper

Peter Hutterer peter.hutterer at who-t.net
Mon May 4 22:43:05 PDT 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/litest.c  | 25 +++++++++++++++++++++----
 test/litest.h  |  4 ++++
 test/pointer.c | 14 ++++----------
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/test/litest.c b/test/litest.c
index c79cca6..563ee39 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -1346,6 +1346,26 @@ litest_is_button_event(struct libinput_event *event,
 	return ptrev;
 }
 
+struct libinput_event_pointer *
+litest_is_axis_event(struct libinput_event *event,
+		     enum libinput_pointer_axis axis,
+		     enum libinput_pointer_axis_source source)
+{
+	struct libinput_event_pointer *ptrev;
+	enum libinput_event_type type = LIBINPUT_EVENT_POINTER_AXIS;
+
+	ck_assert(event != NULL);
+	ck_assert_int_eq(libinput_event_get_type(event), type);
+	ptrev = libinput_event_get_pointer_event(event);
+	ck_assert(libinput_event_pointer_has_axis(ptrev, axis));
+
+	if (source != 0)
+		ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
+				 source);
+
+	return ptrev;
+}
+
 void
 litest_assert_button_event(struct libinput *li, unsigned int button,
 			   enum libinput_button_state state)
@@ -1373,10 +1393,7 @@ litest_assert_scroll(struct libinput *li,
 	ck_assert(next_event != NULL); /* At least 1 scroll + stop scroll */
 
 	while (event) {
-		ck_assert_int_eq(libinput_event_get_type(event),
-				 LIBINPUT_EVENT_POINTER_AXIS);
-		ptrev = libinput_event_get_pointer_event(event);
-		ck_assert(ptrev != NULL);
+		ptrev = litest_is_axis_event(event, axis, 0);
 
 		if (next_event) {
 			/* Normal scroll event, check dir */
diff --git a/test/litest.h b/test/litest.h
index 5d8ce5b..f2d267f 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -178,6 +178,10 @@ struct libinput_event_pointer * litest_is_button_event(
 		       struct libinput_event *event,
 		       unsigned int button,
 		       enum libinput_button_state state);
+struct libinput_event_pointer * litest_is_axis_event(
+		       struct libinput_event *event,
+		       enum libinput_pointer_axis axis,
+		       enum libinput_pointer_axis_source source);
 void litest_assert_button_event(struct libinput *li,
 				unsigned int button,
 				enum libinput_button_state state);
diff --git a/test/pointer.c b/test/pointer.c
index a0f862b..7784941 100644
--- a/test/pointer.c
+++ b/test/pointer.c
@@ -383,22 +383,16 @@ test_wheel_event(struct litest_device *dev, int which, int amount)
 
 	libinput_dispatch(li);
 
-	event = libinput_get_event(li);
-	ck_assert(event != NULL);
-	ck_assert_int_eq(libinput_event_get_type(event),
-			  LIBINPUT_EVENT_POINTER_AXIS);
-
-	ptrev = libinput_event_get_pointer_event(event);
-	ck_assert(ptrev != NULL);
-
 	axis = (which == REL_WHEEL) ?
 				LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL :
 				LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
+	event = libinput_get_event(li);
+	ptrev = litest_is_axis_event(event,
+				     axis,
+				     LIBINPUT_POINTER_AXIS_SOURCE_WHEEL);
 
 	ck_assert_int_eq(libinput_event_pointer_get_axis_value(ptrev, axis),
 			 expected);
-	ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
-			 LIBINPUT_POINTER_AXIS_SOURCE_WHEEL);
 	ck_assert_int_eq(libinput_event_pointer_get_axis_value_discrete(ptrev, axis),
 			 discrete);
 	libinput_event_destroy(event);
-- 
2.3.5



More information about the wayland-devel mailing list