2 * Copyright © 2013 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 #include "libinput-util.h"
34 START_TEST(touch_frame_events)
36 struct litest_device *dev = litest_current_device();
37 struct libinput *li = dev->libinput;
38 struct libinput_event *event;
39 int have_frame_event = 0;
41 litest_drain_events(dev->libinput);
43 litest_touch_down(dev, 0, 10, 10);
44 libinput_dispatch(li);
46 while ((event = libinput_get_event(li))) {
47 if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME)
49 libinput_event_destroy(event);
51 ck_assert_int_eq(have_frame_event, 1);
53 litest_touch_down(dev, 1, 10, 10);
54 libinput_dispatch(li);
56 while ((event = libinput_get_event(li))) {
57 if (libinput_event_get_type(event) == LIBINPUT_EVENT_TOUCH_FRAME)
59 libinput_event_destroy(event);
61 ck_assert_int_eq(have_frame_event, 2);
65 START_TEST(touch_abs_transform)
67 struct litest_device *dev;
68 struct libinput *libinput;
69 struct libinput_event *ev;
70 struct libinput_event_touch *tev;
74 struct input_absinfo abs[] = {
75 { ABS_X, 0, 32767, 75, 0, 0 },
76 { ABS_Y, 0, 32767, 129, 0, 0 },
77 { ABS_MT_POSITION_X, 0, 32767, 0, 0, 10 },
78 { ABS_MT_POSITION_Y, 0, 32767, 0, 0, 9 },
82 dev = litest_create_device_with_overrides(LITEST_WACOM_TOUCH,
83 "Highres touch device",
86 libinput = dev->libinput;
88 litest_touch_down(dev, 0, 100, 100);
90 libinput_dispatch(libinput);
92 while ((ev = libinput_get_event(libinput))) {
93 if (libinput_event_get_type(ev) != LIBINPUT_EVENT_TOUCH_DOWN) {
94 libinput_event_destroy(ev);
98 tev = libinput_event_get_touch_event(ev);
99 fx = libinput_event_touch_get_x_transformed(tev, 1920);
100 ck_assert_int_eq(fx, 1919.0);
101 fy = libinput_event_touch_get_y_transformed(tev, 720);
102 ck_assert_int_eq(fy, 719.0);
106 libinput_event_destroy(ev);
111 litest_delete_device(dev);
116 START_TEST(touch_many_slots)
118 struct libinput *libinput;
119 struct litest_device *dev;
120 struct libinput_event *ev;
122 const int num_tps = 100;
124 enum libinput_event_type type;
126 struct input_absinfo abs[] = {
127 { ABS_MT_SLOT, 0, num_tps - 1, 0, 0, 0 },
131 dev = litest_create_device_with_overrides(LITEST_WACOM_TOUCH,
132 "Multi-touch device",
134 libinput = dev->libinput;
136 for (slot = 0; slot < num_tps; ++slot)
137 litest_touch_down(dev, slot, 0, 0);
138 for (slot = 0; slot < num_tps; ++slot)
139 litest_touch_up(dev, slot);
141 libinput_dispatch(libinput);
142 while ((ev = libinput_get_event(libinput))) {
143 type = libinput_event_get_type(ev);
145 if (type == LIBINPUT_EVENT_TOUCH_DOWN)
147 else if (type == LIBINPUT_EVENT_TOUCH_UP)
150 libinput_event_destroy(ev);
151 libinput_dispatch(libinput);
154 ck_assert_notnull(ev);
155 ck_assert_int_gt(slot_count, 0);
157 libinput_dispatch(libinput);
159 type = libinput_event_get_type(ev);
160 ck_assert_int_ne(type, LIBINPUT_EVENT_TOUCH_DOWN);
161 if (type == LIBINPUT_EVENT_TOUCH_UP)
164 libinput_event_destroy(ev);
165 libinput_dispatch(libinput);
166 } while ((ev = libinput_get_event(libinput)));
168 ck_assert_int_eq(slot_count, 0);
170 litest_delete_device(dev);
174 START_TEST(touch_double_touch_down_up)
176 struct libinput *libinput;
177 struct litest_device *dev;
178 struct libinput_event *ev;
179 bool got_down = false;
182 dev = litest_current_device();
183 libinput = dev->libinput;
185 litest_touch_down(dev, 0, 0, 0);
186 litest_touch_down(dev, 0, 0, 0);
187 litest_touch_up(dev, 0);
188 litest_touch_up(dev, 0);
190 libinput_dispatch(libinput);
192 while ((ev = libinput_get_event(libinput))) {
193 switch (libinput_event_get_type(ev)) {
194 case LIBINPUT_EVENT_TOUCH_DOWN:
195 ck_assert(!got_down);
198 case LIBINPUT_EVENT_TOUCH_UP:
207 libinput_event_destroy(ev);
208 libinput_dispatch(libinput);
217 main(int argc, char **argv)
219 litest_add("touch:frame", touch_frame_events, LITEST_TOUCH, LITEST_ANY);
220 litest_add_no_device("touch:abs-transform", touch_abs_transform);
221 litest_add_no_device("touch:many-slots", touch_many_slots);
222 litest_add("touch:double-touch-down-up", touch_double_touch_down_up, LITEST_TOUCH, LITEST_ANY);
224 return litest_run(argc, argv);