2 * Copyright (c) 2021 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.
30 #include <pcut/pcut.h>
36 PCUT_TEST_SUITE(menu
);
38 static void test_menu_file_open(void *);
39 static void test_menu_file_exit(void *);
41 static nav_menu_cb_t dummy_cb
;
42 static nav_menu_cb_t test_cb
= {
43 .file_open
= test_menu_file_open
,
44 .file_exit
= test_menu_file_exit
53 /** Create and destroy menu. */
54 PCUT_TEST(create_destroy
)
58 ui_wnd_params_t params
;
62 rc
= ui_create_disp(NULL
, &ui
);
63 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
65 ui_wnd_params_init(¶ms
);
66 params
.caption
= "Test";
68 rc
= ui_window_create(ui
, ¶ms
, &window
);
69 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
71 rc
= nav_menu_create(window
, &menu
);
72 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
74 nav_menu_destroy(menu
);
75 ui_window_destroy(window
);
79 /** nav_menu_set_cb() */
84 ui_wnd_params_t params
;
89 rc
= ui_create_disp(NULL
, &ui
);
90 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
92 ui_wnd_params_init(¶ms
);
93 params
.caption
= "Test";
95 rc
= ui_window_create(ui
, ¶ms
, &window
);
96 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
98 rc
= nav_menu_create(window
, &menu
);
99 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
101 nav_menu_set_cb(menu
, &test_cb
, &foo
);
102 PCUT_ASSERT_EQUALS(&test_cb
, menu
->cb
);
103 PCUT_ASSERT_EQUALS(&foo
, menu
->cb_arg
);
105 nav_menu_destroy(menu
);
106 ui_window_destroy(window
);
110 /** File / Open callback */
115 ui_wnd_params_t params
;
120 rc
= ui_create_disp(NULL
, &ui
);
121 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
123 ui_wnd_params_init(¶ms
);
124 params
.caption
= "Test";
126 rc
= ui_window_create(ui
, ¶ms
, &window
);
127 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
129 rc
= nav_menu_create(window
, &menu
);
130 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
132 /* Call back with no callbacks set */
133 nav_menu_file_open(NULL
, menu
);
135 /* Call back with dummy callbacks set */
136 nav_menu_set_cb(menu
, &dummy_cb
, &resp
);
137 nav_menu_file_open(NULL
, menu
);
139 /* Call back with test callbacks set */
140 resp
.file_open
= false;
141 nav_menu_set_cb(menu
, &test_cb
, &resp
);
142 nav_menu_file_open(NULL
, menu
);
143 PCUT_ASSERT_TRUE(resp
.file_open
);
145 nav_menu_destroy(menu
);
146 ui_window_destroy(window
);
150 /** Testing File / Open callback */
151 static void test_menu_file_open(void *arg
)
153 test_resp_t
*resp
= (test_resp_t
*)arg
;
155 resp
->file_open
= true;
158 /** Testing File / Exit callback */
159 static void test_menu_file_exit(void *arg
)
161 test_resp_t
*resp
= (test_resp_t
*)arg
;
163 resp
->file_exit
= true;