Array of strings sys_dirs must be NULL-terminated
[helenos.git] / uspace / app / nav / test / menu.c
blobedd5154323f1045e10b0719f50a53259c7734735
1 /*
2 * Copyright (c) 2021 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 <errno.h>
30 #include <pcut/pcut.h>
31 #include <stdbool.h>
32 #include "../menu.h"
34 PCUT_INIT;
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
47 /** Test response */
48 typedef struct {
49 bool file_open;
50 bool file_exit;
51 } test_resp_t;
53 /** Create and destroy menu. */
54 PCUT_TEST(create_destroy)
56 ui_t *ui;
57 ui_window_t *window;
58 ui_wnd_params_t params;
59 nav_menu_t *menu;
60 errno_t rc;
62 rc = ui_create_disp(NULL, &ui);
63 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
65 ui_wnd_params_init(&params);
66 params.caption = "Test";
68 rc = ui_window_create(ui, &params, &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);
76 ui_destroy(ui);
79 /** nav_menu_set_cb() */
80 PCUT_TEST(set_cb)
82 ui_t *ui;
83 ui_window_t *window;
84 ui_wnd_params_t params;
85 nav_menu_t *menu;
86 int foo;
87 errno_t rc;
89 rc = ui_create_disp(NULL, &ui);
90 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
92 ui_wnd_params_init(&params);
93 params.caption = "Test";
95 rc = ui_window_create(ui, &params, &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);
107 ui_destroy(ui);
110 /** File / Open callback */
111 PCUT_TEST(file_open)
113 ui_t *ui;
114 ui_window_t *window;
115 ui_wnd_params_t params;
116 nav_menu_t *menu;
117 test_resp_t resp;
118 errno_t rc;
120 rc = ui_create_disp(NULL, &ui);
121 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
123 ui_wnd_params_init(&params);
124 params.caption = "Test";
126 rc = ui_window_create(ui, &params, &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);
147 ui_destroy(ui);
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;
166 PCUT_EXPORT(menu);