Editor needs to hide cursor when menu bar is activated
[helenos.git] / uspace / lib / ui / test / menuentry.c
blob25c9602155f92aff4b538b6d2331de1f5a0bf730
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 <ui/control.h>
35 #include <ui/menu.h>
36 #include <ui/menubar.h>
37 #include <ui/menudd.h>
38 #include <ui/menuentry.h>
39 #include <ui/ui.h>
40 #include <ui/window.h>
41 #include "../private/menuentry.h"
43 PCUT_INIT;
45 PCUT_TEST_SUITE(menuentry);
47 typedef struct {
48 bool activated;
49 } test_resp_t;
51 static void test_entry_cb(ui_menu_entry_t *, void *);
53 /** Create and destroy menu entry */
54 PCUT_TEST(create_destroy)
56 ui_t *ui = NULL;
57 ui_window_t *window = NULL;
58 ui_wnd_params_t params;
59 ui_menu_bar_t *mbar = NULL;
60 ui_menu_t *menu = NULL;
61 ui_menu_entry_t *mentry = NULL;
62 errno_t rc;
64 rc = ui_create_disp(NULL, &ui);
65 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
67 ui_wnd_params_init(&params);
68 params.caption = "Hello";
70 rc = ui_window_create(ui, &params, &window);
71 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
72 PCUT_ASSERT_NOT_NULL(window);
74 rc = ui_menu_bar_create(ui, window, &mbar);
75 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
76 PCUT_ASSERT_NOT_NULL(mbar);
78 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
79 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
80 PCUT_ASSERT_NOT_NULL(menu);
82 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry);
83 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
84 PCUT_ASSERT_NOT_NULL(mentry);
86 /* Just for sake of test. Menu entry is destroyed along with menu */
87 ui_menu_entry_destroy(mentry);
89 ui_menu_bar_destroy(mbar);
90 ui_window_destroy(window);
91 ui_destroy(ui);
94 /** Create and destroy separator menu entry */
95 PCUT_TEST(create_sep_destroy)
97 ui_t *ui = NULL;
98 ui_window_t *window = NULL;
99 ui_wnd_params_t params;
100 ui_menu_bar_t *mbar = NULL;
101 ui_menu_t *menu = NULL;
102 ui_menu_entry_t *mentry = NULL;
103 errno_t rc;
105 rc = ui_create_disp(NULL, &ui);
106 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
108 ui_wnd_params_init(&params);
109 params.caption = "Hello";
111 rc = ui_window_create(ui, &params, &window);
112 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
113 PCUT_ASSERT_NOT_NULL(window);
115 rc = ui_menu_bar_create(ui, window, &mbar);
116 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
117 PCUT_ASSERT_NOT_NULL(mbar);
119 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
120 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
121 PCUT_ASSERT_NOT_NULL(menu);
123 rc = ui_menu_entry_sep_create(menu, &mentry);
124 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
125 PCUT_ASSERT_NOT_NULL(mentry);
127 /* Just for sake of test. Menu entry is destroyed along with menu */
128 ui_menu_entry_destroy(mentry);
130 ui_menu_bar_destroy(mbar);
131 ui_window_destroy(window);
132 ui_destroy(ui);
135 /** ui_menu_bar_destroy() can take NULL argument (no-op) */
136 PCUT_TEST(destroy_null)
138 ui_menu_bar_destroy(NULL);
141 /** ui_menu_entry_set_cb() .. */
142 PCUT_TEST(set_cb)
144 ui_t *ui = NULL;
145 ui_window_t *window = NULL;
146 ui_wnd_params_t params;
147 ui_menu_bar_t *mbar = NULL;
148 ui_menu_t *menu = NULL;
149 ui_menu_entry_t *mentry = NULL;
150 test_resp_t resp;
151 errno_t rc;
153 rc = ui_create_disp(NULL, &ui);
154 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
156 ui_wnd_params_init(&params);
157 params.caption = "Hello";
159 rc = ui_window_create(ui, &params, &window);
160 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
161 PCUT_ASSERT_NOT_NULL(window);
163 rc = ui_menu_bar_create(ui, window, &mbar);
164 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
165 PCUT_ASSERT_NOT_NULL(mbar);
167 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
168 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
169 PCUT_ASSERT_NOT_NULL(menu);
171 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry);
172 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
173 PCUT_ASSERT_NOT_NULL(mentry);
175 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
177 resp.activated = false;
178 ui_menu_entry_cb(mentry);
179 PCUT_ASSERT_TRUE(resp.activated);
181 ui_menu_bar_destroy(mbar);
182 ui_window_destroy(window);
183 ui_destroy(ui);
186 /** ui_menu_entry_first() / ui_menu_entry_next() iterate over entries */
187 PCUT_TEST(first_next)
189 ui_t *ui = NULL;
190 ui_window_t *window = NULL;
191 ui_wnd_params_t params;
192 ui_menu_bar_t *mbar = NULL;
193 ui_menu_t *menu = NULL;
194 ui_menu_entry_t *entry1 = NULL;
195 ui_menu_entry_t *entry2 = NULL;
196 ui_menu_entry_t *e;
197 errno_t rc;
199 rc = ui_create_disp(NULL, &ui);
200 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
202 ui_wnd_params_init(&params);
203 params.caption = "Hello";
205 rc = ui_window_create(ui, &params, &window);
206 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
207 PCUT_ASSERT_NOT_NULL(window);
209 rc = ui_menu_bar_create(ui, window, &mbar);
210 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
211 PCUT_ASSERT_NOT_NULL(mbar);
213 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
214 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
215 PCUT_ASSERT_NOT_NULL(menu);
217 rc = ui_menu_entry_create(menu, "Foo", "F1", &entry1);
218 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
219 PCUT_ASSERT_NOT_NULL(entry1);
221 rc = ui_menu_entry_create(menu, "Bar", "F2", &entry2);
222 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
223 PCUT_ASSERT_NOT_NULL(entry2);
225 e = ui_menu_entry_first(menu);
226 PCUT_ASSERT_EQUALS(entry1, e);
228 e = ui_menu_entry_next(e);
229 PCUT_ASSERT_EQUALS(entry2, e);
231 e = ui_menu_entry_next(e);
232 PCUT_ASSERT_NULL(e);
234 ui_menu_bar_destroy(mbar);
235 ui_window_destroy(window);
236 ui_destroy(ui);
239 /** ui_menu_entry_last() / ui_menu_entry_prev() iterate over entries in reverse */
240 PCUT_TEST(last_prev)
242 ui_t *ui = NULL;
243 ui_window_t *window = NULL;
244 ui_wnd_params_t params;
245 ui_menu_bar_t *mbar = NULL;
246 ui_menu_t *menu = NULL;
247 ui_menu_entry_t *entry1 = NULL;
248 ui_menu_entry_t *entry2 = NULL;
249 ui_menu_entry_t *e;
250 errno_t rc;
252 rc = ui_create_disp(NULL, &ui);
253 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
255 ui_wnd_params_init(&params);
256 params.caption = "Hello";
258 rc = ui_window_create(ui, &params, &window);
259 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
260 PCUT_ASSERT_NOT_NULL(window);
262 rc = ui_menu_bar_create(ui, window, &mbar);
263 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
264 PCUT_ASSERT_NOT_NULL(mbar);
266 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
267 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
268 PCUT_ASSERT_NOT_NULL(menu);
270 rc = ui_menu_entry_create(menu, "Foo", "F1", &entry1);
271 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
272 PCUT_ASSERT_NOT_NULL(entry1);
274 rc = ui_menu_entry_create(menu, "Bar", "F2", &entry2);
275 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
276 PCUT_ASSERT_NOT_NULL(entry2);
278 e = ui_menu_entry_last(menu);
279 PCUT_ASSERT_EQUALS(entry2, e);
281 e = ui_menu_entry_prev(e);
282 PCUT_ASSERT_EQUALS(entry1, e);
284 e = ui_menu_entry_prev(e);
285 PCUT_ASSERT_NULL(e);
287 ui_menu_bar_destroy(mbar);
288 ui_window_destroy(window);
289 ui_destroy(ui);
292 /** ui_menu_entry_column_widths() / ui_menu_entry_height() */
293 PCUT_TEST(widths_height)
295 ui_t *ui = NULL;
296 ui_window_t *window = NULL;
297 ui_wnd_params_t params;
298 ui_menu_bar_t *mbar = NULL;
299 ui_menu_t *menu = NULL;
300 ui_menu_entry_t *mentry = NULL;
301 gfx_coord_t caption_w;
302 gfx_coord_t shortcut_w;
303 gfx_coord_t width;
304 gfx_coord_t height;
305 errno_t rc;
307 rc = ui_create_disp(NULL, &ui);
308 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
310 ui_wnd_params_init(&params);
311 params.caption = "Hello";
313 rc = ui_window_create(ui, &params, &window);
314 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
315 PCUT_ASSERT_NOT_NULL(window);
317 rc = ui_menu_bar_create(ui, window, &mbar);
318 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
319 PCUT_ASSERT_NOT_NULL(mbar);
321 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
322 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
323 PCUT_ASSERT_NOT_NULL(menu);
325 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
326 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
327 PCUT_ASSERT_NOT_NULL(mentry);
329 ui_menu_entry_column_widths(mentry, &caption_w, &shortcut_w);
330 PCUT_ASSERT_INT_EQUALS(11, caption_w);
331 PCUT_ASSERT_INT_EQUALS(10, shortcut_w);
333 width = ui_menu_entry_calc_width(menu, caption_w, shortcut_w);
334 PCUT_ASSERT_INT_EQUALS(4 + 11 + 8 + 10 + 4, width);
336 height = ui_menu_entry_height(mentry);
337 PCUT_ASSERT_INT_EQUALS(13 + 8, height);
339 ui_menu_bar_destroy(mbar);
340 ui_window_destroy(window);
341 ui_destroy(ui);
344 /** Paint menu entry */
345 PCUT_TEST(paint)
347 ui_t *ui = NULL;
348 ui_window_t *window = NULL;
349 ui_wnd_params_t params;
350 ui_menu_bar_t *mbar = NULL;
351 ui_menu_t *menu = NULL;
352 ui_menu_entry_t *mentry = NULL;
353 gfx_coord2_t pos;
354 gfx_rect_t prect;
355 errno_t rc;
357 rc = ui_create_disp(NULL, &ui);
358 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
360 ui_wnd_params_init(&params);
361 params.caption = "Hello";
363 rc = ui_window_create(ui, &params, &window);
364 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
365 PCUT_ASSERT_NOT_NULL(window);
367 rc = ui_menu_bar_create(ui, window, &mbar);
368 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
369 PCUT_ASSERT_NOT_NULL(mbar);
371 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
372 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
373 PCUT_ASSERT_NOT_NULL(menu);
375 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry);
376 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
377 PCUT_ASSERT_NOT_NULL(mentry);
379 prect.p0.x = 0;
380 prect.p0.y = 0;
381 prect.p1.x = 0;
382 prect.p1.y = 0;
384 rc = ui_menu_open(menu, &prect, 0);
385 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
387 pos.x = 0;
388 pos.y = 0;
389 rc = ui_menu_entry_paint(mentry, &pos);
390 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
392 ui_menu_bar_destroy(mbar);
393 ui_window_destroy(window);
394 ui_destroy(ui);
397 /** ui_menu_entry_selectable() returns correct value based on entry type */
398 PCUT_TEST(selectable)
400 ui_t *ui = NULL;
401 ui_window_t *window = NULL;
402 ui_wnd_params_t params;
403 ui_menu_bar_t *mbar = NULL;
404 ui_menu_t *menu = NULL;
405 ui_menu_entry_t *mentry = NULL;
406 errno_t rc;
408 rc = ui_create_disp(NULL, &ui);
409 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
411 ui_wnd_params_init(&params);
412 params.caption = "Hello";
414 rc = ui_window_create(ui, &params, &window);
415 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
416 PCUT_ASSERT_NOT_NULL(window);
418 rc = ui_menu_bar_create(ui, window, &mbar);
419 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
420 PCUT_ASSERT_NOT_NULL(mbar);
422 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
423 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
424 PCUT_ASSERT_NOT_NULL(menu);
426 /* Selectable entry */
428 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry);
429 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
430 PCUT_ASSERT_NOT_NULL(mentry);
432 PCUT_ASSERT_TRUE(ui_menu_entry_selectable(mentry));
434 ui_menu_entry_destroy(mentry);
436 /* Non-selectable separator entry */
438 rc = ui_menu_entry_sep_create(menu, &mentry);
439 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
440 PCUT_ASSERT_NOT_NULL(mentry);
442 PCUT_ASSERT_FALSE(ui_menu_entry_selectable(mentry));
444 ui_menu_entry_destroy(mentry);
446 ui_menu_bar_destroy(mbar);
447 ui_window_destroy(window);
448 ui_destroy(ui);
451 /** Press and release activates menu entry */
452 PCUT_TEST(press_release)
454 ui_t *ui = NULL;
455 ui_window_t *window = NULL;
456 ui_wnd_params_t params;
457 ui_menu_bar_t *mbar = NULL;
458 ui_menu_t *menu = NULL;
459 ui_menu_entry_t *mentry = NULL;
460 gfx_coord2_t pos;
461 gfx_rect_t prect;
462 test_resp_t resp;
463 errno_t rc;
465 rc = ui_create_disp(NULL, &ui);
466 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
468 ui_wnd_params_init(&params);
469 params.caption = "Hello";
471 rc = ui_window_create(ui, &params, &window);
472 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
473 PCUT_ASSERT_NOT_NULL(window);
475 rc = ui_menu_bar_create(ui, window, &mbar);
476 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
477 PCUT_ASSERT_NOT_NULL(mbar);
479 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
480 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
481 PCUT_ASSERT_NOT_NULL(menu);
483 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
484 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
485 PCUT_ASSERT_NOT_NULL(mentry);
487 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
488 resp.activated = false;
490 prect.p0.x = 0;
491 prect.p0.y = 0;
492 prect.p1.x = 0;
493 prect.p1.y = 0;
495 rc = ui_menu_open(menu, &prect, 0);
496 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
498 pos.x = 0;
499 pos.y = 0;
500 ui_menu_entry_press(mentry, &pos);
501 PCUT_ASSERT_TRUE(mentry->inside);
502 PCUT_ASSERT_TRUE(mentry->held);
503 PCUT_ASSERT_FALSE(resp.activated);
505 ui_menu_entry_release(mentry);
506 PCUT_ASSERT_FALSE(mentry->held);
507 PCUT_ASSERT_TRUE(resp.activated);
509 ui_menu_bar_destroy(mbar);
510 ui_window_destroy(window);
511 ui_destroy(ui);
514 /** Press, leave and release does not activate entry */
515 PCUT_TEST(press_leave_release)
517 ui_t *ui = NULL;
518 ui_window_t *window = NULL;
519 ui_wnd_params_t params;
520 ui_menu_bar_t *mbar = NULL;
521 ui_menu_t *menu = NULL;
522 ui_menu_entry_t *mentry = NULL;
523 gfx_coord2_t pos;
524 gfx_rect_t prect;
525 test_resp_t resp;
526 errno_t rc;
528 rc = ui_create_disp(NULL, &ui);
529 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
531 ui_wnd_params_init(&params);
532 params.caption = "Hello";
534 rc = ui_window_create(ui, &params, &window);
535 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
536 PCUT_ASSERT_NOT_NULL(window);
538 rc = ui_menu_bar_create(ui, window, &mbar);
539 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
540 PCUT_ASSERT_NOT_NULL(mbar);
542 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
543 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
544 PCUT_ASSERT_NOT_NULL(menu);
546 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
547 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
548 PCUT_ASSERT_NOT_NULL(mentry);
550 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
551 resp.activated = false;
553 prect.p0.x = 0;
554 prect.p0.y = 0;
555 prect.p1.x = 0;
556 prect.p1.y = 0;
558 rc = ui_menu_open(menu, &prect, 0);
559 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
561 pos.x = 0;
562 pos.y = 0;
563 ui_menu_entry_press(mentry, &pos);
564 PCUT_ASSERT_TRUE(mentry->inside);
565 PCUT_ASSERT_TRUE(mentry->held);
566 PCUT_ASSERT_FALSE(resp.activated);
568 ui_menu_entry_leave(mentry, &pos);
569 PCUT_ASSERT_FALSE(mentry->inside);
570 PCUT_ASSERT_TRUE(mentry->held);
571 PCUT_ASSERT_FALSE(resp.activated);
573 ui_menu_entry_release(mentry);
574 PCUT_ASSERT_FALSE(mentry->held);
575 PCUT_ASSERT_FALSE(resp.activated);
577 ui_menu_bar_destroy(mbar);
578 ui_window_destroy(window);
579 ui_destroy(ui);
582 /** Press, leave, enter and release activates menu entry */
583 PCUT_TEST(press_leave_enter_release)
585 ui_t *ui = NULL;
586 ui_window_t *window = NULL;
587 ui_wnd_params_t params;
588 ui_menu_bar_t *mbar = NULL;
589 ui_menu_t *menu = NULL;
590 ui_menu_entry_t *mentry = NULL;
591 gfx_coord2_t pos;
592 gfx_rect_t prect;
593 test_resp_t resp;
594 errno_t rc;
596 rc = ui_create_disp(NULL, &ui);
597 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
599 ui_wnd_params_init(&params);
600 params.caption = "Hello";
602 rc = ui_window_create(ui, &params, &window);
603 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
604 PCUT_ASSERT_NOT_NULL(window);
606 rc = ui_menu_bar_create(ui, window, &mbar);
607 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
608 PCUT_ASSERT_NOT_NULL(mbar);
610 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
611 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
612 PCUT_ASSERT_NOT_NULL(menu);
614 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
615 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
616 PCUT_ASSERT_NOT_NULL(mentry);
618 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
619 resp.activated = false;
621 prect.p0.x = 0;
622 prect.p0.y = 0;
623 prect.p1.x = 0;
624 prect.p1.y = 0;
626 rc = ui_menu_open(menu, &prect, 0);
627 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
629 pos.x = 0;
630 pos.y = 0;
631 ui_menu_entry_press(mentry, &pos);
632 PCUT_ASSERT_TRUE(mentry->inside);
633 PCUT_ASSERT_TRUE(mentry->held);
634 PCUT_ASSERT_FALSE(resp.activated);
636 ui_menu_entry_leave(mentry, &pos);
637 PCUT_ASSERT_FALSE(mentry->inside);
638 PCUT_ASSERT_TRUE(mentry->held);
639 PCUT_ASSERT_FALSE(resp.activated);
641 ui_menu_entry_enter(mentry, &pos);
642 PCUT_ASSERT_TRUE(mentry->inside);
643 PCUT_ASSERT_TRUE(mentry->held);
644 PCUT_ASSERT_FALSE(resp.activated);
646 ui_menu_entry_release(mentry);
647 PCUT_ASSERT_FALSE(mentry->held);
648 PCUT_ASSERT_TRUE(resp.activated);
650 ui_menu_bar_destroy(mbar);
651 ui_window_destroy(window);
652 ui_destroy(ui);
655 /** ui_menu_entry_activate() activates menu entry */
656 PCUT_TEST(activate)
658 ui_t *ui = NULL;
659 ui_window_t *window = NULL;
660 ui_wnd_params_t params;
661 ui_menu_bar_t *mbar = NULL;
662 ui_menu_t *menu = NULL;
663 ui_menu_entry_t *mentry = NULL;
664 gfx_rect_t prect;
665 test_resp_t resp;
666 errno_t rc;
668 rc = ui_create_disp(NULL, &ui);
669 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
671 ui_wnd_params_init(&params);
672 params.caption = "Hello";
674 rc = ui_window_create(ui, &params, &window);
675 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
676 PCUT_ASSERT_NOT_NULL(window);
678 rc = ui_menu_bar_create(ui, window, &mbar);
679 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
680 PCUT_ASSERT_NOT_NULL(mbar);
682 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
683 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
684 PCUT_ASSERT_NOT_NULL(menu);
686 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
687 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
688 PCUT_ASSERT_NOT_NULL(mentry);
690 ui_menu_entry_set_cb(mentry, test_entry_cb, &resp);
691 resp.activated = false;
693 prect.p0.x = 0;
694 prect.p0.y = 0;
695 prect.p1.x = 0;
696 prect.p1.y = 0;
698 rc = ui_menu_open(menu, &prect, 0);
699 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
701 PCUT_ASSERT_FALSE(resp.activated);
702 ui_menu_entry_activate(mentry);
704 ui_menu_entry_release(mentry);
705 PCUT_ASSERT_TRUE(resp.activated);
707 ui_menu_bar_destroy(mbar);
708 ui_window_destroy(window);
709 ui_destroy(ui);
712 /** Press event inside menu entry */
713 PCUT_TEST(pos_press_inside)
715 ui_t *ui = NULL;
716 ui_window_t *window = NULL;
717 ui_wnd_params_t params;
718 ui_menu_bar_t *mbar = NULL;
719 ui_menu_t *menu = NULL;
720 ui_menu_entry_t *mentry = NULL;
721 gfx_coord2_t pos;
722 gfx_rect_t prect;
723 pos_event_t event;
724 errno_t rc;
726 rc = ui_create_disp(NULL, &ui);
727 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
729 ui_wnd_params_init(&params);
730 params.caption = "Hello";
732 rc = ui_window_create(ui, &params, &window);
733 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
734 PCUT_ASSERT_NOT_NULL(window);
736 rc = ui_menu_bar_create(ui, window, &mbar);
737 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
738 PCUT_ASSERT_NOT_NULL(mbar);
740 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
741 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
742 PCUT_ASSERT_NOT_NULL(menu);
744 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
745 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
746 PCUT_ASSERT_NOT_NULL(mentry);
748 prect.p0.x = 0;
749 prect.p0.y = 0;
750 prect.p1.x = 0;
751 prect.p1.y = 0;
753 rc = ui_menu_open(menu, &prect, 0);
754 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
756 pos.x = 0;
757 pos.y = 0;
759 event.type = POS_PRESS;
760 event.hpos = 4;
761 event.vpos = 4;
763 ui_menu_entry_pos_event(mentry, &pos, &event);
764 PCUT_ASSERT_TRUE(mentry->inside);
765 PCUT_ASSERT_TRUE(mentry->held);
767 ui_menu_bar_destroy(mbar);
768 ui_window_destroy(window);
769 ui_destroy(ui);
772 /** Press event outside menu entry */
773 PCUT_TEST(pos_press_outside)
775 ui_t *ui = NULL;
776 ui_window_t *window = NULL;
777 ui_wnd_params_t params;
778 ui_menu_bar_t *mbar = NULL;
779 ui_menu_t *menu = NULL;
780 ui_menu_entry_t *mentry = NULL;
781 gfx_coord2_t pos;
782 gfx_rect_t prect;
783 pos_event_t event;
784 errno_t rc;
786 rc = ui_create_disp(NULL, &ui);
787 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
789 ui_wnd_params_init(&params);
790 params.caption = "Hello";
792 rc = ui_window_create(ui, &params, &window);
793 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
794 PCUT_ASSERT_NOT_NULL(window);
796 rc = ui_menu_bar_create(ui, window, &mbar);
797 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
798 PCUT_ASSERT_NOT_NULL(mbar);
800 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
801 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
802 PCUT_ASSERT_NOT_NULL(menu);
804 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
805 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
806 PCUT_ASSERT_NOT_NULL(mentry);
808 prect.p0.x = 0;
809 prect.p0.y = 0;
810 prect.p1.x = 0;
811 prect.p1.y = 0;
813 rc = ui_menu_open(menu, &prect, 0);
814 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
816 pos.x = 0;
817 pos.y = 0;
819 event.type = POS_PRESS;
820 event.hpos = 40;
821 event.vpos = 20;
823 ui_menu_entry_pos_event(mentry, &pos, &event);
824 PCUT_ASSERT_FALSE(mentry->inside);
825 PCUT_ASSERT_FALSE(mentry->held);
827 ui_menu_bar_destroy(mbar);
828 ui_window_destroy(window);
829 ui_destroy(ui);
832 /** Position event moving out of menu entry */
833 PCUT_TEST(pos_move_out)
835 ui_t *ui = NULL;
836 ui_window_t *window = NULL;
837 ui_wnd_params_t params;
838 ui_menu_bar_t *mbar = NULL;
839 ui_menu_t *menu = NULL;
840 ui_menu_entry_t *mentry = NULL;
841 gfx_coord2_t pos;
842 gfx_rect_t prect;
843 pos_event_t event;
844 errno_t rc;
846 rc = ui_create_disp(NULL, &ui);
847 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
849 ui_wnd_params_init(&params);
850 params.caption = "Hello";
852 rc = ui_window_create(ui, &params, &window);
853 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
854 PCUT_ASSERT_NOT_NULL(window);
856 rc = ui_menu_bar_create(ui, window, &mbar);
857 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
858 PCUT_ASSERT_NOT_NULL(mbar);
860 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
861 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
862 PCUT_ASSERT_NOT_NULL(menu);
864 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
865 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
866 PCUT_ASSERT_NOT_NULL(mentry);
868 prect.p0.x = 0;
869 prect.p0.y = 0;
870 prect.p1.x = 0;
871 prect.p1.y = 0;
873 rc = ui_menu_open(menu, &prect, 0);
874 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
876 pos.x = 0;
877 pos.y = 0;
878 ui_menu_entry_press(mentry, &pos);
879 PCUT_ASSERT_TRUE(mentry->inside);
880 PCUT_ASSERT_TRUE(mentry->held);
882 event.type = POS_UPDATE;
883 event.hpos = 40;
884 event.vpos = 20;
886 ui_menu_entry_pos_event(mentry, &pos, &event);
887 PCUT_ASSERT_FALSE(mentry->inside);
888 PCUT_ASSERT_TRUE(mentry->held);
890 ui_menu_bar_destroy(mbar);
891 ui_window_destroy(window);
892 ui_destroy(ui);
895 /** Position event moving inside menu entry */
896 PCUT_TEST(pos_move_in)
898 ui_t *ui = NULL;
899 ui_window_t *window = NULL;
900 ui_wnd_params_t params;
901 ui_menu_bar_t *mbar = NULL;
902 ui_menu_t *menu = NULL;
903 ui_menu_entry_t *mentry = NULL;
904 gfx_coord2_t pos;
905 gfx_rect_t prect;
906 pos_event_t event;
907 errno_t rc;
909 rc = ui_create_disp(NULL, &ui);
910 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
912 ui_wnd_params_init(&params);
913 params.caption = "Hello";
915 rc = ui_window_create(ui, &params, &window);
916 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
917 PCUT_ASSERT_NOT_NULL(window);
919 rc = ui_menu_bar_create(ui, window, &mbar);
920 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
921 PCUT_ASSERT_NOT_NULL(mbar);
923 rc = ui_menu_dd_create(mbar, "Test", NULL, &menu);
924 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
925 PCUT_ASSERT_NOT_NULL(menu);
927 rc = ui_menu_entry_create(menu, "X", "Y", &mentry);
928 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
929 PCUT_ASSERT_NOT_NULL(mentry);
931 prect.p0.x = 0;
932 prect.p0.y = 0;
933 prect.p1.x = 0;
934 prect.p1.y = 0;
936 rc = ui_menu_open(menu, &prect, 0);
937 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
939 event.type = POS_UPDATE;
940 event.hpos = 4;
941 event.vpos = 4;
943 pos.x = 0;
944 pos.y = 0;
946 ui_menu_entry_pos_event(mentry, &pos, &event);
947 PCUT_ASSERT_TRUE(mentry->inside);
948 PCUT_ASSERT_FALSE(mentry->held);
950 ui_menu_bar_destroy(mbar);
951 ui_window_destroy(window);
952 ui_destroy(ui);
955 static void test_entry_cb(ui_menu_entry_t *mentry, void *arg)
957 test_resp_t *resp = (test_resp_t *) arg;
959 resp->activated = true;
962 PCUT_EXPORT(menuentry);