[PATCH libinput 18/24] test: Add infrastructure for testing tablet events.

Carlos Garnacho carlosg at gnome.org
Mon Apr 21 10:11:27 PDT 2014


no vfuncs are used, only input_event arrays.

Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
---
 test/litest-int.h |  8 +++++
 test/litest.c     | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/litest.h     | 14 +++++++++
 3 files changed, 112 insertions(+)

diff --git a/test/litest-int.h b/test/litest-int.h
index 19e6e68..e64f8b8 100644
--- a/test/litest-int.h
+++ b/test/litest-int.h
@@ -88,6 +88,14 @@ struct litest_device_interface {
 	struct input_event *touch_move_events;
 	struct input_event *touch_up_events;
 
+	/**
+	 * Tablet events, LITEST_AUTO_ASSIGN is allowed on event values for
+	 * ABS_X, ABS_Y, ABS_DISTANCE and ABS_PRESSURE.
+	 */
+	struct input_event *tablet_proximity_in_events;
+	struct input_event *tablet_proximity_out_events;
+	struct input_event *tablet_motion_events;
+
 	int min[2];
 	int max[2];
 };
diff --git a/test/litest.c b/test/litest.c
index af7fd39..d6989cd 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -642,6 +642,96 @@ litest_touch_move_to(struct litest_device *d,
 	litest_touch_move(d, slot, x_to, y_to);
 }
 
+static int32_t
+axis_replacement_value(struct axis_replacement *axes,
+		       int32_t evcode)
+{
+	struct axis_replacement *axis = axes;
+
+	while (axis->evcode != -1) {
+		if (axis->evcode == evcode)
+			return axis->value;
+		axis++;
+	}
+
+	return -1;
+}
+
+static int
+auto_assign_tablet_value(struct litest_device *d,
+			 const struct input_event *ev,
+			 int x, int y,
+			 struct axis_replacement *axes)
+{
+	static int tracking_id;
+	int value = ev->value;
+
+	if (value != LITEST_AUTO_ASSIGN || ev->type != EV_ABS)
+		return value;
+
+	switch (ev->code) {
+	case ABS_X:
+		value = litest_scale(d, ABS_X, x);
+		break;
+	case ABS_Y:
+		value = litest_scale(d, ABS_Y, y);
+		break;
+	default:
+		value = axis_replacement_value(axes, ev->code);
+		break;
+	}
+
+	return value;
+}
+
+static int
+tablet_ignore_event(const struct input_event *ev, int value)
+{
+	return value == -1 && (ev->code == ABS_PRESSURE || ev->code == ABS_DISTANCE);
+}
+
+void
+litest_tablet_proximity_in(struct litest_device *d, int x, int y, struct axis_replacement *axes)
+{
+	struct input_event *ev;
+
+	ev = d->interface->tablet_proximity_in_events;
+	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+		int value = auto_assign_tablet_value(d, ev, x, y, axes);
+		if (!tablet_ignore_event(ev, value))
+			litest_event(d, ev->type, ev->code, value);
+		ev++;
+	}
+}
+
+void
+litest_tablet_proximity_out(struct litest_device *d)
+{
+	struct input_event *ev;
+
+	ev = d->interface->tablet_proximity_out_events;
+	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+		int value = auto_assign_tablet_value(d, ev, -1, -1, NULL);
+		if (!tablet_ignore_event(ev, value))
+			litest_event(d, ev->type, ev->code, value);
+		ev++;
+	}
+}
+
+void
+litest_tablet_motion(struct litest_device *d, int x, int y, struct axis_replacement *axes)
+{
+	struct input_event *ev;
+
+	ev = d->interface->tablet_motion_events;
+	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+		int value = auto_assign_tablet_value(d, ev, x, y, axes);
+		if (!tablet_ignore_event(ev, value))
+			litest_event(d, ev->type, ev->code, value);
+		ev++;
+	}
+}
+
 void
 litest_button_click(struct litest_device *d, unsigned int button, bool is_press)
 {
diff --git a/test/litest.h b/test/litest.h
index 85748cc..80961a7 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -42,6 +42,7 @@ enum litest_device_type {
 	LITEST_TRACKPOINT,
 	LITEST_MOUSE,
 	LITEST_WACOM_TOUCH,
+	LITEST_WACOM_TABLET,
 };
 
 enum litest_device_feature {
@@ -55,6 +56,7 @@ enum litest_device_feature {
 	LITEST_WHEEL = 1 << 5,
 	LITEST_TOUCH = 1 << 6,
 	LITEST_SINGLE_TOUCH = 1 << 7,
+	LITEST_TABLET = 1 << 8,
 };
 
 struct litest_device {
@@ -65,6 +67,11 @@ struct litest_device {
 	struct litest_device_interface *interface;
 };
 
+struct axis_replacement {
+	int32_t evcode;
+	int32_t value;
+};
+
 void litest_add(const char *name, void *func,
 		enum litest_device_feature required_feature,
 		enum litest_device_feature excluded_feature);
@@ -105,6 +112,13 @@ void litest_touch_move_to(struct litest_device *d,
 			  int x_from, int y_from,
 			  int x_to, int y_to,
 			  int steps);
+void litest_tablet_proximity_in(struct litest_device *d,
+				int x, int y,
+				struct axis_replacement *axes);
+void litest_tablet_proximity_out(struct litest_device *d);
+void litest_tablet_motion(struct litest_device *d,
+			  int x, int y,
+			  struct axis_replacement *axes);
 void litest_button_click(struct litest_device *d,
 			 unsigned int button,
 			 bool is_press);
-- 
1.9.0



More information about the wayland-devel mailing list