Changeset fc00f0d in mainline
- Timestamp:
- 2022-11-02T10:19:25Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1f433d
- Parents:
- 1b92d4b
- git-author:
- Jiri Svoboda <jiri@…> (2022-11-01 18:17:04)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-11-02 10:19:25)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/test/wndlist.c
r1b92d4b rfc00f0d 28 28 29 29 #include <errno.h> 30 #include <loc.h> 30 31 #include <pcut/pcut.h> 32 #include <str.h> 31 33 #include <ui/fixed.h> 32 34 #include <ui/ui.h> 33 35 #include <ui/window.h> 36 #include <wndmgt_srv.h> 34 37 #include "../wndlist.h" 35 38 … … 37 40 38 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"; 39 55 40 56 /* Test creating and destroying window list */ … … 70 86 } 71 87 88 /** Test opening WM service */ 89 PCUT_TEST(open_wm) 90 { 91 errno_t rc; 92 service_id_t sid; 93 ui_t *ui = NULL; 94 ui_wnd_params_t params; 95 ui_window_t *window = NULL; 96 ui_fixed_t *fixed = NULL; 97 wndlist_t *wndlist; 98 99 /* Set up a test WM service */ 100 101 async_set_fallback_port_handler(test_wndmgt_conn, NULL); 102 103 // FIXME This causes this test to be non-reentrant! 104 rc = loc_server_register(test_wndmgt_server); 105 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 106 107 rc = loc_service_register(test_wndmgt_svc, &sid); 108 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 109 110 /* Create window list and connect it to our test service */ 111 112 rc = ui_create_disp(NULL, &ui); 113 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 114 115 ui_wnd_params_init(¶ms); 116 params.caption = "Hello"; 117 118 rc = ui_window_create(ui, ¶ms, &window); 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 120 PCUT_ASSERT_NOT_NULL(window); 121 122 rc = ui_fixed_create(&fixed); 123 ui_window_add(window, ui_fixed_ctl(fixed)); 124 125 rc = wndlist_create(window, fixed, &wndlist); 126 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 127 128 rc = wndlist_open_wm(wndlist, test_wndmgt_svc); 129 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 130 131 wndlist_destroy(wndlist); 132 133 ui_window_destroy(window); 134 ui_destroy(ui); 135 136 rc = loc_service_unregister(sid); 137 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 138 } 139 140 /** Test appending new entry */ 141 PCUT_TEST(append) 142 { 143 errno_t rc; 144 ui_t *ui = NULL; 145 ui_wnd_params_t params; 146 ui_window_t *window = NULL; 147 ui_fixed_t *fixed = NULL; 148 wndlist_t *wndlist; 149 wndlist_entry_t *entry; 150 151 rc = ui_create_disp(NULL, &ui); 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 153 154 ui_wnd_params_init(¶ms); 155 params.caption = "Hello"; 156 157 rc = ui_window_create(ui, ¶ms, &window); 158 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 159 PCUT_ASSERT_NOT_NULL(window); 160 161 rc = ui_fixed_create(&fixed); 162 ui_window_add(window, ui_fixed_ctl(fixed)); 163 164 rc = wndlist_create(window, fixed, &wndlist); 165 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 166 167 rc = wndlist_append(wndlist, 123, "Foo", true); 168 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 169 170 entry = wndlist_first(wndlist); 171 PCUT_ASSERT_INT_EQUALS(123, entry->wnd_id); 172 PCUT_ASSERT_NOT_NULL(entry->button); 173 174 wndlist_destroy(wndlist); 175 176 ui_window_destroy(window); 177 ui_destroy(ui); 178 } 179 180 /** Test removing entry */ 181 PCUT_TEST(remove) 182 { 183 errno_t rc; 184 ui_t *ui = NULL; 185 ui_wnd_params_t params; 186 ui_window_t *window = NULL; 187 ui_fixed_t *fixed = NULL; 188 wndlist_t *wndlist; 189 wndlist_entry_t *entry; 190 191 rc = ui_create_disp(NULL, &ui); 192 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 193 194 ui_wnd_params_init(¶ms); 195 params.caption = "Hello"; 196 197 rc = ui_window_create(ui, ¶ms, &window); 198 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 199 PCUT_ASSERT_NOT_NULL(window); 200 201 rc = ui_fixed_create(&fixed); 202 ui_window_add(window, ui_fixed_ctl(fixed)); 203 204 rc = wndlist_create(window, fixed, &wndlist); 205 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 206 207 rc = wndlist_append(wndlist, 1, "Foo", true); 208 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 209 210 rc = wndlist_append(wndlist, 2, "Bar", true); 211 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 212 213 entry = wndlist_first(wndlist); 214 PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id); 215 216 rc = wndlist_remove(wndlist, entry, true); 217 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 218 219 entry = wndlist_first(wndlist); 220 PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id); 221 222 wndlist_destroy(wndlist); 223 224 ui_window_destroy(window); 225 ui_destroy(ui); 226 } 227 228 /** Test setting entry rectangle */ 229 PCUT_TEST(set_entry_rect) 230 { 231 errno_t rc; 232 ui_t *ui = NULL; 233 ui_wnd_params_t params; 234 ui_window_t *window = NULL; 235 ui_fixed_t *fixed = NULL; 236 wndlist_t *wndlist; 237 wndlist_entry_t *entry; 238 239 rc = ui_create_disp(NULL, &ui); 240 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 241 242 ui_wnd_params_init(¶ms); 243 params.caption = "Hello"; 244 245 rc = ui_window_create(ui, ¶ms, &window); 246 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 247 PCUT_ASSERT_NOT_NULL(window); 248 249 rc = ui_fixed_create(&fixed); 250 ui_window_add(window, ui_fixed_ctl(fixed)); 251 252 rc = wndlist_create(window, fixed, &wndlist); 253 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 254 255 rc = wndlist_append(wndlist, 123, "Foo", true); 256 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 258 entry = wndlist_first(wndlist); 259 260 /* Set entry rectangle */ 261 wndlist_set_entry_rect(wndlist, entry); 262 263 wndlist_destroy(wndlist); 264 265 ui_window_destroy(window); 266 ui_destroy(ui); 267 } 268 269 /** Test finding entry by window ID */ 270 PCUT_TEST(entry_by_id) 271 { 272 errno_t rc; 273 ui_t *ui = NULL; 274 ui_wnd_params_t params; 275 ui_window_t *window = NULL; 276 ui_fixed_t *fixed = NULL; 277 wndlist_t *wndlist; 278 wndlist_entry_t *entry; 279 280 rc = ui_create_disp(NULL, &ui); 281 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 282 283 ui_wnd_params_init(¶ms); 284 params.caption = "Hello"; 285 286 rc = ui_window_create(ui, ¶ms, &window); 287 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 288 PCUT_ASSERT_NOT_NULL(window); 289 290 rc = ui_fixed_create(&fixed); 291 ui_window_add(window, ui_fixed_ctl(fixed)); 292 293 rc = wndlist_create(window, fixed, &wndlist); 294 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 295 296 rc = wndlist_append(wndlist, 1, "Foo", true); 297 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 298 299 rc = wndlist_append(wndlist, 2, "Bar", true); 300 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 301 302 entry = wndlist_entry_by_id(wndlist, 1); 303 PCUT_ASSERT_NOT_NULL(entry); 304 PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id); 305 306 entry = wndlist_entry_by_id(wndlist, 2); 307 PCUT_ASSERT_NOT_NULL(entry); 308 PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id); 309 310 wndlist_destroy(wndlist); 311 312 ui_window_destroy(window); 313 ui_destroy(ui); 314 } 315 316 /** Test wndlist_first() / wndlist_next() */ 317 PCUT_TEST(first_next) 318 { 319 errno_t rc; 320 ui_t *ui = NULL; 321 ui_wnd_params_t params; 322 ui_window_t *window = NULL; 323 ui_fixed_t *fixed = NULL; 324 wndlist_t *wndlist; 325 wndlist_entry_t *entry; 326 327 rc = ui_create_disp(NULL, &ui); 328 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 329 330 ui_wnd_params_init(¶ms); 331 params.caption = "Hello"; 332 333 rc = ui_window_create(ui, ¶ms, &window); 334 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 335 PCUT_ASSERT_NOT_NULL(window); 336 337 rc = ui_fixed_create(&fixed); 338 ui_window_add(window, ui_fixed_ctl(fixed)); 339 340 rc = wndlist_create(window, fixed, &wndlist); 341 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 342 343 rc = wndlist_append(wndlist, 1, "Foo", true); 344 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 345 346 rc = wndlist_append(wndlist, 2, "Bar", true); 347 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 348 349 entry = wndlist_first(wndlist); 350 PCUT_ASSERT_NOT_NULL(entry); 351 PCUT_ASSERT_INT_EQUALS(1, entry->wnd_id); 352 353 entry = wndlist_next(entry); 354 PCUT_ASSERT_NOT_NULL(entry); 355 PCUT_ASSERT_INT_EQUALS(2, entry->wnd_id); 356 357 entry = wndlist_next(entry); 358 PCUT_ASSERT_NULL(entry); 359 360 wndlist_destroy(wndlist); 361 362 ui_window_destroy(window); 363 ui_destroy(ui); 364 } 365 366 /** Test repainting window list */ 367 PCUT_TEST(repaint) 368 { 369 errno_t rc; 370 ui_t *ui = NULL; 371 ui_wnd_params_t params; 372 ui_window_t *window = NULL; 373 ui_fixed_t *fixed = NULL; 374 wndlist_t *wndlist; 375 376 rc = ui_create_disp(NULL, &ui); 377 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 378 379 ui_wnd_params_init(¶ms); 380 params.caption = "Hello"; 381 382 rc = ui_window_create(ui, ¶ms, &window); 383 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 384 PCUT_ASSERT_NOT_NULL(window); 385 386 rc = ui_fixed_create(&fixed); 387 ui_window_add(window, ui_fixed_ctl(fixed)); 388 389 rc = wndlist_create(window, fixed, &wndlist); 390 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 391 392 rc = wndlist_append(wndlist, 1, "Foo", true); 393 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 394 395 rc = wndlist_append(wndlist, 2, "Bar", true); 396 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 397 398 rc = wndlist_repaint(wndlist); 399 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 400 401 wndlist_destroy(wndlist); 402 403 ui_window_destroy(window); 404 ui_destroy(ui); 405 } 406 407 /** Test window management service connection. */ 408 static void test_wndmgt_conn(ipc_call_t *icall, void *arg) 409 { 410 wndmgt_srv_t srv; 411 412 /* Set up protocol structure */ 413 wndmgt_srv_initialize(&srv); 414 srv.ops = &test_wndmgt_srv_ops; 415 srv.arg = arg; 416 417 /* Handle connection */ 418 wndmgt_conn(icall, &srv); 419 } 420 421 static errno_t test_get_window_list(void *arg, wndmgt_window_list_t **rlist) 422 { 423 wndmgt_window_list_t *wlist; 424 425 (void)arg; 426 427 wlist = calloc(1, sizeof(wndmgt_window_list_t)); 428 if (wlist == NULL) 429 return ENOMEM; 430 431 wlist->nwindows = 1; 432 wlist->windows = calloc(1, sizeof(sysarg_t)); 433 if (wlist->windows == NULL) { 434 free(wlist); 435 return ENOMEM; 436 } 437 438 wlist->windows[0] = 42; 439 *rlist = wlist; 440 return EOK; 441 } 442 443 static errno_t test_get_window_info(void *arg, sysarg_t wnd_id, 444 wndmgt_window_info_t **rinfo) 445 { 446 wndmgt_window_info_t *winfo; 447 448 (void)arg; 449 450 winfo = calloc(1, sizeof(wndmgt_window_info_t)); 451 if (winfo == NULL) 452 return ENOMEM; 453 454 winfo->caption = str_dup("Hello"); 455 if (winfo->caption == NULL) { 456 free(winfo); 457 return ENOMEM; 458 } 459 460 *rinfo = winfo; 461 return EOK; 462 } 463 72 464 PCUT_EXPORT(wndlist);
Note:
See TracChangeset
for help on using the changeset viewer.