source: mainline/uspace/srv/hid/display/test/window.c@ 3be5366

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

Add pos_id information to move request, too

This will become useful momentarily.

  • Property mode set to 100644
File size: 32.6 KB
Line 
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 <gfx/context.h>
32#include <pcut/pcut.h>
33#include <stdio.h>
34#include <str.h>
35
36#include "../client.h"
37#include "../display.h"
38#include "../seat.h"
39#include "../window.h"
40
41PCUT_INIT;
42
43PCUT_TEST_SUITE(window);
44
45static errno_t dummy_set_color(void *, gfx_color_t *);
46static errno_t dummy_fill_rect(void *, gfx_rect_t *);
47
48static gfx_context_ops_t dummy_ops = {
49 .set_color = dummy_set_color,
50 .fill_rect = dummy_fill_rect
51};
52
53/** Test creating and destroying window */
54PCUT_TEST(create_destroy)
55{
56 ds_display_t *disp;
57 ds_client_t *client;
58 ds_seat_t *seat;
59 ds_window_t *wnd;
60 display_wnd_params_t params;
61 errno_t rc;
62
63 rc = ds_display_create(NULL, df_none, &disp);
64 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
65
66 rc = ds_client_create(disp, NULL, NULL, &client);
67 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
68
69 rc = ds_seat_create(disp, "Alice", &seat);
70 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
71
72 display_wnd_params_init(&params);
73 params.rect.p0.x = params.rect.p0.y = 0;
74 params.rect.p1.x = params.rect.p1.y = 10;
75
76 rc = ds_window_create(client, &params, &wnd);
77 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
78
79 ds_window_destroy(wnd);
80 ds_seat_destroy(seat);
81 ds_client_destroy(client);
82 ds_display_destroy(disp);
83}
84
85/** Test ds_window_bring_to_top() brings window to top */
86PCUT_TEST(bring_to_top)
87{
88 ds_display_t *disp;
89 ds_client_t *client;
90 ds_seat_t *seat;
91 ds_window_t *w1;
92 ds_window_t *w2;
93 display_wnd_params_t params;
94 errno_t rc;
95
96 rc = ds_display_create(NULL, df_none, &disp);
97 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
98
99 rc = ds_client_create(disp, NULL, NULL, &client);
100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
101
102 rc = ds_seat_create(disp, "Alice", &seat);
103 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
104
105 display_wnd_params_init(&params);
106 params.rect.p0.x = params.rect.p0.y = 0;
107 params.rect.p1.x = params.rect.p1.y = 10;
108
109 rc = ds_window_create(client, &params, &w1);
110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
111
112 rc = ds_window_create(client, &params, &w2);
113 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
114
115 /* w2 should be on the top */
116 PCUT_ASSERT_EQUALS(w2, ds_display_first_window(disp));
117
118 /* Bring w1 to top */
119 ds_window_bring_to_top(w1);
120
121 /* Now w1 should be on the top */
122 PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
123
124 ds_window_destroy(w1);
125 ds_window_destroy(w2);
126 ds_seat_destroy(seat);
127 ds_client_destroy(client);
128 ds_display_destroy(disp);
129}
130
131/** Test ds_window_resize(). */
132PCUT_TEST(window_resize)
133{
134 ds_display_t *disp;
135 ds_client_t *client;
136 ds_seat_t *seat;
137 ds_window_t *wnd;
138 display_wnd_params_t params;
139 gfx_coord2_t offs;
140 gfx_rect_t nrect;
141 errno_t rc;
142
143 rc = ds_display_create(NULL, df_none, &disp);
144 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
145
146 rc = ds_client_create(disp, NULL, NULL, &client);
147 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
148
149 rc = ds_seat_create(disp, "Alice", &seat);
150 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
151
152 display_wnd_params_init(&params);
153 params.rect.p0.x = params.rect.p0.y = 0;
154 params.rect.p1.x = params.rect.p1.y = 10;
155
156 rc = ds_window_create(client, &params, &wnd);
157 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
158
159 wnd->dpos.x = 100;
160 wnd->dpos.y = 100;
161
162 offs.x = -2;
163 offs.y = -3;
164 params.rect.p0.x = params.rect.p0.y = 0;
165 params.rect.p1.x = 12;
166 params.rect.p1.y = 13;
167 rc = ds_window_resize(wnd, &offs, &nrect);
168 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
169
170 PCUT_ASSERT_INT_EQUALS(98, wnd->dpos.x);
171 PCUT_ASSERT_INT_EQUALS(97, wnd->dpos.y);
172
173 ds_window_destroy(wnd);
174 ds_seat_destroy(seat);
175 ds_client_destroy(client);
176 ds_display_destroy(disp);
177}
178
179/** Test ds_window_get_pos(). */
180PCUT_TEST(get_pos)
181{
182 ds_display_t *disp;
183 ds_client_t *client;
184 ds_seat_t *seat;
185 ds_window_t *wnd;
186 display_wnd_params_t params;
187 gfx_coord2_t pos;
188 errno_t rc;
189
190 rc = ds_display_create(NULL, df_none, &disp);
191 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
192
193 rc = ds_client_create(disp, NULL, NULL, &client);
194 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
195
196 rc = ds_seat_create(disp, "Alice", &seat);
197 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
198
199 display_wnd_params_init(&params);
200 params.rect.p0.x = params.rect.p0.y = 0;
201 params.rect.p1.x = params.rect.p1.y = 10;
202
203 rc = ds_window_create(client, &params, &wnd);
204 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
205
206 wnd->dpos.x = 100;
207 wnd->dpos.y = 100;
208
209 ds_window_get_pos(wnd, &pos);
210
211 PCUT_ASSERT_INT_EQUALS(100, pos.x);
212 PCUT_ASSERT_INT_EQUALS(100, pos.y);
213
214 ds_window_destroy(wnd);
215 ds_seat_destroy(seat);
216 ds_client_destroy(client);
217 ds_display_destroy(disp);
218}
219
220/** Test ds_window_get_max_rect(). */
221PCUT_TEST(get_max_rect)
222{
223 ds_display_t *disp;
224 ds_client_t *client;
225 ds_seat_t *seat;
226 ds_window_t *wnd;
227 display_wnd_params_t params;
228 gfx_rect_t rect;
229 errno_t rc;
230
231 rc = ds_display_create(NULL, df_none, &disp);
232 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
233
234 rc = ds_client_create(disp, NULL, NULL, &client);
235 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
236
237 rc = ds_seat_create(disp, "Alice", &seat);
238 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
239
240 display_wnd_params_init(&params);
241 params.rect.p0.x = params.rect.p0.y = 0;
242 params.rect.p1.x = params.rect.p1.y = 10;
243
244 rc = ds_window_create(client, &params, &wnd);
245 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
246
247 wnd->dpos.x = 100;
248 wnd->dpos.y = 100;
249
250 ds_window_get_max_rect(wnd, &rect);
251
252 PCUT_ASSERT_INT_EQUALS(disp->rect.p0.x, rect.p0.x);
253 PCUT_ASSERT_INT_EQUALS(disp->rect.p0.y, rect.p0.y);
254 PCUT_ASSERT_INT_EQUALS(disp->rect.p1.x, rect.p1.x);
255 PCUT_ASSERT_INT_EQUALS(disp->rect.p1.y, rect.p1.y);
256
257 ds_window_destroy(wnd);
258 ds_seat_destroy(seat);
259 ds_client_destroy(client);
260 ds_display_destroy(disp);
261}
262
263/** Test ds_window_minimize(). */
264PCUT_TEST(window_minimize)
265{
266 ds_display_t *disp;
267 ds_client_t *client;
268 ds_seat_t *seat;
269 ds_window_t *wnd;
270 display_wnd_params_t params;
271 errno_t rc;
272
273 rc = ds_display_create(NULL, df_none, &disp);
274 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
275
276 rc = ds_client_create(disp, NULL, NULL, &client);
277 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
278
279 rc = ds_seat_create(disp, "Alice", &seat);
280 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
281
282 display_wnd_params_init(&params);
283 params.rect.p0.x = params.rect.p0.y = 0;
284 params.rect.p1.x = params.rect.p1.y = 10;
285
286 rc = ds_window_create(client, &params, &wnd);
287 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
288
289 rc = ds_window_minimize(wnd);
290 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
291
292 PCUT_ASSERT_INT_EQUALS(wndf_minimized, wnd->flags & wndf_minimized);
293
294 ds_window_destroy(wnd);
295 ds_seat_destroy(seat);
296 ds_client_destroy(client);
297 ds_display_destroy(disp);
298}
299
300/** Test ds_window_unminimize(). */
301PCUT_TEST(window_unminimize)
302{
303 ds_display_t *disp;
304 ds_client_t *client;
305 ds_seat_t *seat;
306 ds_window_t *wnd;
307 display_wnd_params_t params;
308 errno_t rc;
309
310 rc = ds_display_create(NULL, df_none, &disp);
311 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
312
313 rc = ds_client_create(disp, NULL, NULL, &client);
314 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
315
316 rc = ds_seat_create(disp, "Alice", &seat);
317 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
318
319 display_wnd_params_init(&params);
320 params.flags |= wndf_minimized;
321 params.rect.p0.x = params.rect.p0.y = 0;
322 params.rect.p1.x = params.rect.p1.y = 10;
323
324 rc = ds_window_create(client, &params, &wnd);
325 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
326
327 rc = ds_window_unminimize(wnd);
328 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
329
330 PCUT_ASSERT_INT_EQUALS(0, wnd->flags & wndf_minimized);
331
332 ds_window_destroy(wnd);
333 ds_seat_destroy(seat);
334 ds_client_destroy(client);
335 ds_display_destroy(disp);
336}
337
338/** Test ds_window_maximize(). */
339PCUT_TEST(window_maximize)
340{
341 ds_display_t *disp;
342 ds_client_t *client;
343 ds_seat_t *seat;
344 ds_window_t *wnd;
345 display_wnd_params_t params;
346 errno_t rc;
347
348 rc = ds_display_create(NULL, df_none, &disp);
349 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
350
351 rc = ds_client_create(disp, NULL, NULL, &client);
352 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
353
354 rc = ds_seat_create(disp, "Alice", &seat);
355 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
356
357 display_wnd_params_init(&params);
358 params.rect.p0.x = params.rect.p0.y = 0;
359 params.rect.p1.x = params.rect.p1.y = 10;
360
361 rc = ds_window_create(client, &params, &wnd);
362 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
363
364 wnd->dpos.x = 100;
365 wnd->dpos.y = 100;
366
367 rc = ds_window_maximize(wnd);
368 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
369
370 PCUT_ASSERT_INT_EQUALS(wndf_maximized, wnd->flags & wndf_maximized);
371
372 ds_window_destroy(wnd);
373 ds_seat_destroy(seat);
374 ds_client_destroy(client);
375 ds_display_destroy(disp);
376}
377
378/** Test ds_window_unmaximize(). */
379PCUT_TEST(window_unmaximize)
380{
381 ds_display_t *disp;
382 ds_client_t *client;
383 ds_seat_t *seat;
384 ds_window_t *wnd;
385 display_wnd_params_t params;
386 errno_t rc;
387
388 rc = ds_display_create(NULL, df_none, &disp);
389 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
390
391 rc = ds_client_create(disp, NULL, NULL, &client);
392 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
393
394 rc = ds_seat_create(disp, "Alice", &seat);
395 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
396
397 display_wnd_params_init(&params);
398 params.rect.p0.x = params.rect.p0.y = 0;
399 params.rect.p1.x = params.rect.p1.y = 10;
400
401 rc = ds_window_create(client, &params, &wnd);
402 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
403
404 wnd->dpos.x = 100;
405 wnd->dpos.y = 100;
406
407 rc = ds_window_maximize(wnd);
408 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
409
410 rc = ds_window_unmaximize(wnd);
411 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
412
413 PCUT_ASSERT_INT_EQUALS(0, wnd->flags & wndf_maximized);
414
415 ds_window_destroy(wnd);
416 ds_seat_destroy(seat);
417 ds_client_destroy(client);
418 ds_display_destroy(disp);
419}
420
421/** Test ds_window_get_ctx(). */
422PCUT_TEST(window_get_ctx)
423{
424 ds_display_t *disp;
425 ds_client_t *client;
426 ds_seat_t *seat;
427 ds_window_t *wnd;
428 display_wnd_params_t params;
429 gfx_context_t *gc;
430 errno_t rc;
431
432 rc = ds_display_create(NULL, df_none, &disp);
433 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
434
435 rc = ds_client_create(disp, NULL, NULL, &client);
436 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
437
438 rc = ds_seat_create(disp, "Alice", &seat);
439 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
440
441 display_wnd_params_init(&params);
442 params.rect.p0.x = params.rect.p0.y = 0;
443 params.rect.p1.x = params.rect.p1.y = 1;
444
445 rc = ds_window_create(client, &params, &wnd);
446 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
447
448 gc = ds_window_get_ctx(wnd);
449 PCUT_ASSERT_NOT_NULL(gc);
450
451 ds_window_destroy(wnd);
452 ds_seat_destroy(seat);
453 ds_client_destroy(client);
454 ds_display_destroy(disp);
455}
456
457/** Test ds_window_is_visible() */
458PCUT_TEST(is_visible)
459{
460 ds_display_t *disp;
461 ds_client_t *client;
462 ds_seat_t *seat;
463 ds_window_t *wnd;
464 display_wnd_params_t params;
465 errno_t rc;
466
467 rc = ds_display_create(NULL, df_none, &disp);
468 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
469
470 rc = ds_client_create(disp, NULL, NULL, &client);
471 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
472
473 rc = ds_seat_create(disp, "Alice", &seat);
474 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
475
476 display_wnd_params_init(&params);
477 params.rect.p0.x = params.rect.p0.y = 0;
478 params.rect.p1.x = params.rect.p1.y = 10;
479
480 rc = ds_window_create(client, &params, &wnd);
481 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
482
483 PCUT_ASSERT_TRUE(ds_window_is_visible(wnd));
484
485 wnd->flags |= wndf_minimized;
486
487 PCUT_ASSERT_FALSE(ds_window_is_visible(wnd));
488
489 ds_window_destroy(wnd);
490 ds_seat_destroy(seat);
491 ds_client_destroy(client);
492 ds_display_destroy(disp);
493}
494
495/** Test ds_window_post_kbd_event() with Alt-F4 sends close event */
496PCUT_TEST(window_post_kbd_event_alt_f4)
497{
498 gfx_context_t *gc;
499 ds_display_t *disp;
500 ds_client_t *client;
501 ds_seat_t *seat;
502 ds_window_t *wnd;
503 ds_window_t *rwindow;
504 display_wnd_ev_t revent;
505 display_wnd_params_t params;
506 kbd_event_t event;
507 errno_t rc;
508
509 rc = gfx_context_new(&dummy_ops, NULL, &gc);
510 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
511
512 rc = ds_display_create(gc, df_none, &disp);
513 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
514
515 rc = ds_client_create(disp, NULL, NULL, &client);
516 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
517
518 rc = ds_seat_create(disp, "Alice", &seat);
519 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
520
521 display_wnd_params_init(&params);
522 params.rect.p0.x = params.rect.p0.y = 0;
523 params.rect.p1.x = params.rect.p1.y = 1;
524
525 rc = ds_window_create(client, &params, &wnd);
526 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
527
528 /* New window gets focused event */
529 rc = ds_client_get_event(client, &rwindow, &revent);
530 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
531
532 event.type = KEY_PRESS;
533 event.mods = KM_ALT;
534 event.key = KC_F4;
535 rc = ds_window_post_kbd_event(wnd, &event);
536 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
537
538 rc = ds_client_get_event(client, &rwindow, &revent);
539 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
540 PCUT_ASSERT_EQUALS(wnd, rwindow);
541 PCUT_ASSERT_EQUALS(wev_close, revent.etype);
542
543 rc = ds_client_get_event(client, &rwindow, &revent);
544 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
545
546 ds_window_destroy(wnd);
547 ds_seat_destroy(seat);
548 ds_client_destroy(client);
549 ds_display_destroy(disp);
550}
551
552/** Test ds_window_post_pos_event() */
553PCUT_TEST(window_post_pos_event)
554{
555 gfx_context_t *gc;
556 ds_display_t *disp;
557 ds_client_t *client;
558 ds_seat_t *seat;
559 ds_window_t *wnd;
560 display_wnd_params_t params;
561 pos_event_t event;
562 errno_t rc;
563
564 rc = gfx_context_new(&dummy_ops, NULL, &gc);
565 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
566
567 rc = ds_display_create(gc, df_none, &disp);
568 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
569
570 rc = ds_client_create(disp, NULL, NULL, &client);
571 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
572
573 rc = ds_seat_create(disp, "Alice", &seat);
574 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
575
576 display_wnd_params_init(&params);
577 params.rect.p0.x = params.rect.p0.y = 0;
578 params.rect.p1.x = params.rect.p1.y = 1;
579
580 rc = ds_window_create(client, &params, &wnd);
581 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
582
583 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
584
585 wnd->dpos.x = 10;
586 wnd->dpos.y = 10;
587
588 event.type = POS_PRESS;
589 event.btn_num = 2;
590 event.hpos = 10;
591 event.vpos = 10;
592 rc = ds_window_post_pos_event(wnd, &event);
593 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
594
595 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
596
597 event.type = POS_UPDATE;
598 event.hpos = 11;
599 event.vpos = 12;
600 rc = ds_window_post_pos_event(wnd, &event);
601 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
602
603 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
604 /* Window position does not update until after release */
605 PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.x);
606 PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.y);
607
608 event.type = POS_RELEASE;
609 event.hpos = 13;
610 event.vpos = 14;
611
612 rc = ds_window_post_pos_event(wnd, &event);
613 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
614
615 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
616 PCUT_ASSERT_INT_EQUALS(13, wnd->dpos.x);
617 PCUT_ASSERT_INT_EQUALS(14, wnd->dpos.y);
618
619 ds_window_destroy(wnd);
620 ds_seat_destroy(seat);
621 ds_client_destroy(client);
622 ds_display_destroy(disp);
623}
624
625/** Test ds_window_post_focus_event() */
626PCUT_TEST(window_post_focus_event)
627{
628 gfx_context_t *gc;
629 ds_display_t *disp;
630 ds_client_t *client;
631 ds_seat_t *seat;
632 ds_window_t *wnd;
633 display_wnd_params_t params;
634 errno_t rc;
635
636 rc = gfx_context_new(&dummy_ops, NULL, &gc);
637 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
638
639 rc = ds_display_create(gc, df_none, &disp);
640 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
641
642 rc = ds_client_create(disp, NULL, NULL, &client);
643 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
644
645 rc = ds_seat_create(disp, "Alice", &seat);
646 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
647
648 display_wnd_params_init(&params);
649 params.rect.p0.x = params.rect.p0.y = 0;
650 params.rect.p1.x = params.rect.p1.y = 1;
651
652 rc = ds_window_create(client, &params, &wnd);
653 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
654
655 rc = ds_window_post_focus_event(wnd);
656 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
657
658 ds_window_destroy(wnd);
659 ds_seat_destroy(seat);
660 ds_client_destroy(client);
661 ds_display_destroy(disp);
662}
663
664/** Test ds_window_post_unfocus_event() */
665PCUT_TEST(window_post_unfocus_event)
666{
667 gfx_context_t *gc;
668 ds_display_t *disp;
669 ds_client_t *client;
670 ds_seat_t *seat;
671 ds_window_t *wnd;
672 display_wnd_params_t params;
673 errno_t rc;
674
675 rc = gfx_context_new(&dummy_ops, NULL, &gc);
676 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
677
678 rc = ds_display_create(gc, df_none, &disp);
679 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
680
681 rc = ds_client_create(disp, NULL, NULL, &client);
682 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
683
684 rc = ds_seat_create(disp, "Alice", &seat);
685 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
686
687 display_wnd_params_init(&params);
688 params.rect.p0.x = params.rect.p0.y = 0;
689 params.rect.p1.x = params.rect.p1.y = 1;
690
691 rc = ds_window_create(client, &params, &wnd);
692 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
693
694 rc = ds_window_post_focus_event(wnd);
695 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
696
697 ds_window_destroy(wnd);
698 ds_seat_destroy(seat);
699 ds_client_destroy(client);
700 ds_display_destroy(disp);
701}
702
703/** Test ds_window_move_req() */
704PCUT_TEST(window_move_req)
705{
706 gfx_context_t *gc;
707 ds_display_t *disp;
708 ds_client_t *client;
709 ds_seat_t *seat;
710 ds_window_t *wnd;
711 display_wnd_params_t params;
712 gfx_coord2_t pos;
713 sysarg_t pos_id;
714 errno_t rc;
715
716 rc = gfx_context_new(&dummy_ops, NULL, &gc);
717 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
718
719 rc = ds_display_create(gc, df_none, &disp);
720 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
721
722 rc = ds_client_create(disp, NULL, NULL, &client);
723 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
724
725 rc = ds_seat_create(disp, "Alice", &seat);
726 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
727
728 display_wnd_params_init(&params);
729 params.rect.p0.x = params.rect.p0.y = 0;
730 params.rect.p1.x = params.rect.p1.y = 1;
731
732 rc = ds_window_create(client, &params, &wnd);
733 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
734
735 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
736
737 pos.x = 42;
738 pos.y = 43;
739 pos_id = 44;
740 ds_window_move_req(wnd, &pos, pos_id);
741
742 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
743 PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
744 PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
745 PCUT_ASSERT_INT_EQUALS(pos_id, wnd->orig_pos_id);
746
747 ds_window_destroy(wnd);
748 ds_seat_destroy(seat);
749 ds_client_destroy(client);
750 ds_display_destroy(disp);
751}
752
753/** Test ds_window_resize_req() */
754PCUT_TEST(window_resize_req)
755{
756 gfx_context_t *gc;
757 ds_display_t *disp;
758 ds_client_t *client;
759 ds_seat_t *seat;
760 ds_window_t *wnd;
761 display_wnd_params_t params;
762 gfx_coord2_t pos;
763 sysarg_t pos_id;
764 errno_t rc;
765
766 rc = gfx_context_new(&dummy_ops, NULL, &gc);
767 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
768
769 rc = ds_display_create(gc, df_none, &disp);
770 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
771
772 rc = ds_client_create(disp, NULL, NULL, &client);
773 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
774
775 rc = ds_seat_create(disp, "Alice", &seat);
776 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
777
778 display_wnd_params_init(&params);
779 params.rect.p0.x = params.rect.p0.y = 0;
780 params.rect.p1.x = params.rect.p1.y = 1;
781
782 rc = ds_window_create(client, &params, &wnd);
783 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
784
785 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
786
787 pos.x = 42;
788 pos.y = 43;
789 pos_id = 44;
790 ds_window_resize_req(wnd, display_wr_top_right, &pos, pos_id);
791
792 PCUT_ASSERT_INT_EQUALS(dsw_resizing, wnd->state);
793 PCUT_ASSERT_INT_EQUALS(display_wr_top_right, wnd->rsztype);
794 PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
795 PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
796 PCUT_ASSERT_INT_EQUALS(pos_id, wnd->orig_pos_id);
797
798 ds_window_destroy(wnd);
799 ds_seat_destroy(seat);
800 ds_client_destroy(client);
801 ds_display_destroy(disp);
802}
803
804PCUT_TEST(window_calc_resize)
805{
806 ds_display_t *disp;
807 ds_client_t *client;
808 ds_seat_t *seat;
809 ds_window_t *wnd;
810 display_wnd_params_t params;
811 gfx_coord2_t dresize;
812 gfx_coord2_t dresizen;
813 gfx_coord2_t dresizeb;
814 gfx_coord2_t dresizebn;
815 gfx_rect_t nrect;
816 errno_t rc;
817
818 rc = ds_display_create(NULL, df_none, &disp);
819 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
820
821 rc = ds_client_create(disp, NULL, NULL, &client);
822 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
823
824 rc = ds_seat_create(disp, "Alice", &seat);
825 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
826
827 display_wnd_params_init(&params);
828 params.rect.p0.x = 10;
829 params.rect.p0.y = 11;
830 params.rect.p1.x = 30;
831 params.rect.p1.y = 31;
832 params.min_size.x = 2;
833 params.min_size.y = 3;
834
835 rc = ds_window_create(client, &params, &wnd);
836 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
837
838 wnd->state = dsw_resizing;
839
840 dresize.x = 5;
841 dresize.y = 6;
842
843 dresizen.x = -5;
844 dresizen.y = -6;
845
846 dresizeb.x = 50;
847 dresizeb.y = 60;
848
849 dresizebn.x = -50;
850 dresizebn.y = -60;
851
852 /* Resize top */
853 wnd->rsztype = display_wr_top;
854
855 ds_window_calc_resize(wnd, &dresize, &nrect);
856 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
857 PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
858 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
859 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
860
861 ds_window_calc_resize(wnd, &dresizen, &nrect);
862 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
863 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
864 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
865 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
866
867 ds_window_calc_resize(wnd, &dresizeb, &nrect);
868 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
869 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
870 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
871 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
872
873 ds_window_calc_resize(wnd, &dresizebn, &nrect);
874 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
875 PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
876 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
877 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
878
879 /* Resize top left */
880 wnd->rsztype = display_wr_top_left;
881
882 ds_window_calc_resize(wnd, &dresize, &nrect);
883 PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
884 PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
885 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
886 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
887
888 ds_window_calc_resize(wnd, &dresizen, &nrect);
889 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
890 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
891 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
892 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
893
894 ds_window_calc_resize(wnd, &dresizeb, &nrect);
895 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
896 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
897 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
898 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
899
900 ds_window_calc_resize(wnd, &dresizebn, &nrect);
901 PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
902 PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
903 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
904 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
905
906 /* Resize left */
907 wnd->rsztype = display_wr_left;
908
909 ds_window_calc_resize(wnd, &dresize, &nrect);
910 PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
911 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
912 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
913 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
914
915 ds_window_calc_resize(wnd, &dresizen, &nrect);
916 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
917 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
918 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
919 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
920
921 ds_window_calc_resize(wnd, &dresizeb, &nrect);
922 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
923 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
924 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
925 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
926
927 ds_window_calc_resize(wnd, &dresizebn, &nrect);
928 PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
929 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
930 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
931 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
932
933 /* Resize bottom left */
934 wnd->rsztype = display_wr_bottom_left;
935
936 ds_window_calc_resize(wnd, &dresize, &nrect);
937 PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
938 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
939 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
940 PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
941
942 ds_window_calc_resize(wnd, &dresizen, &nrect);
943 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
944 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
945 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
946 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
947
948 ds_window_calc_resize(wnd, &dresizeb, &nrect);
949 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
950 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
951 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
952 PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
953
954 ds_window_calc_resize(wnd, &dresizebn, &nrect);
955 PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
956 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
957 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
958 PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
959
960 /* Resize bottom */
961 wnd->rsztype = display_wr_bottom;
962
963 ds_window_calc_resize(wnd, &dresize, &nrect);
964 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
965 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
966 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
967 PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
968
969 ds_window_calc_resize(wnd, &dresizen, &nrect);
970 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
971 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
972 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
973 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
974
975 ds_window_calc_resize(wnd, &dresizeb, &nrect);
976 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
977 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
978 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
979 PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
980
981 ds_window_calc_resize(wnd, &dresizebn, &nrect);
982 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
983 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
984 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
985 PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
986
987 /* Resize bottom right */
988 wnd->rsztype = display_wr_bottom_right;
989
990 ds_window_calc_resize(wnd, &dresize, &nrect);
991 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
992 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
993 PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
994 PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
995
996 ds_window_calc_resize(wnd, &dresizen, &nrect);
997 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
998 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
999 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
1000 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
1001
1002 ds_window_calc_resize(wnd, &dresizeb, &nrect);
1003 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1004 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
1005 PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
1006 PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
1007
1008 ds_window_calc_resize(wnd, &dresizebn, &nrect);
1009 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1010 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
1011 PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
1012 PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
1013
1014 /* Resize right */
1015 wnd->rsztype = display_wr_right;
1016
1017 ds_window_calc_resize(wnd, &dresize, &nrect);
1018 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1019 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
1020 PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
1021 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1022
1023 ds_window_calc_resize(wnd, &dresizen, &nrect);
1024 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1025 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
1026 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
1027 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1028
1029 ds_window_calc_resize(wnd, &dresizeb, &nrect);
1030 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1031 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
1032 PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
1033 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1034
1035 ds_window_calc_resize(wnd, &dresizebn, &nrect);
1036 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1037 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
1038 PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
1039 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1040
1041 /* Resize top right */
1042 wnd->rsztype = display_wr_top_right;
1043
1044 ds_window_calc_resize(wnd, &dresize, &nrect);
1045 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1046 PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
1047 PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
1048 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1049
1050 ds_window_calc_resize(wnd, &dresizen, &nrect);
1051 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1052 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
1053 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
1054 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1055
1056 ds_window_calc_resize(wnd, &dresizeb, &nrect);
1057 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1058 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
1059 PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
1060 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1061
1062 ds_window_calc_resize(wnd, &dresizebn, &nrect);
1063 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
1064 PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
1065 PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
1066 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
1067
1068 ds_window_destroy(wnd);
1069 ds_seat_destroy(seat);
1070 ds_client_destroy(client);
1071 ds_display_destroy(disp);
1072}
1073
1074/** Test ds_window_set_cursor() */
1075PCUT_TEST(window_set_cursor)
1076{
1077 gfx_context_t *gc;
1078 ds_display_t *disp;
1079 ds_client_t *client;
1080 ds_seat_t *seat;
1081 ds_window_t *wnd;
1082 display_wnd_params_t params;
1083 errno_t rc;
1084
1085 rc = gfx_context_new(&dummy_ops, NULL, &gc);
1086 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1087
1088 rc = ds_display_create(gc, df_none, &disp);
1089 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1090
1091 rc = ds_client_create(disp, NULL, NULL, &client);
1092 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1093
1094 rc = ds_seat_create(disp, "Alice", &seat);
1095 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1096
1097 display_wnd_params_init(&params);
1098 params.rect.p0.x = params.rect.p0.y = 0;
1099 params.rect.p1.x = params.rect.p1.y = 1;
1100
1101 rc = ds_window_create(client, &params, &wnd);
1102 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1103
1104 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
1105
1106 rc = ds_window_set_cursor(wnd, -1);
1107 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
1108 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
1109
1110 rc = ds_window_set_cursor(wnd, dcurs_limit);
1111 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
1112 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
1113
1114 rc = ds_window_set_cursor(wnd, dcurs_limit + 1);
1115 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
1116 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
1117
1118 rc = ds_window_set_cursor(wnd, dcurs_size_lr);
1119 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1120 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_size_lr], wnd->cursor);
1121
1122 ds_window_destroy(wnd);
1123 ds_seat_destroy(seat);
1124 ds_client_destroy(client);
1125 ds_display_destroy(disp);
1126}
1127
1128/** Test ds_window_set_caption() */
1129PCUT_TEST(window_set_caption)
1130{
1131 gfx_context_t *gc;
1132 ds_display_t *disp;
1133 ds_client_t *client;
1134 ds_seat_t *seat;
1135 ds_window_t *wnd;
1136 display_wnd_params_t params;
1137 errno_t rc;
1138
1139 rc = gfx_context_new(&dummy_ops, NULL, &gc);
1140 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1141
1142 rc = ds_display_create(gc, df_none, &disp);
1143 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1144
1145 rc = ds_client_create(disp, NULL, NULL, &client);
1146 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1147
1148 rc = ds_seat_create(disp, "Alice", &seat);
1149 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1150
1151 display_wnd_params_init(&params);
1152 params.rect.p0.x = params.rect.p0.y = 0;
1153 params.rect.p1.x = params.rect.p1.y = 1;
1154
1155 rc = ds_window_create(client, &params, &wnd);
1156 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1157
1158 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
1159
1160 rc = ds_window_set_caption(wnd, "Hello");
1161 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1162 PCUT_ASSERT_INT_EQUALS(0, str_cmp("Hello", wnd->caption));
1163
1164 ds_window_destroy(wnd);
1165 ds_seat_destroy(seat);
1166 ds_client_destroy(client);
1167 ds_display_destroy(disp);
1168}
1169
1170/** ds_window_find_alt() finds alternate window by flags */
1171PCUT_TEST(window_find_alt)
1172{
1173 gfx_context_t *gc;
1174 ds_display_t *disp;
1175 ds_client_t *client;
1176 ds_seat_t *seat;
1177 ds_window_t *w0;
1178 ds_window_t *w1;
1179 ds_window_t *w2;
1180 ds_window_t *wnd;
1181 display_wnd_params_t params;
1182 errno_t rc;
1183
1184 rc = gfx_context_new(&dummy_ops, NULL, &gc);
1185 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1186
1187 rc = ds_display_create(gc, df_none, &disp);
1188 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1189
1190 rc = ds_client_create(disp, NULL, NULL, &client);
1191 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1192
1193 rc = ds_seat_create(disp, "Alice", &seat);
1194 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1195
1196 display_wnd_params_init(&params);
1197 params.rect.p0.x = params.rect.p0.y = 0;
1198 params.rect.p1.x = params.rect.p1.y = 1;
1199
1200 rc = ds_window_create(client, &params, &w0);
1201 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1202
1203 rc = ds_window_create(client, &params, &w1);
1204 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1205 w1->flags |= wndf_minimized;
1206
1207 rc = ds_window_create(client, &params, &w2);
1208 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1209 w2->flags |= wndf_system;
1210
1211 wnd = ds_window_find_alt(w0, wndf_minimized);
1212 PCUT_ASSERT_EQUALS(w1, wnd);
1213
1214 wnd = ds_window_find_alt(w0, wndf_system);
1215 PCUT_ASSERT_EQUALS(w2, wnd);
1216
1217 wnd = ds_window_find_alt(w0, wndf_maximized);
1218 PCUT_ASSERT_NULL(wnd);
1219
1220 ds_window_destroy(w0);
1221 ds_window_destroy(w1);
1222 ds_window_destroy(w2);
1223 ds_seat_destroy(seat);
1224 ds_client_destroy(client);
1225 ds_display_destroy(disp);
1226}
1227
1228/** ds_window_unfocus() switches to another window */
1229PCUT_TEST(window_unfocus)
1230{
1231 gfx_context_t *gc;
1232 ds_display_t *disp;
1233 ds_client_t *client;
1234 ds_seat_t *seat;
1235 ds_window_t *w0;
1236 ds_window_t *w1;
1237 display_wnd_params_t params;
1238 errno_t rc;
1239
1240 rc = gfx_context_new(&dummy_ops, NULL, &gc);
1241 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1242
1243 rc = ds_display_create(gc, df_none, &disp);
1244 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1245
1246 rc = ds_client_create(disp, NULL, NULL, &client);
1247 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1248
1249 rc = ds_seat_create(disp, "Alice", &seat);
1250 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1251
1252 display_wnd_params_init(&params);
1253 params.rect.p0.x = params.rect.p0.y = 0;
1254 params.rect.p1.x = params.rect.p1.y = 1;
1255
1256 rc = ds_window_create(client, &params, &w1);
1257 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1258
1259 rc = ds_window_create(client, &params, &w0);
1260 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
1261
1262 PCUT_ASSERT_EQUALS(w0, seat->focus);
1263
1264 ds_window_unfocus(w0);
1265
1266 PCUT_ASSERT_EQUALS(w1, seat->focus);
1267
1268 ds_window_destroy(w0);
1269 ds_window_destroy(w1);
1270 ds_seat_destroy(seat);
1271 ds_client_destroy(client);
1272 ds_display_destroy(disp);
1273}
1274
1275static errno_t dummy_set_color(void *arg, gfx_color_t *color)
1276{
1277 return EOK;
1278}
1279
1280static errno_t dummy_fill_rect(void *arg, gfx_rect_t *rect)
1281{
1282 return EOK;
1283}
1284
1285PCUT_EXPORT(window);
Note: See TracBrowser for help on using the repository browser.