From 204d1d7514fa2620edfcaa191b58620b35a8965d Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 21 Apr 2014 19:11:27 +0200 Subject: [PATCH] test: Add infrastructure for testing tablet events. no vfuncs are used, only input_event arrays. Signed-off-by: Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/litest-int.h | 8 +++++ test/litest.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++ test/litest.h | 13 +++++++ 3 files changed, 110 insertions(+) diff --git a/test/litest-int.h b/test/litest-int.h index 19e6e68d..e64f8b85 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 0a9cc72d..f7287072 100644 --- a/test/litest.c +++ b/test/litest.c @@ -695,6 +695,95 @@ 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) +{ + 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 3e75dd58..ac8f4497 100644 --- a/test/litest.h +++ b/test/litest.h @@ -58,6 +58,8 @@ enum litest_device_feature { LITEST_SINGLE_TOUCH = 1 << 7, LITEST_APPLE_CLICKPAD = 1 << 8, LITEST_TOPBUTTONPAD = 1 << 9, + LITEST_TABLET = 1 << 10, + LITEST_DISTANCE = 1 << 11, }; struct litest_device { @@ -70,6 +72,10 @@ struct litest_device { }; struct libinput *litest_create_context(void); +struct axis_replacement { + int32_t evcode; + int32_t value; +}; void litest_add(const char *name, void *func, enum litest_device_feature required_feature, @@ -119,6 +125,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);