2 * Copyright (c) 2023 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/control.h>
36 #include <ui/menubar.h>
37 #include <ui/menudd.h>
38 #include <ui/menuentry.h>
40 #include <ui/window.h>
41 #include "../private/menuentry.h"
45 PCUT_TEST_SUITE(menuentry
);
51 static void test_entry_cb(ui_menu_entry_t
*, void *);
53 /** Create and destroy menu entry */
54 PCUT_TEST(create_destroy
)
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
;
64 rc
= ui_create_disp(NULL
, &ui
);
65 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
67 ui_wnd_params_init(¶ms
);
68 params
.caption
= "Hello";
70 rc
= ui_window_create(ui
, ¶ms
, &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
);
94 /** Create and destroy separator menu entry */
95 PCUT_TEST(create_sep_destroy
)
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
;
105 rc
= ui_create_disp(NULL
, &ui
);
106 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
108 ui_wnd_params_init(¶ms
);
109 params
.caption
= "Hello";
111 rc
= ui_window_create(ui
, ¶ms
, &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
);
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() .. */
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
;
153 rc
= ui_create_disp(NULL
, &ui
);
154 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
156 ui_wnd_params_init(¶ms
);
157 params
.caption
= "Hello";
159 rc
= ui_window_create(ui
, ¶ms
, &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
);
186 /** ui_menu_entry_first() / ui_menu_entry_next() iterate over entries */
187 PCUT_TEST(first_next
)
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
;
199 rc
= ui_create_disp(NULL
, &ui
);
200 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
202 ui_wnd_params_init(¶ms
);
203 params
.caption
= "Hello";
205 rc
= ui_window_create(ui
, ¶ms
, &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
);
234 ui_menu_bar_destroy(mbar
);
235 ui_window_destroy(window
);
239 /** ui_menu_entry_last() / ui_menu_entry_prev() iterate over entries in reverse */
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
;
252 rc
= ui_create_disp(NULL
, &ui
);
253 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
255 ui_wnd_params_init(¶ms
);
256 params
.caption
= "Hello";
258 rc
= ui_window_create(ui
, ¶ms
, &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
);
287 ui_menu_bar_destroy(mbar
);
288 ui_window_destroy(window
);
292 /** ui_menu_entry_column_widths() / ui_menu_entry_height() */
293 PCUT_TEST(widths_height
)
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
;
307 rc
= ui_create_disp(NULL
, &ui
);
308 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
310 ui_wnd_params_init(¶ms
);
311 params
.caption
= "Hello";
313 rc
= ui_window_create(ui
, ¶ms
, &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
);
344 /** Paint menu entry */
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
;
357 rc
= ui_create_disp(NULL
, &ui
);
358 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
360 ui_wnd_params_init(¶ms
);
361 params
.caption
= "Hello";
363 rc
= ui_window_create(ui
, ¶ms
, &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
);
384 rc
= ui_menu_open(menu
, &prect
, 0);
385 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
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
);
397 /** ui_menu_entry_selectable() returns correct value based on entry type */
398 PCUT_TEST(selectable
)
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
;
408 rc
= ui_create_disp(NULL
, &ui
);
409 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
411 ui_wnd_params_init(¶ms
);
412 params
.caption
= "Hello";
414 rc
= ui_window_create(ui
, ¶ms
, &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
);
451 /** Press and release activates menu entry */
452 PCUT_TEST(press_release
)
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
;
465 rc
= ui_create_disp(NULL
, &ui
);
466 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
468 ui_wnd_params_init(¶ms
);
469 params
.caption
= "Hello";
471 rc
= ui_window_create(ui
, ¶ms
, &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;
495 rc
= ui_menu_open(menu
, &prect
, 0);
496 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
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
);
514 /** Press, leave and release does not activate entry */
515 PCUT_TEST(press_leave_release
)
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
;
528 rc
= ui_create_disp(NULL
, &ui
);
529 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
531 ui_wnd_params_init(¶ms
);
532 params
.caption
= "Hello";
534 rc
= ui_window_create(ui
, ¶ms
, &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;
558 rc
= ui_menu_open(menu
, &prect
, 0);
559 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
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
);
582 /** Press, leave, enter and release activates menu entry */
583 PCUT_TEST(press_leave_enter_release
)
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
;
596 rc
= ui_create_disp(NULL
, &ui
);
597 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
599 ui_wnd_params_init(¶ms
);
600 params
.caption
= "Hello";
602 rc
= ui_window_create(ui
, ¶ms
, &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;
626 rc
= ui_menu_open(menu
, &prect
, 0);
627 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
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
);
655 /** ui_menu_entry_activate() activates menu entry */
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
;
668 rc
= ui_create_disp(NULL
, &ui
);
669 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
671 ui_wnd_params_init(¶ms
);
672 params
.caption
= "Hello";
674 rc
= ui_window_create(ui
, ¶ms
, &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;
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
);
712 /** Press event inside menu entry */
713 PCUT_TEST(pos_press_inside
)
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
;
726 rc
= ui_create_disp(NULL
, &ui
);
727 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
729 ui_wnd_params_init(¶ms
);
730 params
.caption
= "Hello";
732 rc
= ui_window_create(ui
, ¶ms
, &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
);
753 rc
= ui_menu_open(menu
, &prect
, 0);
754 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
759 event
.type
= POS_PRESS
;
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
);
772 /** Press event outside menu entry */
773 PCUT_TEST(pos_press_outside
)
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
;
786 rc
= ui_create_disp(NULL
, &ui
);
787 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
789 ui_wnd_params_init(¶ms
);
790 params
.caption
= "Hello";
792 rc
= ui_window_create(ui
, ¶ms
, &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
);
813 rc
= ui_menu_open(menu
, &prect
, 0);
814 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
819 event
.type
= POS_PRESS
;
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
);
832 /** Position event moving out of menu entry */
833 PCUT_TEST(pos_move_out
)
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
;
846 rc
= ui_create_disp(NULL
, &ui
);
847 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
849 ui_wnd_params_init(¶ms
);
850 params
.caption
= "Hello";
852 rc
= ui_window_create(ui
, ¶ms
, &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
);
873 rc
= ui_menu_open(menu
, &prect
, 0);
874 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
878 ui_menu_entry_press(mentry
, &pos
);
879 PCUT_ASSERT_TRUE(mentry
->inside
);
880 PCUT_ASSERT_TRUE(mentry
->held
);
882 event
.type
= POS_UPDATE
;
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
);
895 /** Position event moving inside menu entry */
896 PCUT_TEST(pos_move_in
)
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
;
909 rc
= ui_create_disp(NULL
, &ui
);
910 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
912 ui_wnd_params_init(¶ms
);
913 params
.caption
= "Hello";
915 rc
= ui_window_create(ui
, ¶ms
, &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
);
936 rc
= ui_menu_open(menu
, &prect
, 0);
937 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
939 event
.type
= POS_UPDATE
;
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
);
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
);