Changeset 1c6c3e1d in mainline for uspace/lib/ui/test/menu.c
- Timestamp:
- 2023-10-22T17:55:33Z (14 months ago)
- Branches:
- ticket/834-toolchain-update
- Children:
- 350ec74
- Parents:
- 315d487 (diff), 133461c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/menu.c
r315d487 r1c6c3e1d 46 46 PCUT_TEST_SUITE(menu); 47 47 48 typedef struct { 49 bool left_called; 50 bool right_called; 51 bool close_req_called; 52 bool press_accel_called; 53 ui_menu_t *menu; 54 sysarg_t idev_id; 55 char32_t c; 56 } test_resp_t; 57 58 static void testmenu_left(ui_menu_t *, void *, sysarg_t); 59 static void testmenu_right(ui_menu_t *, void *, sysarg_t); 60 static void testmenu_close_req(ui_menu_t *, void *); 61 static void testmenu_press_accel(ui_menu_t *, void *, char32_t, sysarg_t); 62 63 ui_menu_cb_t testmenu_cb = { 64 .left = testmenu_left, 65 .right = testmenu_right, 66 .close_req = testmenu_close_req, 67 .press_accel = testmenu_press_accel 68 }; 69 70 ui_menu_cb_t dummy_cb = { 71 }; 72 48 73 /** Create and destroy menu */ 49 74 PCUT_TEST(create_destroy) 50 75 { 51 ui_menu_bar_t *mbar = NULL; 52 ui_menu_t *menu = NULL; 53 errno_t rc; 54 55 rc = ui_menu_bar_create(NULL, NULL, &mbar); 56 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 57 58 rc = ui_menu_create(mbar, "Test", &menu); 59 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 60 PCUT_ASSERT_NOT_NULL(menu); 61 62 /* 63 * Normally we don't need to destroy a menu explicitly, it will 64 * be destroyed along with menu bar, but here we'll test destroying 65 * it explicitly. 66 */ 67 ui_menu_destroy(menu); 68 ui_menu_bar_destroy(mbar); 76 ui_menu_t *menu = NULL; 77 errno_t rc; 78 79 rc = ui_menu_create(NULL, &menu); 80 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 81 PCUT_ASSERT_NOT_NULL(menu); 82 83 ui_menu_destroy(menu); 69 84 } 70 85 … … 75 90 } 76 91 77 /** ui_menu_first() / ui_menu_next() iterate over menus */ 78 PCUT_TEST(first_next) 79 { 80 ui_t *ui = NULL; 81 ui_window_t *window = NULL; 82 ui_wnd_params_t params; 83 ui_menu_bar_t *mbar = NULL; 84 ui_menu_t *menu1 = NULL; 85 ui_menu_t *menu2 = NULL; 86 ui_menu_t *m; 87 errno_t rc; 88 89 rc = ui_create_disp(NULL, &ui); 90 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 91 92 ui_wnd_params_init(¶ms); 93 params.caption = "Hello"; 94 95 rc = ui_window_create(ui, ¶ms, &window); 96 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 97 PCUT_ASSERT_NOT_NULL(window); 98 99 rc = ui_menu_bar_create(ui, window, &mbar); 100 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 101 PCUT_ASSERT_NOT_NULL(mbar); 102 103 rc = ui_menu_create(mbar, "Test 1", &menu1); 104 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 105 PCUT_ASSERT_NOT_NULL(menu1); 106 107 rc = ui_menu_create(mbar, "Test 1", &menu2); 108 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 109 PCUT_ASSERT_NOT_NULL(menu2); 110 111 m = ui_menu_first(mbar); 112 PCUT_ASSERT_EQUALS(menu1, m); 113 114 m = ui_menu_next(m); 115 PCUT_ASSERT_EQUALS(menu2, m); 116 117 m = ui_menu_next(m); 118 PCUT_ASSERT_NULL(m); 119 120 ui_menu_bar_destroy(mbar); 121 ui_window_destroy(window); 122 ui_destroy(ui); 123 } 124 125 /** ui_menu_last() / ui_menu_prev() iterate over menus in reverse */ 126 PCUT_TEST(last_prev) 127 { 128 ui_t *ui = NULL; 129 ui_window_t *window = NULL; 130 ui_wnd_params_t params; 131 ui_menu_bar_t *mbar = NULL; 132 ui_menu_t *menu1 = NULL; 133 ui_menu_t *menu2 = NULL; 134 ui_menu_t *m; 135 errno_t rc; 136 137 rc = ui_create_disp(NULL, &ui); 138 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 139 140 ui_wnd_params_init(¶ms); 141 params.caption = "Hello"; 142 143 rc = ui_window_create(ui, ¶ms, &window); 144 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 PCUT_ASSERT_NOT_NULL(window); 146 147 rc = ui_menu_bar_create(ui, window, &mbar); 148 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 149 PCUT_ASSERT_NOT_NULL(mbar); 150 151 rc = ui_menu_create(mbar, "Test 1", &menu1); 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 153 PCUT_ASSERT_NOT_NULL(menu1); 154 155 rc = ui_menu_create(mbar, "Test 1", &menu2); 156 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 157 PCUT_ASSERT_NOT_NULL(menu2); 158 159 m = ui_menu_last(mbar); 160 PCUT_ASSERT_EQUALS(menu2, m); 161 162 m = ui_menu_prev(m); 163 PCUT_ASSERT_EQUALS(menu1, m); 164 165 m = ui_menu_prev(m); 166 PCUT_ASSERT_NULL(m); 167 168 ui_menu_bar_destroy(mbar); 169 ui_window_destroy(window); 170 ui_destroy(ui); 171 } 172 173 /** ui_menu_caption() returns the menu's caption */ 174 PCUT_TEST(caption) 175 { 176 ui_t *ui = NULL; 177 ui_window_t *window = NULL; 178 ui_wnd_params_t params; 179 ui_menu_bar_t *mbar = NULL; 180 ui_menu_t *menu = NULL; 181 const char *caption; 182 errno_t rc; 183 184 rc = ui_create_disp(NULL, &ui); 185 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 186 187 ui_wnd_params_init(¶ms); 188 params.caption = "Hello"; 189 190 rc = ui_window_create(ui, ¶ms, &window); 191 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 192 PCUT_ASSERT_NOT_NULL(window); 193 194 rc = ui_menu_bar_create(ui, window, &mbar); 195 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 196 PCUT_ASSERT_NOT_NULL(mbar); 197 198 rc = ui_menu_create(mbar, "Test", &menu); 199 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 PCUT_ASSERT_NOT_NULL(menu); 201 202 caption = ui_menu_caption(menu); 203 PCUT_ASSERT_NOT_NULL(caption); 204 205 PCUT_ASSERT_INT_EQUALS(0, str_cmp(caption, "Test")); 206 207 ui_menu_bar_destroy(mbar); 208 ui_window_destroy(window); 209 ui_destroy(ui); 210 } 211 212 /** ui_menu_get_rect() returns outer menu rectangle */ 213 PCUT_TEST(get_rect) 214 { 215 ui_t *ui = NULL; 216 ui_window_t *window = NULL; 217 ui_wnd_params_t params; 218 ui_menu_bar_t *mbar = NULL; 219 ui_menu_t *menu = NULL; 220 gfx_coord2_t pos; 221 gfx_rect_t rect; 222 const char *caption; 223 errno_t rc; 224 225 rc = ui_create_disp(NULL, &ui); 226 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 227 228 ui_wnd_params_init(¶ms); 229 params.caption = "Hello"; 230 231 rc = ui_window_create(ui, ¶ms, &window); 232 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 233 PCUT_ASSERT_NOT_NULL(window); 234 235 rc = ui_menu_bar_create(ui, window, &mbar); 236 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 237 PCUT_ASSERT_NOT_NULL(mbar); 238 239 rc = ui_menu_create(mbar, "Test", &menu); 240 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 241 PCUT_ASSERT_NOT_NULL(menu); 242 243 caption = ui_menu_caption(menu); 244 PCUT_ASSERT_NOT_NULL(caption); 245 246 pos.x = 0; 247 pos.y = 0; 248 ui_menu_get_rect(menu, &pos, &rect); 249 250 PCUT_ASSERT_INT_EQUALS(0, rect.p0.x); 251 PCUT_ASSERT_INT_EQUALS(0, rect.p0.y); 252 PCUT_ASSERT_INT_EQUALS(16, rect.p1.x); 253 PCUT_ASSERT_INT_EQUALS(8, rect.p1.y); 254 255 ui_menu_bar_destroy(mbar); 256 ui_window_destroy(window); 257 ui_destroy(ui); 258 } 259 260 /** Open and close menu with ui_menu_open() / ui_menu_close() */ 261 PCUT_TEST(open_close) 262 { 263 ui_t *ui = NULL; 264 ui_window_t *window = NULL; 265 ui_wnd_params_t params; 266 ui_menu_bar_t *mbar = NULL; 267 ui_menu_t *menu = NULL; 268 gfx_rect_t prect; 269 errno_t rc; 270 271 rc = ui_create_disp(NULL, &ui); 272 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 273 274 ui_wnd_params_init(¶ms); 275 params.caption = "Hello"; 276 277 rc = ui_window_create(ui, ¶ms, &window); 278 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 279 PCUT_ASSERT_NOT_NULL(window); 280 281 rc = ui_menu_bar_create(ui, window, &mbar); 282 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 283 PCUT_ASSERT_NOT_NULL(mbar); 284 285 rc = ui_menu_create(mbar, "Test", &menu); 286 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 287 PCUT_ASSERT_NOT_NULL(menu); 288 289 prect.p0.x = 0; 290 prect.p0.y = 0; 291 prect.p1.x = 0; 292 prect.p1.y = 0; 293 294 /* Open and close */ 295 rc = ui_menu_open(menu, &prect, 0); 296 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 297 298 ui_menu_close(menu); 299 300 ui_menu_bar_destroy(mbar); 301 ui_window_destroy(window); 302 ui_destroy(ui); 303 } 304 305 /** ui_menu_is_open() correctly returns menu state */ 306 PCUT_TEST(is_open) 307 { 308 ui_t *ui = NULL; 309 ui_window_t *window = NULL; 310 ui_wnd_params_t params; 311 ui_menu_bar_t *mbar = NULL; 312 ui_menu_t *menu = NULL; 313 gfx_rect_t prect; 314 bool open; 315 errno_t rc; 316 317 rc = ui_create_disp(NULL, &ui); 318 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 319 320 ui_wnd_params_init(¶ms); 321 params.caption = "Hello"; 322 323 rc = ui_window_create(ui, ¶ms, &window); 324 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 325 PCUT_ASSERT_NOT_NULL(window); 326 327 rc = ui_menu_bar_create(ui, window, &mbar); 328 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 329 PCUT_ASSERT_NOT_NULL(mbar); 330 331 rc = ui_menu_create(mbar, "Test", &menu); 332 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 333 PCUT_ASSERT_NOT_NULL(menu); 334 335 prect.p0.x = 0; 336 prect.p0.y = 0; 337 prect.p1.x = 0; 338 prect.p1.y = 0; 339 340 open = ui_menu_is_open(menu); 341 PCUT_ASSERT_FALSE(open); 342 343 rc = ui_menu_open(menu, &prect, 0); 344 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 345 346 open = ui_menu_is_open(menu); 347 PCUT_ASSERT_TRUE(open); 348 349 ui_menu_close(menu); 350 351 open = ui_menu_is_open(menu); 352 PCUT_ASSERT_FALSE(open); 353 354 ui_menu_bar_destroy(mbar); 355 ui_window_destroy(window); 356 ui_destroy(ui); 357 } 358 359 /** Paint background in graphics mode */ 360 PCUT_TEST(paint_bg_gfx) 361 { 362 ui_t *ui = NULL; 363 ui_window_t *window = NULL; 364 ui_wnd_params_t params; 365 ui_menu_bar_t *mbar = NULL; 366 ui_menu_t *menu = NULL; 367 gfx_rect_t prect; 368 gfx_coord2_t pos; 369 errno_t rc; 370 371 rc = ui_create_disp(NULL, &ui); 372 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 373 374 ui_wnd_params_init(¶ms); 375 params.caption = "Hello"; 376 377 rc = ui_window_create(ui, ¶ms, &window); 378 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 379 PCUT_ASSERT_NOT_NULL(window); 380 381 rc = ui_menu_bar_create(ui, window, &mbar); 382 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 383 PCUT_ASSERT_NOT_NULL(mbar); 384 385 rc = ui_menu_create(mbar, "Test", &menu); 386 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 387 PCUT_ASSERT_NOT_NULL(menu); 388 389 prect.p0.x = 0; 390 prect.p0.y = 0; 391 prect.p1.x = 0; 392 prect.p1.y = 0; 393 394 /* Menu needs to be open to be able to paint it */ 395 rc = ui_menu_open(menu, &prect, 0); 396 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 397 398 pos.x = 0; 399 pos.y = 0; 400 rc = ui_menu_paint_bg_gfx(menu, &pos); 401 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 402 403 ui_menu_bar_destroy(mbar); 404 ui_window_destroy(window); 405 ui_destroy(ui); 406 } 407 408 /** Paint background in text mode */ 409 PCUT_TEST(paint_bg_text) 410 { 411 ui_t *ui = NULL; 412 ui_window_t *window = NULL; 413 ui_wnd_params_t params; 414 ui_menu_bar_t *mbar = NULL; 415 ui_menu_t *menu = NULL; 416 gfx_rect_t prect; 417 gfx_coord2_t pos; 418 errno_t rc; 419 420 rc = ui_create_disp(NULL, &ui); 421 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 422 423 ui_wnd_params_init(¶ms); 424 params.caption = "Hello"; 425 426 rc = ui_window_create(ui, ¶ms, &window); 427 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 428 PCUT_ASSERT_NOT_NULL(window); 429 430 rc = ui_menu_bar_create(ui, window, &mbar); 431 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 432 PCUT_ASSERT_NOT_NULL(mbar); 433 434 rc = ui_menu_create(mbar, "Test", &menu); 435 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 436 PCUT_ASSERT_NOT_NULL(menu); 437 438 prect.p0.x = 0; 439 prect.p0.y = 0; 440 prect.p1.x = 0; 441 prect.p1.y = 0; 442 443 /* Menu needs to be open to be able to paint it */ 444 rc = ui_menu_open(menu, &prect, 0); 445 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 446 447 pos.x = 0; 448 pos.y = 0; 449 rc = ui_menu_paint_bg_text(menu, &pos); 450 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 451 452 ui_menu_bar_destroy(mbar); 453 ui_window_destroy(window); 454 ui_destroy(ui); 455 } 456 457 /** Paint menu */ 458 PCUT_TEST(paint) 459 { 460 ui_t *ui = NULL; 461 ui_window_t *window = NULL; 462 ui_wnd_params_t params; 463 ui_menu_bar_t *mbar = NULL; 464 ui_menu_t *menu = NULL; 465 gfx_rect_t prect; 466 gfx_coord2_t pos; 467 errno_t rc; 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_menu_bar_create(ui, window, &mbar); 480 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 481 PCUT_ASSERT_NOT_NULL(mbar); 482 483 rc = ui_menu_create(mbar, "Test", &menu); 484 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 485 PCUT_ASSERT_NOT_NULL(menu); 486 487 prect.p0.x = 0; 488 prect.p0.y = 0; 489 prect.p1.x = 0; 490 prect.p1.y = 0; 491 492 /* Menu needs to be open to be able to paint it */ 493 rc = ui_menu_open(menu, &prect, 0); 494 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 495 496 pos.x = 0; 497 pos.y = 0; 498 rc = ui_menu_paint(menu, &pos); 499 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 500 501 ui_menu_bar_destroy(mbar); 502 ui_window_destroy(window); 503 ui_destroy(ui); 504 } 505 506 /** ui_menu_up() with empty menu does nothing */ 507 PCUT_TEST(up_empty) 508 { 509 ui_t *ui = NULL; 510 ui_window_t *window = NULL; 511 ui_wnd_params_t params; 512 ui_menu_bar_t *mbar = NULL; 513 ui_menu_t *menu = NULL; 514 gfx_rect_t prect; 515 errno_t rc; 516 517 rc = ui_create_disp(NULL, &ui); 518 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 519 520 ui_wnd_params_init(¶ms); 521 params.caption = "Hello"; 522 523 rc = ui_window_create(ui, ¶ms, &window); 524 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 525 PCUT_ASSERT_NOT_NULL(window); 526 527 rc = ui_menu_bar_create(ui, window, &mbar); 528 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 529 PCUT_ASSERT_NOT_NULL(mbar); 530 531 rc = ui_menu_create(mbar, "Test", &menu); 532 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 533 PCUT_ASSERT_NOT_NULL(menu); 534 535 prect.p0.x = 0; 536 prect.p0.y = 0; 537 prect.p1.x = 0; 538 prect.p1.y = 0; 539 540 /* Menu needs to be open to be able to move around it */ 541 rc = ui_menu_open(menu, &prect, 0); 542 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 543 544 ui_menu_up(menu); 545 546 ui_menu_bar_destroy(mbar); 547 ui_window_destroy(window); 548 ui_destroy(ui); 549 } 550 551 /** ui_menu_up() moves one entry up, skips separators, wraps around */ 552 PCUT_TEST(up) 553 { 554 ui_t *ui = NULL; 555 ui_window_t *window = NULL; 556 ui_wnd_params_t params; 557 ui_menu_bar_t *mbar = NULL; 558 ui_menu_t *menu = NULL; 559 ui_menu_entry_t *mentry1 = NULL; 560 ui_menu_entry_t *mentry2 = NULL; 561 ui_menu_entry_t *mentry3 = NULL; 562 gfx_rect_t prect; 563 errno_t rc; 564 565 rc = ui_create_disp(NULL, &ui); 566 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 567 568 ui_wnd_params_init(¶ms); 569 params.caption = "Hello"; 570 571 rc = ui_window_create(ui, ¶ms, &window); 572 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 573 PCUT_ASSERT_NOT_NULL(window); 574 575 rc = ui_menu_bar_create(ui, window, &mbar); 576 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 577 PCUT_ASSERT_NOT_NULL(mbar); 578 579 rc = ui_menu_create(mbar, "Test", &menu); 580 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 581 PCUT_ASSERT_NOT_NULL(menu); 582 583 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry1); 584 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 585 PCUT_ASSERT_NOT_NULL(mentry1); 586 587 rc = ui_menu_entry_sep_create(menu, &mentry2); 588 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 589 PCUT_ASSERT_NOT_NULL(mentry2); 590 591 rc = ui_menu_entry_create(menu, "Bar", "F2", &mentry3); 592 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 593 PCUT_ASSERT_NOT_NULL(mentry3); 594 595 prect.p0.x = 0; 596 prect.p0.y = 0; 597 prect.p1.x = 0; 598 prect.p1.y = 0; 599 600 /* Menu needs to be open to be able to move around it */ 601 rc = ui_menu_open(menu, &prect, 0); 602 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 603 604 /* When menu is open, the first entry is selected */ 605 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 606 607 ui_menu_up(menu); 608 609 /* Now we've wrapped around to the last entry */ 610 PCUT_ASSERT_EQUALS(mentry3, menu->selected); 611 612 ui_menu_up(menu); 613 614 /* mentry2 is a separator and was skipped */ 615 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 616 617 ui_menu_bar_destroy(mbar); 618 ui_window_destroy(window); 619 ui_destroy(ui); 620 } 621 622 /** ui_menu_down() with empty menu does nothing */ 623 PCUT_TEST(down_empty) 624 { 625 ui_t *ui = NULL; 626 ui_window_t *window = NULL; 627 ui_wnd_params_t params; 628 ui_menu_bar_t *mbar = NULL; 629 ui_menu_t *menu = NULL; 630 gfx_rect_t prect; 631 errno_t rc; 632 633 rc = ui_create_disp(NULL, &ui); 634 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 635 636 ui_wnd_params_init(¶ms); 637 params.caption = "Hello"; 638 639 rc = ui_window_create(ui, ¶ms, &window); 640 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 641 PCUT_ASSERT_NOT_NULL(window); 642 643 rc = ui_menu_bar_create(ui, window, &mbar); 644 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 645 PCUT_ASSERT_NOT_NULL(mbar); 646 647 rc = ui_menu_create(mbar, "Test", &menu); 648 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 649 PCUT_ASSERT_NOT_NULL(menu); 650 651 prect.p0.x = 0; 652 prect.p0.y = 0; 653 prect.p1.x = 0; 654 prect.p1.y = 0; 655 656 /* Menu needs to be open to be able to move around it */ 657 rc = ui_menu_open(menu, &prect, 0); 658 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 659 660 ui_menu_down(menu); 661 662 ui_menu_bar_destroy(mbar); 663 ui_window_destroy(window); 664 ui_destroy(ui); 665 } 666 667 /** ui_menu_down() moves one entry down, skips separators, wraps around */ 668 PCUT_TEST(down) 669 { 670 ui_t *ui = NULL; 671 ui_window_t *window = NULL; 672 ui_wnd_params_t params; 673 ui_menu_bar_t *mbar = NULL; 674 ui_menu_t *menu = NULL; 675 ui_menu_entry_t *mentry1 = NULL; 676 ui_menu_entry_t *mentry2 = NULL; 677 ui_menu_entry_t *mentry3 = NULL; 678 gfx_rect_t prect; 679 errno_t rc; 680 681 rc = ui_create_disp(NULL, &ui); 682 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 683 684 ui_wnd_params_init(¶ms); 685 params.caption = "Hello"; 686 687 rc = ui_window_create(ui, ¶ms, &window); 688 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 689 PCUT_ASSERT_NOT_NULL(window); 690 691 rc = ui_menu_bar_create(ui, window, &mbar); 692 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 693 PCUT_ASSERT_NOT_NULL(mbar); 694 695 rc = ui_menu_create(mbar, "Test", &menu); 696 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 697 PCUT_ASSERT_NOT_NULL(menu); 698 699 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry1); 700 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 701 PCUT_ASSERT_NOT_NULL(mentry1); 702 703 rc = ui_menu_entry_sep_create(menu, &mentry2); 704 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 705 PCUT_ASSERT_NOT_NULL(mentry2); 706 707 rc = ui_menu_entry_create(menu, "Bar", "F2", &mentry3); 708 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 709 PCUT_ASSERT_NOT_NULL(mentry3); 710 711 prect.p0.x = 0; 712 prect.p0.y = 0; 713 prect.p1.x = 0; 714 prect.p1.y = 0; 715 716 /* Menu needs to be open to be able to move around it */ 717 rc = ui_menu_open(menu, &prect, 0); 718 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 719 720 /* When menu is open, the first entry is selected */ 721 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 722 723 ui_menu_down(menu); 724 725 /* mentry2 is a separator and was skipped */ 726 PCUT_ASSERT_EQUALS(mentry3, menu->selected); 727 728 ui_menu_up(menu); 729 730 /* Now we've wrapped around to the first entry */ 731 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 732 733 ui_menu_bar_destroy(mbar); 734 ui_window_destroy(window); 735 ui_destroy(ui); 736 } 737 738 /** ui_menu_pos_event() inside menu is claimed */ 739 PCUT_TEST(pos_event_inside) 740 { 741 ui_t *ui = NULL; 742 ui_window_t *window = NULL; 743 ui_wnd_params_t params; 744 ui_menu_bar_t *mbar = NULL; 745 ui_menu_t *menu = NULL; 746 ui_evclaim_t claimed; 747 gfx_coord2_t pos; 748 pos_event_t event; 749 errno_t rc; 750 751 rc = ui_create_disp(NULL, &ui); 752 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 753 754 ui_wnd_params_init(¶ms); 755 params.caption = "Hello"; 756 757 rc = ui_window_create(ui, ¶ms, &window); 758 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 759 PCUT_ASSERT_NOT_NULL(window); 760 761 rc = ui_menu_bar_create(ui, window, &mbar); 762 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 763 PCUT_ASSERT_NOT_NULL(mbar); 764 765 rc = ui_menu_create(mbar, "Test", &menu); 766 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 767 PCUT_ASSERT_NOT_NULL(menu); 768 769 pos.x = 0; 770 pos.y = 0; 771 event.type = POS_PRESS; 772 event.hpos = 0; 773 event.vpos = 0; 774 claimed = ui_menu_pos_event(menu, &pos, &event); 775 PCUT_ASSERT_EQUALS(ui_claimed, claimed); 776 777 ui_menu_bar_destroy(mbar); 778 ui_window_destroy(window); 779 ui_destroy(ui); 92 /** ui_menu_set_cb() sets the internal fields */ 93 PCUT_TEST(set_cb) 94 { 95 ui_menu_t *menu = NULL; 96 ui_menu_cb_t cb; 97 int obj; 98 errno_t rc; 99 100 rc = ui_menu_create(NULL, &menu); 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 PCUT_ASSERT_NOT_NULL(menu); 103 104 ui_menu_set_cb(menu, &cb, (void *)&obj); 105 PCUT_ASSERT_EQUALS(&cb, menu->cb); 106 PCUT_ASSERT_EQUALS((void *)&obj, menu->arg); 107 108 ui_menu_destroy(menu); 780 109 } 781 110 … … 786 115 ui_window_t *window = NULL; 787 116 ui_wnd_params_t params; 788 ui_menu_bar_t *mbar = NULL;789 117 ui_menu_t *menu = NULL; 790 118 ui_menu_geom_t geom; … … 802 130 PCUT_ASSERT_NOT_NULL(window); 803 131 804 rc = ui_menu_bar_create(ui, window, &mbar); 805 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 806 PCUT_ASSERT_NOT_NULL(mbar); 807 808 rc = ui_menu_create(mbar, "Test", &menu); 132 rc = ui_menu_create(window, &menu); 809 133 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 810 134 PCUT_ASSERT_NOT_NULL(menu); … … 823 147 PCUT_ASSERT_INT_EQUALS(4, geom.entries_rect.p1.y); 824 148 825 ui_menu_bar_destroy(mbar); 826 ui_window_destroy(window); 827 ui_destroy(ui); 149 ui_menu_destroy(menu); 150 ui_window_destroy(window); 151 ui_destroy(ui); 152 } 153 154 /** ui_menu_get_res() gets the menu's resource */ 155 PCUT_TEST(get_res) 156 { 157 ui_t *ui = NULL; 158 ui_window_t *window = NULL; 159 ui_wnd_params_t params; 160 ui_menu_t *menu = NULL; 161 ui_resource_t *res; 162 gfx_rect_t prect; 163 errno_t rc; 164 165 rc = ui_create_disp(NULL, &ui); 166 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 167 168 ui_wnd_params_init(¶ms); 169 params.caption = "Hello"; 170 171 rc = ui_window_create(ui, ¶ms, &window); 172 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 173 PCUT_ASSERT_NOT_NULL(window); 174 175 rc = ui_menu_create(window, &menu); 176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 177 PCUT_ASSERT_NOT_NULL(menu); 178 179 prect.p0.x = 0; 180 prect.p0.y = 0; 181 prect.p1.x = 0; 182 prect.p1.y = 0; 183 184 /* The menu must be open first */ 185 rc = ui_menu_open(menu, &prect, 0); 186 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 187 188 res = ui_menu_get_res(menu); 189 PCUT_ASSERT_NOT_NULL(res); 190 191 ui_menu_destroy(menu); 192 193 ui_window_destroy(window); 194 ui_destroy(ui); 195 } 196 197 /** Open and close menu with ui_menu_open() / ui_menu_close() */ 198 PCUT_TEST(open_close) 199 { 200 ui_t *ui = NULL; 201 ui_window_t *window = NULL; 202 ui_wnd_params_t params; 203 ui_menu_t *menu = NULL; 204 gfx_rect_t prect; 205 errno_t rc; 206 207 rc = ui_create_disp(NULL, &ui); 208 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 209 210 ui_wnd_params_init(¶ms); 211 params.caption = "Hello"; 212 213 rc = ui_window_create(ui, ¶ms, &window); 214 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 215 PCUT_ASSERT_NOT_NULL(window); 216 217 rc = ui_menu_create(window, &menu); 218 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 219 PCUT_ASSERT_NOT_NULL(menu); 220 221 prect.p0.x = 0; 222 prect.p0.y = 0; 223 prect.p1.x = 0; 224 prect.p1.y = 0; 225 226 /* Open and close */ 227 rc = ui_menu_open(menu, &prect, 0); 228 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 229 230 ui_menu_close(menu); 231 232 ui_menu_destroy(menu); 233 ui_window_destroy(window); 234 ui_destroy(ui); 235 } 236 237 /** ui_menu_is_open() correctly returns menu state */ 238 PCUT_TEST(is_open) 239 { 240 ui_t *ui = NULL; 241 ui_window_t *window = NULL; 242 ui_wnd_params_t params; 243 ui_menu_t *menu = NULL; 244 gfx_rect_t prect; 245 bool open; 246 errno_t rc; 247 248 rc = ui_create_disp(NULL, &ui); 249 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 250 251 ui_wnd_params_init(¶ms); 252 params.caption = "Hello"; 253 254 rc = ui_window_create(ui, ¶ms, &window); 255 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 256 PCUT_ASSERT_NOT_NULL(window); 257 258 rc = ui_menu_create(window, &menu); 259 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 260 PCUT_ASSERT_NOT_NULL(menu); 261 262 prect.p0.x = 0; 263 prect.p0.y = 0; 264 prect.p1.x = 0; 265 prect.p1.y = 0; 266 267 open = ui_menu_is_open(menu); 268 PCUT_ASSERT_FALSE(open); 269 270 rc = ui_menu_open(menu, &prect, 0); 271 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 272 273 open = ui_menu_is_open(menu); 274 PCUT_ASSERT_TRUE(open); 275 276 ui_menu_close(menu); 277 278 open = ui_menu_is_open(menu); 279 PCUT_ASSERT_FALSE(open); 280 281 ui_menu_destroy(menu); 282 ui_window_destroy(window); 283 ui_destroy(ui); 284 } 285 286 /** Paint background in graphics mode */ 287 PCUT_TEST(paint_bg_gfx) 288 { 289 ui_t *ui = NULL; 290 ui_window_t *window = NULL; 291 ui_wnd_params_t params; 292 ui_menu_t *menu = NULL; 293 gfx_rect_t prect; 294 gfx_coord2_t pos; 295 errno_t rc; 296 297 rc = ui_create_disp(NULL, &ui); 298 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 299 300 ui_wnd_params_init(¶ms); 301 params.caption = "Hello"; 302 303 rc = ui_window_create(ui, ¶ms, &window); 304 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 305 PCUT_ASSERT_NOT_NULL(window); 306 307 rc = ui_menu_create(window, &menu); 308 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 309 PCUT_ASSERT_NOT_NULL(menu); 310 311 prect.p0.x = 0; 312 prect.p0.y = 0; 313 prect.p1.x = 0; 314 prect.p1.y = 0; 315 316 /* Menu needs to be open to be able to paint it */ 317 rc = ui_menu_open(menu, &prect, 0); 318 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 319 320 pos.x = 0; 321 pos.y = 0; 322 rc = ui_menu_paint_bg_gfx(menu, &pos); 323 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 324 325 ui_window_destroy(window); 326 ui_destroy(ui); 327 } 328 329 /** Paint background in text mode */ 330 PCUT_TEST(paint_bg_text) 331 { 332 ui_t *ui = NULL; 333 ui_window_t *window = NULL; 334 ui_wnd_params_t params; 335 ui_menu_t *menu = NULL; 336 gfx_rect_t prect; 337 gfx_coord2_t pos; 338 errno_t rc; 339 340 rc = ui_create_disp(NULL, &ui); 341 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 342 343 ui_wnd_params_init(¶ms); 344 params.caption = "Hello"; 345 346 rc = ui_window_create(ui, ¶ms, &window); 347 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 348 PCUT_ASSERT_NOT_NULL(window); 349 350 rc = ui_menu_create(window, &menu); 351 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 352 PCUT_ASSERT_NOT_NULL(menu); 353 354 prect.p0.x = 0; 355 prect.p0.y = 0; 356 prect.p1.x = 0; 357 prect.p1.y = 0; 358 359 /* Menu needs to be open to be able to paint it */ 360 rc = ui_menu_open(menu, &prect, 0); 361 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 362 363 pos.x = 0; 364 pos.y = 0; 365 rc = ui_menu_paint_bg_text(menu, &pos); 366 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 367 368 ui_window_destroy(window); 369 ui_destroy(ui); 370 } 371 372 /** Paint menu */ 373 PCUT_TEST(paint) 374 { 375 ui_t *ui = NULL; 376 ui_window_t *window = NULL; 377 ui_wnd_params_t params; 378 ui_menu_t *menu = NULL; 379 gfx_rect_t prect; 380 gfx_coord2_t pos; 381 errno_t rc; 382 383 rc = ui_create_disp(NULL, &ui); 384 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 385 386 ui_wnd_params_init(¶ms); 387 params.caption = "Hello"; 388 389 rc = ui_window_create(ui, ¶ms, &window); 390 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 391 PCUT_ASSERT_NOT_NULL(window); 392 393 rc = ui_menu_create(window, &menu); 394 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 395 PCUT_ASSERT_NOT_NULL(menu); 396 397 prect.p0.x = 0; 398 prect.p0.y = 0; 399 prect.p1.x = 0; 400 prect.p1.y = 0; 401 402 /* Menu needs to be open to be able to paint it */ 403 rc = ui_menu_open(menu, &prect, 0); 404 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 405 406 pos.x = 0; 407 pos.y = 0; 408 rc = ui_menu_paint(menu, &pos); 409 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 410 411 ui_window_destroy(window); 412 ui_destroy(ui); 413 } 414 415 /** ui_menu_pos_event() inside menu is claimed */ 416 PCUT_TEST(pos_event_inside) 417 { 418 ui_t *ui = NULL; 419 ui_window_t *window = NULL; 420 ui_wnd_params_t params; 421 ui_menu_t *menu = NULL; 422 ui_evclaim_t claimed; 423 gfx_coord2_t pos; 424 pos_event_t event; 425 errno_t rc; 426 427 rc = ui_create_disp(NULL, &ui); 428 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 429 430 ui_wnd_params_init(¶ms); 431 params.caption = "Hello"; 432 433 rc = ui_window_create(ui, ¶ms, &window); 434 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 435 PCUT_ASSERT_NOT_NULL(window); 436 437 rc = ui_menu_create(window, &menu); 438 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 439 PCUT_ASSERT_NOT_NULL(menu); 440 441 pos.x = 0; 442 pos.y = 0; 443 event.type = POS_PRESS; 444 event.hpos = 0; 445 event.vpos = 0; 446 claimed = ui_menu_pos_event(menu, &pos, &event); 447 PCUT_ASSERT_EQUALS(ui_claimed, claimed); 448 449 ui_window_destroy(window); 450 ui_destroy(ui); 451 } 452 453 /** ui_menu_up() with empty menu does nothing */ 454 PCUT_TEST(up_empty) 455 { 456 ui_t *ui = NULL; 457 ui_window_t *window = NULL; 458 ui_wnd_params_t params; 459 ui_menu_t *menu = NULL; 460 gfx_rect_t prect; 461 errno_t rc; 462 463 rc = ui_create_disp(NULL, &ui); 464 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 465 466 ui_wnd_params_init(¶ms); 467 params.caption = "Hello"; 468 469 rc = ui_window_create(ui, ¶ms, &window); 470 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 471 PCUT_ASSERT_NOT_NULL(window); 472 473 rc = ui_menu_create(window, &menu); 474 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 475 PCUT_ASSERT_NOT_NULL(menu); 476 477 prect.p0.x = 0; 478 prect.p0.y = 0; 479 prect.p1.x = 0; 480 prect.p1.y = 0; 481 482 /* Menu needs to be open to be able to move around it */ 483 rc = ui_menu_open(menu, &prect, 0); 484 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 485 486 ui_menu_up(menu); 487 488 ui_window_destroy(window); 489 ui_destroy(ui); 490 } 491 492 /** ui_menu_up() moves one entry up, skips separators, wraps around */ 493 PCUT_TEST(up) 494 { 495 ui_t *ui = NULL; 496 ui_window_t *window = NULL; 497 ui_wnd_params_t params; 498 ui_menu_t *menu = NULL; 499 ui_menu_entry_t *mentry1 = NULL; 500 ui_menu_entry_t *mentry2 = NULL; 501 ui_menu_entry_t *mentry3 = NULL; 502 gfx_rect_t prect; 503 errno_t rc; 504 505 rc = ui_create_disp(NULL, &ui); 506 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 507 508 ui_wnd_params_init(¶ms); 509 params.caption = "Hello"; 510 511 rc = ui_window_create(ui, ¶ms, &window); 512 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 513 PCUT_ASSERT_NOT_NULL(window); 514 515 rc = ui_menu_create(window, &menu); 516 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 517 PCUT_ASSERT_NOT_NULL(menu); 518 519 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry1); 520 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 521 PCUT_ASSERT_NOT_NULL(mentry1); 522 523 rc = ui_menu_entry_sep_create(menu, &mentry2); 524 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 525 PCUT_ASSERT_NOT_NULL(mentry2); 526 527 rc = ui_menu_entry_create(menu, "Bar", "F2", &mentry3); 528 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 529 PCUT_ASSERT_NOT_NULL(mentry3); 530 531 prect.p0.x = 0; 532 prect.p0.y = 0; 533 prect.p1.x = 0; 534 prect.p1.y = 0; 535 536 /* Menu needs to be open to be able to move around it */ 537 rc = ui_menu_open(menu, &prect, 0); 538 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 539 540 /* When menu is open, the first entry is selected */ 541 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 542 543 ui_menu_up(menu); 544 545 /* Now we've wrapped around to the last entry */ 546 PCUT_ASSERT_EQUALS(mentry3, menu->selected); 547 548 ui_menu_up(menu); 549 550 /* mentry2 is a separator and was skipped */ 551 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 552 553 ui_window_destroy(window); 554 ui_destroy(ui); 555 } 556 557 /** ui_menu_down() with empty menu does nothing */ 558 PCUT_TEST(down_empty) 559 { 560 ui_t *ui = NULL; 561 ui_window_t *window = NULL; 562 ui_wnd_params_t params; 563 ui_menu_t *menu = NULL; 564 gfx_rect_t prect; 565 errno_t rc; 566 567 rc = ui_create_disp(NULL, &ui); 568 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 569 570 ui_wnd_params_init(¶ms); 571 params.caption = "Hello"; 572 573 rc = ui_window_create(ui, ¶ms, &window); 574 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 575 PCUT_ASSERT_NOT_NULL(window); 576 577 rc = ui_menu_create(window, &menu); 578 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 579 PCUT_ASSERT_NOT_NULL(menu); 580 581 prect.p0.x = 0; 582 prect.p0.y = 0; 583 prect.p1.x = 0; 584 prect.p1.y = 0; 585 586 /* Menu needs to be open to be able to move around it */ 587 rc = ui_menu_open(menu, &prect, 0); 588 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 589 590 ui_menu_down(menu); 591 592 ui_window_destroy(window); 593 ui_destroy(ui); 594 } 595 596 /** ui_menu_down() moves one entry down, skips separators, wraps around */ 597 PCUT_TEST(down) 598 { 599 ui_t *ui = NULL; 600 ui_window_t *window = NULL; 601 ui_wnd_params_t params; 602 ui_menu_t *menu = NULL; 603 ui_menu_entry_t *mentry1 = NULL; 604 ui_menu_entry_t *mentry2 = NULL; 605 ui_menu_entry_t *mentry3 = NULL; 606 gfx_rect_t prect; 607 errno_t rc; 608 609 rc = ui_create_disp(NULL, &ui); 610 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 611 612 ui_wnd_params_init(¶ms); 613 params.caption = "Hello"; 614 615 rc = ui_window_create(ui, ¶ms, &window); 616 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 617 PCUT_ASSERT_NOT_NULL(window); 618 619 rc = ui_menu_create(window, &menu); 620 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 621 PCUT_ASSERT_NOT_NULL(menu); 622 623 rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry1); 624 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 625 PCUT_ASSERT_NOT_NULL(mentry1); 626 627 rc = ui_menu_entry_sep_create(menu, &mentry2); 628 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 629 PCUT_ASSERT_NOT_NULL(mentry2); 630 631 rc = ui_menu_entry_create(menu, "Bar", "F2", &mentry3); 632 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 633 PCUT_ASSERT_NOT_NULL(mentry3); 634 635 prect.p0.x = 0; 636 prect.p0.y = 0; 637 prect.p1.x = 0; 638 prect.p1.y = 0; 639 640 /* Menu needs to be open to be able to move around it */ 641 rc = ui_menu_open(menu, &prect, 0); 642 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 643 644 /* When menu is open, the first entry is selected */ 645 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 646 647 ui_menu_down(menu); 648 649 /* mentry2 is a separator and was skipped */ 650 PCUT_ASSERT_EQUALS(mentry3, menu->selected); 651 652 ui_menu_up(menu); 653 654 /* Now we've wrapped around to the first entry */ 655 PCUT_ASSERT_EQUALS(mentry1, menu->selected); 656 657 ui_window_destroy(window); 658 ui_destroy(ui); 659 } 660 661 /** Sending an unhandled event does nothing. */ 662 PCUT_TEST(send_unhandled) 663 { 664 ui_menu_t *menu = NULL; 665 errno_t rc; 666 sysarg_t idev_id; 667 char32_t c; 668 669 rc = ui_menu_create(NULL, &menu); 670 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 671 PCUT_ASSERT_NOT_NULL(menu); 672 673 /* Send events without setting callback */ 674 c = 'A'; 675 idev_id = 42; 676 ui_menu_left(menu, idev_id); 677 ui_menu_right(menu, idev_id); 678 ui_menu_close_req(menu); 679 ui_menu_press_accel(menu, c, idev_id); 680 681 /* Set dummy callback structure */ 682 ui_menu_set_cb(menu, &dummy_cb, NULL); 683 684 /* Send unhandled events */ 685 ui_menu_left(menu, idev_id); 686 ui_menu_right(menu, idev_id); 687 ui_menu_close_req(menu); 688 ui_menu_press_accel(menu, c, idev_id); 689 690 ui_menu_destroy(menu); 691 } 692 693 /** ui_menu_left() sends left event */ 694 PCUT_TEST(left) 695 { 696 ui_menu_t *menu = NULL; 697 errno_t rc; 698 test_resp_t resp; 699 sysarg_t idev_id; 700 701 rc = ui_menu_create(NULL, &menu); 702 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 703 PCUT_ASSERT_NOT_NULL(menu); 704 705 ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp); 706 707 memset(&resp, 0, sizeof(resp)); 708 PCUT_ASSERT_FALSE(resp.left_called); 709 710 idev_id = 42; 711 ui_menu_left(menu, idev_id); 712 713 PCUT_ASSERT_TRUE(resp.left_called); 714 PCUT_ASSERT_EQUALS(menu, resp.menu); 715 PCUT_ASSERT_INT_EQUALS(idev_id, resp.idev_id); 716 717 ui_menu_destroy(menu); 718 } 719 720 /** ui_menu_right() sends right event */ 721 PCUT_TEST(right) 722 { 723 ui_menu_t *menu = NULL; 724 errno_t rc; 725 test_resp_t resp; 726 sysarg_t idev_id; 727 728 rc = ui_menu_create(NULL, &menu); 729 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 730 PCUT_ASSERT_NOT_NULL(menu); 731 732 ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp); 733 734 memset(&resp, 0, sizeof(resp)); 735 PCUT_ASSERT_FALSE(resp.right_called); 736 737 idev_id = 42; 738 ui_menu_right(menu, idev_id); 739 740 PCUT_ASSERT_TRUE(resp.right_called); 741 PCUT_ASSERT_EQUALS(menu, resp.menu); 742 PCUT_ASSERT_INT_EQUALS(idev_id, resp.idev_id); 743 744 ui_menu_destroy(menu); 745 } 746 747 /** ui_menu_close_req() sends close_req event */ 748 PCUT_TEST(close_req) 749 { 750 ui_menu_t *menu = NULL; 751 errno_t rc; 752 test_resp_t resp; 753 754 rc = ui_menu_create(NULL, &menu); 755 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 756 PCUT_ASSERT_NOT_NULL(menu); 757 758 ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp); 759 760 memset(&resp, 0, sizeof(resp)); 761 PCUT_ASSERT_FALSE(resp.close_req_called); 762 763 ui_menu_close_req(menu); 764 765 PCUT_ASSERT_TRUE(resp.close_req_called); 766 PCUT_ASSERT_EQUALS(menu, resp.menu); 767 768 ui_menu_destroy(menu); 769 } 770 771 /** ui_menu_press_accel() sends press_accel event */ 772 PCUT_TEST(press_accel) 773 { 774 ui_menu_t *menu = NULL; 775 errno_t rc; 776 test_resp_t resp; 777 char32_t c; 778 sysarg_t idev_id; 779 780 rc = ui_menu_create(NULL, &menu); 781 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 782 PCUT_ASSERT_NOT_NULL(menu); 783 784 ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp); 785 786 memset(&resp, 0, sizeof(resp)); 787 PCUT_ASSERT_FALSE(resp.press_accel_called); 788 789 c = 'A'; 790 idev_id = 42; 791 ui_menu_press_accel(menu, c, idev_id); 792 793 PCUT_ASSERT_TRUE(resp.press_accel_called); 794 PCUT_ASSERT_EQUALS(menu, resp.menu); 795 PCUT_ASSERT_EQUALS(c, resp.c); 796 PCUT_ASSERT_INT_EQUALS(idev_id, resp.idev_id); 797 798 ui_menu_destroy(menu); 799 } 800 801 /** Test menu left callback */ 802 static void testmenu_left(ui_menu_t *menu, void *arg, sysarg_t idev_id) 803 { 804 test_resp_t *resp = (test_resp_t *)arg; 805 806 resp->left_called = true; 807 resp->menu = menu; 808 resp->idev_id = idev_id; 809 } 810 811 /** Test menu right callback */ 812 static void testmenu_right(ui_menu_t *menu, void *arg, sysarg_t idev_id) 813 { 814 test_resp_t *resp = (test_resp_t *)arg; 815 816 resp->right_called = true; 817 resp->menu = menu; 818 resp->idev_id = idev_id; 819 } 820 821 /** Test menu close callback */ 822 static void testmenu_close_req(ui_menu_t *menu, void *arg) 823 { 824 test_resp_t *resp = (test_resp_t *)arg; 825 826 resp->close_req_called = true; 827 resp->menu = menu; 828 } 829 830 /** Test menu press accel callback */ 831 static void testmenu_press_accel(ui_menu_t *menu, void *arg, 832 char32_t c, sysarg_t kbd_id) 833 { 834 test_resp_t *resp = (test_resp_t *)arg; 835 836 resp->press_accel_called = true; 837 resp->menu = menu; 838 resp->c = c; 839 resp->idev_id = kbd_id; 828 840 } 829 841
Note:
See TracChangeset
for help on using the changeset viewer.