[PATCH libinput 2/6] test: add litest_assert_empty_queue helper function

Peter Hutterer peter.hutterer at who-t.net
Tue Jun 10 17:11:31 PDT 2014


Checks if the queue is empty and prints informatino about any events before
failing.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/litest.c   | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/litest.h   |  1 +
 test/touchpad.c |  9 ++-------
 3 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/test/litest.c b/test/litest.c
index 1f1bf7b..571cf76 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -737,6 +737,67 @@ litest_drain_events(struct libinput *li)
 	}
 }
 
+static void
+litest_print_event(struct libinput_event *event)
+{
+	struct libinput_event_pointer *p;
+	struct libinput_device *dev;
+	enum libinput_event_type type;
+	double x, y;
+
+	dev = libinput_event_get_device(event);
+	type = libinput_event_get_type(event);
+
+	fprintf(stderr,
+		"device %s type %d ",
+		libinput_device_get_sysname(dev),
+		type);
+	switch (type) {
+	case LIBINPUT_EVENT_POINTER_MOTION:
+		p = libinput_event_get_pointer_event(event);
+		x = libinput_event_pointer_get_dx(p);
+		y = libinput_event_pointer_get_dy(p);
+		fprintf(stderr, "motion: %.2f/%.2f", x, y);
+		break;
+	case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
+		p = libinput_event_get_pointer_event(event);
+		x = libinput_event_pointer_get_absolute_x(p);
+		y = libinput_event_pointer_get_absolute_y(p);
+		fprintf(stderr, "motion: %.2f/%.2f", x, y);
+		break;
+	case LIBINPUT_EVENT_POINTER_BUTTON:
+		p = libinput_event_get_pointer_event(event);
+		fprintf(stderr,
+			"button: %d state %d",
+			libinput_event_pointer_get_button(p),
+			libinput_event_pointer_get_button_state(p));
+		break;
+	default:
+		break;
+	}
+
+	fprintf(stderr, "\n");
+}
+
+void
+litest_assert_empty_queue(struct libinput *li)
+{
+	bool empty_queue = true;
+	struct libinput_event *event;
+
+	libinput_dispatch(li);
+	while ((event = libinput_get_event(li))) {
+		empty_queue = false;
+		fprintf(stderr,
+			"Unexpected event: ");
+		litest_print_event(event);
+		libinput_event_destroy(event);
+		libinput_dispatch(li);
+	}
+
+	ck_assert(empty_queue);
+}
+
 struct libevdev_uinput *
 litest_create_uinput_device_from_description(const char *name,
 					     const struct input_id *id,
diff --git a/test/litest.h b/test/litest.h
index 32e1cb0..170c87c 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -123,6 +123,7 @@ void litest_keyboard_key(struct litest_device *d,
 			 unsigned int key,
 			 bool is_press);
 void litest_drain_events(struct libinput *li);
+void litest_assert_empty_queue(struct libinput *li);
 
 struct libevdev_uinput * litest_create_uinput_device(const char *name,
 						     struct input_id *id,
diff --git a/test/touchpad.c b/test/touchpad.c
index 9c95309..ec412d3 100644
--- a/test/touchpad.c
+++ b/test/touchpad.c
@@ -182,9 +182,7 @@ START_TEST(touchpad_1fg_tap_n_drag)
 	assert_button_event(li, BTN_LEFT,
 			    LIBINPUT_BUTTON_STATE_RELEASED);
 
-	libinput_dispatch(li);
-	event = libinput_get_event(li);
-	ck_assert(event == NULL);
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
@@ -192,7 +190,6 @@ START_TEST(touchpad_2fg_tap)
 {
 	struct litest_device *dev = litest_current_device();
 	struct libinput *li = dev->libinput;
-	struct libinput_event *event;
 
 	litest_drain_events(dev->libinput);
 
@@ -209,9 +206,7 @@ START_TEST(touchpad_2fg_tap)
 	assert_button_event(li, BTN_RIGHT,
 			    LIBINPUT_BUTTON_STATE_RELEASED);
 
-	libinput_dispatch(li);
-	event = libinput_get_event(li);
-	ck_assert(event == NULL);
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
-- 
1.9.3



More information about the wayland-devel mailing list