1 | /*
|
---|
2 | * Copyright (c) 2023 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 "../cfgclient.h"
|
---|
35 | #include "../client.h"
|
---|
36 | #include "../display.h"
|
---|
37 | #include "../idevcfg.h"
|
---|
38 | #include "../seat.h"
|
---|
39 | #include "../window.h"
|
---|
40 | #include "../wmclient.h"
|
---|
41 |
|
---|
42 | PCUT_INIT;
|
---|
43 |
|
---|
44 | PCUT_TEST_SUITE(display);
|
---|
45 |
|
---|
46 | static void test_ds_ev_pending(void *);
|
---|
47 |
|
---|
48 | static ds_client_cb_t test_ds_client_cb = {
|
---|
49 | .ev_pending = test_ds_ev_pending
|
---|
50 | };
|
---|
51 |
|
---|
52 | static void test_ds_wmev_pending(void *);
|
---|
53 |
|
---|
54 | static ds_wmclient_cb_t test_ds_wmclient_cb = {
|
---|
55 | .ev_pending = test_ds_wmev_pending
|
---|
56 | };
|
---|
57 |
|
---|
58 | static void test_ds_cfgev_pending(void *);
|
---|
59 |
|
---|
60 | static ds_cfgclient_cb_t test_ds_cfgclient_cb = {
|
---|
61 | .ev_pending = test_ds_cfgev_pending
|
---|
62 | };
|
---|
63 |
|
---|
64 | static void test_ds_ev_pending(void *arg)
|
---|
65 | {
|
---|
66 | bool *called_cb = (bool *) arg;
|
---|
67 | *called_cb = true;
|
---|
68 | }
|
---|
69 |
|
---|
70 | static void test_ds_wmev_pending(void *arg)
|
---|
71 | {
|
---|
72 | bool *called_cb = (bool *) arg;
|
---|
73 | *called_cb = true;
|
---|
74 | }
|
---|
75 |
|
---|
76 | static void test_ds_cfgev_pending(void *arg)
|
---|
77 | {
|
---|
78 | bool *called_cb = (bool *) arg;
|
---|
79 | *called_cb = true;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /** Display creation and destruction. */
|
---|
83 | PCUT_TEST(display_create_destroy)
|
---|
84 | {
|
---|
85 | ds_display_t *disp;
|
---|
86 | errno_t rc;
|
---|
87 |
|
---|
88 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
89 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
90 |
|
---|
91 | ds_display_destroy(disp);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /** Basic client operation. */
|
---|
95 | PCUT_TEST(display_client)
|
---|
96 | {
|
---|
97 | ds_display_t *disp;
|
---|
98 | ds_client_t *client;
|
---|
99 | ds_client_t *c0, *c1;
|
---|
100 | errno_t rc;
|
---|
101 |
|
---|
102 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
103 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
104 |
|
---|
105 | rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
|
---|
106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
107 |
|
---|
108 | c0 = ds_display_first_client(disp);
|
---|
109 | PCUT_ASSERT_EQUALS(c0, client);
|
---|
110 |
|
---|
111 | c1 = ds_display_next_client(c0);
|
---|
112 | PCUT_ASSERT_NULL(c1);
|
---|
113 |
|
---|
114 | ds_client_destroy(client);
|
---|
115 | ds_display_destroy(disp);
|
---|
116 | }
|
---|
117 |
|
---|
118 | /** Basic WM client operation. */
|
---|
119 | PCUT_TEST(display_wmclient)
|
---|
120 | {
|
---|
121 | ds_display_t *disp;
|
---|
122 | ds_wmclient_t *wmclient;
|
---|
123 | ds_wmclient_t *c0, *c1;
|
---|
124 | errno_t rc;
|
---|
125 |
|
---|
126 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
127 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
128 |
|
---|
129 | rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, NULL, &wmclient);
|
---|
130 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
131 |
|
---|
132 | c0 = ds_display_first_wmclient(disp);
|
---|
133 | PCUT_ASSERT_EQUALS(c0, wmclient);
|
---|
134 |
|
---|
135 | c1 = ds_display_next_wmclient(c0);
|
---|
136 | PCUT_ASSERT_NULL(c1);
|
---|
137 |
|
---|
138 | ds_wmclient_destroy(wmclient);
|
---|
139 | ds_display_destroy(disp);
|
---|
140 | }
|
---|
141 |
|
---|
142 | /** Basic CFG client operation. */
|
---|
143 | PCUT_TEST(display_cfgclient)
|
---|
144 | {
|
---|
145 | ds_display_t *disp;
|
---|
146 | ds_cfgclient_t *cfgclient;
|
---|
147 | errno_t rc;
|
---|
148 |
|
---|
149 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
150 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
151 |
|
---|
152 | rc = ds_cfgclient_create(disp, &test_ds_cfgclient_cb, NULL, &cfgclient);
|
---|
153 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
154 |
|
---|
155 | ds_cfgclient_destroy(cfgclient);
|
---|
156 | ds_display_destroy(disp);
|
---|
157 | }
|
---|
158 |
|
---|
159 | /** Test ds_display_find_window(). */
|
---|
160 | PCUT_TEST(display_find_window)
|
---|
161 | {
|
---|
162 | ds_display_t *disp;
|
---|
163 | ds_client_t *client;
|
---|
164 | ds_seat_t *seat;
|
---|
165 | ds_window_t *w0;
|
---|
166 | ds_window_t *w1;
|
---|
167 | ds_window_t *wnd;
|
---|
168 | display_wnd_params_t params;
|
---|
169 | bool called_cb = false;
|
---|
170 | errno_t rc;
|
---|
171 |
|
---|
172 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
173 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
174 |
|
---|
175 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
176 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
177 |
|
---|
178 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
179 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
180 |
|
---|
181 | display_wnd_params_init(¶ms);
|
---|
182 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
183 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
184 |
|
---|
185 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
186 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
187 |
|
---|
188 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
189 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
190 |
|
---|
191 | wnd = ds_display_first_window(disp);
|
---|
192 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
193 |
|
---|
194 | wnd = ds_display_next_window(wnd);
|
---|
195 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
196 |
|
---|
197 | wnd = ds_display_next_window(wnd);
|
---|
198 | PCUT_ASSERT_NULL(wnd);
|
---|
199 |
|
---|
200 | wnd = ds_display_last_window(disp);
|
---|
201 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
202 |
|
---|
203 | wnd = ds_display_prev_window(wnd);
|
---|
204 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
205 |
|
---|
206 | wnd = ds_display_prev_window(wnd);
|
---|
207 | PCUT_ASSERT_NULL(wnd);
|
---|
208 |
|
---|
209 | wnd = ds_display_find_window(disp, w0->id);
|
---|
210 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
211 |
|
---|
212 | wnd = ds_display_find_window(disp, w1->id);
|
---|
213 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
214 |
|
---|
215 | wnd = ds_display_find_window(disp, 0);
|
---|
216 | PCUT_ASSERT_NULL(wnd);
|
---|
217 |
|
---|
218 | wnd = ds_display_find_window(disp, w0->id + 1);
|
---|
219 | PCUT_ASSERT_NULL(wnd);
|
---|
220 |
|
---|
221 | ds_window_destroy(w0);
|
---|
222 | ds_window_destroy(w1);
|
---|
223 | ds_seat_destroy(seat);
|
---|
224 | ds_client_destroy(client);
|
---|
225 | ds_display_destroy(disp);
|
---|
226 | }
|
---|
227 |
|
---|
228 | /** Test ds_display_enlist_window() */
|
---|
229 | PCUT_TEST(display_enlist_window)
|
---|
230 | {
|
---|
231 | ds_display_t *disp;
|
---|
232 | ds_client_t *client;
|
---|
233 | ds_seat_t *seat;
|
---|
234 | ds_window_t *w0;
|
---|
235 | ds_window_t *w1;
|
---|
236 | ds_window_t *w2;
|
---|
237 | ds_window_t *w3;
|
---|
238 | ds_window_t *w;
|
---|
239 | display_wnd_params_t params;
|
---|
240 | bool called_cb = false;
|
---|
241 | errno_t rc;
|
---|
242 |
|
---|
243 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
244 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
245 |
|
---|
246 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
247 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
248 |
|
---|
249 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
250 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
251 |
|
---|
252 | display_wnd_params_init(¶ms);
|
---|
253 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
254 | params.rect.p1.x = params.rect.p1.y = 100;
|
---|
255 |
|
---|
256 | /* Regular windows */
|
---|
257 |
|
---|
258 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
259 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
260 |
|
---|
261 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
262 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
263 |
|
---|
264 | /* Topmost windows */
|
---|
265 |
|
---|
266 | params.flags |= wndf_topmost;
|
---|
267 |
|
---|
268 | rc = ds_window_create(client, ¶ms, &w2);
|
---|
269 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
270 |
|
---|
271 | rc = ds_window_create(client, ¶ms, &w3);
|
---|
272 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
273 |
|
---|
274 | /* Delist w1 and w2 */
|
---|
275 | list_remove(&w1->ldwindows);
|
---|
276 | list_remove(&w2->ldwindows);
|
---|
277 |
|
---|
278 | /* Enlist the windows back and check their order */
|
---|
279 | ds_display_enlist_window(disp, w1);
|
---|
280 | ds_display_enlist_window(disp, w2);
|
---|
281 |
|
---|
282 | w = ds_display_first_window(disp);
|
---|
283 | PCUT_ASSERT_EQUALS(w2, w);
|
---|
284 | w = ds_display_next_window(w);
|
---|
285 | PCUT_ASSERT_EQUALS(w3, w);
|
---|
286 | w = ds_display_next_window(w);
|
---|
287 | PCUT_ASSERT_EQUALS(w1, w);
|
---|
288 | w = ds_display_next_window(w);
|
---|
289 | PCUT_ASSERT_EQUALS(w0, w);
|
---|
290 | w = ds_display_next_window(w);
|
---|
291 | PCUT_ASSERT_EQUALS(NULL, w);
|
---|
292 |
|
---|
293 | ds_window_destroy(w0);
|
---|
294 | ds_window_destroy(w1);
|
---|
295 | ds_window_destroy(w2);
|
---|
296 | ds_window_destroy(w3);
|
---|
297 | ds_seat_destroy(seat);
|
---|
298 | ds_client_destroy(client);
|
---|
299 | ds_display_destroy(disp);
|
---|
300 | }
|
---|
301 |
|
---|
302 | /** Test ds_display_window_to_top() */
|
---|
303 | PCUT_TEST(display_window_to_top)
|
---|
304 | {
|
---|
305 | ds_display_t *disp;
|
---|
306 | ds_client_t *client;
|
---|
307 | ds_seat_t *seat;
|
---|
308 | ds_window_t *w0;
|
---|
309 | ds_window_t *w1;
|
---|
310 | display_wnd_params_t params;
|
---|
311 | bool called_cb = false;
|
---|
312 | errno_t rc;
|
---|
313 |
|
---|
314 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
315 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
316 |
|
---|
317 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
318 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
319 |
|
---|
320 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
321 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
322 |
|
---|
323 | display_wnd_params_init(¶ms);
|
---|
324 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
325 | params.rect.p1.x = params.rect.p1.y = 100;
|
---|
326 |
|
---|
327 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
328 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
329 |
|
---|
330 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
331 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
332 |
|
---|
333 | PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
|
---|
334 | ds_display_window_to_top(w0);
|
---|
335 | PCUT_ASSERT_EQUALS(w0, ds_display_first_window(disp));
|
---|
336 |
|
---|
337 | ds_window_destroy(w0);
|
---|
338 | ds_window_destroy(w1);
|
---|
339 | ds_seat_destroy(seat);
|
---|
340 | ds_client_destroy(client);
|
---|
341 | ds_display_destroy(disp);
|
---|
342 | }
|
---|
343 |
|
---|
344 | /** Test ds_display_window_by_pos(). */
|
---|
345 | PCUT_TEST(display_window_by_pos)
|
---|
346 | {
|
---|
347 | ds_display_t *disp;
|
---|
348 | ds_client_t *client;
|
---|
349 | ds_seat_t *seat;
|
---|
350 | ds_window_t *w0;
|
---|
351 | ds_window_t *w1;
|
---|
352 | ds_window_t *wnd;
|
---|
353 | display_wnd_params_t params;
|
---|
354 | gfx_coord2_t pos;
|
---|
355 | bool called_cb = false;
|
---|
356 | errno_t rc;
|
---|
357 |
|
---|
358 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
359 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
360 |
|
---|
361 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
362 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
363 |
|
---|
364 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
365 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
366 |
|
---|
367 | display_wnd_params_init(¶ms);
|
---|
368 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
369 | params.rect.p1.x = params.rect.p1.y = 100;
|
---|
370 |
|
---|
371 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
372 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
373 |
|
---|
374 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
375 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
376 |
|
---|
377 | w0->dpos.x = 10;
|
---|
378 | w0->dpos.y = 10;
|
---|
379 |
|
---|
380 | w1->dpos.x = 400;
|
---|
381 | w1->dpos.y = 400;
|
---|
382 |
|
---|
383 | pos.x = 10;
|
---|
384 | pos.y = 10;
|
---|
385 | wnd = ds_display_window_by_pos(disp, &pos);
|
---|
386 | PCUT_ASSERT_EQUALS(w0, wnd);
|
---|
387 |
|
---|
388 | pos.x = 400;
|
---|
389 | pos.y = 400;
|
---|
390 | wnd = ds_display_window_by_pos(disp, &pos);
|
---|
391 | PCUT_ASSERT_EQUALS(w1, wnd);
|
---|
392 |
|
---|
393 | ds_window_destroy(w0);
|
---|
394 | ds_window_destroy(w1);
|
---|
395 | ds_seat_destroy(seat);
|
---|
396 | ds_client_destroy(client);
|
---|
397 | ds_display_destroy(disp);
|
---|
398 | }
|
---|
399 |
|
---|
400 | /** Basic idevcfg operation */
|
---|
401 | PCUT_TEST(display_idevcfg)
|
---|
402 | {
|
---|
403 | ds_display_t *disp;
|
---|
404 | ds_seat_t *seat;
|
---|
405 | ds_idevcfg_t *idevcfg;
|
---|
406 | errno_t rc;
|
---|
407 |
|
---|
408 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
409 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
410 |
|
---|
411 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
412 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
413 |
|
---|
414 | rc = ds_idevcfg_create(disp, 42, seat, &idevcfg);
|
---|
415 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
416 |
|
---|
417 | ds_idevcfg_destroy(idevcfg);
|
---|
418 |
|
---|
419 | ds_seat_destroy(seat);
|
---|
420 | ds_display_destroy(disp);
|
---|
421 | }
|
---|
422 |
|
---|
423 | /** Basic seat operation. */
|
---|
424 | PCUT_TEST(display_seat)
|
---|
425 | {
|
---|
426 | ds_display_t *disp;
|
---|
427 | ds_seat_t *seat;
|
---|
428 | ds_seat_t *s0, *s1, *s2;
|
---|
429 | errno_t rc;
|
---|
430 |
|
---|
431 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
432 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
433 |
|
---|
434 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
435 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
436 |
|
---|
437 | s0 = ds_display_first_seat(disp);
|
---|
438 | PCUT_ASSERT_EQUALS(s0, seat);
|
---|
439 |
|
---|
440 | s1 = ds_display_next_seat(s0);
|
---|
441 | PCUT_ASSERT_NULL(s1);
|
---|
442 |
|
---|
443 | s2 = ds_display_find_seat(disp, seat->id);
|
---|
444 | PCUT_ASSERT_EQUALS(s2, seat);
|
---|
445 |
|
---|
446 | ds_seat_destroy(seat);
|
---|
447 | ds_display_destroy(disp);
|
---|
448 | }
|
---|
449 |
|
---|
450 | /** ds_display_seat_by_idev() returns the correct seat. */
|
---|
451 | PCUT_TEST(display_seat_by_idev)
|
---|
452 | {
|
---|
453 | // XXX TODO
|
---|
454 | }
|
---|
455 |
|
---|
456 | /** Test ds_display_post_kbd_event() delivers event to client callback.
|
---|
457 | */
|
---|
458 | PCUT_TEST(display_post_kbd_event)
|
---|
459 | {
|
---|
460 | ds_display_t *disp;
|
---|
461 | ds_seat_t *seat;
|
---|
462 | ds_client_t *client;
|
---|
463 | ds_window_t *wnd;
|
---|
464 | display_wnd_params_t params;
|
---|
465 | kbd_event_t event;
|
---|
466 | bool called_cb = false;
|
---|
467 | errno_t rc;
|
---|
468 |
|
---|
469 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
470 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
471 |
|
---|
472 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
473 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
474 |
|
---|
475 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
476 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
477 |
|
---|
478 | display_wnd_params_init(¶ms);
|
---|
479 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
480 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
481 |
|
---|
482 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
483 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
484 |
|
---|
485 | ds_seat_set_focus(seat, wnd);
|
---|
486 |
|
---|
487 | event.type = KEY_PRESS;
|
---|
488 | event.key = KC_ENTER;
|
---|
489 | event.mods = 0;
|
---|
490 | event.c = L'\0';
|
---|
491 |
|
---|
492 | called_cb = false;
|
---|
493 |
|
---|
494 | rc = ds_display_post_kbd_event(disp, &event);
|
---|
495 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
496 | PCUT_ASSERT_TRUE(called_cb);
|
---|
497 |
|
---|
498 | ds_window_destroy(wnd);
|
---|
499 | ds_client_destroy(client);
|
---|
500 | ds_seat_destroy(seat);
|
---|
501 | ds_display_destroy(disp);
|
---|
502 | }
|
---|
503 |
|
---|
504 | /** Test ds_display_post_kbd_event() with Alt-Tab switches focus.
|
---|
505 | */
|
---|
506 | PCUT_TEST(display_post_kbd_event_alt_tab)
|
---|
507 | {
|
---|
508 | ds_display_t *disp;
|
---|
509 | ds_seat_t *seat;
|
---|
510 | ds_client_t *client;
|
---|
511 | ds_window_t *w0, *w1;
|
---|
512 | display_wnd_params_t params;
|
---|
513 | kbd_event_t event;
|
---|
514 | bool called_cb = false;
|
---|
515 | errno_t rc;
|
---|
516 |
|
---|
517 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
518 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
519 |
|
---|
520 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
521 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
522 |
|
---|
523 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
524 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
525 |
|
---|
526 | display_wnd_params_init(¶ms);
|
---|
527 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
528 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
529 |
|
---|
530 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
531 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
532 |
|
---|
533 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
534 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
535 |
|
---|
536 | ds_seat_set_focus(seat, w0);
|
---|
537 |
|
---|
538 | event.type = KEY_PRESS;
|
---|
539 | event.key = KC_TAB;
|
---|
540 | event.mods = KM_ALT;
|
---|
541 | event.c = L'\0';
|
---|
542 |
|
---|
543 | called_cb = false;
|
---|
544 |
|
---|
545 | rc = ds_display_post_kbd_event(disp, &event);
|
---|
546 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
547 |
|
---|
548 | /* Got gocus/unfocus events */
|
---|
549 | PCUT_ASSERT_TRUE(called_cb);
|
---|
550 |
|
---|
551 | /* Next window should be focused */
|
---|
552 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
---|
553 |
|
---|
554 | called_cb = false;
|
---|
555 |
|
---|
556 | rc = ds_display_post_kbd_event(disp, &event);
|
---|
557 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
558 |
|
---|
559 | /* Got gocus/unfocus events */
|
---|
560 | PCUT_ASSERT_TRUE(called_cb);
|
---|
561 |
|
---|
562 | /* Focus should be back to the first window */
|
---|
563 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
---|
564 |
|
---|
565 | ds_window_destroy(w0);
|
---|
566 | ds_window_destroy(w1);
|
---|
567 | ds_client_destroy(client);
|
---|
568 | ds_seat_destroy(seat);
|
---|
569 | ds_display_destroy(disp);
|
---|
570 | }
|
---|
571 |
|
---|
572 | /** Test ds_display_post_ptd_event() with click on window switches focus
|
---|
573 | */
|
---|
574 | PCUT_TEST(display_post_ptd_event_wnd_switch)
|
---|
575 | {
|
---|
576 | ds_display_t *disp;
|
---|
577 | ds_seat_t *seat;
|
---|
578 | ds_client_t *client;
|
---|
579 | ds_window_t *w0, *w1;
|
---|
580 | display_wnd_params_t params;
|
---|
581 | ptd_event_t event;
|
---|
582 | bool called_cb = false;
|
---|
583 | errno_t rc;
|
---|
584 |
|
---|
585 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
586 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
587 |
|
---|
588 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
589 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
590 |
|
---|
591 | rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
|
---|
592 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
593 |
|
---|
594 | /*
|
---|
595 | * For PTD_MOVE to work we need to set display dimensions (as pointer
|
---|
596 | * move is clipped to the display rectangle. Here we do it directly
|
---|
597 | * instead of adding a display device.
|
---|
598 | */
|
---|
599 | disp->rect.p0.x = 0;
|
---|
600 | disp->rect.p0.y = 0;
|
---|
601 | disp->rect.p1.x = 500;
|
---|
602 | disp->rect.p1.y = 500;
|
---|
603 |
|
---|
604 | display_wnd_params_init(¶ms);
|
---|
605 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
606 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
607 |
|
---|
608 | rc = ds_window_create(client, ¶ms, &w0);
|
---|
609 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
610 |
|
---|
611 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
612 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
613 |
|
---|
614 | w0->dpos.x = 10;
|
---|
615 | w0->dpos.y = 10;
|
---|
616 |
|
---|
617 | w1->dpos.x = 400;
|
---|
618 | w1->dpos.y = 400;
|
---|
619 |
|
---|
620 | ds_seat_set_focus(seat, w0);
|
---|
621 |
|
---|
622 | event.type = PTD_MOVE;
|
---|
623 | event.dmove.x = 400;
|
---|
624 | event.dmove.y = 400;
|
---|
625 | rc = ds_display_post_ptd_event(disp, &event);
|
---|
626 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
627 |
|
---|
628 | event.type = PTD_PRESS;
|
---|
629 | event.btn_num = 1;
|
---|
630 | rc = ds_display_post_ptd_event(disp, &event);
|
---|
631 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
632 |
|
---|
633 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
---|
634 |
|
---|
635 | event.type = PTD_RELEASE;
|
---|
636 | event.btn_num = 1;
|
---|
637 | rc = ds_display_post_ptd_event(disp, &event);
|
---|
638 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
639 |
|
---|
640 | event.type = PTD_MOVE;
|
---|
641 | event.dmove.x = -400 + 10;
|
---|
642 | event.dmove.y = -400 + 10;
|
---|
643 | rc = ds_display_post_ptd_event(disp, &event);
|
---|
644 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
645 |
|
---|
646 | event.type = PTD_PRESS;
|
---|
647 | event.btn_num = 1;
|
---|
648 | rc = ds_display_post_ptd_event(disp, &event);
|
---|
649 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
650 |
|
---|
651 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
---|
652 |
|
---|
653 | ds_window_destroy(w0);
|
---|
654 | ds_window_destroy(w1);
|
---|
655 | ds_client_destroy(client);
|
---|
656 | ds_seat_destroy(seat);
|
---|
657 | ds_display_destroy(disp);
|
---|
658 | }
|
---|
659 |
|
---|
660 | /** ds_display_update_max_rect() updates maximization rectangle */
|
---|
661 | PCUT_TEST(display_update_max_rect)
|
---|
662 | {
|
---|
663 | ds_display_t *disp;
|
---|
664 | ds_seat_t *seat;
|
---|
665 | ds_client_t *client;
|
---|
666 | ds_window_t *wnd;
|
---|
667 | display_wnd_params_t params;
|
---|
668 | errno_t rc;
|
---|
669 |
|
---|
670 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
671 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
672 |
|
---|
673 | rc = ds_seat_create(disp, "Alice", &seat);
|
---|
674 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
675 |
|
---|
676 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
677 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
678 |
|
---|
679 | /*
|
---|
680 | * We need to set display dimensions Here we do it directly
|
---|
681 | * instead of adding a display device.
|
---|
682 | */
|
---|
683 | disp->rect.p0.x = 0;
|
---|
684 | disp->rect.p0.y = 0;
|
---|
685 | disp->rect.p1.x = 500;
|
---|
686 | disp->rect.p1.y = 500;
|
---|
687 |
|
---|
688 | /* Set maximize rectangle as well */
|
---|
689 | disp->max_rect = disp->rect;
|
---|
690 |
|
---|
691 | /* A panel-like window at the bottom */
|
---|
692 | display_wnd_params_init(¶ms);
|
---|
693 | params.flags |= wndf_setpos;
|
---|
694 | params.pos.x = 0;
|
---|
695 | params.pos.y = 450;
|
---|
696 | params.rect.p0.x = 0;
|
---|
697 | params.rect.p0.y = 0;
|
---|
698 | params.rect.p1.x = 500;
|
---|
699 | params.rect.p1.y = 50;
|
---|
700 |
|
---|
701 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
702 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
703 |
|
---|
704 | /*
|
---|
705 | * At this point the maximize rect should be unaltered because
|
---|
706 | * the avoid flag has not been set.
|
---|
707 | */
|
---|
708 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
|
---|
709 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
|
---|
710 | PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
|
---|
711 | PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.y);
|
---|
712 |
|
---|
713 | wnd->flags |= wndf_avoid;
|
---|
714 |
|
---|
715 | /* Update maximize rectangle */
|
---|
716 | ds_display_update_max_rect(disp);
|
---|
717 |
|
---|
718 | /* Verify maximize rectangle */
|
---|
719 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
|
---|
720 | PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
|
---|
721 | PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
|
---|
722 | PCUT_ASSERT_INT_EQUALS(450, disp->max_rect.p1.y);
|
---|
723 |
|
---|
724 | ds_window_destroy(wnd);
|
---|
725 | ds_client_destroy(client);
|
---|
726 | ds_seat_destroy(seat);
|
---|
727 | ds_display_destroy(disp);
|
---|
728 | }
|
---|
729 |
|
---|
730 | /** Cropping maximization rectangle from the top */
|
---|
731 | PCUT_TEST(display_crop_max_rect_top)
|
---|
732 | {
|
---|
733 | gfx_rect_t arect;
|
---|
734 | gfx_rect_t mrect;
|
---|
735 |
|
---|
736 | arect.p0.x = 10;
|
---|
737 | arect.p0.y = 20;
|
---|
738 | arect.p1.x = 30;
|
---|
739 | arect.p1.y = 5;
|
---|
740 |
|
---|
741 | mrect.p0.x = 10;
|
---|
742 | mrect.p0.y = 20;
|
---|
743 | mrect.p1.x = 30;
|
---|
744 | mrect.p1.y = 40;
|
---|
745 |
|
---|
746 | ds_display_crop_max_rect(&arect, &mrect);
|
---|
747 |
|
---|
748 | PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
|
---|
749 | PCUT_ASSERT_INT_EQUALS(5, mrect.p0.y);
|
---|
750 | PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
|
---|
751 | PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
|
---|
752 | }
|
---|
753 |
|
---|
754 | /** Cropping maximization rectangle from the bottom */
|
---|
755 | PCUT_TEST(display_crop_max_rect_bottom)
|
---|
756 | {
|
---|
757 | gfx_rect_t arect;
|
---|
758 | gfx_rect_t mrect;
|
---|
759 |
|
---|
760 | arect.p0.x = 10;
|
---|
761 | arect.p0.y = 35;
|
---|
762 | arect.p1.x = 30;
|
---|
763 | arect.p1.y = 40;
|
---|
764 |
|
---|
765 | mrect.p0.x = 10;
|
---|
766 | mrect.p0.y = 20;
|
---|
767 | mrect.p1.x = 30;
|
---|
768 | mrect.p1.y = 40;
|
---|
769 |
|
---|
770 | ds_display_crop_max_rect(&arect, &mrect);
|
---|
771 |
|
---|
772 | PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
|
---|
773 | PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
|
---|
774 | PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
|
---|
775 | PCUT_ASSERT_INT_EQUALS(35, mrect.p1.y);
|
---|
776 | }
|
---|
777 |
|
---|
778 | /** Cropping maximization rectangle from the left */
|
---|
779 | PCUT_TEST(display_crop_max_rect_left)
|
---|
780 | {
|
---|
781 | gfx_rect_t arect;
|
---|
782 | gfx_rect_t mrect;
|
---|
783 |
|
---|
784 | arect.p0.x = 10;
|
---|
785 | arect.p0.y = 20;
|
---|
786 | arect.p1.x = 15;
|
---|
787 | arect.p1.y = 40;
|
---|
788 |
|
---|
789 | mrect.p0.x = 10;
|
---|
790 | mrect.p0.y = 20;
|
---|
791 | mrect.p1.x = 30;
|
---|
792 | mrect.p1.y = 40;
|
---|
793 |
|
---|
794 | ds_display_crop_max_rect(&arect, &mrect);
|
---|
795 |
|
---|
796 | PCUT_ASSERT_INT_EQUALS(15, mrect.p0.x);
|
---|
797 | PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
|
---|
798 | PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
|
---|
799 | PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
|
---|
800 | }
|
---|
801 |
|
---|
802 | /** Cropping maximization rectangle from the right */
|
---|
803 | PCUT_TEST(display_crop_max_rect_right)
|
---|
804 | {
|
---|
805 | gfx_rect_t arect;
|
---|
806 | gfx_rect_t mrect;
|
---|
807 |
|
---|
808 | arect.p0.x = 25;
|
---|
809 | arect.p0.y = 20;
|
---|
810 | arect.p1.x = 30;
|
---|
811 | arect.p1.y = 40;
|
---|
812 |
|
---|
813 | mrect.p0.x = 10;
|
---|
814 | mrect.p0.y = 20;
|
---|
815 | mrect.p1.x = 30;
|
---|
816 | mrect.p1.y = 40;
|
---|
817 |
|
---|
818 | ds_display_crop_max_rect(&arect, &mrect);
|
---|
819 |
|
---|
820 | PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
|
---|
821 | PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
|
---|
822 | PCUT_ASSERT_INT_EQUALS(25, mrect.p1.x);
|
---|
823 | PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
|
---|
824 | }
|
---|
825 |
|
---|
826 | PCUT_EXPORT(display);
|
---|