source: mainline/uspace/app/taskbar/test/wndlist.c@ 2f106b0

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2f106b0 was 2f106b0, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Do not show window buttons that do not fit

  • Property mode set to 100644
File size: 11.7 KB
Line 
1/*
2 * Copyright (c) 2022 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
39PCUT_INIT;
40
41PCUT_TEST_SUITE(taskbar);
42
43static void test_wndmgt_conn(ipc_call_t *, void *);
44
45static errno_t test_get_window_list(void *, wndmgt_window_list_t **);
46static errno_t test_get_window_info(void *, sysarg_t, wndmgt_window_info_t **);
47
48static 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
53static const char *test_wndmgt_server = "test-wndlist-wm";
54static const char *test_wndmgt_svc = "test/wndlist-wm";
55
56/* Test creating and destroying window list */
57PCUT_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(&params);
70 params.caption = "Hello";
71
72 rc = ui_window_create(ui, &params, &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 */
89PCUT_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(&params);
103 params.caption = "Hello";
104
105 rc = ui_window_create(ui, &params, &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 */
132PCUT_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(&params);
159 params.caption = "Hello";
160
161 rc = ui_window_create(ui, &params, &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 */
184PCUT_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(&params);
198 params.caption = "Hello";
199
200 rc = ui_window_create(ui, &params, &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);
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
217 wndlist_destroy(wndlist);
218
219 ui_window_destroy(window);
220 ui_destroy(ui);
221}
222
223/** Test removing entry */
224PCUT_TEST(remove)
225{
226 errno_t rc;
227 ui_t *ui = NULL;
228 ui_wnd_params_t params;
229 ui_window_t *window = NULL;
230 ui_fixed_t *fixed = NULL;
231 wndlist_t *wndlist;
232 wndlist_entry_t *entry;
233
234 rc = ui_create_disp(NULL, &ui);
235 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
236
237 ui_wnd_params_init(&params);
238 params.caption = "Hello";
239
240 rc = ui_window_create(ui, &params, &window);
241 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
242 PCUT_ASSERT_NOT_NULL(window);
243
244 rc = ui_fixed_create(&fixed);
245 ui_window_add(window, ui_fixed_ctl(fixed));
246
247 rc = wndlist_create(window, fixed, &wndlist);
248 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
249
250 rc = wndlist_append(wndlist, 1, "Foo", true);
251 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
252
253 rc = wndlist_append(wndlist, 2, "Bar", true);
254 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
255
256 entry = wndlist_first(wndlist);
257 PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
258
259 rc = wndlist_remove(wndlist, entry, true);
260 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
261
262 entry = wndlist_first(wndlist);
263 PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id);
264
265 wndlist_destroy(wndlist);
266
267 ui_window_destroy(window);
268 ui_destroy(ui);
269}
270
271/** Test setting entry rectangle */
272PCUT_TEST(set_entry_rect)
273{
274 errno_t rc;
275 ui_t *ui = NULL;
276 ui_wnd_params_t params;
277 ui_window_t *window = NULL;
278 ui_fixed_t *fixed = NULL;
279 wndlist_t *wndlist;
280 wndlist_entry_t *entry;
281
282 rc = ui_create_disp(NULL, &ui);
283 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
284
285 ui_wnd_params_init(&params);
286 params.caption = "Hello";
287
288 rc = ui_window_create(ui, &params, &window);
289 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
290 PCUT_ASSERT_NOT_NULL(window);
291
292 rc = ui_fixed_create(&fixed);
293 ui_window_add(window, ui_fixed_ctl(fixed));
294
295 rc = wndlist_create(window, fixed, &wndlist);
296 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
297
298 rc = wndlist_append(wndlist, 123, "Foo", true);
299 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
300
301 entry = wndlist_first(wndlist);
302
303 /* Set entry rectangle */
304 wndlist_set_entry_rect(wndlist, entry);
305
306 wndlist_destroy(wndlist);
307
308 ui_window_destroy(window);
309 ui_destroy(ui);
310}
311
312/** Test finding entry by window ID */
313PCUT_TEST(entry_by_id)
314{
315 errno_t rc;
316 ui_t *ui = NULL;
317 ui_wnd_params_t params;
318 ui_window_t *window = NULL;
319 ui_fixed_t *fixed = NULL;
320 wndlist_t *wndlist;
321 wndlist_entry_t *entry;
322
323 rc = ui_create_disp(NULL, &ui);
324 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
325
326 ui_wnd_params_init(&params);
327 params.caption = "Hello";
328
329 rc = ui_window_create(ui, &params, &window);
330 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
331 PCUT_ASSERT_NOT_NULL(window);
332
333 rc = ui_fixed_create(&fixed);
334 ui_window_add(window, ui_fixed_ctl(fixed));
335
336 rc = wndlist_create(window, fixed, &wndlist);
337 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
338
339 rc = wndlist_append(wndlist, 1, "Foo", true);
340 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
341
342 rc = wndlist_append(wndlist, 2, "Bar", true);
343 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
344
345 entry = wndlist_entry_by_id(wndlist, 1);
346 PCUT_ASSERT_NOT_NULL(entry);
347 PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
348
349 entry = wndlist_entry_by_id(wndlist, 2);
350 PCUT_ASSERT_NOT_NULL(entry);
351 PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id);
352
353 wndlist_destroy(wndlist);
354
355 ui_window_destroy(window);
356 ui_destroy(ui);
357}
358
359/** Test wndlist_first() / wndlist_next() */
360PCUT_TEST(first_next)
361{
362 errno_t rc;
363 ui_t *ui = NULL;
364 ui_wnd_params_t params;
365 ui_window_t *window = NULL;
366 ui_fixed_t *fixed = NULL;
367 wndlist_t *wndlist;
368 wndlist_entry_t *entry;
369
370 rc = ui_create_disp(NULL, &ui);
371 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
372
373 ui_wnd_params_init(&params);
374 params.caption = "Hello";
375
376 rc = ui_window_create(ui, &params, &window);
377 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
378 PCUT_ASSERT_NOT_NULL(window);
379
380 rc = ui_fixed_create(&fixed);
381 ui_window_add(window, ui_fixed_ctl(fixed));
382
383 rc = wndlist_create(window, fixed, &wndlist);
384 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
385
386 rc = wndlist_append(wndlist, 1, "Foo", true);
387 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
388
389 rc = wndlist_append(wndlist, 2, "Bar", true);
390 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
391
392 entry = wndlist_first(wndlist);
393 PCUT_ASSERT_NOT_NULL(entry);
394 PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id);
395
396 entry = wndlist_next(entry);
397 PCUT_ASSERT_NOT_NULL(entry);
398 PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id);
399
400 entry = wndlist_next(entry);
401 PCUT_ASSERT_NULL(entry);
402
403 wndlist_destroy(wndlist);
404
405 ui_window_destroy(window);
406 ui_destroy(ui);
407}
408
409/** Test repainting window list */
410PCUT_TEST(repaint)
411{
412 errno_t rc;
413 ui_t *ui = NULL;
414 ui_wnd_params_t params;
415 ui_window_t *window = NULL;
416 ui_fixed_t *fixed = NULL;
417 wndlist_t *wndlist;
418
419 rc = ui_create_disp(NULL, &ui);
420 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
421
422 ui_wnd_params_init(&params);
423 params.caption = "Hello";
424
425 rc = ui_window_create(ui, &params, &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);
436 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
437
438 rc = wndlist_append(wndlist, 2, "Bar", true);
439 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
440
441 rc = wndlist_repaint(wndlist);
442 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
443
444 wndlist_destroy(wndlist);
445
446 ui_window_destroy(window);
447 ui_destroy(ui);
448}
449
450/** Test window management service connection. */
451static void test_wndmgt_conn(ipc_call_t *icall, void *arg)
452{
453 wndmgt_srv_t srv;
454
455 /* Set up protocol structure */
456 wndmgt_srv_initialize(&srv);
457 srv.ops = &test_wndmgt_srv_ops;
458 srv.arg = arg;
459
460 /* Handle connection */
461 wndmgt_conn(icall, &srv);
462}
463
464static errno_t test_get_window_list(void *arg, wndmgt_window_list_t **rlist)
465{
466 wndmgt_window_list_t *wlist;
467
468 (void)arg;
469
470 wlist = calloc(1, sizeof(wndmgt_window_list_t));
471 if (wlist == NULL)
472 return ENOMEM;
473
474 wlist->nwindows = 1;
475 wlist->windows = calloc(1, sizeof(sysarg_t));
476 if (wlist->windows == NULL) {
477 free(wlist);
478 return ENOMEM;
479 }
480
481 wlist->windows[0] = 42;
482 *rlist = wlist;
483 return EOK;
484}
485
486static errno_t test_get_window_info(void *arg, sysarg_t wnd_id,
487 wndmgt_window_info_t **rinfo)
488{
489 wndmgt_window_info_t *winfo;
490
491 (void)arg;
492
493 winfo = calloc(1, sizeof(wndmgt_window_info_t));
494 if (winfo == NULL)
495 return ENOMEM;
496
497 winfo->caption = str_dup("Hello");
498 if (winfo->caption == NULL) {
499 free(winfo);
500 return ENOMEM;
501 }
502
503 *rinfo = winfo;
504 return EOK;
505}
506
507PCUT_EXPORT(wndlist);
Note: See TracBrowser for help on using the repository browser.