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