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 <errno.h>
|
---|
30 | #include <loc.h>
|
---|
31 | #include <pcut/pcut.h>
|
---|
32 | #include <str.h>
|
---|
33 | #include <ui/fixed.h>
|
---|
34 | #include <ui/ui.h>
|
---|
35 | #include <ui/window.h>
|
---|
36 | #include <wndmgt_srv.h>
|
---|
37 | #include "../wndlist.h"
|
---|
38 |
|
---|
39 | PCUT_INIT;
|
---|
40 |
|
---|
41 | PCUT_TEST_SUITE(taskbar);
|
---|
42 |
|
---|
43 | static void test_wndmgt_conn(ipc_call_t *, void *);
|
---|
44 |
|
---|
45 | static errno_t test_get_window_list(void *, wndmgt_window_list_t **);
|
---|
46 | static errno_t test_get_window_info(void *, sysarg_t, wndmgt_window_info_t **);
|
---|
47 |
|
---|
48 | static wndmgt_ops_t test_wndmgt_srv_ops = {
|
---|
49 | .get_window_list = test_get_window_list,
|
---|
50 | .get_window_info = test_get_window_info
|
---|
51 | };
|
---|
52 |
|
---|
53 | static const char *test_wndmgt_server = "test-wndlist-wm";
|
---|
54 | static const char *test_wndmgt_svc = "test/wndlist-wm";
|
---|
55 |
|
---|
56 | /* Test creating and destroying window list */
|
---|
57 | PCUT_TEST(create_destroy)
|
---|
58 | {
|
---|
59 | errno_t rc;
|
---|
60 | ui_t *ui = NULL;
|
---|
61 | ui_wnd_params_t params;
|
---|
62 | ui_window_t *window = NULL;
|
---|
63 | ui_fixed_t *fixed = NULL;
|
---|
64 | wndlist_t *wndlist;
|
---|
65 |
|
---|
66 | rc = ui_create_disp(NULL, &ui);
|
---|
67 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
68 |
|
---|
69 | ui_wnd_params_init(¶ms);
|
---|
70 | params.caption = "Hello";
|
---|
71 |
|
---|
72 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
73 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
74 | PCUT_ASSERT_NOT_NULL(window);
|
---|
75 |
|
---|
76 | rc = ui_fixed_create(&fixed);
|
---|
77 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
78 |
|
---|
79 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
80 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
81 |
|
---|
82 | wndlist_destroy(wndlist);
|
---|
83 |
|
---|
84 | ui_window_destroy(window);
|
---|
85 | ui_destroy(ui);
|
---|
86 | }
|
---|
87 |
|
---|
88 | /* Test setting window list rectangle */
|
---|
89 | PCUT_TEST(set_rect)
|
---|
90 | {
|
---|
91 | errno_t rc;
|
---|
92 | ui_t *ui = NULL;
|
---|
93 | ui_wnd_params_t params;
|
---|
94 | ui_window_t *window = NULL;
|
---|
95 | ui_fixed_t *fixed = NULL;
|
---|
96 | gfx_rect_t rect;
|
---|
97 | wndlist_t *wndlist;
|
---|
98 |
|
---|
99 | rc = ui_create_disp(NULL, &ui);
|
---|
100 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
101 |
|
---|
102 | ui_wnd_params_init(¶ms);
|
---|
103 | params.caption = "Hello";
|
---|
104 |
|
---|
105 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
106 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
107 | PCUT_ASSERT_NOT_NULL(window);
|
---|
108 |
|
---|
109 | rc = ui_fixed_create(&fixed);
|
---|
110 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
111 |
|
---|
112 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
113 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
114 |
|
---|
115 | rect.p0.x = 1;
|
---|
116 | rect.p0.y = 2;
|
---|
117 | rect.p1.x = 3;
|
---|
118 | rect.p1.y = 4;
|
---|
119 | wndlist_set_rect(wndlist, &rect);
|
---|
120 | PCUT_ASSERT_INT_EQUALS(1, wndlist->rect.p0.x);
|
---|
121 | PCUT_ASSERT_INT_EQUALS(2, wndlist->rect.p0.y);
|
---|
122 | PCUT_ASSERT_INT_EQUALS(3, wndlist->rect.p1.x);
|
---|
123 | PCUT_ASSERT_INT_EQUALS(4, wndlist->rect.p1.y);
|
---|
124 |
|
---|
125 | wndlist_destroy(wndlist);
|
---|
126 |
|
---|
127 | ui_window_destroy(window);
|
---|
128 | ui_destroy(ui);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Test opening WM service */
|
---|
132 | PCUT_TEST(open_wm)
|
---|
133 | {
|
---|
134 | errno_t rc;
|
---|
135 | service_id_t sid;
|
---|
136 | ui_t *ui = NULL;
|
---|
137 | ui_wnd_params_t params;
|
---|
138 | ui_window_t *window = NULL;
|
---|
139 | ui_fixed_t *fixed = NULL;
|
---|
140 | wndlist_t *wndlist;
|
---|
141 | loc_srv_t *srv;
|
---|
142 |
|
---|
143 | /* Set up a test WM service */
|
---|
144 |
|
---|
145 | async_set_fallback_port_handler(test_wndmgt_conn, NULL);
|
---|
146 |
|
---|
147 | // FIXME This causes this test to be non-reentrant!
|
---|
148 | rc = loc_server_register(test_wndmgt_server, &srv);
|
---|
149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
150 |
|
---|
151 | rc = loc_service_register(srv, test_wndmgt_svc, fallback_port_id, &sid);
|
---|
152 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
153 |
|
---|
154 | /* Create window list and connect it to our test service */
|
---|
155 |
|
---|
156 | rc = ui_create_disp(NULL, &ui);
|
---|
157 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
158 |
|
---|
159 | ui_wnd_params_init(¶ms);
|
---|
160 | params.caption = "Hello";
|
---|
161 |
|
---|
162 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
163 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
164 | PCUT_ASSERT_NOT_NULL(window);
|
---|
165 |
|
---|
166 | rc = ui_fixed_create(&fixed);
|
---|
167 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
168 |
|
---|
169 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
170 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
171 |
|
---|
172 | rc = wndlist_open_wm(wndlist, test_wndmgt_svc);
|
---|
173 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
174 |
|
---|
175 | wndlist_destroy(wndlist);
|
---|
176 |
|
---|
177 | ui_window_destroy(window);
|
---|
178 | ui_destroy(ui);
|
---|
179 |
|
---|
180 | rc = loc_service_unregister(srv, sid);
|
---|
181 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
182 | loc_server_unregister(srv);
|
---|
183 | }
|
---|
184 |
|
---|
185 | /** Test appending new entry */
|
---|
186 | PCUT_TEST(append)
|
---|
187 | {
|
---|
188 | errno_t rc;
|
---|
189 | ui_t *ui = NULL;
|
---|
190 | ui_wnd_params_t params;
|
---|
191 | ui_window_t *window = NULL;
|
---|
192 | ui_fixed_t *fixed = NULL;
|
---|
193 | wndlist_t *wndlist;
|
---|
194 | wndlist_entry_t *entry;
|
---|
195 |
|
---|
196 | rc = ui_create_disp(NULL, &ui);
|
---|
197 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
198 |
|
---|
199 | ui_wnd_params_init(¶ms);
|
---|
200 | params.caption = "Hello";
|
---|
201 |
|
---|
202 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
203 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
204 | PCUT_ASSERT_NOT_NULL(window);
|
---|
205 |
|
---|
206 | rc = ui_fixed_create(&fixed);
|
---|
207 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
208 |
|
---|
209 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
210 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
211 |
|
---|
212 | rc = wndlist_append(wndlist, 123, "Foo", true, true);
|
---|
213 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
214 |
|
---|
215 | entry = wndlist_first(wndlist);
|
---|
216 | PCUT_ASSERT_INT_EQUALS(123, entry->wnd_id);
|
---|
217 | PCUT_ASSERT_NOT_NULL(entry->button);
|
---|
218 | PCUT_ASSERT_TRUE(ui_pbutton_get_light(entry->button));
|
---|
219 |
|
---|
220 | wndlist_destroy(wndlist);
|
---|
221 |
|
---|
222 | ui_window_destroy(window);
|
---|
223 | ui_destroy(ui);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /** Test removing entry */
|
---|
227 | PCUT_TEST(remove)
|
---|
228 | {
|
---|
229 | errno_t rc;
|
---|
230 | ui_t *ui = NULL;
|
---|
231 | ui_wnd_params_t params;
|
---|
232 | ui_window_t *window = NULL;
|
---|
233 | ui_fixed_t *fixed = NULL;
|
---|
234 | wndlist_t *wndlist;
|
---|
235 | wndlist_entry_t *entry;
|
---|
236 |
|
---|
237 | rc = ui_create_disp(NULL, &ui);
|
---|
238 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
239 |
|
---|
240 | ui_wnd_params_init(¶ms);
|
---|
241 | params.caption = "Hello";
|
---|
242 |
|
---|
243 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
244 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
245 | PCUT_ASSERT_NOT_NULL(window);
|
---|
246 |
|
---|
247 | rc = ui_fixed_create(&fixed);
|
---|
248 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
249 |
|
---|
250 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
251 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
252 |
|
---|
253 | rc = wndlist_append(wndlist, 1, "Foo", true, true);
|
---|
254 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
255 |
|
---|
256 | rc = wndlist_append(wndlist, 2, "Bar", false, true);
|
---|
257 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
258 |
|
---|
259 | entry = wndlist_first(wndlist);
|
---|
260 | PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
|
---|
261 |
|
---|
262 | rc = wndlist_remove(wndlist, entry, true);
|
---|
263 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
264 |
|
---|
265 | entry = wndlist_first(wndlist);
|
---|
266 | PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id);
|
---|
267 |
|
---|
268 | wndlist_destroy(wndlist);
|
---|
269 |
|
---|
270 | ui_window_destroy(window);
|
---|
271 | ui_destroy(ui);
|
---|
272 | }
|
---|
273 |
|
---|
274 | /** Test updating entry */
|
---|
275 | PCUT_TEST(update)
|
---|
276 | {
|
---|
277 | errno_t rc;
|
---|
278 | ui_t *ui = NULL;
|
---|
279 | ui_wnd_params_t params;
|
---|
280 | ui_window_t *window = NULL;
|
---|
281 | ui_fixed_t *fixed = NULL;
|
---|
282 | wndlist_t *wndlist;
|
---|
283 | wndlist_entry_t *entry;
|
---|
284 |
|
---|
285 | rc = ui_create_disp(NULL, &ui);
|
---|
286 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
287 |
|
---|
288 | ui_wnd_params_init(¶ms);
|
---|
289 | params.caption = "Hello";
|
---|
290 |
|
---|
291 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
292 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
293 | PCUT_ASSERT_NOT_NULL(window);
|
---|
294 |
|
---|
295 | rc = ui_fixed_create(&fixed);
|
---|
296 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
297 |
|
---|
298 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
299 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
300 |
|
---|
301 | rc = wndlist_append(wndlist, 1, "Foo", true, true);
|
---|
302 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
303 |
|
---|
304 | entry = wndlist_first(wndlist);
|
---|
305 | PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
|
---|
306 | PCUT_ASSERT_NOT_NULL(entry->button);
|
---|
307 | PCUT_ASSERT_TRUE(ui_pbutton_get_light(entry->button));
|
---|
308 |
|
---|
309 | rc = wndlist_update(wndlist, entry, "Bar", false);
|
---|
310 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
311 |
|
---|
312 | PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
|
---|
313 | PCUT_ASSERT_NOT_NULL(entry->button);
|
---|
314 | PCUT_ASSERT_FALSE(ui_pbutton_get_light(entry->button));
|
---|
315 |
|
---|
316 | wndlist_destroy(wndlist);
|
---|
317 |
|
---|
318 | ui_window_destroy(window);
|
---|
319 | ui_destroy(ui);
|
---|
320 | }
|
---|
321 |
|
---|
322 | /** Test setting entry rectangle */
|
---|
323 | PCUT_TEST(set_entry_rect)
|
---|
324 | {
|
---|
325 | errno_t rc;
|
---|
326 | ui_t *ui = NULL;
|
---|
327 | ui_wnd_params_t params;
|
---|
328 | ui_window_t *window = NULL;
|
---|
329 | ui_fixed_t *fixed = NULL;
|
---|
330 | wndlist_t *wndlist;
|
---|
331 | wndlist_entry_t *entry;
|
---|
332 |
|
---|
333 | rc = ui_create_disp(NULL, &ui);
|
---|
334 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
335 |
|
---|
336 | ui_wnd_params_init(¶ms);
|
---|
337 | params.caption = "Hello";
|
---|
338 |
|
---|
339 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
340 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
341 | PCUT_ASSERT_NOT_NULL(window);
|
---|
342 |
|
---|
343 | rc = ui_fixed_create(&fixed);
|
---|
344 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
345 |
|
---|
346 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
347 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
348 |
|
---|
349 | rc = wndlist_append(wndlist, 123, "Foo", true, true);
|
---|
350 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
351 |
|
---|
352 | entry = wndlist_first(wndlist);
|
---|
353 |
|
---|
354 | /* Set entry rectangle */
|
---|
355 | wndlist_set_entry_rect(wndlist, entry);
|
---|
356 |
|
---|
357 | wndlist_destroy(wndlist);
|
---|
358 |
|
---|
359 | ui_window_destroy(window);
|
---|
360 | ui_destroy(ui);
|
---|
361 | }
|
---|
362 |
|
---|
363 | /** Test finding entry by window ID */
|
---|
364 | PCUT_TEST(entry_by_id)
|
---|
365 | {
|
---|
366 | errno_t rc;
|
---|
367 | ui_t *ui = NULL;
|
---|
368 | ui_wnd_params_t params;
|
---|
369 | ui_window_t *window = NULL;
|
---|
370 | ui_fixed_t *fixed = NULL;
|
---|
371 | wndlist_t *wndlist;
|
---|
372 | wndlist_entry_t *entry;
|
---|
373 |
|
---|
374 | rc = ui_create_disp(NULL, &ui);
|
---|
375 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
376 |
|
---|
377 | ui_wnd_params_init(¶ms);
|
---|
378 | params.caption = "Hello";
|
---|
379 |
|
---|
380 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
381 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
382 | PCUT_ASSERT_NOT_NULL(window);
|
---|
383 |
|
---|
384 | rc = ui_fixed_create(&fixed);
|
---|
385 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
386 |
|
---|
387 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
388 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
389 |
|
---|
390 | rc = wndlist_append(wndlist, 1, "Foo", true, true);
|
---|
391 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
392 |
|
---|
393 | rc = wndlist_append(wndlist, 2, "Bar", false, true);
|
---|
394 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
395 |
|
---|
396 | entry = wndlist_entry_by_id(wndlist, 1);
|
---|
397 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
398 | PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
|
---|
399 |
|
---|
400 | entry = wndlist_entry_by_id(wndlist, 2);
|
---|
401 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
402 | PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id);
|
---|
403 |
|
---|
404 | wndlist_destroy(wndlist);
|
---|
405 |
|
---|
406 | ui_window_destroy(window);
|
---|
407 | ui_destroy(ui);
|
---|
408 | }
|
---|
409 |
|
---|
410 | /** Test wndlist_first() / wndlist_next() */
|
---|
411 | PCUT_TEST(first_next)
|
---|
412 | {
|
---|
413 | errno_t rc;
|
---|
414 | ui_t *ui = NULL;
|
---|
415 | ui_wnd_params_t params;
|
---|
416 | ui_window_t *window = NULL;
|
---|
417 | ui_fixed_t *fixed = NULL;
|
---|
418 | wndlist_t *wndlist;
|
---|
419 | wndlist_entry_t *entry;
|
---|
420 |
|
---|
421 | rc = ui_create_disp(NULL, &ui);
|
---|
422 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
423 |
|
---|
424 | ui_wnd_params_init(¶ms);
|
---|
425 | params.caption = "Hello";
|
---|
426 |
|
---|
427 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
428 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
429 | PCUT_ASSERT_NOT_NULL(window);
|
---|
430 |
|
---|
431 | rc = ui_fixed_create(&fixed);
|
---|
432 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
433 |
|
---|
434 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
435 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
436 |
|
---|
437 | rc = wndlist_append(wndlist, 1, "Foo", true, true);
|
---|
438 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
439 |
|
---|
440 | rc = wndlist_append(wndlist, 2, "Bar", false, true);
|
---|
441 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
442 |
|
---|
443 | entry = wndlist_first(wndlist);
|
---|
444 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
445 | PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
|
---|
446 |
|
---|
447 | entry = wndlist_next(entry);
|
---|
448 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
449 | PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id);
|
---|
450 |
|
---|
451 | entry = wndlist_next(entry);
|
---|
452 | PCUT_ASSERT_NULL(entry);
|
---|
453 |
|
---|
454 | wndlist_destroy(wndlist);
|
---|
455 |
|
---|
456 | ui_window_destroy(window);
|
---|
457 | ui_destroy(ui);
|
---|
458 | }
|
---|
459 |
|
---|
460 | /** Test wndlist_last() */
|
---|
461 | PCUT_TEST(last)
|
---|
462 | {
|
---|
463 | errno_t rc;
|
---|
464 | ui_t *ui = NULL;
|
---|
465 | ui_wnd_params_t params;
|
---|
466 | ui_window_t *window = NULL;
|
---|
467 | ui_fixed_t *fixed = NULL;
|
---|
468 | wndlist_t *wndlist;
|
---|
469 | wndlist_entry_t *entry;
|
---|
470 |
|
---|
471 | rc = ui_create_disp(NULL, &ui);
|
---|
472 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
473 |
|
---|
474 | ui_wnd_params_init(¶ms);
|
---|
475 | params.caption = "Hello";
|
---|
476 |
|
---|
477 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
478 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
479 | PCUT_ASSERT_NOT_NULL(window);
|
---|
480 |
|
---|
481 | rc = ui_fixed_create(&fixed);
|
---|
482 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
483 |
|
---|
484 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
485 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
486 |
|
---|
487 | rc = wndlist_append(wndlist, 1, "Foo", true, true);
|
---|
488 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
489 |
|
---|
490 | rc = wndlist_append(wndlist, 2, "Bar", false, true);
|
---|
491 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
492 |
|
---|
493 | entry = wndlist_last(wndlist);
|
---|
494 | PCUT_ASSERT_NOT_NULL(entry);
|
---|
495 | PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id);
|
---|
496 |
|
---|
497 | wndlist_destroy(wndlist);
|
---|
498 |
|
---|
499 | ui_window_destroy(window);
|
---|
500 | ui_destroy(ui);
|
---|
501 | }
|
---|
502 |
|
---|
503 | /** Test wndlist_count() */
|
---|
504 | PCUT_TEST(count)
|
---|
505 | {
|
---|
506 | errno_t rc;
|
---|
507 | ui_t *ui = NULL;
|
---|
508 | ui_wnd_params_t params;
|
---|
509 | ui_window_t *window = NULL;
|
---|
510 | ui_fixed_t *fixed = NULL;
|
---|
511 | wndlist_t *wndlist;
|
---|
512 | size_t count;
|
---|
513 |
|
---|
514 | rc = ui_create_disp(NULL, &ui);
|
---|
515 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
516 |
|
---|
517 | ui_wnd_params_init(¶ms);
|
---|
518 | params.caption = "Hello";
|
---|
519 |
|
---|
520 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
521 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
522 | PCUT_ASSERT_NOT_NULL(window);
|
---|
523 |
|
---|
524 | rc = ui_fixed_create(&fixed);
|
---|
525 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
526 |
|
---|
527 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
528 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
529 |
|
---|
530 | count = wndlist_count(wndlist);
|
---|
531 | PCUT_ASSERT_INT_EQUALS(0, count);
|
---|
532 |
|
---|
533 | rc = wndlist_append(wndlist, 1, "Foo", true, true);
|
---|
534 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
535 |
|
---|
536 | count = wndlist_count(wndlist);
|
---|
537 | PCUT_ASSERT_INT_EQUALS(1, count);
|
---|
538 |
|
---|
539 | rc = wndlist_append(wndlist, 2, "Bar", false, true);
|
---|
540 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
541 |
|
---|
542 | count = wndlist_count(wndlist);
|
---|
543 | PCUT_ASSERT_INT_EQUALS(2, count);
|
---|
544 |
|
---|
545 | wndlist_destroy(wndlist);
|
---|
546 |
|
---|
547 | ui_window_destroy(window);
|
---|
548 | ui_destroy(ui);
|
---|
549 | }
|
---|
550 |
|
---|
551 | /** Test repainting window list */
|
---|
552 | PCUT_TEST(repaint)
|
---|
553 | {
|
---|
554 | errno_t rc;
|
---|
555 | ui_t *ui = NULL;
|
---|
556 | ui_wnd_params_t params;
|
---|
557 | ui_window_t *window = NULL;
|
---|
558 | ui_fixed_t *fixed = NULL;
|
---|
559 | wndlist_t *wndlist;
|
---|
560 |
|
---|
561 | rc = ui_create_disp(NULL, &ui);
|
---|
562 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
563 |
|
---|
564 | ui_wnd_params_init(¶ms);
|
---|
565 | params.caption = "Hello";
|
---|
566 |
|
---|
567 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
568 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
569 | PCUT_ASSERT_NOT_NULL(window);
|
---|
570 |
|
---|
571 | rc = ui_fixed_create(&fixed);
|
---|
572 | ui_window_add(window, ui_fixed_ctl(fixed));
|
---|
573 |
|
---|
574 | rc = wndlist_create(window, fixed, &wndlist);
|
---|
575 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
576 |
|
---|
577 | rc = wndlist_append(wndlist, 1, "Foo", true, true);
|
---|
578 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
579 |
|
---|
580 | rc = wndlist_append(wndlist, 2, "Bar", false, true);
|
---|
581 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
582 |
|
---|
583 | rc = wndlist_repaint(wndlist);
|
---|
584 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
585 |
|
---|
586 | wndlist_destroy(wndlist);
|
---|
587 |
|
---|
588 | ui_window_destroy(window);
|
---|
589 | ui_destroy(ui);
|
---|
590 | }
|
---|
591 |
|
---|
592 | /** Test window management service connection. */
|
---|
593 | static void test_wndmgt_conn(ipc_call_t *icall, void *arg)
|
---|
594 | {
|
---|
595 | wndmgt_srv_t srv;
|
---|
596 |
|
---|
597 | /* Set up protocol structure */
|
---|
598 | wndmgt_srv_initialize(&srv);
|
---|
599 | srv.ops = &test_wndmgt_srv_ops;
|
---|
600 | srv.arg = arg;
|
---|
601 |
|
---|
602 | /* Handle connection */
|
---|
603 | wndmgt_conn(icall, &srv);
|
---|
604 | }
|
---|
605 |
|
---|
606 | static errno_t test_get_window_list(void *arg, wndmgt_window_list_t **rlist)
|
---|
607 | {
|
---|
608 | wndmgt_window_list_t *wlist;
|
---|
609 |
|
---|
610 | (void)arg;
|
---|
611 |
|
---|
612 | wlist = calloc(1, sizeof(wndmgt_window_list_t));
|
---|
613 | if (wlist == NULL)
|
---|
614 | return ENOMEM;
|
---|
615 |
|
---|
616 | wlist->nwindows = 1;
|
---|
617 | wlist->windows = calloc(1, sizeof(sysarg_t));
|
---|
618 | if (wlist->windows == NULL) {
|
---|
619 | free(wlist);
|
---|
620 | return ENOMEM;
|
---|
621 | }
|
---|
622 |
|
---|
623 | wlist->windows[0] = 42;
|
---|
624 | *rlist = wlist;
|
---|
625 | return EOK;
|
---|
626 | }
|
---|
627 |
|
---|
628 | static errno_t test_get_window_info(void *arg, sysarg_t wnd_id,
|
---|
629 | wndmgt_window_info_t **rinfo)
|
---|
630 | {
|
---|
631 | wndmgt_window_info_t *winfo;
|
---|
632 |
|
---|
633 | (void)arg;
|
---|
634 |
|
---|
635 | winfo = calloc(1, sizeof(wndmgt_window_info_t));
|
---|
636 | if (winfo == NULL)
|
---|
637 | return ENOMEM;
|
---|
638 |
|
---|
639 | winfo->caption = str_dup("Hello");
|
---|
640 | if (winfo->caption == NULL) {
|
---|
641 | free(winfo);
|
---|
642 | return ENOMEM;
|
---|
643 | }
|
---|
644 |
|
---|
645 | *rinfo = winfo;
|
---|
646 | return EOK;
|
---|
647 | }
|
---|
648 |
|
---|
649 | PCUT_EXPORT(wndlist);
|
---|