1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
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.
|
---|
16 | *
|
---|
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.
|
---|
27 | */
|
---|
28 |
|
---|
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"
|
---|
38 |
|
---|
39 | PCUT_INIT;
|
---|
40 |
|
---|
41 | PCUT_TEST_SUITE(seats);
|
---|
42 |
|
---|
43 | static const char *test_dispcfg_server = "test-dispcfg";
|
---|
44 | static const char *test_dispcfg_svc = "test/dispcfg";
|
---|
45 |
|
---|
46 | /** Test dcfg_seats_create() and dcfg_seats_destroy() */
|
---|
47 | PCUT_TEST(create_destroy)
|
---|
48 | {
|
---|
49 | display_cfg_t *dcfg;
|
---|
50 | dcfg_seats_t *seats;
|
---|
51 | errno_t rc;
|
---|
52 |
|
---|
53 | rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
|
---|
54 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
55 |
|
---|
56 | rc = dcfg_seats_create(dcfg, &seats);
|
---|
57 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
58 |
|
---|
59 | dcfg_seats_destroy(seats);
|
---|
60 | display_cfg_destroy(dcfg);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /** dcfg_seats_insert() inserts an entry into the seat list */
|
---|
64 | PCUT_TEST(seats_insert)
|
---|
65 | {
|
---|
66 | display_cfg_t *dcfg;
|
---|
67 | dcfg_seats_t *seats;
|
---|
68 | dcfg_seats_entry_t *entry = NULL;
|
---|
69 | errno_t rc;
|
---|
70 |
|
---|
71 | rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
|
---|
72 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
73 |
|
---|
74 | rc = dcfg_seats_create(dcfg, &seats);
|
---|
75 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
76 |
|
---|
77 | rc = dcfg_seats_insert(seats, "Alice", 42, &entry);
|
---|
78 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
79 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
80 |
|
---|
81 | PCUT_ASSERT_STR_EQUALS("Alice", entry->name);
|
---|
82 | PCUT_ASSERT_INT_EQUALS(42, entry->seat_id);
|
---|
83 |
|
---|
84 | dcfg_seats_destroy(seats);
|
---|
85 | display_cfg_destroy(dcfg);
|
---|
86 | }
|
---|
87 |
|
---|
88 | /** dcfg_seats_list_populate() populates seat list */
|
---|
89 | PCUT_TEST(seats_list_populate)
|
---|
90 | {
|
---|
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;
|
---|
97 |
|
---|
98 | async_set_fallback_port_handler(test_dispcfg_conn, &resp);
|
---|
99 |
|
---|
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);
|
---|
103 |
|
---|
104 | rc = loc_service_register(srv, test_dispcfg_svc, fallback_port_id,
|
---|
105 | &sid);
|
---|
106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
107 |
|
---|
108 | rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
|
---|
109 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
110 |
|
---|
111 | rc = display_cfg_open(dcfg, test_dispcfg_svc);
|
---|
112 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
113 |
|
---|
114 | rc = dcfg_seats_create(dcfg, &seats);
|
---|
115 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * dcfg_seat_list_populate() calls dispcfg_get_seat_list()
|
---|
119 | * and dispcfg_get_seat_info()
|
---|
120 | */
|
---|
121 | resp.rc = EOK;
|
---|
122 | resp.get_seat_list_rlist = calloc(1, sizeof(dispcfg_seat_list_t));
|
---|
123 | PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist);
|
---|
124 | resp.get_seat_list_rlist->nseats = 1;
|
---|
125 | resp.get_seat_list_rlist->seats = calloc(1, sizeof(sysarg_t));
|
---|
126 | PCUT_ASSERT_NOT_NULL(resp.get_seat_list_rlist->seats);
|
---|
127 | resp.get_seat_list_rlist->seats[0] = 42;
|
---|
128 |
|
---|
129 | resp.get_seat_info_rinfo = calloc(1, sizeof(dispcfg_seat_info_t));
|
---|
130 | PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo);
|
---|
131 | resp.get_seat_info_rinfo->name = str_dup("Alice");
|
---|
132 | PCUT_ASSERT_NOT_NULL(resp.get_seat_info_rinfo->name);
|
---|
133 |
|
---|
134 | rc = dcfg_seats_list_populate(seats);
|
---|
135 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
136 |
|
---|
137 | dcfg_seats_destroy(seats);
|
---|
138 | display_cfg_destroy(dcfg);
|
---|
139 |
|
---|
140 | rc = loc_service_unregister(srv, sid);
|
---|
141 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
142 | loc_server_unregister(srv);
|
---|
143 | }
|
---|
144 |
|
---|
145 | /** dcfg_devices_insert() inserts an entry into the device list */
|
---|
146 | PCUT_TEST(devices_insert)
|
---|
147 | {
|
---|
148 | display_cfg_t *dcfg;
|
---|
149 | dcfg_seats_t *seats;
|
---|
150 | ui_list_entry_t *lentry;
|
---|
151 | dcfg_devices_entry_t *entry;
|
---|
152 | errno_t rc;
|
---|
153 |
|
---|
154 | rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
|
---|
155 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
156 |
|
---|
157 | rc = dcfg_seats_create(dcfg, &seats);
|
---|
158 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
159 |
|
---|
160 | rc = dcfg_devices_insert(seats, "mydevice", 42);
|
---|
161 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
162 |
|
---|
163 | lentry = ui_list_first(seats->device_list);
|
---|
164 | PCUT_ASSERT_NOT_NULL(lentry);
|
---|
165 | entry = (dcfg_devices_entry_t *)ui_list_entry_get_arg(lentry);
|
---|
166 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
167 |
|
---|
168 | PCUT_ASSERT_STR_EQUALS("mydevice", entry->name);
|
---|
169 | PCUT_ASSERT_INT_EQUALS(42, entry->svc_id);
|
---|
170 |
|
---|
171 | dcfg_seats_destroy(seats);
|
---|
172 | display_cfg_destroy(dcfg);
|
---|
173 | }
|
---|
174 |
|
---|
175 | /** dcfg_avail_devices_insert() inserts entry into available devices list */
|
---|
176 | PCUT_TEST(avail_devices_insert)
|
---|
177 | {
|
---|
178 | display_cfg_t *dcfg;
|
---|
179 | dcfg_seats_t *seats;
|
---|
180 | ui_list_entry_t *lentry;
|
---|
181 | dcfg_devices_entry_t *entry;
|
---|
182 | ui_select_dialog_t *dialog;
|
---|
183 | ui_select_dialog_params_t sdparams;
|
---|
184 | errno_t rc;
|
---|
185 |
|
---|
186 | rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
|
---|
187 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
188 |
|
---|
189 | rc = dcfg_seats_create(dcfg, &seats);
|
---|
190 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
191 |
|
---|
192 | ui_select_dialog_params_init(&sdparams);
|
---|
193 | sdparams.caption = "Dialog";
|
---|
194 | sdparams.prompt = "Select";
|
---|
195 |
|
---|
196 | rc = ui_select_dialog_create(seats->dcfg->ui, &sdparams, &dialog);
|
---|
197 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
198 |
|
---|
199 | rc = dcfg_avail_devices_insert(seats, dialog, "mydevice", 42);
|
---|
200 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
201 |
|
---|
202 | lentry = ui_list_first(ui_select_dialog_list(dialog));
|
---|
203 | PCUT_ASSERT_NOT_NULL(lentry);
|
---|
204 | entry = (dcfg_devices_entry_t *)ui_list_entry_get_arg(lentry);
|
---|
205 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
206 |
|
---|
207 | PCUT_ASSERT_STR_EQUALS("mydevice", entry->name);
|
---|
208 | PCUT_ASSERT_INT_EQUALS(42, entry->svc_id);
|
---|
209 |
|
---|
210 | ui_select_dialog_destroy(dialog);
|
---|
211 | dcfg_seats_destroy(seats);
|
---|
212 | display_cfg_destroy(dcfg);
|
---|
213 | }
|
---|
214 |
|
---|
215 | PCUT_TEST(asgn_dev_list_populate)
|
---|
216 | {
|
---|
217 | }
|
---|
218 |
|
---|
219 | PCUT_TEST(avail_dev_list_populate)
|
---|
220 | {
|
---|
221 | }
|
---|
222 |
|
---|
223 | PCUT_TEST(seats_get_selected)
|
---|
224 | {
|
---|
225 | }
|
---|
226 |
|
---|
227 | PCUT_TEST(devices_get_selected)
|
---|
228 | {
|
---|
229 | }
|
---|
230 |
|
---|
231 | PCUT_TEST(seats_list_selected)
|
---|
232 | {
|
---|
233 | }
|
---|
234 |
|
---|
235 | PCUT_TEST(add_seat_clicked)
|
---|
236 | {
|
---|
237 | }
|
---|
238 |
|
---|
239 | PCUT_TEST(remove_seat_clicked)
|
---|
240 | {
|
---|
241 | }
|
---|
242 |
|
---|
243 | PCUT_TEST(add_seat_dialog_bok)
|
---|
244 | {
|
---|
245 | }
|
---|
246 |
|
---|
247 | PCUT_TEST(add_seat_dialog_bcancel)
|
---|
248 | {
|
---|
249 | }
|
---|
250 |
|
---|
251 | PCUT_TEST(add_seat_dialog_close)
|
---|
252 | {
|
---|
253 | }
|
---|
254 |
|
---|
255 | PCUT_TEST(add_device_clicked)
|
---|
256 | {
|
---|
257 | }
|
---|
258 |
|
---|
259 | PCUT_TEST(remove_device_clicked)
|
---|
260 | {
|
---|
261 | }
|
---|
262 |
|
---|
263 | PCUT_TEST(add_device_dialog_bok)
|
---|
264 | {
|
---|
265 | }
|
---|
266 |
|
---|
267 | PCUT_TEST(add_device_dialog_bcancel)
|
---|
268 | {
|
---|
269 | }
|
---|
270 |
|
---|
271 | PCUT_TEST(add_device_dialog_close)
|
---|
272 | {
|
---|
273 | }
|
---|
274 |
|
---|
275 | PCUT_EXPORT(seats);
|
---|