2014-01-22 10:34:11 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <check.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <libinput.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "libinput-util.h"
|
|
|
|
|
#include "litest.h"
|
|
|
|
|
|
|
|
|
|
START_TEST(touch_frame_events)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
int have_frame_event = 0;
|
|
|
|
|
|
|
|
|
|
litest_drain_events(dev->libinput);
|
|
|
|
|
|
|
|
|
|
litest_touch_down(dev, 0, 10, 10);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME)
|
|
|
|
|
have_frame_event++;
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
ck_assert_int_eq(have_frame_event, 1);
|
|
|
|
|
|
|
|
|
|
litest_touch_down(dev, 1, 10, 10);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME)
|
|
|
|
|
have_frame_event++;
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
ck_assert_int_eq(have_frame_event, 2);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-02-18 20:13:58 +01:00
|
|
|
START_TEST(touch_abs_transform)
|
|
|
|
|
{
|
2014-04-03 22:35:47 +02:00
|
|
|
struct litest_device *dev;
|
|
|
|
|
struct libinput *libinput;
|
2014-02-18 20:13:58 +01:00
|
|
|
struct libinput_event *ev;
|
|
|
|
|
struct libinput_event_touch *tev;
|
2014-06-02 23:09:27 +02:00
|
|
|
double fx, fy;
|
2014-02-18 20:13:58 +01:00
|
|
|
bool tested = false;
|
|
|
|
|
|
2014-04-03 22:35:47 +02:00
|
|
|
struct input_absinfo abs[] = {
|
|
|
|
|
{ ABS_X, 0, 32767, 75, 0, 0 },
|
|
|
|
|
{ ABS_Y, 0, 32767, 129, 0, 0 },
|
|
|
|
|
{ ABS_MT_POSITION_X, 0, 32767, 0, 0, 10 },
|
|
|
|
|
{ ABS_MT_POSITION_Y, 0, 32767, 0, 0, 9 },
|
|
|
|
|
{ .value = -1 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dev = litest_create_device_with_overrides(LITEST_WACOM_TOUCH,
|
|
|
|
|
"Highres touch device",
|
|
|
|
|
NULL, abs, NULL);
|
|
|
|
|
|
|
|
|
|
libinput = dev->libinput;
|
|
|
|
|
|
2014-02-18 20:13:58 +01:00
|
|
|
litest_touch_down(dev, 0, 100, 100);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
|
|
|
|
|
while ((ev = libinput_get_event(libinput))) {
|
2014-03-27 08:43:04 +10:00
|
|
|
if (libinput_event_get_type(ev) != LIBINPUT_EVENT_TOUCH_DOWN) {
|
|
|
|
|
libinput_event_destroy(ev);
|
2014-02-18 20:13:58 +01:00
|
|
|
continue;
|
2014-03-27 08:43:04 +10:00
|
|
|
}
|
2014-02-18 20:13:58 +01:00
|
|
|
|
|
|
|
|
tev = libinput_event_get_touch_event(ev);
|
|
|
|
|
fx = libinput_event_touch_get_x_transformed(tev, 1920);
|
2014-06-02 23:09:27 +02:00
|
|
|
ck_assert_int_eq(fx, 1919.0);
|
2014-02-18 20:13:58 +01:00
|
|
|
fy = libinput_event_touch_get_y_transformed(tev, 720);
|
2014-06-02 23:09:27 +02:00
|
|
|
ck_assert_int_eq(fy, 719.0);
|
2014-01-22 10:34:11 +10:00
|
|
|
|
2014-02-18 20:13:58 +01:00
|
|
|
tested = true;
|
2014-03-27 08:43:04 +10:00
|
|
|
|
|
|
|
|
libinput_event_destroy(ev);
|
2014-02-18 20:13:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert(tested);
|
2014-04-10 11:11:43 +10:00
|
|
|
|
|
|
|
|
litest_delete_device(dev);
|
2014-02-18 20:13:58 +01:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
2014-03-24 22:37:00 +01:00
|
|
|
START_TEST(touch_many_slots)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *libinput;
|
|
|
|
|
struct litest_device *dev;
|
|
|
|
|
struct libinput_event *ev;
|
|
|
|
|
int slot;
|
|
|
|
|
const int num_tps = 100;
|
|
|
|
|
int slot_count = 0;
|
|
|
|
|
enum libinput_event_type type;
|
|
|
|
|
|
|
|
|
|
struct input_absinfo abs[] = {
|
|
|
|
|
{ ABS_MT_SLOT, 0, num_tps - 1, 0, 0, 0 },
|
|
|
|
|
{ .value = -1 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dev = litest_create_device_with_overrides(LITEST_WACOM_TOUCH,
|
|
|
|
|
"Multi-touch device",
|
|
|
|
|
NULL, abs, NULL);
|
|
|
|
|
libinput = dev->libinput;
|
|
|
|
|
|
|
|
|
|
for (slot = 0; slot < num_tps; ++slot)
|
|
|
|
|
litest_touch_down(dev, slot, 0, 0);
|
|
|
|
|
for (slot = 0; slot < num_tps; ++slot)
|
|
|
|
|
litest_touch_up(dev, slot);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
while ((ev = libinput_get_event(libinput))) {
|
|
|
|
|
type = libinput_event_get_type(ev);
|
|
|
|
|
|
|
|
|
|
if (type == LIBINPUT_EVENT_TOUCH_DOWN)
|
|
|
|
|
slot_count++;
|
|
|
|
|
else if (type == LIBINPUT_EVENT_TOUCH_UP)
|
|
|
|
|
break;
|
|
|
|
|
|
2014-04-23 11:04:48 +10:00
|
|
|
libinput_event_destroy(ev);
|
2014-03-24 22:37:00 +01:00
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert_notnull(ev);
|
|
|
|
|
ck_assert_int_gt(slot_count, 0);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
do {
|
|
|
|
|
type = libinput_event_get_type(ev);
|
|
|
|
|
ck_assert_int_ne(type, LIBINPUT_EVENT_TOUCH_DOWN);
|
|
|
|
|
if (type == LIBINPUT_EVENT_TOUCH_UP)
|
|
|
|
|
slot_count--;
|
|
|
|
|
|
2014-04-23 11:04:48 +10:00
|
|
|
libinput_event_destroy(ev);
|
2014-03-24 22:37:00 +01:00
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
} while ((ev = libinput_get_event(libinput)));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(slot_count, 0);
|
2014-04-23 11:04:48 +10:00
|
|
|
|
|
|
|
|
litest_delete_device(dev);
|
2014-03-24 22:37:00 +01:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-03-24 23:05:21 +01:00
|
|
|
START_TEST(touch_double_touch_down_up)
|
|
|
|
|
{
|
|
|
|
|
struct libinput *libinput;
|
|
|
|
|
struct litest_device *dev;
|
|
|
|
|
struct libinput_event *ev;
|
|
|
|
|
bool got_down = false;
|
|
|
|
|
bool got_up = false;
|
|
|
|
|
|
|
|
|
|
dev = litest_current_device();
|
|
|
|
|
libinput = dev->libinput;
|
|
|
|
|
|
|
|
|
|
litest_touch_down(dev, 0, 0, 0);
|
|
|
|
|
litest_touch_down(dev, 0, 0, 0);
|
|
|
|
|
litest_touch_up(dev, 0);
|
|
|
|
|
litest_touch_up(dev, 0);
|
|
|
|
|
|
|
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
|
|
|
|
|
while ((ev = libinput_get_event(libinput))) {
|
|
|
|
|
switch (libinput_event_get_type(ev)) {
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_DOWN:
|
|
|
|
|
ck_assert(!got_down);
|
|
|
|
|
got_down = true;
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_UP:
|
|
|
|
|
ck_assert(got_down);
|
|
|
|
|
ck_assert(!got_up);
|
|
|
|
|
got_up = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 11:04:48 +10:00
|
|
|
libinput_event_destroy(ev);
|
2014-03-24 23:05:21 +01:00
|
|
|
libinput_dispatch(libinput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ck_assert(got_down);
|
|
|
|
|
ck_assert(got_up);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-02-18 20:13:58 +01:00
|
|
|
int
|
|
|
|
|
main(int argc, char **argv)
|
|
|
|
|
{
|
2014-01-22 10:34:11 +10:00
|
|
|
litest_add("touch:frame", touch_frame_events, LITEST_TOUCH, LITEST_ANY);
|
2014-04-03 22:35:47 +02:00
|
|
|
litest_add_no_device("touch:abs-transform", touch_abs_transform);
|
2014-03-24 22:37:00 +01:00
|
|
|
litest_add_no_device("touch:many-slots", touch_many_slots);
|
2014-03-24 23:05:21 +01:00
|
|
|
litest_add("touch:double-touch-down-up", touch_double_touch_down_up, LITEST_TOUCH, LITEST_ANY);
|
2014-01-22 10:34:11 +10:00
|
|
|
|
|
|
|
|
return litest_run(argc, argv);
|
|
|
|
|
}
|