source: mainline/uspace/srv/hid/display/test/seat.c@ 195b7b3

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

Clean up debug messages and logging

  • Property mode set to 100644
File size: 9.5 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 <str.h>
33
34#include "../client.h"
35#include "../display.h"
36#include "../seat.h"
37#include "../window.h"
38
39PCUT_INIT;
40
41PCUT_TEST_SUITE(seat);
42
43static void test_ds_ev_pending(void *);
44
45static ds_client_cb_t test_ds_client_cb = {
46 .ev_pending = test_ds_ev_pending
47};
48
49static void test_ds_ev_pending(void *arg)
50{
51 bool *called_cb = (bool *) arg;
52 *called_cb = true;
53}
54
55/** Set focus. */
56PCUT_TEST(set_focus)
57{
58 ds_display_t *disp;
59 ds_client_t *client;
60 ds_seat_t *seat;
61 ds_window_t *wnd;
62 display_wnd_params_t params;
63 bool called_cb = false;
64 errno_t rc;
65
66 rc = ds_display_create(NULL, df_none, &disp);
67 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
68
69 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
70 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
71
72 rc = ds_seat_create(disp, &seat);
73 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
74
75 display_wnd_params_init(&params);
76 params.rect.p0.x = params.rect.p0.y = 0;
77 params.rect.p1.x = params.rect.p1.y = 1;
78
79 rc = ds_window_create(client, &params, &wnd);
80 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
81
82 ds_seat_set_focus(seat, wnd);
83 PCUT_ASSERT_EQUALS(wnd, seat->focus);
84 PCUT_ASSERT_TRUE(called_cb);
85
86 ds_window_destroy(wnd);
87 ds_seat_destroy(seat);
88 ds_client_destroy(client);
89 ds_display_destroy(disp);
90}
91
92/** Evacuate focus. */
93PCUT_TEST(evac_focus)
94{
95 ds_display_t *disp;
96 ds_client_t *client;
97 ds_seat_t *seat;
98 ds_window_t *w0;
99 ds_window_t *w1;
100 display_wnd_params_t params;
101 bool called_cb = false;
102 errno_t rc;
103
104 rc = ds_display_create(NULL, df_none, &disp);
105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
106
107 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &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 PCUT_ASSERT_TRUE(called_cb);
126 called_cb = false;
127
128 ds_seat_evac_focus(seat, w1);
129 PCUT_ASSERT_EQUALS(w0, seat->focus);
130 PCUT_ASSERT_TRUE(called_cb);
131
132 ds_window_destroy(w0);
133 ds_window_destroy(w1);
134 ds_seat_destroy(seat);
135 ds_client_destroy(client);
136 ds_display_destroy(disp);
137}
138
139/** Test ds_seat_post_kbd_event() with Alt-Tab switches focus */
140PCUT_TEST(post_kbd_event_alt_tab)
141{
142 ds_display_t *disp;
143 ds_client_t *client;
144 ds_seat_t *seat;
145 ds_window_t *w0;
146 ds_window_t *w1;
147 display_wnd_params_t params;
148 bool called_cb = false;
149 kbd_event_t event;
150 errno_t rc;
151
152 rc = ds_display_create(NULL, df_none, &disp);
153 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
154
155 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
156 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
157
158 rc = ds_seat_create(disp, &seat);
159 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
160
161 display_wnd_params_init(&params);
162 params.rect.p0.x = params.rect.p0.y = 0;
163 params.rect.p1.x = params.rect.p1.y = 1;
164
165 rc = ds_window_create(client, &params, &w1);
166 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
167
168 rc = ds_window_create(client, &params, &w0);
169 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
170
171 ds_seat_set_focus(seat, w1);
172 PCUT_ASSERT_EQUALS(w1, seat->focus);
173 PCUT_ASSERT_TRUE(called_cb);
174 called_cb = false;
175
176 event.type = KEY_PRESS;
177 event.mods = KM_ALT;
178 event.key = KC_TAB;
179 rc = ds_seat_post_kbd_event(seat, &event);
180 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
181 PCUT_ASSERT_EQUALS(w0, seat->focus);
182 PCUT_ASSERT_TRUE(called_cb);
183
184 ds_window_destroy(w0);
185 ds_window_destroy(w1);
186 ds_seat_destroy(seat);
187 ds_client_destroy(client);
188 ds_display_destroy(disp);
189}
190
191/** Test ds_seat_post_kbd_event() with regular key press delivers to client queue */
192PCUT_TEST(post_kbd_event_regular)
193{
194 ds_display_t *disp;
195 ds_client_t *client;
196 ds_seat_t *seat;
197 ds_window_t *wnd;
198 display_wnd_params_t params;
199 kbd_event_t event;
200 ds_window_t *rwindow;
201 display_wnd_ev_t revent;
202 bool called_cb = false;
203 errno_t rc;
204
205 rc = ds_display_create(NULL, df_none, &disp);
206 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
207
208 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
209 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
210
211 rc = ds_seat_create(disp, &seat);
212 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
213
214 display_wnd_params_init(&params);
215 params.rect.p0.x = params.rect.p0.y = 0;
216 params.rect.p1.x = params.rect.p1.y = 1;
217
218 rc = ds_window_create(client, &params, &wnd);
219 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
220
221 ds_seat_set_focus(seat, wnd);
222 PCUT_ASSERT_EQUALS(wnd, seat->focus);
223
224 PCUT_ASSERT_TRUE(called_cb);
225 rc = ds_client_get_event(client, &rwindow, &revent);
226 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
227 called_cb = false;
228
229 event.type = KEY_PRESS;
230 event.key = KC_ENTER;
231 event.mods = 0;
232 event.c = L'\0';
233
234 rc = ds_client_get_event(client, &rwindow, &revent);
235 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
236
237 rc = ds_seat_post_kbd_event(seat, &event);
238 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
239 PCUT_ASSERT_TRUE(called_cb);
240
241 rc = ds_client_get_event(client, &rwindow, &revent);
242 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
243 PCUT_ASSERT_EQUALS(wnd, rwindow);
244 PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
245 PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
246 PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
247 PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
248 PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
249
250 rc = ds_client_get_event(client, &rwindow, &revent);
251 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
252
253 ds_window_destroy(wnd);
254 ds_seat_destroy(seat);
255 ds_client_destroy(client);
256 ds_display_destroy(disp);
257}
258
259/** Test ds_seat_post_ptd_event() with click on window switches focus
260 */
261PCUT_TEST(post_ptd_event_wnd_switch)
262{
263 ds_display_t *disp;
264 ds_seat_t *seat;
265 ds_client_t *client;
266 ds_window_t *w0, *w1;
267 display_wnd_params_t params;
268 ptd_event_t event;
269 bool called_cb = false;
270 errno_t rc;
271
272 rc = ds_display_create(NULL, df_none, &disp);
273 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
274
275 rc = ds_seat_create(disp, &seat);
276 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
277
278 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
279 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
280
281 /* Set up display size to allow the pointer a range of movement */
282 disp->rect.p1.x = 500;
283 disp->rect.p1.y = 500;
284
285 display_wnd_params_init(&params);
286 params.rect.p0.x = params.rect.p0.y = 0;
287 params.rect.p1.x = params.rect.p1.y = 1;
288
289 rc = ds_window_create(client, &params, &w0);
290 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
291
292 rc = ds_window_create(client, &params, &w1);
293 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
294
295 w0->dpos.x = 10;
296 w0->dpos.y = 10;
297
298 w1->dpos.x = 400;
299 w1->dpos.y = 400;
300
301 PCUT_ASSERT_FALSE(called_cb);
302
303 ds_seat_set_focus(seat, w0);
304
305 event.type = PTD_MOVE;
306 event.dmove.x = 400;
307 event.dmove.y = 400;
308 rc = ds_seat_post_ptd_event(seat, &event);
309 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
310
311 PCUT_ASSERT_TRUE(called_cb);
312 called_cb = false;
313
314 event.type = PTD_PRESS;
315 event.btn_num = 1;
316 rc = ds_seat_post_ptd_event(seat, &event);
317 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
318 PCUT_ASSERT_TRUE(called_cb);
319 called_cb = false;
320
321 PCUT_ASSERT_EQUALS(w1, seat->focus);
322
323 event.type = PTD_MOVE;
324 event.dmove.x = -400 + 10;
325 event.dmove.y = -400 + 10;
326 rc = ds_seat_post_ptd_event(seat, &event);
327 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
328 PCUT_ASSERT_TRUE(called_cb);
329 called_cb = false;
330
331 event.type = PTD_PRESS;
332 event.btn_num = 1;
333 rc = ds_seat_post_ptd_event(seat, &event);
334 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
335 PCUT_ASSERT_TRUE(called_cb);
336 called_cb = false;
337
338 PCUT_ASSERT_EQUALS(w0, seat->focus);
339
340 ds_window_destroy(w0);
341 ds_window_destroy(w1);
342 ds_client_destroy(client);
343 ds_seat_destroy(seat);
344 ds_display_destroy(disp);
345}
346
347/** Test ds_seat_post_pos_event() */
348PCUT_TEST(post_pos_event)
349{
350 // XXX
351}
352
353/** Set WM cursor */
354PCUT_TEST(set_wm_cursor)
355{
356 ds_display_t *disp;
357 ds_client_t *client;
358 ds_seat_t *seat;
359 bool called_cb = false;
360 errno_t rc;
361
362 rc = ds_display_create(NULL, df_none, &disp);
363 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
364
365 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
366 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
367
368 rc = ds_seat_create(disp, &seat);
369 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
370
371 ds_seat_set_wm_cursor(seat, disp->cursor[dcurs_size_ud]);
372 ds_seat_set_wm_cursor(seat, NULL);
373
374 ds_seat_destroy(seat);
375 ds_client_destroy(client);
376 ds_display_destroy(disp);
377}
378
379PCUT_EXPORT(seat);
Note: See TracBrowser for help on using the repository browser.