2 * Copyright (c) 2024 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include <gfx/context.h>
30 #include <gfx/coord.h>
32 #include <pcut/pcut.h>
34 #include <ui/pbutton.h>
35 #include <ui/resource.h>
37 #include <ui/wdecor.h>
38 #include "../private/wdecor.h"
42 PCUT_TEST_SUITE(wdecor
);
44 static errno_t
testgc_set_clip_rect(void *, gfx_rect_t
*);
45 static errno_t
testgc_set_color(void *, gfx_color_t
*);
46 static errno_t
testgc_fill_rect(void *, gfx_rect_t
*);
47 static errno_t
testgc_update(void *);
48 static errno_t
testgc_bitmap_create(void *, gfx_bitmap_params_t
*,
49 gfx_bitmap_alloc_t
*, void **);
50 static errno_t
testgc_bitmap_destroy(void *);
51 static errno_t
testgc_bitmap_render(void *, gfx_rect_t
*, gfx_coord2_t
*);
52 static errno_t
testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t
*);
54 static gfx_context_ops_t ops
= {
55 .set_clip_rect
= testgc_set_clip_rect
,
56 .set_color
= testgc_set_color
,
57 .fill_rect
= testgc_fill_rect
,
58 .update
= testgc_update
,
59 .bitmap_create
= testgc_bitmap_create
,
60 .bitmap_destroy
= testgc_bitmap_destroy
,
61 .bitmap_render
= testgc_bitmap_render
,
62 .bitmap_get_alloc
= testgc_bitmap_get_alloc
65 static void test_wdecor_sysmenu_open(ui_wdecor_t
*, void *, sysarg_t
);
66 static void test_wdecor_sysmenu_left(ui_wdecor_t
*, void *, sysarg_t
);
67 static void test_wdecor_sysmenu_right(ui_wdecor_t
*, void *, sysarg_t
);
68 static void test_wdecor_sysmenu_accel(ui_wdecor_t
*, void *, char32_t
,
70 static void test_wdecor_minimize(ui_wdecor_t
*, void *);
71 static void test_wdecor_maximize(ui_wdecor_t
*, void *);
72 static void test_wdecor_unmaximize(ui_wdecor_t
*, void *);
73 static void test_wdecor_close(ui_wdecor_t
*, void *);
74 static void test_wdecor_move(ui_wdecor_t
*, void *, gfx_coord2_t
*, sysarg_t
);
75 static void test_wdecor_resize(ui_wdecor_t
*, void *, ui_wdecor_rsztype_t
,
76 gfx_coord2_t
*, sysarg_t
);
77 static void test_wdecor_set_cursor(ui_wdecor_t
*, void *, ui_stock_cursor_t
);
79 static ui_wdecor_cb_t test_wdecor_cb
= {
80 .sysmenu_open
= test_wdecor_sysmenu_open
,
81 .sysmenu_left
= test_wdecor_sysmenu_left
,
82 .sysmenu_right
= test_wdecor_sysmenu_right
,
83 .sysmenu_accel
= test_wdecor_sysmenu_accel
,
84 .minimize
= test_wdecor_minimize
,
85 .maximize
= test_wdecor_maximize
,
86 .unmaximize
= test_wdecor_unmaximize
,
87 .close
= test_wdecor_close
,
88 .move
= test_wdecor_move
,
89 .resize
= test_wdecor_resize
,
90 .set_cursor
= test_wdecor_set_cursor
93 static ui_wdecor_cb_t dummy_wdecor_cb
= {
99 gfx_bitmap_params_t bm_params
;
102 gfx_coord2_t bm_offs
;
109 gfx_bitmap_alloc_t alloc
;
128 ui_wdecor_rsztype_t rsztype
;
130 ui_stock_cursor_t cursor
;
133 /** Create and destroy window decoration */
134 PCUT_TEST(create_destroy
)
136 ui_wdecor_t
*wdecor
= NULL
;
139 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
140 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
141 PCUT_ASSERT_NOT_NULL(wdecor
);
143 ui_wdecor_destroy(wdecor
);
146 /** ui_wdecor_destroy() can take NULL argument (no-op) */
147 PCUT_TEST(destroy_null
)
149 ui_wdecor_destroy(NULL
);
152 /** Set window decoration rectangle sets internal field */
155 gfx_context_t
*gc
= NULL
;
157 ui_resource_t
*resource
= NULL
;
162 memset(&tgc
, 0, sizeof(tgc
));
163 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
164 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
166 rc
= ui_resource_create(gc
, false, &resource
);
167 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
168 PCUT_ASSERT_NOT_NULL(resource
);
170 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_none
, &wdecor
);
171 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
178 ui_wdecor_set_rect(wdecor
, &rect
);
179 PCUT_ASSERT_INT_EQUALS(rect
.p0
.x
, wdecor
->rect
.p0
.x
);
180 PCUT_ASSERT_INT_EQUALS(rect
.p0
.y
, wdecor
->rect
.p0
.y
);
181 PCUT_ASSERT_INT_EQUALS(rect
.p1
.x
, wdecor
->rect
.p1
.x
);
182 PCUT_ASSERT_INT_EQUALS(rect
.p1
.y
, wdecor
->rect
.p1
.y
);
184 ui_wdecor_destroy(wdecor
);
185 ui_resource_destroy(resource
);
187 rc
= gfx_context_delete(gc
);
188 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
191 /** Set window decoration active sets internal field */
192 PCUT_TEST(set_active
)
197 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
198 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
200 PCUT_ASSERT_TRUE(wdecor
->active
);
202 ui_wdecor_set_active(wdecor
, false);
203 PCUT_ASSERT_FALSE(wdecor
->active
);
205 ui_wdecor_set_active(wdecor
, true);
206 PCUT_ASSERT_TRUE(wdecor
->active
);
208 ui_wdecor_destroy(wdecor
);
211 /** Set window decoration maximized sets internal field */
212 PCUT_TEST(set_maximized
)
217 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
218 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
220 PCUT_ASSERT_TRUE(wdecor
->active
);
222 ui_wdecor_set_maximized(wdecor
, false);
223 PCUT_ASSERT_FALSE(wdecor
->maximized
);
225 ui_wdecor_set_maximized(wdecor
, true);
226 PCUT_ASSERT_TRUE(wdecor
->maximized
);
228 ui_wdecor_destroy(wdecor
);
231 /** Setting system menu handle as active/inactive */
232 PCUT_TEST(sysmenu_hdl_set_active
)
235 gfx_context_t
*gc
= NULL
;
237 ui_resource_t
*resource
= NULL
;
240 memset(&tgc
, 0, sizeof(tgc
));
241 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
242 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
244 rc
= ui_resource_create(gc
, false, &resource
);
245 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
246 PCUT_ASSERT_NOT_NULL(resource
);
248 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
249 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
251 PCUT_ASSERT_FALSE(wdecor
->sysmenu_hdl_active
);
252 ui_wdecor_sysmenu_hdl_set_active(wdecor
, true);
253 PCUT_ASSERT_TRUE(wdecor
->sysmenu_hdl_active
);
254 ui_wdecor_sysmenu_hdl_set_active(wdecor
, false);
255 PCUT_ASSERT_FALSE(wdecor
->sysmenu_hdl_active
);
257 ui_wdecor_destroy(wdecor
);
258 ui_resource_destroy(resource
);
260 rc
= gfx_context_delete(gc
);
261 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
264 /** Paint system menu handle */
265 PCUT_TEST(sysmenu_hdl_paint
)
268 gfx_context_t
*gc
= NULL
;
270 ui_resource_t
*resource
= NULL
;
272 ui_wdecor_geom_t geom
;
274 memset(&tgc
, 0, sizeof(tgc
));
275 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
276 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
278 rc
= ui_resource_create(gc
, false, &resource
);
279 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
280 PCUT_ASSERT_NOT_NULL(resource
);
282 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
283 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
285 ui_wdecor_get_geom(wdecor
, &geom
);
286 rc
= ui_wdecor_sysmenu_hdl_paint(wdecor
, &geom
.sysmenu_hdl_rect
);
287 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
289 ui_wdecor_destroy(wdecor
);
290 ui_resource_destroy(resource
);
292 rc
= gfx_context_delete(gc
);
293 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
296 /** Paint window decoration */
300 gfx_context_t
*gc
= NULL
;
302 ui_resource_t
*resource
= NULL
;
305 memset(&tgc
, 0, sizeof(tgc
));
306 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
307 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
309 rc
= ui_resource_create(gc
, false, &resource
);
310 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
311 PCUT_ASSERT_NOT_NULL(resource
);
313 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
314 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
316 rc
= ui_wdecor_paint(wdecor
);
317 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
319 ui_wdecor_destroy(wdecor
);
320 ui_resource_destroy(resource
);
322 rc
= gfx_context_delete(gc
);
323 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
326 /** Test ui_wdecor_sysmenu_open() */
327 PCUT_TEST(sysmenu_open
)
333 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
334 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
336 /* Sysmenu open callback with no callbacks set */
337 ui_wdecor_sysmenu_open(wdecor
, 42);
339 /* Sysmenu open callback with sysmenu callback not implemented */
340 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
341 ui_wdecor_sysmenu_open(wdecor
, 42);
343 /* Sysmenu open callback with real callback set */
344 resp
.sysmenu_open
= false;
346 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
347 ui_wdecor_sysmenu_open(wdecor
, 42);
348 PCUT_ASSERT_TRUE(resp
.sysmenu_open
);
349 PCUT_ASSERT_INT_EQUALS(42, resp
.idev_id
);
351 ui_wdecor_destroy(wdecor
);
354 /** Test ui_wdecor_sysmenu_left() */
355 PCUT_TEST(sysmenu_left
)
361 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
362 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
364 /* Sysmenu left callback with no callbacks set */
365 ui_wdecor_sysmenu_left(wdecor
, 42);
367 /* Sysmenu left callback with sysmenu callback not implemented */
368 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
369 ui_wdecor_sysmenu_left(wdecor
, 42);
371 /* Sysmenu left callback with real callback set */
372 resp
.sysmenu_left
= false;
374 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
375 ui_wdecor_sysmenu_left(wdecor
, 42);
376 PCUT_ASSERT_TRUE(resp
.sysmenu_left
);
377 PCUT_ASSERT_INT_EQUALS(42, resp
.idev_id
);
379 ui_wdecor_destroy(wdecor
);
382 /** Test ui_wdecor_sysmenu_right() */
383 PCUT_TEST(sysmenu_right
)
389 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
390 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
392 /* Sysmenu right callback with no callbacks set */
393 ui_wdecor_sysmenu_right(wdecor
, 42);
395 /* Sysmenu right callback with sysmenu callback not implemented */
396 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
397 ui_wdecor_sysmenu_right(wdecor
, 42);
399 /* Sysmenu right callback with real callback set */
400 resp
.sysmenu_right
= false;
402 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
403 ui_wdecor_sysmenu_right(wdecor
, 42);
404 PCUT_ASSERT_TRUE(resp
.sysmenu_right
);
405 PCUT_ASSERT_INT_EQUALS(42, resp
.idev_id
);
407 ui_wdecor_destroy(wdecor
);
410 /** Test ui_wdecor_sysmenu_accel() */
411 PCUT_TEST(sysmenu_accel
)
417 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
418 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
420 /* Sysmenu accelerator callback with no callbacks set */
421 ui_wdecor_sysmenu_accel(wdecor
, 'a', 42);
423 /* Sysmenu accelerator callback with sysmenu callback not implemented */
424 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
425 ui_wdecor_sysmenu_accel(wdecor
, 'a', 42);
427 /* Sysmenu accelerator callback with real callback set */
428 resp
.sysmenu_accel
= false;
430 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
431 ui_wdecor_sysmenu_accel(wdecor
, 'a', 42);
432 PCUT_ASSERT_TRUE(resp
.sysmenu_accel
);
433 PCUT_ASSERT_INT_EQUALS('a', resp
.accel
);
434 PCUT_ASSERT_INT_EQUALS(42, resp
.idev_id
);
436 ui_wdecor_destroy(wdecor
);
439 /** Test ui_wdecor_minimize() */
446 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
447 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
449 /* Minimize callback with no callbacks set */
450 ui_wdecor_minimize(wdecor
);
452 /* Minimize callback with minimize callback not implemented */
453 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
454 ui_wdecor_minimize(wdecor
);
456 /* Minimize callback with real callback set */
457 resp
.minimize
= false;
458 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
459 ui_wdecor_minimize(wdecor
);
460 PCUT_ASSERT_TRUE(resp
.minimize
);
462 ui_wdecor_destroy(wdecor
);
465 /** Test ui_wdecor_maximize() */
472 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
473 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
475 /* Maximize callback with no callbacks set */
476 ui_wdecor_maximize(wdecor
);
478 /* Maxmimize callback with maximize callback not implemented */
479 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
480 ui_wdecor_maximize(wdecor
);
482 /* Maximize callback with real callback set */
483 resp
.maximize
= false;
484 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
485 ui_wdecor_maximize(wdecor
);
486 PCUT_ASSERT_TRUE(resp
.maximize
);
488 ui_wdecor_destroy(wdecor
);
491 /** Test ui_wdecor_unmaximize() */
492 PCUT_TEST(unmaximize
)
498 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
499 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
501 /* Unmaximize callback with no callbacks set */
502 ui_wdecor_unmaximize(wdecor
);
504 /* Unmaximize callback with unmaximize callback not implemented */
505 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
506 ui_wdecor_unmaximize(wdecor
);
508 /* Unmaximize callback with real callback set */
509 resp
.unmaximize
= false;
510 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
511 ui_wdecor_unmaximize(wdecor
);
512 PCUT_ASSERT_TRUE(resp
.unmaximize
);
514 ui_wdecor_destroy(wdecor
);
517 /** Test ui_wdecor_close() */
524 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
525 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
527 /* Close callback with no callbacks set */
528 ui_wdecor_close(wdecor
);
530 /* Close callback with close callback not implemented */
531 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
532 ui_wdecor_close(wdecor
);
534 /* Close callback with real callback set */
536 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
537 ui_wdecor_close(wdecor
);
538 PCUT_ASSERT_TRUE(resp
.close
);
540 ui_wdecor_destroy(wdecor
);
543 /** Test ui_wdecor_move() */
552 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
553 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
559 /* Move callback with no callbacks set */
560 ui_wdecor_move(wdecor
, &pos
, pos_id
);
562 /* Move callback with move callback not implemented */
563 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
564 ui_wdecor_move(wdecor
, &pos
, pos_id
);
566 /* Move callback with real callback set */
571 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
572 ui_wdecor_move(wdecor
, &pos
, pos_id
);
573 PCUT_ASSERT_TRUE(resp
.move
);
574 PCUT_ASSERT_INT_EQUALS(pos
.x
, resp
.pos
.x
);
575 PCUT_ASSERT_INT_EQUALS(pos
.y
, resp
.pos
.y
);
576 PCUT_ASSERT_INT_EQUALS(pos_id
, resp
.pos_id
);
578 ui_wdecor_destroy(wdecor
);
581 /** Test ui_wdecor_resize() */
587 ui_wdecor_rsztype_t rsztype
;
591 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
592 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
594 rsztype
= ui_wr_bottom
;
599 /* Resize callback with no callbacks set */
600 ui_wdecor_resize(wdecor
, rsztype
, &pos
, pos_id
);
602 /* Resize callback with move callback not implemented */
603 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
604 ui_wdecor_resize(wdecor
, rsztype
, &pos
, pos_id
);
606 /* Resize callback with real callback set */
608 resp
.rsztype
= ui_wr_none
;
611 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
612 ui_wdecor_resize(wdecor
, rsztype
, &pos
, pos_id
);
613 PCUT_ASSERT_TRUE(resp
.resize
);
614 PCUT_ASSERT_INT_EQUALS(rsztype
, resp
.rsztype
);
615 PCUT_ASSERT_INT_EQUALS(pos
.x
, resp
.pos
.x
);
616 PCUT_ASSERT_INT_EQUALS(pos
.y
, resp
.pos
.y
);
617 PCUT_ASSERT_INT_EQUALS(pos_id
, resp
.pos_id
);
619 ui_wdecor_destroy(wdecor
);
622 /** Test ui_wdecor_set_cursor() */
623 PCUT_TEST(set_cursor
)
628 ui_stock_cursor_t cursor
;
630 rc
= ui_wdecor_create(NULL
, "Hello", ui_wds_none
, &wdecor
);
631 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
633 cursor
= ui_curs_size_uldr
;
635 /* Set cursor callback with no callbacks set */
636 ui_wdecor_set_cursor(wdecor
, cursor
);
638 /* Set cursor callback with move callback not implemented */
639 ui_wdecor_set_cb(wdecor
, &dummy_wdecor_cb
, NULL
);
640 ui_wdecor_set_cursor(wdecor
, cursor
);
642 /* Set cursor callback with real callback set */
643 resp
.set_cursor
= false;
644 resp
.cursor
= ui_curs_arrow
;
645 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
646 ui_wdecor_set_cursor(wdecor
, cursor
);
647 PCUT_ASSERT_TRUE(resp
.set_cursor
);
648 PCUT_ASSERT_INT_EQUALS(cursor
, resp
.cursor
);
650 ui_wdecor_destroy(wdecor
);
653 /** Clicking the close button generates close callback */
654 PCUT_TEST(close_btn_clicked
)
656 gfx_context_t
*gc
= NULL
;
658 ui_resource_t
*resource
= NULL
;
664 memset(&tgc
, 0, sizeof(tgc
));
665 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
666 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
668 rc
= ui_resource_create(gc
, false, &resource
);
669 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
670 PCUT_ASSERT_NOT_NULL(resource
);
672 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
673 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
680 ui_wdecor_set_rect(wdecor
, &rect
);
682 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, (void *) &resp
);
686 ui_pbutton_clicked(wdecor
->btn_close
);
687 PCUT_ASSERT_TRUE(resp
.close
);
689 ui_wdecor_destroy(wdecor
);
690 ui_resource_destroy(resource
);
692 rc
= gfx_context_delete(gc
);
693 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
696 /** Button press on title bar generates move callback */
697 PCUT_TEST(pos_event_move
)
702 gfx_context_t
*gc
= NULL
;
705 ui_resource_t
*resource
= NULL
;
708 memset(&tgc
, 0, sizeof(tgc
));
709 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
710 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
712 rc
= ui_resource_create(gc
, false, &resource
);
713 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
714 PCUT_ASSERT_NOT_NULL(resource
);
716 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
717 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
724 ui_wdecor_set_rect(wdecor
, &rect
);
726 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, (void *) &resp
);
732 event
.type
= POS_PRESS
;
735 ui_wdecor_pos_event(wdecor
, &event
);
737 PCUT_ASSERT_TRUE(resp
.move
);
738 PCUT_ASSERT_INT_EQUALS(event
.hpos
, resp
.pos
.x
);
739 PCUT_ASSERT_INT_EQUALS(event
.vpos
, resp
.pos
.y
);
741 ui_wdecor_destroy(wdecor
);
742 ui_resource_destroy(resource
);
744 rc
= gfx_context_delete(gc
);
745 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
748 /** Pressing F10 generates sysmenu event.
750 * Note that in a window with menu bar the menu bar would claim F10
751 * so it would never be delivered to window decoration.
753 PCUT_TEST(kbd_f10_sysmenu
)
758 gfx_context_t
*gc
= NULL
;
761 ui_resource_t
*resource
= NULL
;
764 memset(&tgc
, 0, sizeof(tgc
));
765 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
766 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
768 rc
= ui_resource_create(gc
, false, &resource
);
769 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
770 PCUT_ASSERT_NOT_NULL(resource
);
772 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
773 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
780 ui_wdecor_set_rect(wdecor
, &rect
);
782 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, (void *) &resp
);
784 resp
.sysmenu_open
= false;
786 event
.type
= KEY_PRESS
;
790 ui_wdecor_kbd_event(wdecor
, &event
);
792 PCUT_ASSERT_TRUE(resp
.sysmenu_open
);
793 PCUT_ASSERT_INT_EQUALS(event
.kbd_id
, resp
.idev_id
);
795 ui_wdecor_destroy(wdecor
);
796 ui_resource_destroy(resource
);
798 rc
= gfx_context_delete(gc
);
799 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
802 /** Down key with active sysmenu handle generates sysmenu open event */
803 PCUT_TEST(kbd_down_sysmenu
)
808 gfx_context_t
*gc
= NULL
;
811 ui_resource_t
*resource
= NULL
;
814 memset(&tgc
, 0, sizeof(tgc
));
815 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
816 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
818 rc
= ui_resource_create(gc
, false, &resource
);
819 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
820 PCUT_ASSERT_NOT_NULL(resource
);
822 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
823 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
830 ui_wdecor_set_rect(wdecor
, &rect
);
832 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, (void *) &resp
);
834 ui_wdecor_sysmenu_hdl_set_active(wdecor
, true);
836 resp
.sysmenu_open
= false;
838 event
.type
= KEY_PRESS
;
842 ui_wdecor_kbd_event(wdecor
, &event
);
844 PCUT_ASSERT_TRUE(resp
.sysmenu_open
);
845 PCUT_ASSERT_INT_EQUALS(event
.kbd_id
, resp
.idev_id
);
847 ui_wdecor_destroy(wdecor
);
848 ui_resource_destroy(resource
);
850 rc
= gfx_context_delete(gc
);
851 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
854 /** Left key with active sysmenu handle generates sysmenu left event */
855 PCUT_TEST(kbd_left_sysmenu
)
860 gfx_context_t
*gc
= NULL
;
863 ui_resource_t
*resource
= NULL
;
866 memset(&tgc
, 0, sizeof(tgc
));
867 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
868 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
870 rc
= ui_resource_create(gc
, false, &resource
);
871 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
872 PCUT_ASSERT_NOT_NULL(resource
);
874 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
875 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
882 ui_wdecor_set_rect(wdecor
, &rect
);
884 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, (void *) &resp
);
886 ui_wdecor_sysmenu_hdl_set_active(wdecor
, true);
888 resp
.sysmenu_left
= false;
890 event
.type
= KEY_PRESS
;
894 ui_wdecor_kbd_event(wdecor
, &event
);
896 PCUT_ASSERT_TRUE(resp
.sysmenu_left
);
897 PCUT_ASSERT_INT_EQUALS(event
.kbd_id
, resp
.idev_id
);
899 ui_wdecor_destroy(wdecor
);
900 ui_resource_destroy(resource
);
902 rc
= gfx_context_delete(gc
);
903 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
906 /** Right key with active sysmenu handle generates sysmenu right event */
907 PCUT_TEST(kbd_right_sysmenu
)
912 gfx_context_t
*gc
= NULL
;
915 ui_resource_t
*resource
= NULL
;
918 memset(&tgc
, 0, sizeof(tgc
));
919 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
920 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
922 rc
= ui_resource_create(gc
, false, &resource
);
923 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
924 PCUT_ASSERT_NOT_NULL(resource
);
926 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
927 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
934 ui_wdecor_set_rect(wdecor
, &rect
);
936 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, (void *) &resp
);
938 ui_wdecor_sysmenu_hdl_set_active(wdecor
, true);
940 resp
.sysmenu_right
= false;
942 event
.type
= KEY_PRESS
;
944 event
.key
= KC_RIGHT
;
946 ui_wdecor_kbd_event(wdecor
, &event
);
948 PCUT_ASSERT_TRUE(resp
.sysmenu_right
);
949 PCUT_ASSERT_INT_EQUALS(event
.kbd_id
, resp
.idev_id
);
951 ui_wdecor_destroy(wdecor
);
952 ui_resource_destroy(resource
);
954 rc
= gfx_context_delete(gc
);
955 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
958 /** Character key with active sysmenu handle generates sysmenu accel event */
959 PCUT_TEST(kbd_accel_sysmenu
)
964 gfx_context_t
*gc
= NULL
;
967 ui_resource_t
*resource
= NULL
;
970 memset(&tgc
, 0, sizeof(tgc
));
971 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
972 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
974 rc
= ui_resource_create(gc
, false, &resource
);
975 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
976 PCUT_ASSERT_NOT_NULL(resource
);
978 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
979 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
986 ui_wdecor_set_rect(wdecor
, &rect
);
988 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, (void *) &resp
);
990 ui_wdecor_sysmenu_hdl_set_active(wdecor
, true);
992 resp
.sysmenu_accel
= false;
994 event
.type
= KEY_PRESS
;
999 ui_wdecor_kbd_event(wdecor
, &event
);
1001 PCUT_ASSERT_TRUE(resp
.sysmenu_accel
);
1002 PCUT_ASSERT_INT_EQUALS(event
.c
, resp
.accel
);
1003 PCUT_ASSERT_INT_EQUALS(event
.kbd_id
, resp
.idev_id
);
1005 ui_wdecor_destroy(wdecor
);
1006 ui_resource_destroy(resource
);
1008 rc
= gfx_context_delete(gc
);
1009 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1012 /** ui_wdecor_get_geom() with ui_wds_none produces the correct geometry */
1013 PCUT_TEST(get_geom_none
)
1015 gfx_context_t
*gc
= NULL
;
1017 ui_resource_t
*resource
= NULL
;
1018 ui_wdecor_t
*wdecor
;
1020 ui_wdecor_geom_t geom
;
1023 memset(&tgc
, 0, sizeof(tgc
));
1024 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
1025 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1027 rc
= ui_resource_create(gc
, false, &resource
);
1028 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1029 PCUT_ASSERT_NOT_NULL(resource
);
1031 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_none
, &wdecor
);
1032 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1039 ui_wdecor_set_rect(wdecor
, &rect
);
1040 ui_wdecor_get_geom(wdecor
, &geom
);
1042 PCUT_ASSERT_INT_EQUALS(10, geom
.interior_rect
.p0
.x
);
1043 PCUT_ASSERT_INT_EQUALS(20, geom
.interior_rect
.p0
.y
);
1044 PCUT_ASSERT_INT_EQUALS(100, geom
.interior_rect
.p1
.x
);
1045 PCUT_ASSERT_INT_EQUALS(200, geom
.interior_rect
.p1
.y
);
1047 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p0
.x
);
1048 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p0
.y
);
1049 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p1
.x
);
1050 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p1
.y
);
1052 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p0
.x
);
1053 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p0
.y
);
1054 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p1
.x
);
1055 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p1
.y
);
1057 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p0
.x
);
1058 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p0
.y
);
1059 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p1
.x
);
1060 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p1
.y
);
1062 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p0
.x
);
1063 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p0
.y
);
1064 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p1
.x
);
1065 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p1
.y
);
1067 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.x
);
1068 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.y
);
1069 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.x
);
1070 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.y
);
1072 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p0
.x
);
1073 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p0
.y
);
1074 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p1
.x
);
1075 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p1
.y
);
1077 PCUT_ASSERT_INT_EQUALS(10, geom
.app_area_rect
.p0
.x
);
1078 PCUT_ASSERT_INT_EQUALS(20, geom
.app_area_rect
.p0
.y
);
1079 PCUT_ASSERT_INT_EQUALS(100, geom
.app_area_rect
.p1
.x
);
1080 PCUT_ASSERT_INT_EQUALS(200, geom
.app_area_rect
.p1
.y
);
1082 ui_wdecor_destroy(wdecor
);
1083 ui_resource_destroy(resource
);
1085 rc
= gfx_context_delete(gc
);
1086 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1089 /** ui_wdecor_get_geom() with ui_wds_frame produces the correct geometry */
1090 PCUT_TEST(get_geom_frame
)
1092 gfx_context_t
*gc
= NULL
;
1094 ui_resource_t
*resource
= NULL
;
1095 ui_wdecor_t
*wdecor
;
1097 ui_wdecor_geom_t geom
;
1100 memset(&tgc
, 0, sizeof(tgc
));
1101 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
1102 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1104 rc
= ui_resource_create(gc
, false, &resource
);
1105 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1106 PCUT_ASSERT_NOT_NULL(resource
);
1108 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_frame
, &wdecor
);
1109 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1116 ui_wdecor_set_rect(wdecor
, &rect
);
1117 ui_wdecor_get_geom(wdecor
, &geom
);
1119 PCUT_ASSERT_INT_EQUALS(14, geom
.interior_rect
.p0
.x
);
1120 PCUT_ASSERT_INT_EQUALS(24, geom
.interior_rect
.p0
.y
);
1121 PCUT_ASSERT_INT_EQUALS(96, geom
.interior_rect
.p1
.x
);
1122 PCUT_ASSERT_INT_EQUALS(196, geom
.interior_rect
.p1
.y
);
1124 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p0
.x
);
1125 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p0
.y
);
1126 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p1
.x
);
1127 PCUT_ASSERT_INT_EQUALS(0, geom
.title_bar_rect
.p1
.y
);
1129 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p0
.x
);
1130 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p0
.y
);
1131 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p1
.x
);
1132 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p1
.y
);
1134 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p0
.x
);
1135 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p0
.y
);
1136 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p1
.x
);
1137 PCUT_ASSERT_INT_EQUALS(0, geom
.caption_rect
.p1
.y
);
1139 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p0
.x
);
1140 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p0
.y
);
1141 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p1
.x
);
1142 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p1
.y
);
1144 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.x
);
1145 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.y
);
1146 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.x
);
1147 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.y
);
1149 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p0
.x
);
1150 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p0
.y
);
1151 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p1
.x
);
1152 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p1
.y
);
1154 PCUT_ASSERT_INT_EQUALS(14, geom
.app_area_rect
.p0
.x
);
1155 PCUT_ASSERT_INT_EQUALS(24, geom
.app_area_rect
.p0
.y
);
1156 PCUT_ASSERT_INT_EQUALS(96, geom
.app_area_rect
.p1
.x
);
1157 PCUT_ASSERT_INT_EQUALS(196, geom
.app_area_rect
.p1
.y
);
1159 ui_wdecor_destroy(wdecor
);
1160 ui_resource_destroy(resource
);
1162 rc
= gfx_context_delete(gc
);
1163 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1166 /** ui_wdecor_get_geom() with ui_wds_frame | ui_wds_titlebar */
1167 PCUT_TEST(get_geom_frame_titlebar
)
1169 gfx_context_t
*gc
= NULL
;
1171 ui_resource_t
*resource
= NULL
;
1172 ui_wdecor_t
*wdecor
;
1174 ui_wdecor_geom_t geom
;
1177 memset(&tgc
, 0, sizeof(tgc
));
1178 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
1179 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1181 rc
= ui_resource_create(gc
, false, &resource
);
1182 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1183 PCUT_ASSERT_NOT_NULL(resource
);
1185 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_frame
| ui_wds_titlebar
,
1187 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1194 ui_wdecor_set_rect(wdecor
, &rect
);
1195 ui_wdecor_get_geom(wdecor
, &geom
);
1197 PCUT_ASSERT_INT_EQUALS(14, geom
.interior_rect
.p0
.x
);
1198 PCUT_ASSERT_INT_EQUALS(24, geom
.interior_rect
.p0
.y
);
1199 PCUT_ASSERT_INT_EQUALS(96, geom
.interior_rect
.p1
.x
);
1200 PCUT_ASSERT_INT_EQUALS(196, geom
.interior_rect
.p1
.y
);
1202 PCUT_ASSERT_INT_EQUALS(14, geom
.title_bar_rect
.p0
.x
);
1203 PCUT_ASSERT_INT_EQUALS(24, geom
.title_bar_rect
.p0
.y
);
1204 PCUT_ASSERT_INT_EQUALS(96, geom
.title_bar_rect
.p1
.x
);
1205 PCUT_ASSERT_INT_EQUALS(46, geom
.title_bar_rect
.p1
.y
);
1207 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p0
.x
);
1208 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p0
.y
);
1209 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p1
.x
);
1210 PCUT_ASSERT_INT_EQUALS(0, geom
.sysmenu_hdl_rect
.p1
.y
);
1212 PCUT_ASSERT_INT_EQUALS(18, geom
.caption_rect
.p0
.x
);
1213 PCUT_ASSERT_INT_EQUALS(24, geom
.caption_rect
.p0
.y
);
1214 PCUT_ASSERT_INT_EQUALS(91, geom
.caption_rect
.p1
.x
);
1215 PCUT_ASSERT_INT_EQUALS(46, geom
.caption_rect
.p1
.y
);
1217 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p0
.x
);
1218 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p0
.y
);
1219 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p1
.x
);
1220 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_min_rect
.p1
.y
);
1222 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.x
);
1223 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.y
);
1224 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.x
);
1225 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.y
);
1227 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p0
.x
);
1228 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p0
.y
);
1229 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p1
.x
);
1230 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_close_rect
.p1
.y
);
1232 PCUT_ASSERT_INT_EQUALS(14, geom
.app_area_rect
.p0
.x
);
1233 PCUT_ASSERT_INT_EQUALS(46, geom
.app_area_rect
.p0
.y
);
1234 PCUT_ASSERT_INT_EQUALS(96, geom
.app_area_rect
.p1
.x
);
1235 PCUT_ASSERT_INT_EQUALS(196, geom
.app_area_rect
.p1
.y
);
1237 ui_wdecor_destroy(wdecor
);
1238 ui_resource_destroy(resource
);
1240 rc
= gfx_context_delete(gc
);
1241 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1244 /** ui_wdecor_get_geom() with ui_wds_decorated produces the correct geometry */
1245 PCUT_TEST(get_geom_decorated
)
1247 gfx_context_t
*gc
= NULL
;
1249 ui_resource_t
*resource
= NULL
;
1250 ui_wdecor_t
*wdecor
;
1252 ui_wdecor_geom_t geom
;
1255 memset(&tgc
, 0, sizeof(tgc
));
1256 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
1257 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1259 rc
= ui_resource_create(gc
, false, &resource
);
1260 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1261 PCUT_ASSERT_NOT_NULL(resource
);
1263 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_decorated
, &wdecor
);
1264 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1271 ui_wdecor_set_rect(wdecor
, &rect
);
1272 ui_wdecor_get_geom(wdecor
, &geom
);
1274 PCUT_ASSERT_INT_EQUALS(14, geom
.interior_rect
.p0
.x
);
1275 PCUT_ASSERT_INT_EQUALS(24, geom
.interior_rect
.p0
.y
);
1276 PCUT_ASSERT_INT_EQUALS(96, geom
.interior_rect
.p1
.x
);
1277 PCUT_ASSERT_INT_EQUALS(196, geom
.interior_rect
.p1
.y
);
1279 PCUT_ASSERT_INT_EQUALS(14, geom
.title_bar_rect
.p0
.x
);
1280 PCUT_ASSERT_INT_EQUALS(24, geom
.title_bar_rect
.p0
.y
);
1281 PCUT_ASSERT_INT_EQUALS(96, geom
.title_bar_rect
.p1
.x
);
1282 PCUT_ASSERT_INT_EQUALS(46, geom
.title_bar_rect
.p1
.y
);
1284 PCUT_ASSERT_INT_EQUALS(15, geom
.sysmenu_hdl_rect
.p0
.x
);
1285 PCUT_ASSERT_INT_EQUALS(25, geom
.sysmenu_hdl_rect
.p0
.y
);
1286 PCUT_ASSERT_INT_EQUALS(35, geom
.sysmenu_hdl_rect
.p1
.x
);
1287 PCUT_ASSERT_INT_EQUALS(45, geom
.sysmenu_hdl_rect
.p1
.y
);
1289 PCUT_ASSERT_INT_EQUALS(38, geom
.caption_rect
.p0
.x
);
1290 PCUT_ASSERT_INT_EQUALS(24, geom
.caption_rect
.p0
.y
);
1291 PCUT_ASSERT_INT_EQUALS(51, geom
.caption_rect
.p1
.x
);
1292 PCUT_ASSERT_INT_EQUALS(46, geom
.caption_rect
.p1
.y
);
1294 PCUT_ASSERT_INT_EQUALS(55, geom
.btn_min_rect
.p0
.x
);
1295 PCUT_ASSERT_INT_EQUALS(25, geom
.btn_min_rect
.p0
.y
);
1296 PCUT_ASSERT_INT_EQUALS(75, geom
.btn_min_rect
.p1
.x
);
1297 PCUT_ASSERT_INT_EQUALS(45, geom
.btn_min_rect
.p1
.y
);
1299 /* Maximize button is not in ui_wds_decorated */
1300 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.x
);
1301 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p0
.y
);
1302 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.x
);
1303 PCUT_ASSERT_INT_EQUALS(0, geom
.btn_max_rect
.p1
.y
);
1305 PCUT_ASSERT_INT_EQUALS(75, geom
.btn_close_rect
.p0
.x
);
1306 PCUT_ASSERT_INT_EQUALS(25, geom
.btn_close_rect
.p0
.y
);
1307 PCUT_ASSERT_INT_EQUALS(95, geom
.btn_close_rect
.p1
.x
);
1308 PCUT_ASSERT_INT_EQUALS(45, geom
.btn_close_rect
.p1
.y
);
1310 PCUT_ASSERT_INT_EQUALS(14, geom
.app_area_rect
.p0
.x
);
1311 PCUT_ASSERT_INT_EQUALS(46, geom
.app_area_rect
.p0
.y
);
1312 PCUT_ASSERT_INT_EQUALS(96, geom
.app_area_rect
.p1
.x
);
1313 PCUT_ASSERT_INT_EQUALS(196, geom
.app_area_rect
.p1
.y
);
1315 ui_wdecor_destroy(wdecor
);
1316 ui_resource_destroy(resource
);
1318 rc
= gfx_context_delete(gc
);
1319 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1322 /** ui_wdecor_rect_from_app() correctly converts application to window rect */
1323 PCUT_TEST(rect_from_app
)
1330 rc
= ui_create_disp(NULL
, &ui
);
1331 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1338 ui_wdecor_rect_from_app(ui
, ui_wds_none
, &arect
, &rect
);
1340 PCUT_ASSERT_INT_EQUALS(14, rect
.p0
.x
);
1341 PCUT_ASSERT_INT_EQUALS(46, rect
.p0
.y
);
1342 PCUT_ASSERT_INT_EQUALS(96, rect
.p1
.x
);
1343 PCUT_ASSERT_INT_EQUALS(196, rect
.p1
.y
);
1345 ui_wdecor_rect_from_app(ui
, ui_wds_frame
, &arect
, &rect
);
1347 PCUT_ASSERT_INT_EQUALS(10, rect
.p0
.x
);
1348 PCUT_ASSERT_INT_EQUALS(42, rect
.p0
.y
);
1349 PCUT_ASSERT_INT_EQUALS(100, rect
.p1
.x
);
1350 PCUT_ASSERT_INT_EQUALS(200, rect
.p1
.y
);
1352 ui_wdecor_rect_from_app(ui
, ui_wds_decorated
, &arect
, &rect
);
1354 PCUT_ASSERT_INT_EQUALS(10, rect
.p0
.x
);
1355 PCUT_ASSERT_INT_EQUALS(20, rect
.p0
.y
);
1356 PCUT_ASSERT_INT_EQUALS(100, rect
.p1
.x
);
1357 PCUT_ASSERT_INT_EQUALS(200, rect
.p1
.y
);
1362 /** Test ui_wdecor_get_rsztype() */
1363 PCUT_TEST(get_rsztype
)
1365 gfx_context_t
*gc
= NULL
;
1367 ui_resource_t
*resource
= NULL
;
1368 ui_wdecor_t
*wdecor
;
1370 ui_wdecor_rsztype_t rsztype
;
1374 memset(&tgc
, 0, sizeof(tgc
));
1375 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
1376 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1378 rc
= ui_resource_create(gc
, false, &resource
);
1379 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1380 PCUT_ASSERT_NOT_NULL(resource
);
1382 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_resizable
, &wdecor
);
1383 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1390 ui_wdecor_set_rect(wdecor
, &rect
);
1392 /* Outside of the window */
1395 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1396 PCUT_ASSERT_EQUALS(ui_wr_none
, rsztype
);
1398 /* Middle of the window */
1401 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1402 PCUT_ASSERT_EQUALS(ui_wr_none
, rsztype
);
1404 /* Top-left corner, but not on edge */
1407 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1408 PCUT_ASSERT_EQUALS(ui_wr_none
, rsztype
);
1410 /* Top-left corner on top edge */
1413 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1414 PCUT_ASSERT_EQUALS(ui_wr_top_left
, rsztype
);
1416 /* Top-left corner on left edge */
1419 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1420 PCUT_ASSERT_EQUALS(ui_wr_top_left
, rsztype
);
1422 /* Top-right corner on top edge */
1425 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1426 PCUT_ASSERT_EQUALS(ui_wr_top_right
, rsztype
);
1428 /* Top-right corner on right edge */
1431 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1432 PCUT_ASSERT_EQUALS(ui_wr_top_right
, rsztype
);
1437 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1438 PCUT_ASSERT_EQUALS(ui_wr_top
, rsztype
);
1443 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1444 PCUT_ASSERT_EQUALS(ui_wr_bottom
, rsztype
);
1449 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1450 PCUT_ASSERT_EQUALS(ui_wr_left
, rsztype
);
1455 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1456 PCUT_ASSERT_EQUALS(ui_wr_right
, rsztype
);
1458 ui_wdecor_destroy(wdecor
);
1460 /* Non-resizable window */
1462 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_none
, &wdecor
);
1463 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1470 ui_wdecor_set_rect(wdecor
, &rect
);
1474 rsztype
= ui_wdecor_get_rsztype(wdecor
, &pos
);
1475 PCUT_ASSERT_EQUALS(ui_wr_none
, rsztype
);
1477 ui_wdecor_destroy(wdecor
);
1478 ui_resource_destroy(resource
);
1480 rc
= gfx_context_delete(gc
);
1481 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1484 /** Test ui_wdecor_cursor_from_rsztype() */
1485 PCUT_TEST(cursor_from_rsztype
)
1487 PCUT_ASSERT_EQUALS(ui_curs_arrow
,
1488 ui_wdecor_cursor_from_rsztype(ui_wr_none
));
1489 PCUT_ASSERT_EQUALS(ui_curs_size_ud
,
1490 ui_wdecor_cursor_from_rsztype(ui_wr_top
));
1491 PCUT_ASSERT_EQUALS(ui_curs_size_ud
,
1492 ui_wdecor_cursor_from_rsztype(ui_wr_bottom
));
1493 PCUT_ASSERT_EQUALS(ui_curs_size_lr
,
1494 ui_wdecor_cursor_from_rsztype(ui_wr_left
));
1495 PCUT_ASSERT_EQUALS(ui_curs_size_lr
,
1496 ui_wdecor_cursor_from_rsztype(ui_wr_right
));
1497 PCUT_ASSERT_EQUALS(ui_curs_size_uldr
,
1498 ui_wdecor_cursor_from_rsztype(ui_wr_top_left
));
1499 PCUT_ASSERT_EQUALS(ui_curs_size_uldr
,
1500 ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right
));
1501 PCUT_ASSERT_EQUALS(ui_curs_size_urdl
,
1502 ui_wdecor_cursor_from_rsztype(ui_wr_top_right
));
1503 PCUT_ASSERT_EQUALS(ui_curs_size_urdl
,
1504 ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left
));
1507 /** Test ui_wdecor_frame_pos_event() */
1508 PCUT_TEST(frame_pos_event
)
1510 gfx_context_t
*gc
= NULL
;
1512 ui_resource_t
*resource
= NULL
;
1513 ui_wdecor_t
*wdecor
;
1515 test_cb_resp_t resp
;
1519 memset(&tgc
, 0, sizeof(tgc
));
1520 rc
= gfx_context_new(&ops
, &tgc
, &gc
);
1521 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1523 rc
= ui_resource_create(gc
, false, &resource
);
1524 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1525 PCUT_ASSERT_NOT_NULL(resource
);
1527 rc
= ui_wdecor_create(resource
, "Hello", ui_wds_resizable
, &wdecor
);
1528 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1535 ui_wdecor_set_rect(wdecor
, &rect
);
1536 ui_wdecor_set_cb(wdecor
, &test_wdecor_cb
, &resp
);
1538 /* Release on window border should do nothing */
1539 resp
.resize
= false;
1540 event
.type
= POS_RELEASE
;
1543 ui_wdecor_frame_pos_event(wdecor
, &event
);
1544 PCUT_ASSERT_FALSE(resp
.resize
);
1546 /* Press in the middle of the window should do nothing */
1547 resp
.resize
= false;
1548 event
.type
= POS_PRESS
;
1551 ui_wdecor_frame_pos_event(wdecor
, &event
);
1552 PCUT_ASSERT_FALSE(resp
.resize
);
1554 /* Press on window border should cause resize to be called */
1555 resp
.resize
= false;
1556 event
.type
= POS_PRESS
;
1559 ui_wdecor_frame_pos_event(wdecor
, &event
);
1560 PCUT_ASSERT_TRUE(resp
.resize
);
1562 ui_wdecor_destroy(wdecor
);
1563 ui_resource_destroy(resource
);
1565 rc
= gfx_context_delete(gc
);
1566 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
1569 static errno_t
testgc_set_clip_rect(void *arg
, gfx_rect_t
*rect
)
1576 static errno_t
testgc_set_color(void *arg
, gfx_color_t
*color
)
1583 static errno_t
testgc_fill_rect(void *arg
, gfx_rect_t
*rect
)
1590 static errno_t
testgc_update(void *arg
)
1596 static errno_t
testgc_bitmap_create(void *arg
, gfx_bitmap_params_t
*params
,
1597 gfx_bitmap_alloc_t
*alloc
, void **rbm
)
1599 test_gc_t
*tgc
= (test_gc_t
*) arg
;
1600 testgc_bitmap_t
*tbm
;
1602 tbm
= calloc(1, sizeof(testgc_bitmap_t
));
1606 if (alloc
== NULL
) {
1607 tbm
->alloc
.pitch
= (params
->rect
.p1
.x
- params
->rect
.p0
.x
) *
1609 tbm
->alloc
.off0
= 0;
1610 tbm
->alloc
.pixels
= calloc(sizeof(uint32_t),
1611 (params
->rect
.p1
.x
- params
->rect
.p0
.x
) *
1612 (params
->rect
.p1
.y
- params
->rect
.p0
.y
));
1613 tbm
->myalloc
= true;
1614 if (tbm
->alloc
.pixels
== NULL
) {
1619 tbm
->alloc
= *alloc
;
1623 tgc
->bm_created
= true;
1624 tgc
->bm_params
= *params
;
1625 tgc
->bm_pixels
= tbm
->alloc
.pixels
;
1630 static errno_t
testgc_bitmap_destroy(void *bm
)
1632 testgc_bitmap_t
*tbm
= (testgc_bitmap_t
*)bm
;
1634 free(tbm
->alloc
.pixels
);
1635 tbm
->tgc
->bm_destroyed
= true;
1640 static errno_t
testgc_bitmap_render(void *bm
, gfx_rect_t
*srect
,
1643 testgc_bitmap_t
*tbm
= (testgc_bitmap_t
*)bm
;
1644 tbm
->tgc
->bm_rendered
= true;
1645 tbm
->tgc
->bm_srect
= *srect
;
1646 tbm
->tgc
->bm_offs
= *offs
;
1650 static errno_t
testgc_bitmap_get_alloc(void *bm
, gfx_bitmap_alloc_t
*alloc
)
1652 testgc_bitmap_t
*tbm
= (testgc_bitmap_t
*)bm
;
1653 *alloc
= tbm
->alloc
;
1654 tbm
->tgc
->bm_got_alloc
= true;
1658 static void test_wdecor_sysmenu_open(ui_wdecor_t
*wdecor
, void *arg
,
1661 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1663 resp
->sysmenu_open
= true;
1664 resp
->idev_id
= idev_id
;
1667 static void test_wdecor_sysmenu_left(ui_wdecor_t
*wdecor
, void *arg
,
1670 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1672 resp
->sysmenu_left
= true;
1673 resp
->idev_id
= idev_id
;
1676 static void test_wdecor_sysmenu_right(ui_wdecor_t
*wdecor
, void *arg
,
1679 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1681 resp
->sysmenu_right
= true;
1682 resp
->idev_id
= idev_id
;
1685 static void test_wdecor_sysmenu_accel(ui_wdecor_t
*wdecor
, void *arg
,
1686 char32_t accel
, sysarg_t idev_id
)
1688 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1690 resp
->sysmenu_accel
= true;
1691 resp
->accel
= accel
;
1692 resp
->idev_id
= idev_id
;
1695 static void test_wdecor_minimize(ui_wdecor_t
*wdecor
, void *arg
)
1697 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1699 resp
->minimize
= true;
1702 static void test_wdecor_maximize(ui_wdecor_t
*wdecor
, void *arg
)
1704 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1706 resp
->maximize
= true;
1709 static void test_wdecor_unmaximize(ui_wdecor_t
*wdecor
, void *arg
)
1711 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1713 resp
->unmaximize
= true;
1716 static void test_wdecor_close(ui_wdecor_t
*wdecor
, void *arg
)
1718 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1723 static void test_wdecor_move(ui_wdecor_t
*wdecor
, void *arg
, gfx_coord2_t
*pos
,
1726 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1730 resp
->pos_id
= pos_id
;
1733 static void test_wdecor_resize(ui_wdecor_t
*wdecor
, void *arg
,
1734 ui_wdecor_rsztype_t rsztype
, gfx_coord2_t
*pos
, sysarg_t pos_id
)
1736 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1738 resp
->resize
= true;
1739 resp
->rsztype
= rsztype
;
1741 resp
->pos_id
= pos_id
;
1744 static void test_wdecor_set_cursor(ui_wdecor_t
*wdecor
, void *arg
,
1745 ui_stock_cursor_t cursor
)
1747 test_cb_resp_t
*resp
= (test_cb_resp_t
*) arg
;
1749 resp
->set_cursor
= true;
1750 resp
->cursor
= cursor
;
1753 PCUT_EXPORT(wdecor
);