source: mainline/uspace/srv/hid/display/test/window.c@ 0da03df

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

Configurable display double-buffering

On by default (since turning off creates flicker in the absence of
front-to-back rendering). This is the quick and dirty way: display
server renders locally to a bitmap (using mem GC) and renders the
bitmap when ready.

The more sophisticated way would be to implement buffering in the
display device. That would require, however, enhancing the protocols
to communicate frame boundaries.

  • Property mode set to 100644
File size: 18.2 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 <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 ds_window_resize(). */
54PCUT_TEST(window_resize)
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 gfx_coord2_t offs;
62 gfx_rect_t nrect;
63 errno_t rc;
64
65 rc = ds_display_create(NULL, df_none, &disp);
66 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
67
68 rc = ds_client_create(disp, NULL, NULL, &client);
69 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
70
71 rc = ds_seat_create(disp, &seat);
72 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
73
74 display_wnd_params_init(&params);
75 params.rect.p0.x = params.rect.p0.y = 0;
76 params.rect.p1.x = params.rect.p1.y = 10;
77
78 rc = ds_window_create(client, &params, &wnd);
79 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
80
81 wnd->dpos.x = 100;
82 wnd->dpos.y = 100;
83
84 offs.x = -2;
85 offs.y = -3;
86 params.rect.p0.x = params.rect.p0.y = 0;
87 params.rect.p1.x = 12;
88 params.rect.p1.y = 13;
89 rc = ds_window_resize(wnd, &offs, &nrect);
90 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
91
92 PCUT_ASSERT_INT_EQUALS(98, wnd->dpos.x);
93 PCUT_ASSERT_INT_EQUALS(97, wnd->dpos.y);
94
95 ds_window_destroy(wnd);
96 ds_seat_destroy(seat);
97 ds_client_destroy(client);
98 ds_display_destroy(disp);
99}
100
101/** Test ds_window_get_ctx(). */
102PCUT_TEST(window_get_ctx)
103{
104 ds_display_t *disp;
105 ds_client_t *client;
106 ds_window_t *wnd;
107 display_wnd_params_t params;
108 gfx_context_t *gc;
109 errno_t rc;
110
111 rc = ds_display_create(NULL, df_none, &disp);
112 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
113
114 rc = ds_client_create(disp, NULL, NULL, &client);
115 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
116
117 display_wnd_params_init(&params);
118 params.rect.p0.x = params.rect.p0.y = 0;
119 params.rect.p1.x = params.rect.p1.y = 1;
120
121 rc = ds_window_create(client, &params, &wnd);
122 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
123
124 gc = ds_window_get_ctx(wnd);
125 PCUT_ASSERT_NOT_NULL(gc);
126
127 ds_window_destroy(wnd);
128 ds_client_destroy(client);
129 ds_display_destroy(disp);
130}
131
132/** Test ds_window_post_kbd_event() with Alt-F4 sends close event */
133PCUT_TEST(window_post_kbd_event_alt_f4)
134{
135 gfx_context_t *gc;
136 ds_display_t *disp;
137 ds_client_t *client;
138 ds_window_t *wnd;
139 ds_window_t *rwindow;
140 display_wnd_ev_t revent;
141 display_wnd_params_t params;
142 kbd_event_t event;
143 errno_t rc;
144
145 rc = gfx_context_new(&dummy_ops, NULL, &gc);
146 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
147
148 rc = ds_display_create(gc, df_none, &disp);
149 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
150
151 rc = ds_client_create(disp, NULL, NULL, &client);
152 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
153
154 display_wnd_params_init(&params);
155 params.rect.p0.x = params.rect.p0.y = 0;
156 params.rect.p1.x = params.rect.p1.y = 1;
157
158 rc = ds_window_create(client, &params, &wnd);
159 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
160
161 event.type = KEY_PRESS;
162 event.mods = KM_ALT;
163 event.key = KC_F4;
164 rc = ds_window_post_kbd_event(wnd, &event);
165 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
166
167 rc = ds_client_get_event(client, &rwindow, &revent);
168 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
169 PCUT_ASSERT_EQUALS(wnd, rwindow);
170 PCUT_ASSERT_EQUALS(wev_close, revent.etype);
171
172 rc = ds_client_get_event(client, &rwindow, &revent);
173 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
174
175 ds_window_destroy(wnd);
176 ds_client_destroy(client);
177 ds_display_destroy(disp);
178}
179
180/** Test ds_window_post_pos_event() */
181PCUT_TEST(window_post_pos_event)
182{
183 gfx_context_t *gc;
184 ds_display_t *disp;
185 ds_client_t *client;
186 ds_window_t *wnd;
187 display_wnd_params_t params;
188 pos_event_t event;
189 errno_t rc;
190
191 rc = gfx_context_new(&dummy_ops, NULL, &gc);
192 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
193
194 rc = ds_display_create(gc, df_none, &disp);
195 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
196
197 rc = ds_client_create(disp, NULL, NULL, &client);
198 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
199
200 display_wnd_params_init(&params);
201 params.rect.p0.x = params.rect.p0.y = 0;
202 params.rect.p1.x = params.rect.p1.y = 1;
203
204 rc = ds_window_create(client, &params, &wnd);
205 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
206
207 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
208
209 wnd->dpos.x = 10;
210 wnd->dpos.y = 10;
211
212 event.type = POS_PRESS;
213 event.btn_num = 2;
214 event.hpos = 10;
215 event.vpos = 10;
216 rc = ds_window_post_pos_event(wnd, &event);
217 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
218
219 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
220
221 event.type = POS_UPDATE;
222 event.hpos = 11;
223 event.vpos = 12;
224 rc = ds_window_post_pos_event(wnd, &event);
225 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
226
227 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
228 /* Window position does not update until after release */
229 PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.x);
230 PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.y);
231
232 event.type = POS_RELEASE;
233 event.hpos = 13;
234 event.vpos = 14;
235
236 rc = ds_window_post_pos_event(wnd, &event);
237 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
238
239 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
240 PCUT_ASSERT_INT_EQUALS(13, wnd->dpos.x);
241 PCUT_ASSERT_INT_EQUALS(14, wnd->dpos.y);
242
243 ds_window_destroy(wnd);
244 ds_client_destroy(client);
245 ds_display_destroy(disp);
246}
247
248/** Test ds_window_move_req() */
249PCUT_TEST(window_move_req)
250{
251 gfx_context_t *gc;
252 ds_display_t *disp;
253 ds_client_t *client;
254 ds_window_t *wnd;
255 display_wnd_params_t params;
256 gfx_coord2_t pos;
257 errno_t rc;
258
259 rc = gfx_context_new(&dummy_ops, NULL, &gc);
260 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
261
262 rc = ds_display_create(gc, df_none, &disp);
263 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
264
265 rc = ds_client_create(disp, NULL, NULL, &client);
266 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
267
268 display_wnd_params_init(&params);
269 params.rect.p0.x = params.rect.p0.y = 0;
270 params.rect.p1.x = params.rect.p1.y = 1;
271
272 rc = ds_window_create(client, &params, &wnd);
273 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
274
275 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
276
277 pos.x = 42;
278 pos.y = 43;
279 ds_window_move_req(wnd, &pos);
280
281 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
282 PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
283 PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
284
285 ds_window_destroy(wnd);
286 ds_client_destroy(client);
287 ds_display_destroy(disp);
288}
289
290/** Test ds_window_resize_req() */
291PCUT_TEST(window_resize_req)
292{
293 gfx_context_t *gc;
294 ds_display_t *disp;
295 ds_client_t *client;
296 ds_seat_t *seat;
297 ds_window_t *wnd;
298 display_wnd_params_t params;
299 gfx_coord2_t pos;
300 errno_t rc;
301
302 rc = gfx_context_new(&dummy_ops, NULL, &gc);
303 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
304
305 rc = ds_display_create(gc, df_none, &disp);
306 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
307
308 rc = ds_client_create(disp, NULL, NULL, &client);
309 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
310
311 rc = ds_seat_create(disp, &seat);
312 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
313
314 display_wnd_params_init(&params);
315 params.rect.p0.x = params.rect.p0.y = 0;
316 params.rect.p1.x = params.rect.p1.y = 1;
317
318 rc = ds_window_create(client, &params, &wnd);
319 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
320
321 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
322
323 pos.x = 42;
324 pos.y = 43;
325 ds_window_resize_req(wnd, display_wr_top_right, &pos);
326
327 PCUT_ASSERT_INT_EQUALS(dsw_resizing, wnd->state);
328 PCUT_ASSERT_INT_EQUALS(display_wr_top_right, wnd->rsztype);
329 PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
330 PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
331
332 ds_window_destroy(wnd);
333 ds_seat_destroy(seat);
334 ds_client_destroy(client);
335 ds_display_destroy(disp);
336}
337
338PCUT_TEST(window_calc_resize)
339{
340 ds_display_t *disp;
341 ds_client_t *client;
342 ds_window_t *wnd;
343 display_wnd_params_t params;
344 gfx_coord2_t dresize;
345 gfx_coord2_t dresizen;
346 gfx_coord2_t dresizeb;
347 gfx_coord2_t dresizebn;
348 gfx_rect_t nrect;
349 errno_t rc;
350
351 rc = ds_display_create(NULL, df_none, &disp);
352 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
353
354 rc = ds_client_create(disp, NULL, NULL, &client);
355 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
356
357 display_wnd_params_init(&params);
358 params.rect.p0.x = 10;
359 params.rect.p0.y = 11;
360 params.rect.p1.x = 30;
361 params.rect.p1.y = 31;
362 params.min_size.x = 2;
363 params.min_size.y = 3;
364
365 rc = ds_window_create(client, &params, &wnd);
366 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
367
368 wnd->state = dsw_resizing;
369
370 dresize.x = 5;
371 dresize.y = 6;
372
373 dresizen.x = -5;
374 dresizen.y = -6;
375
376 dresizeb.x = 50;
377 dresizeb.y = 60;
378
379 dresizebn.x = -50;
380 dresizebn.y = -60;
381
382 /* Resize top */
383 wnd->rsztype = display_wr_top;
384
385 ds_window_calc_resize(wnd, &dresize, &nrect);
386 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
387 PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
388 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
389 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
390
391 ds_window_calc_resize(wnd, &dresizen, &nrect);
392 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
393 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
394 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
395 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
396
397 ds_window_calc_resize(wnd, &dresizeb, &nrect);
398 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
399 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
400 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
401 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
402
403 ds_window_calc_resize(wnd, &dresizebn, &nrect);
404 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
405 PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
406 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
407 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
408
409 /* Resize top left */
410 wnd->rsztype = display_wr_top_left;
411
412 ds_window_calc_resize(wnd, &dresize, &nrect);
413 PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
414 PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
415 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
416 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
417
418 ds_window_calc_resize(wnd, &dresizen, &nrect);
419 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
420 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
421 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
422 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
423
424 ds_window_calc_resize(wnd, &dresizeb, &nrect);
425 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
426 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
427 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
428 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
429
430 ds_window_calc_resize(wnd, &dresizebn, &nrect);
431 PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
432 PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
433 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
434 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
435
436 /* Resize left */
437 wnd->rsztype = display_wr_left;
438
439 ds_window_calc_resize(wnd, &dresize, &nrect);
440 PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
441 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
442 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
443 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
444
445 ds_window_calc_resize(wnd, &dresizen, &nrect);
446 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
447 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
448 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
449 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
450
451 ds_window_calc_resize(wnd, &dresizeb, &nrect);
452 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
453 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
454 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
455 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
456
457 ds_window_calc_resize(wnd, &dresizebn, &nrect);
458 PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
459 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
460 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
461 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
462
463 /* Resize bottom left */
464 wnd->rsztype = display_wr_bottom_left;
465
466 ds_window_calc_resize(wnd, &dresize, &nrect);
467 PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
468 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
469 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
470 PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
471
472 ds_window_calc_resize(wnd, &dresizen, &nrect);
473 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
474 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
475 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
476 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
477
478 ds_window_calc_resize(wnd, &dresizeb, &nrect);
479 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
480 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
481 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
482 PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
483
484 ds_window_calc_resize(wnd, &dresizebn, &nrect);
485 PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
486 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
487 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
488 PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
489
490 /* Resize bottom */
491 wnd->rsztype = display_wr_bottom;
492
493 ds_window_calc_resize(wnd, &dresize, &nrect);
494 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
495 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
496 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
497 PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
498
499 ds_window_calc_resize(wnd, &dresizen, &nrect);
500 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
501 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
502 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
503 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
504
505 ds_window_calc_resize(wnd, &dresizeb, &nrect);
506 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
507 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
508 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
509 PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
510
511 ds_window_calc_resize(wnd, &dresizebn, &nrect);
512 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
513 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
514 PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
515 PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
516
517 /* Resize bottom right */
518 wnd->rsztype = display_wr_bottom_right;
519
520 ds_window_calc_resize(wnd, &dresize, &nrect);
521 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
522 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
523 PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
524 PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
525
526 ds_window_calc_resize(wnd, &dresizen, &nrect);
527 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
528 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
529 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
530 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
531
532 ds_window_calc_resize(wnd, &dresizeb, &nrect);
533 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
534 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
535 PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
536 PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
537
538 ds_window_calc_resize(wnd, &dresizebn, &nrect);
539 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
540 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
541 PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
542 PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
543
544 /* Resize right */
545 wnd->rsztype = display_wr_right;
546
547 ds_window_calc_resize(wnd, &dresize, &nrect);
548 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
549 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
550 PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
551 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
552
553 ds_window_calc_resize(wnd, &dresizen, &nrect);
554 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
555 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
556 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
557 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
558
559 ds_window_calc_resize(wnd, &dresizeb, &nrect);
560 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
561 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
562 PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
563 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
564
565 ds_window_calc_resize(wnd, &dresizebn, &nrect);
566 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
567 PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
568 PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
569 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
570
571 /* Resize top right */
572 wnd->rsztype = display_wr_top_right;
573
574 ds_window_calc_resize(wnd, &dresize, &nrect);
575 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
576 PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
577 PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
578 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
579
580 ds_window_calc_resize(wnd, &dresizen, &nrect);
581 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
582 PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
583 PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
584 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
585
586 ds_window_calc_resize(wnd, &dresizeb, &nrect);
587 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
588 PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
589 PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
590 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
591
592 ds_window_calc_resize(wnd, &dresizebn, &nrect);
593 PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
594 PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
595 PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
596 PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
597
598 ds_window_destroy(wnd);
599 ds_client_destroy(client);
600 ds_display_destroy(disp);
601}
602
603/** Test ds_window_set_cursor() */
604PCUT_TEST(window_set_cursor)
605{
606 gfx_context_t *gc;
607 ds_display_t *disp;
608 ds_client_t *client;
609 ds_window_t *wnd;
610 display_wnd_params_t params;
611 errno_t rc;
612
613 rc = gfx_context_new(&dummy_ops, NULL, &gc);
614 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
615
616 rc = ds_display_create(gc, df_none, &disp);
617 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
618
619 rc = ds_client_create(disp, NULL, NULL, &client);
620 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
621
622 display_wnd_params_init(&params);
623 params.rect.p0.x = params.rect.p0.y = 0;
624 params.rect.p1.x = params.rect.p1.y = 1;
625
626 rc = ds_window_create(client, &params, &wnd);
627 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
628
629 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
630
631 rc = ds_window_set_cursor(wnd, -1);
632 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
633 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
634
635 rc = ds_window_set_cursor(wnd, dcurs_limit);
636 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
637 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
638
639 rc = ds_window_set_cursor(wnd, dcurs_limit + 1);
640 PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
641 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
642
643 rc = ds_window_set_cursor(wnd, dcurs_size_lr);
644 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
645 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_size_lr], wnd->cursor);
646
647 ds_window_destroy(wnd);
648 ds_client_destroy(client);
649 ds_display_destroy(disp);
650}
651
652static errno_t dummy_set_color(void *arg, gfx_color_t *color)
653{
654 return EOK;
655}
656
657static errno_t dummy_fill_rect(void *arg, gfx_rect_t *rect)
658{
659 return EOK;
660}
661
662PCUT_EXPORT(window);
Note: See TracBrowser for help on using the repository browser.