source: mainline/uspace/srv/hid/display/test/window.c@ 9242ad9

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

Switch to double-arrow cursors when pointer is above resize areas

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