Editor needs to hide cursor when menu bar is activated
[helenos.git] / uspace / lib / ui / test / tab.c
blobe0331eb2685bf486995a19009f4d78717c7f72a5
1 /*
2 * Copyright (c) 2023 Jiri Svoboda
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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>
31 #include <mem.h>
32 #include <pcut/pcut.h>
33 #include <stdbool.h>
34 #include <str.h>
35 #include <ui/control.h>
36 #include <ui/tab.h>
37 #include <ui/tabset.h>
38 #include <ui/testctl.h>
39 #include <ui/ui.h>
40 #include <ui/window.h>
41 #include "../private/resource.h"
42 #include "../private/tab.h"
43 #include "../private/tabset.h"
45 PCUT_INIT;
47 PCUT_TEST_SUITE(tab);
49 /** Create and destroy tab */
50 PCUT_TEST(create_destroy)
52 ui_t *ui = NULL;
53 ui_window_t *window = NULL;
54 ui_wnd_params_t params;
55 ui_resource_t *res;
56 ui_tab_set_t *tabset = NULL;
57 ui_tab_t *tab = NULL;
58 errno_t rc;
60 rc = ui_create_disp(NULL, &ui);
61 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
63 ui_wnd_params_init(&params);
64 params.caption = "Hello";
66 rc = ui_window_create(ui, &params, &window);
67 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
68 PCUT_ASSERT_NOT_NULL(window);
70 res = ui_window_get_res(window);
72 rc = ui_tab_set_create(res, &tabset);
73 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
75 rc = ui_tab_create(tabset, "Test", &tab);
76 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
77 PCUT_ASSERT_NOT_NULL(tab);
80 * Normally we don't need to destroy a tab explicitly, it will
81 * be destroyed along with tab bar, but here we'll test destroying
82 * it explicitly.
84 ui_tab_destroy(tab);
85 ui_tab_set_destroy(tabset);
87 ui_window_destroy(window);
88 ui_destroy(ui);
91 /** Destroy tab implicitly by destroying the tab set */
92 PCUT_TEST(implicit_destroy)
94 ui_t *ui = NULL;
95 ui_window_t *window = NULL;
96 ui_wnd_params_t params;
97 ui_resource_t *res;
98 ui_tab_set_t *tabset = NULL;
99 ui_tab_t *tab = NULL;
100 errno_t rc;
102 rc = ui_create_disp(NULL, &ui);
103 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
105 ui_wnd_params_init(&params);
106 params.caption = "Hello";
108 rc = ui_window_create(ui, &params, &window);
109 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
110 PCUT_ASSERT_NOT_NULL(window);
112 res = ui_window_get_res(window);
114 rc = ui_tab_set_create(res, &tabset);
115 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
117 rc = ui_tab_create(tabset, "Test", &tab);
118 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
119 PCUT_ASSERT_NOT_NULL(tab);
121 /* Let the tab be destroyed as part of destroying tab set */
122 ui_tab_set_destroy(tabset);
124 ui_window_destroy(window);
125 ui_destroy(ui);
128 /** ui_tab_destroy() can take NULL argument (no-op) */
129 PCUT_TEST(destroy_null)
131 ui_tab_destroy(NULL);
134 /** ui_tab_first() / ui_tab_next() iterate over tabs */
135 PCUT_TEST(first_next)
137 ui_t *ui = NULL;
138 ui_window_t *window = NULL;
139 ui_wnd_params_t params;
140 ui_resource_t *res;
141 ui_tab_set_t *tabset = NULL;
142 ui_tab_t *tab1 = NULL;
143 ui_tab_t *tab2 = NULL;
144 ui_tab_t *t;
145 errno_t rc;
147 rc = ui_create_disp(NULL, &ui);
148 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
150 ui_wnd_params_init(&params);
151 params.caption = "Hello";
153 rc = ui_window_create(ui, &params, &window);
154 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
155 PCUT_ASSERT_NOT_NULL(window);
157 res = ui_window_get_res(window);
159 rc = ui_tab_set_create(res, &tabset);
160 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
161 PCUT_ASSERT_NOT_NULL(tabset);
163 rc = ui_tab_create(tabset, "Test 1", &tab1);
164 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
165 PCUT_ASSERT_NOT_NULL(tab1);
167 rc = ui_tab_create(tabset, "Test 2", &tab2);
168 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
169 PCUT_ASSERT_NOT_NULL(tab2);
171 t = ui_tab_first(tabset);
172 PCUT_ASSERT_EQUALS(tab1, t);
174 t = ui_tab_next(t);
175 PCUT_ASSERT_EQUALS(tab2, t);
177 t = ui_tab_next(t);
178 PCUT_ASSERT_NULL(t);
180 ui_tab_set_destroy(tabset);
181 ui_window_destroy(window);
182 ui_destroy(ui);
185 /** ui_tab_last() / ui_tab_prev() iterate over tabs in reverse */
186 PCUT_TEST(last_prev)
188 ui_t *ui = NULL;
189 ui_window_t *window = NULL;
190 ui_wnd_params_t params;
191 ui_resource_t *res;
192 ui_tab_set_t *tabset = NULL;
193 ui_tab_t *tab1 = NULL;
194 ui_tab_t *tab2 = NULL;
195 ui_tab_t *t;
196 errno_t rc;
198 rc = ui_create_disp(NULL, &ui);
199 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
201 ui_wnd_params_init(&params);
202 params.caption = "Hello";
204 rc = ui_window_create(ui, &params, &window);
205 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
206 PCUT_ASSERT_NOT_NULL(window);
208 res = ui_window_get_res(window);
210 rc = ui_tab_set_create(res, &tabset);
211 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
212 PCUT_ASSERT_NOT_NULL(tabset);
214 rc = ui_tab_create(tabset, "Test 1", &tab1);
215 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
216 PCUT_ASSERT_NOT_NULL(tab1);
218 rc = ui_tab_create(tabset, "Test 2", &tab2);
219 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
220 PCUT_ASSERT_NOT_NULL(tab2);
222 t = ui_tab_last(tabset);
223 PCUT_ASSERT_EQUALS(tab2, t);
225 t = ui_tab_prev(t);
226 PCUT_ASSERT_EQUALS(tab1, t);
228 t = ui_tab_prev(t);
229 PCUT_ASSERT_NULL(t);
231 ui_tab_set_destroy(tabset);
232 ui_window_destroy(window);
233 ui_destroy(ui);
236 /** ui_tab_is_selected() correctly returns tab state */
237 PCUT_TEST(is_selected)
239 ui_t *ui = NULL;
240 ui_window_t *window = NULL;
241 ui_wnd_params_t params;
242 ui_resource_t *res;
243 ui_tab_set_t *tabset = NULL;
244 ui_tab_t *tab1 = NULL;
245 ui_tab_t *tab2 = NULL;
246 errno_t rc;
248 rc = ui_create_disp(NULL, &ui);
249 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
251 ui_wnd_params_init(&params);
252 params.caption = "Hello";
254 rc = ui_window_create(ui, &params, &window);
255 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
256 PCUT_ASSERT_NOT_NULL(window);
258 res = ui_window_get_res(window);
260 rc = ui_tab_set_create(res, &tabset);
261 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
262 PCUT_ASSERT_NOT_NULL(tabset);
264 rc = ui_tab_create(tabset, "Test 1", &tab1);
265 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
267 /* The first added tab should be automatically selected */
268 PCUT_ASSERT_TRUE(ui_tab_is_selected(tab1));
270 rc = ui_tab_create(tabset, "Test 2", &tab2);
271 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
273 /* After adding a second tab the first should still be selected */
274 PCUT_ASSERT_TRUE(ui_tab_is_selected(tab1));
275 PCUT_ASSERT_FALSE(ui_tab_is_selected(tab2));
277 /* Select second tab */
278 ui_tab_set_select(tabset, tab2);
280 /* Now the second tab should be selected */
281 PCUT_ASSERT_FALSE(ui_tab_is_selected(tab1));
282 PCUT_ASSERT_TRUE(ui_tab_is_selected(tab2));
284 ui_tab_set_destroy(tabset);
285 ui_window_destroy(window);
286 ui_destroy(ui);
289 /** ui_tab_add() adds control to tab */
290 PCUT_TEST(add)
292 ui_t *ui = NULL;
293 ui_window_t *window = NULL;
294 ui_wnd_params_t params;
295 ui_resource_t *res;
296 ui_tab_set_t *tabset = NULL;
297 ui_tab_t *tab = NULL;
298 ui_test_ctl_t *testctl = NULL;
299 ui_tc_resp_t resp;
300 errno_t rc;
302 rc = ui_create_disp(NULL, &ui);
303 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
305 ui_wnd_params_init(&params);
306 params.caption = "Hello";
308 rc = ui_window_create(ui, &params, &window);
309 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
310 PCUT_ASSERT_NOT_NULL(window);
312 res = ui_window_get_res(window);
314 rc = ui_tab_set_create(res, &tabset);
315 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
316 PCUT_ASSERT_NOT_NULL(tabset);
318 rc = ui_tab_create(tabset, "Test", &tab);
319 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
320 PCUT_ASSERT_NOT_NULL(tab);
322 rc = ui_test_ctl_create(&resp, &testctl);
323 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
325 /* Add test control to tab */
326 ui_tab_add(tab, ui_test_ctl_ctl(testctl));
328 resp.destroy = false;
330 ui_tab_set_destroy(tabset);
332 /* Destroying the tab should have destroyed the control as well */
333 PCUT_ASSERT_TRUE(resp.destroy);
335 ui_window_destroy(window);
336 ui_destroy(ui);
339 /** ui_tab_remove() removes control to tab */
340 PCUT_TEST(remove)
342 ui_t *ui = NULL;
343 ui_window_t *window = NULL;
344 ui_wnd_params_t params;
345 ui_resource_t *res;
346 ui_tab_set_t *tabset = NULL;
347 ui_tab_t *tab = NULL;
348 ui_test_ctl_t *testctl = NULL;
349 ui_tc_resp_t resp;
350 errno_t rc;
352 rc = ui_create_disp(NULL, &ui);
353 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
355 ui_wnd_params_init(&params);
356 params.caption = "Hello";
358 rc = ui_window_create(ui, &params, &window);
359 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
360 PCUT_ASSERT_NOT_NULL(window);
362 res = ui_window_get_res(window);
364 rc = ui_tab_set_create(res, &tabset);
365 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
366 PCUT_ASSERT_NOT_NULL(tabset);
368 rc = ui_tab_create(tabset, "Test", &tab);
369 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
370 PCUT_ASSERT_NOT_NULL(tab);
372 rc = ui_test_ctl_create(&resp, &testctl);
373 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
375 /* Add test control to tab */
376 ui_tab_add(tab, ui_test_ctl_ctl(testctl));
378 /* Rmove control from tab */
379 ui_tab_remove(tab, ui_test_ctl_ctl(testctl));
381 resp.destroy = false;
383 ui_tab_set_destroy(tabset);
385 /* Destroying the tab should NOT have destroyed the control */
386 PCUT_ASSERT_FALSE(resp.destroy);
388 ui_test_ctl_destroy(testctl);
389 ui_window_destroy(window);
390 ui_destroy(ui);
393 /** Paint tab */
394 PCUT_TEST(paint)
396 ui_t *ui = NULL;
397 ui_window_t *window = NULL;
398 ui_wnd_params_t params;
399 ui_resource_t *res;
400 ui_tab_set_t *tabset = NULL;
401 ui_tab_t *tab = NULL;
402 errno_t rc;
404 rc = ui_create_disp(NULL, &ui);
405 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
407 ui_wnd_params_init(&params);
408 params.caption = "Hello";
410 rc = ui_window_create(ui, &params, &window);
411 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
412 PCUT_ASSERT_NOT_NULL(window);
414 res = ui_window_get_res(window);
416 rc = ui_tab_set_create(res, &tabset);
417 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
418 PCUT_ASSERT_NOT_NULL(tabset);
420 rc = ui_tab_create(tabset, "Test", &tab);
421 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
422 PCUT_ASSERT_NOT_NULL(tab);
424 rc = ui_tab_paint(tab);
425 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
427 ui_tab_set_destroy(tabset);
428 ui_window_destroy(window);
429 ui_destroy(ui);
432 /** ui_tab_kbd_event() delivers keyboard event */
433 PCUT_TEST(kbd_event)
435 ui_t *ui = NULL;
436 ui_window_t *window = NULL;
437 ui_wnd_params_t params;
438 ui_resource_t *res;
439 ui_tab_set_t *tabset = NULL;
440 ui_tab_t *tab = NULL;
441 ui_evclaim_t claimed;
442 kbd_event_t event;
443 ui_test_ctl_t *testctl = NULL;
444 ui_tc_resp_t resp;
445 errno_t rc;
447 rc = ui_create_disp(NULL, &ui);
448 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
450 ui_wnd_params_init(&params);
451 params.caption = "Hello";
453 rc = ui_window_create(ui, &params, &window);
454 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
455 PCUT_ASSERT_NOT_NULL(window);
457 res = ui_window_get_res(window);
459 rc = ui_tab_set_create(res, &tabset);
460 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
461 PCUT_ASSERT_NOT_NULL(tabset);
463 /* Without anytabs, event should be unclaimed */
464 event.type = KEY_PRESS;
465 event.key = KC_ENTER;
466 event.mods = 0;
467 claimed = ui_tab_set_kbd_event(tabset, &event);
468 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
469 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
471 rc = ui_tab_create(tabset, "Test", &tab);
472 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
473 PCUT_ASSERT_NOT_NULL(tab);
475 rc = ui_test_ctl_create(&resp, &testctl);
476 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
478 /* Set up response */
479 ui_tab_add(tab, ui_test_ctl_ctl(testctl));
480 resp.claim = ui_claimed;
481 resp.kbd = false;
483 /* Send keyboard event */
484 event.type = KEY_PRESS;
485 event.key = KC_F10;
486 event.mods = 0;
487 claimed = ui_tab_kbd_event(tab, &event);
488 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
489 PCUT_ASSERT_EQUALS(ui_claimed, claimed);
491 /* Make sure event was delivered */
492 PCUT_ASSERT_TRUE(resp.kbd);
493 PCUT_ASSERT_EQUALS(event.type, resp.kevent.type);
494 PCUT_ASSERT_EQUALS(event.key, resp.kevent.key);
495 PCUT_ASSERT_EQUALS(event.mods, resp.kevent.mods);
497 ui_tab_set_destroy(tabset);
498 ui_window_destroy(window);
499 ui_destroy(ui);
502 /** ui_tab_pos_event() delivers position event */
503 PCUT_TEST(pos_event)
505 ui_t *ui = NULL;
506 ui_window_t *window = NULL;
507 ui_wnd_params_t params;
508 ui_resource_t *res;
509 ui_tab_set_t *tabset = NULL;
510 gfx_rect_t rect;
511 ui_tab_t *tab = NULL;
512 ui_evclaim_t claimed;
513 pos_event_t event;
514 ui_test_ctl_t *testctl = NULL;
515 ui_tc_resp_t resp;
516 errno_t rc;
518 rc = ui_create_disp(NULL, &ui);
519 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
521 ui_wnd_params_init(&params);
522 params.caption = "Hello";
524 rc = ui_window_create(ui, &params, &window);
525 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
526 PCUT_ASSERT_NOT_NULL(window);
528 res = ui_window_get_res(window);
530 rc = ui_tab_set_create(res, &tabset);
531 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
532 PCUT_ASSERT_NOT_NULL(tabset);
534 rect.p0.x = 0;
535 rect.p0.y = 0;
536 rect.p1.x = 100;
537 rect.p1.y = 200;
538 ui_tab_set_set_rect(tabset, &rect);
540 rc = ui_tab_create(tabset, "Test", &tab);
541 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
542 PCUT_ASSERT_NOT_NULL(tab);
544 rc = ui_test_ctl_create(&resp, &testctl);
545 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
547 /* Set up response */
548 ui_tab_add(tab, ui_test_ctl_ctl(testctl));
549 resp.claim = ui_claimed;
550 resp.pos = false;
552 /* Send position event */
553 event.type = POS_PRESS;
554 event.hpos = 10;
555 event.vpos = 40;
556 claimed = ui_tab_pos_event(tab, &event);
557 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
558 PCUT_ASSERT_EQUALS(ui_claimed, claimed);
560 /* Make sure event was delivered */
561 PCUT_ASSERT_TRUE(resp.pos);
562 PCUT_ASSERT_EQUALS(event.type, resp.pevent.type);
563 PCUT_ASSERT_EQUALS(event.hpos, resp.pevent.hpos);
564 PCUT_ASSERT_EQUALS(event.vpos, resp.pevent.vpos);
566 ui_tab_set_destroy(tabset);
567 ui_window_destroy(window);
568 ui_destroy(ui);
571 /** ui_tab_handle_width() and ui_tab_handle_height() return dimensions */
572 PCUT_TEST(handle_width_height)
574 ui_t *ui = NULL;
575 ui_window_t *window = NULL;
576 ui_wnd_params_t params;
577 ui_resource_t *res;
578 ui_tab_set_t *tabset = NULL;
579 ui_tab_t *tab = NULL;
580 gfx_coord_t w, h;
581 errno_t rc;
583 rc = ui_create_disp(NULL, &ui);
584 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
586 ui_wnd_params_init(&params);
587 params.caption = "Hello";
589 rc = ui_window_create(ui, &params, &window);
590 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
591 PCUT_ASSERT_NOT_NULL(window);
593 res = ui_window_get_res(window);
595 rc = ui_tab_set_create(res, &tabset);
596 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
597 PCUT_ASSERT_NOT_NULL(tabset);
599 rc = ui_tab_create(tabset, "Test", &tab);
600 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
601 PCUT_ASSERT_NOT_NULL(tab);
603 w = ui_tab_handle_width(tab);
604 h = ui_tab_handle_height(tab);
606 PCUT_ASSERT_INT_EQUALS(50, w);
607 PCUT_ASSERT_INT_EQUALS(25, h);
609 ui_tab_set_destroy(tabset);
610 ui_window_destroy(window);
611 ui_destroy(ui);
614 /** Computing tab geometry */
615 PCUT_TEST(get_geom)
617 ui_t *ui = NULL;
618 ui_window_t *window = NULL;
619 ui_wnd_params_t params;
620 ui_resource_t *res;
621 ui_tab_set_t *tabset = NULL;
622 ui_tab_t *tab = NULL;
623 ui_tab_geom_t geom;
624 gfx_rect_t rect;
625 errno_t rc;
627 rc = ui_create_disp(NULL, &ui);
628 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
630 ui_wnd_params_init(&params);
631 params.caption = "Hello";
633 rc = ui_window_create(ui, &params, &window);
634 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
635 PCUT_ASSERT_NOT_NULL(window);
637 res = ui_window_get_res(window);
639 rc = ui_tab_set_create(res, &tabset);
640 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
641 PCUT_ASSERT_NOT_NULL(tabset);
643 rect.p0.x = 1000;
644 rect.p0.y = 2000;
645 rect.p1.x = 1100;
646 rect.p1.y = 2200;
647 ui_tab_set_set_rect(tabset, &rect);
649 rc = ui_tab_create(tabset, "Test", &tab);
650 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
651 PCUT_ASSERT_NOT_NULL(tab);
653 ui_tab_get_geom(tab, &geom);
655 PCUT_ASSERT_INT_EQUALS(1006, geom.handle.p0.x);
656 PCUT_ASSERT_INT_EQUALS(2000, geom.handle.p0.y);
657 PCUT_ASSERT_INT_EQUALS(1056, geom.handle.p1.x);
658 PCUT_ASSERT_INT_EQUALS(2027, geom.handle.p1.y);
660 PCUT_ASSERT_INT_EQUALS(1006, geom.handle_area.p0.x);
661 PCUT_ASSERT_INT_EQUALS(2000, geom.handle_area.p0.y);
662 PCUT_ASSERT_INT_EQUALS(1056, geom.handle_area.p1.x);
663 PCUT_ASSERT_INT_EQUALS(2027, geom.handle_area.p1.y);
665 PCUT_ASSERT_INT_EQUALS(1000, geom.body.p0.x);
666 PCUT_ASSERT_INT_EQUALS(2025, geom.body.p0.y);
667 PCUT_ASSERT_INT_EQUALS(1100, geom.body.p1.x);
668 PCUT_ASSERT_INT_EQUALS(2200, geom.body.p1.y);
670 PCUT_ASSERT_INT_EQUALS(1014, geom.text_pos.x);
671 PCUT_ASSERT_INT_EQUALS(2007, geom.text_pos.y);
673 ui_tab_set_destroy(tabset);
674 ui_window_destroy(window);
675 ui_destroy(ui);
678 /** ui_tab_patint_handle_frame() */
679 PCUT_TEST(paint_handle_frame)
681 ui_t *ui = NULL;
682 ui_window_t *window = NULL;
683 ui_wnd_params_t params;
684 ui_resource_t *res;
685 gfx_context_t *gc;
686 gfx_rect_t rect;
687 gfx_rect_t irect;
688 gfx_coord_t chamfer;
689 gfx_color_t *hi_color;
690 gfx_color_t *sh_color;
691 errno_t rc;
693 rc = ui_create_disp(NULL, &ui);
694 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
696 ui_wnd_params_init(&params);
697 params.caption = "Hello";
699 rc = ui_window_create(ui, &params, &window);
700 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
701 PCUT_ASSERT_NOT_NULL(window);
703 res = ui_window_get_res(window);
704 gc = ui_window_get_gc(window);
706 rect.p0.x = 10;
707 rect.p0.y = 20;
708 rect.p1.x = 100;
709 rect.p1.y = 200;
711 chamfer = 4;
713 hi_color = res->wnd_highlight_color;
714 sh_color = res->wnd_shadow_color;
716 rc = ui_tab_paint_handle_frame(gc, &rect, chamfer, hi_color, sh_color,
717 true, &irect);
718 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
720 rc = ui_tab_paint_handle_frame(gc, &rect, chamfer, hi_color, sh_color,
721 false, &irect);
722 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
724 ui_window_destroy(window);
725 ui_destroy(ui);
728 /** ui_tab_paint_body_frame() */
729 PCUT_TEST(paint_body_frame)
731 ui_t *ui = NULL;
732 ui_window_t *window = NULL;
733 ui_wnd_params_t params;
734 ui_resource_t *res;
735 ui_tab_set_t *tabset = NULL;
736 ui_tab_t *tab = NULL;
737 errno_t rc;
739 rc = ui_create_disp(NULL, &ui);
740 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
742 ui_wnd_params_init(&params);
743 params.caption = "Hello";
745 rc = ui_window_create(ui, &params, &window);
746 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
747 PCUT_ASSERT_NOT_NULL(window);
749 res = ui_window_get_res(window);
751 rc = ui_tab_set_create(res, &tabset);
752 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
753 PCUT_ASSERT_NOT_NULL(tabset);
755 rc = ui_tab_create(tabset, "Test", &tab);
756 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
757 PCUT_ASSERT_NOT_NULL(tab);
759 rc = ui_tab_paint_body_frame(tab);
760 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
762 ui_tab_set_destroy(tabset);
763 ui_window_destroy(window);
764 ui_destroy(ui);
767 /** ui_tab_paint_frame() */
768 PCUT_TEST(paint_frame)
770 ui_t *ui = NULL;
771 ui_window_t *window = NULL;
772 ui_wnd_params_t params;
773 ui_resource_t *res;
774 ui_tab_set_t *tabset = NULL;
775 ui_tab_t *tab = NULL;
776 errno_t rc;
778 rc = ui_create_disp(NULL, &ui);
779 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
781 ui_wnd_params_init(&params);
782 params.caption = "Hello";
784 rc = ui_window_create(ui, &params, &window);
785 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
786 PCUT_ASSERT_NOT_NULL(window);
788 res = ui_window_get_res(window);
790 rc = ui_tab_set_create(res, &tabset);
791 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
792 PCUT_ASSERT_NOT_NULL(tabset);
794 rc = ui_tab_create(tabset, "Test", &tab);
795 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
796 PCUT_ASSERT_NOT_NULL(tab);
798 rc = ui_tab_paint_frame(tab);
799 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
801 ui_tab_set_destroy(tabset);
802 ui_window_destroy(window);
803 ui_destroy(ui);
806 /** ui_tab_get_res() returns the resource */
807 PCUT_TEST(get_res)
809 ui_t *ui = NULL;
810 ui_window_t *window = NULL;
811 ui_wnd_params_t params;
812 ui_resource_t *res;
813 ui_tab_set_t *tabset = NULL;
814 ui_tab_t *tab = NULL;
815 errno_t rc;
817 rc = ui_create_disp(NULL, &ui);
818 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
820 ui_wnd_params_init(&params);
821 params.caption = "Hello";
823 rc = ui_window_create(ui, &params, &window);
824 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
825 PCUT_ASSERT_NOT_NULL(window);
827 res = ui_window_get_res(window);
829 rc = ui_tab_set_create(res, &tabset);
830 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
831 PCUT_ASSERT_NOT_NULL(tabset);
833 rc = ui_tab_create(tabset, "Test", &tab);
834 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
835 PCUT_ASSERT_NOT_NULL(tab);
837 PCUT_ASSERT_EQUALS(res, ui_tab_get_res(tab));
839 ui_tab_set_destroy(tabset);
840 ui_window_destroy(window);
841 ui_destroy(ui);
844 PCUT_EXPORT(tab);