2 * Copyright © 2014 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(touchpad_1fg_motion)
36 struct litest_device *dev = litest_current_device();
37 struct libinput *li = dev->libinput;
38 struct libinput_event *event;
39 struct libinput_event_pointer *ptrev;
41 litest_drain_events(li);
43 litest_touch_down(dev, 0, 50, 50);
44 litest_touch_move_to(dev, 0, 50, 50, 80, 50, 5);
45 litest_touch_up(dev, 0);
47 libinput_dispatch(li);
49 event = libinput_get_event(li);
50 ck_assert(event != NULL);
53 ck_assert_int_eq(libinput_event_get_type(event),
54 LIBINPUT_EVENT_POINTER_MOTION);
56 ptrev = libinput_event_get_pointer_event(event);
57 ck_assert_int_ge(libinput_event_pointer_get_dx(ptrev), 0);
58 ck_assert_int_eq(libinput_event_pointer_get_dy(ptrev), 0);
59 libinput_event_destroy(event);
60 event = libinput_get_event(li);
65 START_TEST(touchpad_2fg_no_motion)
67 struct litest_device *dev = litest_current_device();
68 struct libinput *li = dev->libinput;
69 struct libinput_event *event;
71 litest_drain_events(li);
73 litest_touch_down(dev, 0, 20, 20);
74 litest_touch_down(dev, 1, 70, 20);
75 litest_touch_move_to(dev, 0, 20, 20, 80, 80, 5);
76 litest_touch_move_to(dev, 1, 70, 20, 80, 50, 5);
77 litest_touch_up(dev, 1);
78 litest_touch_up(dev, 0);
80 libinput_dispatch(li);
82 event = libinput_get_event(li);
84 ck_assert_int_ne(libinput_event_get_type(event),
85 LIBINPUT_EVENT_POINTER_MOTION);
86 libinput_event_destroy(event);
87 event = libinput_get_event(li);
93 assert_button_event(struct libinput *li, int button,
94 enum libinput_pointer_button_state state)
96 struct libinput_event *event;
97 struct libinput_event_pointer *ptrev;
99 libinput_dispatch(li);
100 event = libinput_get_event(li);
102 ck_assert(event != NULL);
103 ck_assert_int_eq(libinput_event_get_type(event),
104 LIBINPUT_EVENT_POINTER_BUTTON);
105 ptrev = libinput_event_get_pointer_event(event);
106 ck_assert_int_eq(libinput_event_pointer_get_button(ptrev),
108 ck_assert_int_eq(libinput_event_pointer_get_button_state(ptrev),
110 libinput_event_destroy(event);
113 START_TEST(touchpad_1fg_tap)
115 struct litest_device *dev = litest_current_device();
116 struct libinput *li = dev->libinput;
117 struct libinput_event *event;
119 litest_drain_events(li);
121 litest_touch_down(dev, 0, 50, 50);
122 litest_touch_up(dev, 0);
124 libinput_dispatch(li);
126 assert_button_event(li, BTN_LEFT,
127 LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
128 usleep(300000); /* tap-n-drag timeout */
129 assert_button_event(li, BTN_LEFT,
130 LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
132 libinput_dispatch(li);
133 event = libinput_get_event(li);
134 ck_assert(event == NULL);
138 START_TEST(touchpad_1fg_tap_n_drag)
140 struct litest_device *dev = litest_current_device();
141 struct libinput *li = dev->libinput;
142 struct libinput_event *event;
144 litest_drain_events(li);
146 litest_touch_down(dev, 0, 50, 50);
147 litest_touch_up(dev, 0);
148 litest_touch_down(dev, 0, 50, 50);
149 litest_touch_move_to(dev, 0, 50, 50, 80, 80, 5);
150 litest_touch_up(dev, 0);
152 libinput_dispatch(li);
154 assert_button_event(li, BTN_LEFT,
155 LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
157 libinput_dispatch(li);
158 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
159 event = libinput_get_event(li);
160 libinput_event_destroy(event);
161 libinput_dispatch(li);
164 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
166 /* lift finger, set down again, should continue dragging */
167 litest_touch_down(dev, 0, 50, 50);
168 litest_touch_move_to(dev, 0, 50, 50, 80, 80, 5);
169 litest_touch_up(dev, 0);
171 libinput_dispatch(li);
172 while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION) {
173 event = libinput_get_event(li);
174 libinput_event_destroy(event);
175 libinput_dispatch(li);
178 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
180 usleep(300000); /* tap-n-drag timeout */
182 assert_button_event(li, BTN_LEFT,
183 LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
185 libinput_dispatch(li);
186 event = libinput_get_event(li);
187 ck_assert(event == NULL);
191 START_TEST(touchpad_2fg_tap)
193 struct litest_device *dev = litest_current_device();
194 struct libinput *li = dev->libinput;
195 struct libinput_event *event;
197 litest_drain_events(dev->libinput);
199 litest_touch_down(dev, 0, 50, 50);
200 litest_touch_down(dev, 1, 70, 70);
201 litest_touch_up(dev, 0);
202 litest_touch_up(dev, 1);
204 libinput_dispatch(li);
206 assert_button_event(li, BTN_RIGHT,
207 LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
208 usleep(300000); /* tap-n-drag timeout */
209 assert_button_event(li, BTN_RIGHT,
210 LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
212 libinput_dispatch(li);
213 event = libinput_get_event(li);
214 ck_assert(event == NULL);
218 START_TEST(touchpad_1fg_clickfinger)
220 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
221 struct libinput *li = dev->libinput;
223 litest_drain_events(li);
225 litest_touch_down(dev, 0, 50, 50);
226 litest_event(dev, EV_KEY, BTN_LEFT, 1);
227 litest_event(dev, EV_SYN, SYN_REPORT, 0);
228 litest_event(dev, EV_KEY, BTN_LEFT, 0);
229 litest_event(dev, EV_SYN, SYN_REPORT, 0);
230 litest_touch_up(dev, 0);
232 libinput_dispatch(li);
234 assert_button_event(li, BTN_LEFT,
235 LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
236 assert_button_event(li, BTN_LEFT,
237 LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
239 litest_delete_device(dev);
243 START_TEST(touchpad_2fg_clickfinger)
245 struct litest_device *dev = litest_create_device(LITEST_BCM5974);
246 struct libinput *li = dev->libinput;
248 litest_drain_events(li);
250 litest_touch_down(dev, 0, 50, 50);
251 litest_touch_down(dev, 1, 70, 70);
252 litest_event(dev, EV_KEY, BTN_LEFT, 1);
253 litest_event(dev, EV_SYN, SYN_REPORT, 0);
254 litest_event(dev, EV_KEY, BTN_LEFT, 0);
255 litest_event(dev, EV_SYN, SYN_REPORT, 0);
256 litest_touch_up(dev, 0);
257 litest_touch_up(dev, 1);
259 libinput_dispatch(li);
261 assert_button_event(li, BTN_RIGHT,
262 LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
263 assert_button_event(li, BTN_RIGHT,
264 LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
266 litest_delete_device(dev);
270 START_TEST(touchpad_btn_left)
272 struct litest_device *dev = litest_current_device();
273 struct libinput *li = dev->libinput;
275 litest_drain_events(li);
277 litest_event(dev, EV_KEY, BTN_LEFT, 1);
278 litest_event(dev, EV_SYN, SYN_REPORT, 0);
279 litest_event(dev, EV_KEY, BTN_LEFT, 0);
280 litest_event(dev, EV_SYN, SYN_REPORT, 0);
282 libinput_dispatch(li);
284 assert_button_event(li, BTN_LEFT,
285 LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
286 assert_button_event(li, BTN_LEFT,
287 LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
291 START_TEST(clickpad_btn_left)
293 struct litest_device *dev = litest_current_device();
294 struct libinput *li = dev->libinput;
296 litest_drain_events(li);
298 /* A clickpad always needs a finger down to tell where the
300 litest_event(dev, EV_KEY, BTN_LEFT, 1);
301 litest_event(dev, EV_SYN, SYN_REPORT, 0);
302 litest_event(dev, EV_KEY, BTN_LEFT, 0);
303 litest_event(dev, EV_SYN, SYN_REPORT, 0);
305 libinput_dispatch(li);
306 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
310 START_TEST(clickpad_click_n_drag)
312 struct litest_device *dev = litest_current_device();
313 struct libinput *li = dev->libinput;
314 struct libinput_event *event;
316 litest_drain_events(li);
318 litest_touch_down(dev, 0, 50, 50);
319 litest_event(dev, EV_KEY, BTN_LEFT, 1);
320 litest_event(dev, EV_SYN, SYN_REPORT, 0);
322 libinput_dispatch(li);
323 assert_button_event(li, BTN_LEFT,
324 LIBINPUT_POINTER_BUTTON_STATE_PRESSED);
326 libinput_dispatch(li);
327 ck_assert_int_eq(libinput_next_event_type(li), LIBINPUT_EVENT_NONE);
329 /* now put a second finger down */
330 litest_touch_down(dev, 1, 70, 70);
331 litest_touch_move_to(dev, 1, 70, 70, 80, 50, 5);
332 litest_touch_up(dev, 1);
334 libinput_dispatch(li);
335 ck_assert_int_eq(libinput_next_event_type(li),
336 LIBINPUT_EVENT_POINTER_MOTION);
338 event = libinput_get_event(li);
339 libinput_event_destroy(event);
340 libinput_dispatch(li);
341 } while (libinput_next_event_type(li) == LIBINPUT_EVENT_POINTER_MOTION);
343 litest_event(dev, EV_KEY, BTN_LEFT, 0);
344 litest_event(dev, EV_SYN, SYN_REPORT, 0);
345 litest_touch_up(dev, 0);
347 assert_button_event(li, BTN_LEFT,
348 LIBINPUT_POINTER_BUTTON_STATE_RELEASED);
352 int main(int argc, char **argv) {
354 litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
355 litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
357 litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
358 litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
359 litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
361 litest_add_no_device("touchpad:clickfinger", touchpad_1fg_clickfinger);
362 litest_add_no_device("touchpad:clickfinger", touchpad_2fg_clickfinger);
364 litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD, LITEST_CLICKPAD);
365 litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY);
366 litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
368 return litest_run(argc, argv);