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>
35 #include <ui/control.h>
37 #include <ui/menubar.h>
38 #include <ui/menuentry.h>
40 #include <ui/window.h>
41 #include "../private/menu.h"
42 #include "../private/menubar.h"
46 PCUT_TEST_SUITE(menu
);
51 bool close_req_called
;
52 bool press_accel_called
;
58 static void testmenu_left(ui_menu_t
*, void *, sysarg_t
);
59 static void testmenu_right(ui_menu_t
*, void *, sysarg_t
);
60 static void testmenu_close_req(ui_menu_t
*, void *);
61 static void testmenu_press_accel(ui_menu_t
*, void *, char32_t
, sysarg_t
);
63 ui_menu_cb_t testmenu_cb
= {
64 .left
= testmenu_left
,
65 .right
= testmenu_right
,
66 .close_req
= testmenu_close_req
,
67 .press_accel
= testmenu_press_accel
70 ui_menu_cb_t dummy_cb
= {
73 /** Create and destroy menu */
74 PCUT_TEST(create_destroy
)
76 ui_menu_t
*menu
= NULL
;
79 rc
= ui_menu_create(NULL
, &menu
);
80 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
81 PCUT_ASSERT_NOT_NULL(menu
);
83 ui_menu_destroy(menu
);
86 /** ui_menu_destroy() can take NULL argument (no-op) */
87 PCUT_TEST(destroy_null
)
89 ui_menu_destroy(NULL
);
92 /** ui_menu_set_cb() sets the internal fields */
95 ui_menu_t
*menu
= NULL
;
100 rc
= ui_menu_create(NULL
, &menu
);
101 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
102 PCUT_ASSERT_NOT_NULL(menu
);
104 ui_menu_set_cb(menu
, &cb
, (void *)&obj
);
105 PCUT_ASSERT_EQUALS(&cb
, menu
->cb
);
106 PCUT_ASSERT_EQUALS((void *)&obj
, menu
->arg
);
108 ui_menu_destroy(menu
);
111 /** Computing menu geometry */
115 ui_window_t
*window
= NULL
;
116 ui_wnd_params_t params
;
117 ui_menu_t
*menu
= NULL
;
122 rc
= ui_create_disp(NULL
, &ui
);
123 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
125 ui_wnd_params_init(¶ms
);
126 params
.caption
= "Hello";
128 rc
= ui_window_create(ui
, ¶ms
, &window
);
129 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
130 PCUT_ASSERT_NOT_NULL(window
);
132 rc
= ui_menu_create(window
, &menu
);
133 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
134 PCUT_ASSERT_NOT_NULL(menu
);
138 ui_menu_get_geom(menu
, &pos
, &geom
);
140 PCUT_ASSERT_INT_EQUALS(0, geom
.outer_rect
.p0
.x
);
141 PCUT_ASSERT_INT_EQUALS(0, geom
.outer_rect
.p0
.y
);
142 PCUT_ASSERT_INT_EQUALS(16, geom
.outer_rect
.p1
.x
);
143 PCUT_ASSERT_INT_EQUALS(8, geom
.outer_rect
.p1
.y
);
144 PCUT_ASSERT_INT_EQUALS(4, geom
.entries_rect
.p0
.x
);
145 PCUT_ASSERT_INT_EQUALS(4, geom
.entries_rect
.p0
.y
);
146 PCUT_ASSERT_INT_EQUALS(12, geom
.entries_rect
.p1
.x
);
147 PCUT_ASSERT_INT_EQUALS(4, geom
.entries_rect
.p1
.y
);
149 ui_menu_destroy(menu
);
150 ui_window_destroy(window
);
154 /** ui_menu_get_res() gets the menu's resource */
158 ui_window_t
*window
= NULL
;
159 ui_wnd_params_t params
;
160 ui_menu_t
*menu
= NULL
;
165 rc
= ui_create_disp(NULL
, &ui
);
166 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
168 ui_wnd_params_init(¶ms
);
169 params
.caption
= "Hello";
171 rc
= ui_window_create(ui
, ¶ms
, &window
);
172 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
173 PCUT_ASSERT_NOT_NULL(window
);
175 rc
= ui_menu_create(window
, &menu
);
176 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
177 PCUT_ASSERT_NOT_NULL(menu
);
184 /* The menu must be open first */
185 rc
= ui_menu_open(menu
, &prect
, 0);
186 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
188 res
= ui_menu_get_res(menu
);
189 PCUT_ASSERT_NOT_NULL(res
);
191 ui_menu_destroy(menu
);
193 ui_window_destroy(window
);
197 /** Open and close menu with ui_menu_open() / ui_menu_close() */
198 PCUT_TEST(open_close
)
201 ui_window_t
*window
= NULL
;
202 ui_wnd_params_t params
;
203 ui_menu_t
*menu
= NULL
;
207 rc
= ui_create_disp(NULL
, &ui
);
208 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
210 ui_wnd_params_init(¶ms
);
211 params
.caption
= "Hello";
213 rc
= ui_window_create(ui
, ¶ms
, &window
);
214 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
215 PCUT_ASSERT_NOT_NULL(window
);
217 rc
= ui_menu_create(window
, &menu
);
218 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
219 PCUT_ASSERT_NOT_NULL(menu
);
227 rc
= ui_menu_open(menu
, &prect
, 0);
228 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
232 ui_menu_destroy(menu
);
233 ui_window_destroy(window
);
237 /** ui_menu_is_open() correctly returns menu state */
241 ui_window_t
*window
= NULL
;
242 ui_wnd_params_t params
;
243 ui_menu_t
*menu
= NULL
;
248 rc
= ui_create_disp(NULL
, &ui
);
249 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
251 ui_wnd_params_init(¶ms
);
252 params
.caption
= "Hello";
254 rc
= ui_window_create(ui
, ¶ms
, &window
);
255 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
256 PCUT_ASSERT_NOT_NULL(window
);
258 rc
= ui_menu_create(window
, &menu
);
259 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
260 PCUT_ASSERT_NOT_NULL(menu
);
267 open
= ui_menu_is_open(menu
);
268 PCUT_ASSERT_FALSE(open
);
270 rc
= ui_menu_open(menu
, &prect
, 0);
271 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
273 open
= ui_menu_is_open(menu
);
274 PCUT_ASSERT_TRUE(open
);
278 open
= ui_menu_is_open(menu
);
279 PCUT_ASSERT_FALSE(open
);
281 ui_menu_destroy(menu
);
282 ui_window_destroy(window
);
286 /** Paint background in graphics mode */
287 PCUT_TEST(paint_bg_gfx
)
290 ui_window_t
*window
= NULL
;
291 ui_wnd_params_t params
;
292 ui_menu_t
*menu
= NULL
;
297 rc
= ui_create_disp(NULL
, &ui
);
298 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
300 ui_wnd_params_init(¶ms
);
301 params
.caption
= "Hello";
303 rc
= ui_window_create(ui
, ¶ms
, &window
);
304 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
305 PCUT_ASSERT_NOT_NULL(window
);
307 rc
= ui_menu_create(window
, &menu
);
308 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
309 PCUT_ASSERT_NOT_NULL(menu
);
316 /* Menu needs to be open to be able to paint it */
317 rc
= ui_menu_open(menu
, &prect
, 0);
318 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
322 rc
= ui_menu_paint_bg_gfx(menu
, &pos
);
323 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
325 ui_window_destroy(window
);
329 /** Paint background in text mode */
330 PCUT_TEST(paint_bg_text
)
333 ui_window_t
*window
= NULL
;
334 ui_wnd_params_t params
;
335 ui_menu_t
*menu
= NULL
;
340 rc
= ui_create_disp(NULL
, &ui
);
341 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
343 ui_wnd_params_init(¶ms
);
344 params
.caption
= "Hello";
346 rc
= ui_window_create(ui
, ¶ms
, &window
);
347 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
348 PCUT_ASSERT_NOT_NULL(window
);
350 rc
= ui_menu_create(window
, &menu
);
351 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
352 PCUT_ASSERT_NOT_NULL(menu
);
359 /* Menu needs to be open to be able to paint it */
360 rc
= ui_menu_open(menu
, &prect
, 0);
361 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
365 rc
= ui_menu_paint_bg_text(menu
, &pos
);
366 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
368 ui_window_destroy(window
);
376 ui_window_t
*window
= NULL
;
377 ui_wnd_params_t params
;
378 ui_menu_t
*menu
= NULL
;
383 rc
= ui_create_disp(NULL
, &ui
);
384 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
386 ui_wnd_params_init(¶ms
);
387 params
.caption
= "Hello";
389 rc
= ui_window_create(ui
, ¶ms
, &window
);
390 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
391 PCUT_ASSERT_NOT_NULL(window
);
393 rc
= ui_menu_create(window
, &menu
);
394 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
395 PCUT_ASSERT_NOT_NULL(menu
);
402 /* Menu needs to be open to be able to paint it */
403 rc
= ui_menu_open(menu
, &prect
, 0);
404 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
408 rc
= ui_menu_paint(menu
, &pos
);
409 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
411 ui_window_destroy(window
);
415 /** ui_menu_pos_event() inside menu is claimed */
416 PCUT_TEST(pos_event_inside
)
419 ui_window_t
*window
= NULL
;
420 ui_wnd_params_t params
;
421 ui_menu_t
*menu
= NULL
;
422 ui_evclaim_t claimed
;
427 rc
= ui_create_disp(NULL
, &ui
);
428 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
430 ui_wnd_params_init(¶ms
);
431 params
.caption
= "Hello";
433 rc
= ui_window_create(ui
, ¶ms
, &window
);
434 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
435 PCUT_ASSERT_NOT_NULL(window
);
437 rc
= ui_menu_create(window
, &menu
);
438 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
439 PCUT_ASSERT_NOT_NULL(menu
);
443 event
.type
= POS_PRESS
;
446 claimed
= ui_menu_pos_event(menu
, &pos
, &event
);
447 PCUT_ASSERT_EQUALS(ui_claimed
, claimed
);
449 ui_window_destroy(window
);
453 /** ui_menu_up() with empty menu does nothing */
457 ui_window_t
*window
= NULL
;
458 ui_wnd_params_t params
;
459 ui_menu_t
*menu
= NULL
;
463 rc
= ui_create_disp(NULL
, &ui
);
464 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
466 ui_wnd_params_init(¶ms
);
467 params
.caption
= "Hello";
469 rc
= ui_window_create(ui
, ¶ms
, &window
);
470 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
471 PCUT_ASSERT_NOT_NULL(window
);
473 rc
= ui_menu_create(window
, &menu
);
474 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
475 PCUT_ASSERT_NOT_NULL(menu
);
482 /* Menu needs to be open to be able to move around it */
483 rc
= ui_menu_open(menu
, &prect
, 0);
484 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
488 ui_window_destroy(window
);
492 /** ui_menu_up() moves one entry up, skips separators, wraps around */
496 ui_window_t
*window
= NULL
;
497 ui_wnd_params_t params
;
498 ui_menu_t
*menu
= NULL
;
499 ui_menu_entry_t
*mentry1
= NULL
;
500 ui_menu_entry_t
*mentry2
= NULL
;
501 ui_menu_entry_t
*mentry3
= NULL
;
505 rc
= ui_create_disp(NULL
, &ui
);
506 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
508 ui_wnd_params_init(¶ms
);
509 params
.caption
= "Hello";
511 rc
= ui_window_create(ui
, ¶ms
, &window
);
512 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
513 PCUT_ASSERT_NOT_NULL(window
);
515 rc
= ui_menu_create(window
, &menu
);
516 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
517 PCUT_ASSERT_NOT_NULL(menu
);
519 rc
= ui_menu_entry_create(menu
, "Foo", "F1", &mentry1
);
520 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
521 PCUT_ASSERT_NOT_NULL(mentry1
);
523 rc
= ui_menu_entry_sep_create(menu
, &mentry2
);
524 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
525 PCUT_ASSERT_NOT_NULL(mentry2
);
527 rc
= ui_menu_entry_create(menu
, "Bar", "F2", &mentry3
);
528 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
529 PCUT_ASSERT_NOT_NULL(mentry3
);
536 /* Menu needs to be open to be able to move around it */
537 rc
= ui_menu_open(menu
, &prect
, 0);
538 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
540 /* When menu is open, the first entry is selected */
541 PCUT_ASSERT_EQUALS(mentry1
, menu
->selected
);
545 /* Now we've wrapped around to the last entry */
546 PCUT_ASSERT_EQUALS(mentry3
, menu
->selected
);
550 /* mentry2 is a separator and was skipped */
551 PCUT_ASSERT_EQUALS(mentry1
, menu
->selected
);
553 ui_window_destroy(window
);
557 /** ui_menu_down() with empty menu does nothing */
558 PCUT_TEST(down_empty
)
561 ui_window_t
*window
= NULL
;
562 ui_wnd_params_t params
;
563 ui_menu_t
*menu
= NULL
;
567 rc
= ui_create_disp(NULL
, &ui
);
568 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
570 ui_wnd_params_init(¶ms
);
571 params
.caption
= "Hello";
573 rc
= ui_window_create(ui
, ¶ms
, &window
);
574 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
575 PCUT_ASSERT_NOT_NULL(window
);
577 rc
= ui_menu_create(window
, &menu
);
578 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
579 PCUT_ASSERT_NOT_NULL(menu
);
586 /* Menu needs to be open to be able to move around it */
587 rc
= ui_menu_open(menu
, &prect
, 0);
588 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
592 ui_window_destroy(window
);
596 /** ui_menu_down() moves one entry down, skips separators, wraps around */
600 ui_window_t
*window
= NULL
;
601 ui_wnd_params_t params
;
602 ui_menu_t
*menu
= NULL
;
603 ui_menu_entry_t
*mentry1
= NULL
;
604 ui_menu_entry_t
*mentry2
= NULL
;
605 ui_menu_entry_t
*mentry3
= NULL
;
609 rc
= ui_create_disp(NULL
, &ui
);
610 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
612 ui_wnd_params_init(¶ms
);
613 params
.caption
= "Hello";
615 rc
= ui_window_create(ui
, ¶ms
, &window
);
616 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
617 PCUT_ASSERT_NOT_NULL(window
);
619 rc
= ui_menu_create(window
, &menu
);
620 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
621 PCUT_ASSERT_NOT_NULL(menu
);
623 rc
= ui_menu_entry_create(menu
, "Foo", "F1", &mentry1
);
624 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
625 PCUT_ASSERT_NOT_NULL(mentry1
);
627 rc
= ui_menu_entry_sep_create(menu
, &mentry2
);
628 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
629 PCUT_ASSERT_NOT_NULL(mentry2
);
631 rc
= ui_menu_entry_create(menu
, "Bar", "F2", &mentry3
);
632 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
633 PCUT_ASSERT_NOT_NULL(mentry3
);
640 /* Menu needs to be open to be able to move around it */
641 rc
= ui_menu_open(menu
, &prect
, 0);
642 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
644 /* When menu is open, the first entry is selected */
645 PCUT_ASSERT_EQUALS(mentry1
, menu
->selected
);
649 /* mentry2 is a separator and was skipped */
650 PCUT_ASSERT_EQUALS(mentry3
, menu
->selected
);
654 /* Now we've wrapped around to the first entry */
655 PCUT_ASSERT_EQUALS(mentry1
, menu
->selected
);
657 ui_window_destroy(window
);
661 /** Sending an unhandled event does nothing. */
662 PCUT_TEST(send_unhandled
)
664 ui_menu_t
*menu
= NULL
;
669 rc
= ui_menu_create(NULL
, &menu
);
670 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
671 PCUT_ASSERT_NOT_NULL(menu
);
673 /* Send events without setting callback */
676 ui_menu_left(menu
, idev_id
);
677 ui_menu_right(menu
, idev_id
);
678 ui_menu_close_req(menu
);
679 ui_menu_press_accel(menu
, c
, idev_id
);
681 /* Set dummy callback structure */
682 ui_menu_set_cb(menu
, &dummy_cb
, NULL
);
684 /* Send unhandled events */
685 ui_menu_left(menu
, idev_id
);
686 ui_menu_right(menu
, idev_id
);
687 ui_menu_close_req(menu
);
688 ui_menu_press_accel(menu
, c
, idev_id
);
690 ui_menu_destroy(menu
);
693 /** ui_menu_left() sends left event */
696 ui_menu_t
*menu
= NULL
;
701 rc
= ui_menu_create(NULL
, &menu
);
702 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
703 PCUT_ASSERT_NOT_NULL(menu
);
705 ui_menu_set_cb(menu
, &testmenu_cb
, (void *)&resp
);
707 memset(&resp
, 0, sizeof(resp
));
708 PCUT_ASSERT_FALSE(resp
.left_called
);
711 ui_menu_left(menu
, idev_id
);
713 PCUT_ASSERT_TRUE(resp
.left_called
);
714 PCUT_ASSERT_EQUALS(menu
, resp
.menu
);
715 PCUT_ASSERT_INT_EQUALS(idev_id
, resp
.idev_id
);
717 ui_menu_destroy(menu
);
720 /** ui_menu_right() sends right event */
723 ui_menu_t
*menu
= NULL
;
728 rc
= ui_menu_create(NULL
, &menu
);
729 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
730 PCUT_ASSERT_NOT_NULL(menu
);
732 ui_menu_set_cb(menu
, &testmenu_cb
, (void *)&resp
);
734 memset(&resp
, 0, sizeof(resp
));
735 PCUT_ASSERT_FALSE(resp
.right_called
);
738 ui_menu_right(menu
, idev_id
);
740 PCUT_ASSERT_TRUE(resp
.right_called
);
741 PCUT_ASSERT_EQUALS(menu
, resp
.menu
);
742 PCUT_ASSERT_INT_EQUALS(idev_id
, resp
.idev_id
);
744 ui_menu_destroy(menu
);
747 /** ui_menu_close_req() sends close_req event */
750 ui_menu_t
*menu
= NULL
;
754 rc
= ui_menu_create(NULL
, &menu
);
755 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
756 PCUT_ASSERT_NOT_NULL(menu
);
758 ui_menu_set_cb(menu
, &testmenu_cb
, (void *)&resp
);
760 memset(&resp
, 0, sizeof(resp
));
761 PCUT_ASSERT_FALSE(resp
.close_req_called
);
763 ui_menu_close_req(menu
);
765 PCUT_ASSERT_TRUE(resp
.close_req_called
);
766 PCUT_ASSERT_EQUALS(menu
, resp
.menu
);
768 ui_menu_destroy(menu
);
771 /** ui_menu_press_accel() sends press_accel event */
772 PCUT_TEST(press_accel
)
774 ui_menu_t
*menu
= NULL
;
780 rc
= ui_menu_create(NULL
, &menu
);
781 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
782 PCUT_ASSERT_NOT_NULL(menu
);
784 ui_menu_set_cb(menu
, &testmenu_cb
, (void *)&resp
);
786 memset(&resp
, 0, sizeof(resp
));
787 PCUT_ASSERT_FALSE(resp
.press_accel_called
);
791 ui_menu_press_accel(menu
, c
, idev_id
);
793 PCUT_ASSERT_TRUE(resp
.press_accel_called
);
794 PCUT_ASSERT_EQUALS(menu
, resp
.menu
);
795 PCUT_ASSERT_EQUALS(c
, resp
.c
);
796 PCUT_ASSERT_INT_EQUALS(idev_id
, resp
.idev_id
);
798 ui_menu_destroy(menu
);
801 /** Test menu left callback */
802 static void testmenu_left(ui_menu_t
*menu
, void *arg
, sysarg_t idev_id
)
804 test_resp_t
*resp
= (test_resp_t
*)arg
;
806 resp
->left_called
= true;
808 resp
->idev_id
= idev_id
;
811 /** Test menu right callback */
812 static void testmenu_right(ui_menu_t
*menu
, void *arg
, sysarg_t idev_id
)
814 test_resp_t
*resp
= (test_resp_t
*)arg
;
816 resp
->right_called
= true;
818 resp
->idev_id
= idev_id
;
821 /** Test menu close callback */
822 static void testmenu_close_req(ui_menu_t
*menu
, void *arg
)
824 test_resp_t
*resp
= (test_resp_t
*)arg
;
826 resp
->close_req_called
= true;
830 /** Test menu press accel callback */
831 static void testmenu_press_accel(ui_menu_t
*menu
, void *arg
,
832 char32_t c
, sysarg_t kbd_id
)
834 test_resp_t
*resp
= (test_resp_t
*)arg
;
836 resp
->press_accel_called
= true;
839 resp
->idev_id
= kbd_id
;