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, 10 },
76 { ABS_Y, 0, 32767, 129, 0, 9 },
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 "litest 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);
115 START_TEST(touch_many_slots)
117 struct libinput *libinput;
118 struct litest_device *dev;
119 struct libinput_event *ev;
121 const int num_tps = 100;
123 enum libinput_event_type type;
125 struct input_absinfo abs[] = {
126 { ABS_MT_SLOT, 0, num_tps - 1, 0, 0, 0 },
130 dev = litest_create_device_with_overrides(LITEST_WACOM_TOUCH,
131 "litest Multi-touch device",
133 libinput = dev->libinput;
135 for (slot = 0; slot < num_tps; ++slot)
136 litest_touch_down(dev, slot, 0, 0);
137 for (slot = 0; slot < num_tps; ++slot)
138 litest_touch_up(dev, slot);
140 libinput_dispatch(libinput);
141 while ((ev = libinput_get_event(libinput))) {
142 type = libinput_event_get_type(ev);
144 if (type == LIBINPUT_EVENT_TOUCH_DOWN)
146 else if (type == LIBINPUT_EVENT_TOUCH_UP)
149 libinput_event_destroy(ev);
150 libinput_dispatch(libinput);
153 ck_assert_notnull(ev);
154 ck_assert_int_gt(slot_count, 0);
156 libinput_dispatch(libinput);
158 type = libinput_event_get_type(ev);
159 ck_assert_int_ne(type, LIBINPUT_EVENT_TOUCH_DOWN);
160 if (type == LIBINPUT_EVENT_TOUCH_UP)
163 libinput_event_destroy(ev);
164 libinput_dispatch(libinput);
165 } while ((ev = libinput_get_event(libinput)));
167 ck_assert_int_eq(slot_count, 0);
169 litest_delete_device(dev);
173 START_TEST(touch_double_touch_down_up)
175 struct libinput *libinput;
176 struct litest_device *dev;
177 struct libinput_event *ev;
178 bool got_down = false;
181 dev = litest_current_device();
182 libinput = dev->libinput;
184 litest_touch_down(dev, 0, 0, 0);
185 litest_touch_down(dev, 0, 0, 0);
186 litest_touch_up(dev, 0);
187 litest_touch_up(dev, 0);
189 libinput_dispatch(libinput);
191 while ((ev = libinput_get_event(libinput))) {
192 switch (libinput_event_get_type(ev)) {
193 case LIBINPUT_EVENT_TOUCH_DOWN:
194 ck_assert(!got_down);
197 case LIBINPUT_EVENT_TOUCH_UP:
206 libinput_event_destroy(ev);
207 libinput_dispatch(libinput);
216 main(int argc, char **argv)
218 litest_add("touch:frame", touch_frame_events, LITEST_TOUCH, LITEST_ANY);
219 litest_add_no_device("touch:abs-transform", touch_abs_transform);
220 litest_add_no_device("touch:many-slots", touch_many_slots);
221 litest_add("touch:double-touch-down-up", touch_double_touch_down_up, LITEST_TOUCH, LITEST_ANY);
223 return litest_run(argc, argv);