Handle Enter/Escape keys in message dialog.
[helenos.git] / uspace / app / taskbar-cfg / test / startmenu.c
blob0cbd2b9e6315e19d508f9e2f3a5bb57b06212e3d
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 <async.h>
30 #include <dispcfg.h>
31 #include <dispcfg_srv.h>
32 #include <errno.h>
33 #include <pcut/pcut.h>
34 #include <str.h>
35 #include <testdc.h>
36 #include "../display-cfg.h"
37 #include "../seats.h"
39 PCUT_INIT;
41 PCUT_TEST_SUITE(seats);
43 static const char *test_dispcfg_server = "test-dispcfg";
44 static const char *test_dispcfg_svc = "test/dispcfg";
46 /** Test dcfg_seats_create() and dcfg_seats_destroy() */
47 PCUT_TEST(create_destroy)
49 display_cfg_t *dcfg;
50 dcfg_seats_t *seats;
51 errno_t rc;
53 rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
54 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
56 rc = dcfg_seats_create(dcfg, &seats);
57 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
59 dcfg_seats_destroy(seats);
60 display_cfg_destroy(dcfg);
63 /** dcfg_seats_insert() inserts an entry into the seat list */
64 PCUT_TEST(seats_insert)
66 display_cfg_t *dcfg;
67 dcfg_seats_t *seats;
68 dcfg_seats_entry_t *entry = NULL;
69 errno_t rc;
71 rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
72 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
74 rc = dcfg_seats_create(dcfg, &seats);
75 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
77 rc = dcfg_seats_insert(seats, "Alice", 42, &entry);
78 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
79 PCUT_ASSERT_NOT_NULL(entry);
81 PCUT_ASSERT_STR_EQUALS("Alice", entry->name);
82 PCUT_ASSERT_INT_EQUALS(42, entry->seat_id);
84 dcfg_seats_destroy(seats);
85 display_cfg_destroy(dcfg);
88 /** dcfg_seats_list_populate() populates seat list */
89 PCUT_TEST(seats_list_populate)
91 display_cfg_t *dcfg;
92 dcfg_seats_t *seats;
93 errno_t rc;
94 service_id_t sid;
95 test_response_t resp;
96 loc_srv_t *srv;
98 async_set_fallback_port_handler(test_dispcfg_conn, &resp);
100 // FIXME This causes this test to be non-reentrant!
101 rc = loc_server_register(test_dispcfg_server, &srv);
102 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
104 rc = loc_service_register(srv, test_dispcfg_svc, &sid);
105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
107 rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
108 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
110 rc = display_cfg_open(dcfg, test_dispcfg_svc);
111 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
113 rc = dcfg_seats_create(dcfg, &seats);
114 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
117 * dcfg_seat_list_populate() calls dispcfg_get_seat_list()
118 * and dispcfg_get_seat_info()
120 resp.rc = EOK;
121 resp.get_seat_list_rlist = calloc(1, sizeof(dispcfg_seat_list_t));
122 PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist);
123 resp.get_seat_list_rlist->nseats = 1;
124 resp.get_seat_list_rlist->seats = calloc(1, sizeof(sysarg_t));
125 PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist->seats);
126 resp.get_seat_list_rlist->seats[0] = 42;
128 resp.get_seat_info_rinfo = calloc(1, sizeof(dispcfg_seat_info_t));
129 PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo);
130 resp.get_seat_info_rinfo->name = str_dup("Alice");
131 PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo->name);
133 rc = dcfg_seats_list_populate(seats);
134 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
136 dcfg_seats_destroy(seats);
137 display_cfg_destroy(dcfg);
139 rc = loc_service_unregister(srv, sid);
140 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
141 loc_server_unregister(srv);
144 /** dcfg_devices_insert() inserts an entry into the device list */
145 PCUT_TEST(devices_insert)
147 display_cfg_t *dcfg;
148 dcfg_seats_t *seats;
149 ui_list_entry_t *lentry;
150 dcfg_devices_entry_t *entry;
151 errno_t rc;
153 rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
154 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
156 rc = dcfg_seats_create(dcfg, &seats);
157 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
159 rc = dcfg_devices_insert(seats, "mydevice", 42);
160 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
162 lentry = ui_list_first(seats->device_list);
163 PCUT_ASSERT_NOT_NULL(lentry);
164 entry = (dcfg_devices_entry_t *)ui_list_entry_get_arg(lentry);
165 PCUT_ASSERT_NOT_NULL(entry);
167 PCUT_ASSERT_STR_EQUALS("mydevice", entry->name);
168 PCUT_ASSERT_INT_EQUALS(42, entry->svc_id);
170 dcfg_seats_destroy(seats);
171 display_cfg_destroy(dcfg);
174 /** dcfg_avail_devices_insert() inserts entry into available devices list */
175 PCUT_TEST(avail_devices_insert)
177 display_cfg_t *dcfg;
178 dcfg_seats_t *seats;
179 ui_list_entry_t *lentry;
180 dcfg_devices_entry_t *entry;
181 ui_select_dialog_t *dialog;
182 ui_select_dialog_params_t sdparams;
183 errno_t rc;
185 rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
186 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
188 rc = dcfg_seats_create(dcfg, &seats);
189 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
191 ui_select_dialog_params_init(&sdparams);
192 sdparams.caption = "Dialog";
193 sdparams.prompt = "Select";
195 rc = ui_select_dialog_create(seats->dcfg->ui, &sdparams, &dialog);
196 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
198 rc = dcfg_avail_devices_insert(seats, dialog, "mydevice", 42);
199 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
201 lentry = ui_list_first(ui_select_dialog_list(dialog));
202 PCUT_ASSERT_NOT_NULL(lentry);
203 entry = (dcfg_devices_entry_t *)ui_list_entry_get_arg(lentry);
204 PCUT_ASSERT_NOT_NULL(entry);
206 PCUT_ASSERT_STR_EQUALS("mydevice", entry->name);
207 PCUT_ASSERT_INT_EQUALS(42, entry->svc_id);
209 ui_select_dialog_destroy(dialog);
210 dcfg_seats_destroy(seats);
211 display_cfg_destroy(dcfg);
214 PCUT_TEST(asgn_dev_list_populate)
218 PCUT_TEST(avail_dev_list_populate)
222 PCUT_TEST(seats_get_selected)
226 PCUT_TEST(devices_get_selected)
230 PCUT_TEST(seats_list_selected)
234 PCUT_TEST(add_seat_clicked)
238 PCUT_TEST(remove_seat_clicked)
242 PCUT_TEST(add_seat_dialog_bok)
246 PCUT_TEST(add_seat_dialog_bcancel)
250 PCUT_TEST(add_seat_dialog_close)
254 PCUT_TEST(add_device_clicked)
258 PCUT_TEST(remove_device_clicked)
262 PCUT_TEST(add_device_dialog_bok)
266 PCUT_TEST(add_device_dialog_bcancel)
270 PCUT_TEST(add_device_dialog_close)
274 PCUT_EXPORT(seats);