source: mainline/uspace/srv/hid/display/test/seat.c@ 338d0935

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 338d0935 was f7fb2b21, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Propagate position event to display clients

  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 * Copyright (c) 2019 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <disp_srv.h>
30#include <errno.h>
31#include <pcut/pcut.h>
32#include <stdio.h>
33#include <str.h>
34
35#include "../client.h"
36#include "../display.h"
37#include "../seat.h"
38#include "../window.h"
39
40PCUT_INIT;
41
42PCUT_TEST_SUITE(seat);
43
44static void test_ds_ev_pending(void *);
45
46static ds_client_cb_t test_ds_client_cb = {
47 .ev_pending = test_ds_ev_pending
48};
49
50static void test_ds_ev_pending(void *arg)
51{
52 bool *called_cb = (bool *) arg;
53 printf("test_ds_ev_pending\n");
54 *called_cb = true;
55
56}
57
58/** Set focus. */
59PCUT_TEST(set_focus)
60{
61 ds_display_t *disp;
62 ds_client_t *client;
63 ds_seat_t *seat;
64 ds_window_t *wnd;
65 display_wnd_params_t params;
66 errno_t rc;
67
68 rc = ds_display_create(NULL, &disp);
69 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
70
71 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
72 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
73
74 rc = ds_seat_create(disp, &seat);
75 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
76
77 display_wnd_params_init(&params);
78 params.rect.p0.x = params.rect.p0.y = 0;
79 params.rect.p1.x = params.rect.p1.y = 1;
80
81 rc = ds_window_create(client, &params, &wnd);
82 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
83
84 ds_seat_set_focus(seat, wnd);
85 PCUT_ASSERT_EQUALS(wnd, seat->focus);
86
87 ds_window_destroy(wnd);
88 ds_seat_destroy(seat);
89 ds_client_destroy(client);
90 ds_display_destroy(disp);
91}
92
93/** Evacuate focus. */
94PCUT_TEST(evac_focus)
95{
96 ds_display_t *disp;
97 ds_client_t *client;
98 ds_seat_t *seat;
99 ds_window_t *w0;
100 ds_window_t *w1;
101 display_wnd_params_t params;
102 errno_t rc;
103
104 rc = ds_display_create(NULL, &disp);
105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
106
107 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
108 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
109
110 rc = ds_seat_create(disp, &seat);
111 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
112
113 display_wnd_params_init(&params);
114 params.rect.p0.x = params.rect.p0.y = 0;
115 params.rect.p1.x = params.rect.p1.y = 1;
116
117 rc = ds_window_create(client, &params, &w1);
118 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
119
120 rc = ds_window_create(client, &params, &w0);
121 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
122
123 ds_seat_set_focus(seat, w1);
124 PCUT_ASSERT_EQUALS(w1, seat->focus);
125
126 ds_seat_evac_focus(seat, w1);
127 PCUT_ASSERT_EQUALS(w0, seat->focus);
128
129 ds_window_destroy(w0);
130 ds_window_destroy(w1);
131 ds_seat_destroy(seat);
132 ds_client_destroy(client);
133 ds_display_destroy(disp);
134}
135
136/** Test ds_seat_post_kbd_event() with Alt-Tab switches focus */
137PCUT_TEST(post_kbd_event_alt_tab)
138{
139 ds_display_t *disp;
140 ds_client_t *client;
141 ds_seat_t *seat;
142 ds_window_t *w0;
143 ds_window_t *w1;
144 display_wnd_params_t params;
145 kbd_event_t event;
146 errno_t rc;
147
148 rc = ds_display_create(NULL, &disp);
149 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
150
151 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
152 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
153
154 rc = ds_seat_create(disp, &seat);
155 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
156
157 display_wnd_params_init(&params);
158 params.rect.p0.x = params.rect.p0.y = 0;
159 params.rect.p1.x = params.rect.p1.y = 1;
160
161 rc = ds_window_create(client, &params, &w1);
162 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
163
164 rc = ds_window_create(client, &params, &w0);
165 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
166
167 ds_seat_set_focus(seat, w1);
168 PCUT_ASSERT_EQUALS(w1, seat->focus);
169
170 event.type = KEY_PRESS;
171 event.mods = KM_ALT;
172 event.key = KC_TAB;
173 rc = ds_seat_post_kbd_event(seat, &event);
174 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
175 PCUT_ASSERT_EQUALS(w0, seat->focus);
176
177 ds_window_destroy(w0);
178 ds_window_destroy(w1);
179 ds_seat_destroy(seat);
180 ds_client_destroy(client);
181 ds_display_destroy(disp);
182}
183
184/** Test ds_seat_post_kbd_event() with regular key press delivers to client queue */
185PCUT_TEST(post_kbd_event_regular)
186{
187 ds_display_t *disp;
188 ds_client_t *client;
189 ds_seat_t *seat;
190 ds_window_t *wnd;
191 display_wnd_params_t params;
192 kbd_event_t event;
193 ds_window_t *rwindow;
194 display_wnd_ev_t revent;
195 bool called_cb = NULL;
196 errno_t rc;
197
198 rc = ds_display_create(NULL, &disp);
199 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
200
201 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
202 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
203
204 rc = ds_seat_create(disp, &seat);
205 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
206
207 display_wnd_params_init(&params);
208 params.rect.p0.x = params.rect.p0.y = 0;
209 params.rect.p1.x = params.rect.p1.y = 1;
210
211 rc = ds_window_create(client, &params, &wnd);
212 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
213
214 ds_seat_set_focus(seat, wnd);
215 PCUT_ASSERT_EQUALS(wnd, seat->focus);
216
217 event.type = KEY_PRESS;
218 event.key = KC_ENTER;
219 event.mods = 0;
220 event.c = L'\0';
221
222 PCUT_ASSERT_FALSE(called_cb);
223
224 rc = ds_client_get_event(client, &rwindow, &revent);
225 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
226
227 rc = ds_seat_post_kbd_event(seat, &event);
228 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
229 PCUT_ASSERT_TRUE(called_cb);
230
231 rc = ds_client_get_event(client, &rwindow, &revent);
232 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
233 PCUT_ASSERT_EQUALS(wnd, rwindow);
234 PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
235 PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
236 PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
237 PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
238 PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
239
240 rc = ds_client_get_event(client, &rwindow, &revent);
241 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
242
243 ds_window_destroy(wnd);
244 ds_client_destroy(client);
245 ds_display_destroy(disp);
246}
247
248/** Test ds_seat_post_ptd_event() with click on window switches focus
249 */
250PCUT_TEST(post_ptd_event_wnd_switch)
251{
252 ds_display_t *disp;
253 ds_seat_t *seat;
254 ds_client_t *client;
255 ds_window_t *w0, *w1;
256 display_wnd_params_t params;
257 ptd_event_t event;
258 bool called_cb = false;
259 errno_t rc;
260
261 rc = ds_display_create(NULL, &disp);
262 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
263
264 rc = ds_seat_create(disp, &seat);
265 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
266
267 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
268 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
269
270 display_wnd_params_init(&params);
271 params.rect.p0.x = params.rect.p0.y = 0;
272 params.rect.p1.x = params.rect.p1.y = 1;
273
274 rc = ds_window_create(client, &params, &w0);
275 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
276
277 rc = ds_window_create(client, &params, &w1);
278 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
279
280 w0->dpos.x = 10;
281 w0->dpos.y = 10;
282
283 w1->dpos.x = 400;
284 w1->dpos.y = 400;
285
286 PCUT_ASSERT_FALSE(called_cb);
287
288 ds_seat_set_focus(seat, w0);
289
290 event.type = PTD_MOVE;
291 event.dmove.x = 400;
292 event.dmove.y = 400;
293 rc = ds_seat_post_ptd_event(seat, &event);
294 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
295 PCUT_ASSERT_FALSE(called_cb);
296
297 event.type = PTD_PRESS;
298 event.btn_num = 1;
299 rc = ds_seat_post_ptd_event(seat, &event);
300 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
301 PCUT_ASSERT_FALSE(called_cb);
302
303 PCUT_ASSERT_EQUALS(w1, seat->focus);
304
305 event.type = PTD_MOVE;
306 event.dmove.x = -400 + 10;
307 event.dmove.y = -400 + 10;
308 rc = ds_seat_post_ptd_event(seat, &event);
309 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
310 PCUT_ASSERT_FALSE(called_cb);
311
312 event.type = PTD_PRESS;
313 event.btn_num = 1;
314 rc = ds_seat_post_ptd_event(seat, &event);
315 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
316 PCUT_ASSERT_FALSE(called_cb);
317
318 PCUT_ASSERT_EQUALS(w0, seat->focus);
319
320 ds_window_destroy(w0);
321 ds_window_destroy(w1);
322 ds_client_destroy(client);
323 ds_seat_destroy(seat);
324 ds_display_destroy(disp);
325}
326
327/** Test ds_seat_post_pos_event() */
328PCUT_TEST(post_pos_event)
329{
330 // XXX
331}
332
333PCUT_EXPORT(seat);
Note: See TracBrowser for help on using the repository browser.