test: switch the protocol A test device to be an actual protocol A device

This device mostly behaved like a normal touch device except for
SYN_MT_REPORT. Switch it to behave like a real protocol A device and adjust
the test accordingly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-03-22 15:47:21 +10:00
parent 11adaadd51
commit 44702e947c
2 changed files with 159 additions and 49 deletions

View file

@ -26,32 +26,152 @@
#include "litest.h"
#include "litest-int.h"
static struct input_event down[] = {
{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_SYN, .code = SYN_MT_REPORT, .value = 0 },
{ .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
#define PROTOCOL_A_MAX_SLOTS 10
struct protocolA_device {
struct slot {
bool active;
int x, y;
int tracking_id;
} slots[PROTOCOL_A_MAX_SLOTS];
unsigned int nslots;
};
static struct input_event move[] = {
{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
{ .type = EV_SYN, .code = SYN_MT_REPORT, .value = 0 },
{ .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
{ .type = -1, .code = -1 },
};
static bool
protocolA_create(struct litest_device *d)
{
struct protocolA_device *dev = zalloc(sizeof(*dev));
dev->nslots = PROTOCOL_A_MAX_SLOTS;
d->private = dev;
return true; /* we want litest to create our device */
}
static void
protocolA_down(struct litest_device *d, unsigned int slot, double x, double y)
{
struct protocolA_device *dev = d->private;
static int tracking_id;
bool first = true;
assert(slot <= PROTOCOL_A_MAX_SLOTS);
x = litest_scale(d, ABS_X, x);
y = litest_scale(d, ABS_Y, y);
for (unsigned int i = 0; i < dev->nslots; i++) {
struct slot *s = &dev->slots[i];
if (slot == i) {
assert(!s->active);
s->active = true;
s->x = x;
s->y = y;
s->tracking_id = ++tracking_id;
}
if (!s->active)
continue;
if (first) {
litest_event(d, EV_ABS, ABS_X, s->x);
litest_event(d, EV_ABS, ABS_X, s->y);
first = false;
}
litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id);
litest_event(d, EV_ABS, ABS_MT_POSITION_X, s->x);
litest_event(d, EV_ABS, ABS_MT_POSITION_Y, s->y);
litest_event(d, EV_SYN, SYN_MT_REPORT, 0);
}
if (!first) {
litest_event(d, EV_KEY, BTN_TOUCH, 1);
litest_event(d, EV_SYN, SYN_REPORT, 0);
}
}
static void
protocolA_move(struct litest_device *d, unsigned int slot, double x, double y)
{
struct protocolA_device *dev = d->private;
bool first = true;
assert(slot <= PROTOCOL_A_MAX_SLOTS);
x = litest_scale(d, ABS_X, x);
y = litest_scale(d, ABS_Y, y);
for (unsigned int i = 0; i < dev->nslots; i++) {
struct slot *s = &dev->slots[i];
if (slot == i) {
assert(s->active);
s->x = x;
s->y = y;
}
if (!s->active)
continue;
if (first) {
litest_event(d, EV_ABS, ABS_X, s->x);
litest_event(d, EV_ABS, ABS_X, s->y);
first = false;
}
litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id);
litest_event(d, EV_ABS, ABS_MT_POSITION_X, s->x);
litest_event(d, EV_ABS, ABS_MT_POSITION_Y, s->y);
litest_event(d, EV_SYN, SYN_MT_REPORT, 0);
}
if (!first)
litest_event(d, EV_SYN, SYN_REPORT, 0);
}
static void
protocolA_up(struct litest_device *d, unsigned int slot)
{
struct protocolA_device *dev = d->private;
bool first = true;
assert(slot <= PROTOCOL_A_MAX_SLOTS);
for (unsigned int i = 0; i < dev->nslots; i++) {
struct slot *s = &dev->slots[i];
if (slot == i) {
assert(s->active);
s->active = false;
litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id);
litest_event(d, EV_SYN, SYN_MT_REPORT, 0);
}
if (!s->active)
continue;
if (first) {
litest_event(d, EV_ABS, ABS_X, s->x);
litest_event(d, EV_ABS, ABS_X, s->y);
first = false;
}
litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, s->tracking_id);
litest_event(d, EV_ABS, ABS_MT_POSITION_X, s->x);
litest_event(d, EV_ABS, ABS_MT_POSITION_Y, s->y);
litest_event(d, EV_SYN, SYN_MT_REPORT, 0);
}
if (first)
litest_event(d, EV_KEY, BTN_TOUCH, 0);
litest_event(d, EV_SYN, SYN_REPORT, 0);
}
static struct litest_device_interface interface = {
.touch_down_events = down,
.touch_move_events = move,
.touch_down = protocolA_down,
.touch_move = protocolA_move,
.touch_up = protocolA_up,
};
static struct input_absinfo absinfo[] = {
@ -78,6 +198,8 @@ static int events[] = {
TEST_DEVICE("protocol-a",
.type = LITEST_PROTOCOL_A_SCREEN,
.features = LITEST_PROTOCOL_A,
.create = protocolA_create,
.interface = &interface,
.name = "Protocol A touch screen",

View file

@ -716,15 +716,11 @@ START_TEST(touch_protocol_a_2fg_touch)
litest_drain_events(li);
litest_push_event_frame(dev);
litest_touch_down(dev, 0, 5, 95);
litest_touch_down(dev, 0, 95, 5);
litest_pop_event_frame(dev);
litest_touch_down(dev, 1, 95, 5);
libinput_dispatch(li);
ev = libinput_get_event(li);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
libinput_event_destroy(ev);
litest_assert_touch_down_frame(li);
ev = libinput_get_event(li);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_DOWN);
@ -735,22 +731,22 @@ START_TEST(touch_protocol_a_2fg_touch)
libinput_event_destroy(ev);
for (pos = 10; pos < 100; pos += 10) {
litest_push_event_frame(dev);
litest_touch_move_to(dev, 0, pos, 100 - pos, pos, 100 - pos, 1);
litest_touch_move_to(dev, 0, 100 - pos, pos, 100 - pos, pos, 1);
litest_pop_event_frame(dev);
litest_touch_move(dev, 0, pos, 100 - pos);
litest_touch_move(dev, 1, 100 - pos, pos);
libinput_dispatch(li);
ev = libinput_get_event(li);
tev = libinput_event_get_touch_event(ev);
ck_assert_int_eq(libinput_event_touch_get_slot(tev),
0);
ck_assert_int_eq(libinput_event_touch_get_slot(tev), 0);
libinput_event_destroy(ev);
ev = libinput_get_event(li);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME);
libinput_event_destroy(ev);
ev = libinput_get_event(li);
tev = libinput_event_get_touch_event(ev);
ck_assert_int_eq(libinput_event_touch_get_slot(tev),
1);
ck_assert_int_eq(libinput_event_touch_get_slot(tev), 1);
libinput_event_destroy(ev);
ev = libinput_get_event(li);
@ -758,21 +754,13 @@ START_TEST(touch_protocol_a_2fg_touch)
libinput_event_destroy(ev);
}
litest_event(dev, EV_SYN, SYN_MT_REPORT, 0);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_touch_up(dev, 0);
libinput_dispatch(li);
ev = libinput_get_event(li);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_UP);
libinput_event_destroy(ev);
litest_assert_touch_up_frame(li);
ev = libinput_get_event(li);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_UP);
libinput_event_destroy(ev);
ev = libinput_get_event(li);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_FRAME);
libinput_event_destroy(ev);
litest_touch_up(dev, 1);
libinput_dispatch(li);
litest_assert_touch_up_frame(li);
}
END_TEST