Changeset be1d74c1 in mainline for uspace/app/nav/test/panel.c
- Timestamp:
- 2021-10-25T00:32:45Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8c72f533
- Parents:
- 9f7e9bb
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-12 17:06:35)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/test/panel.c
r9f7e9bb rbe1d74c1 28 28 29 29 #include <errno.h> 30 #include <io/kbd_event.h> 31 #include <io/pos_event.h> 30 32 #include <pcut/pcut.h> 31 33 #include <stdio.h> … … 49 51 } 50 52 51 /** Test panel_ paint() */52 PCUT_TEST( paint)53 /** Test panel_entry_paint() */ 54 PCUT_TEST(entry_paint) 53 55 { 54 56 ui_t *ui; … … 70 72 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 71 73 72 rc = panel_paint(panel); 74 rc = panel_entry_append(panel, "a", 1); 75 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 76 77 rc = panel_entry_paint(panel_first(panel), 0); 73 78 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 74 79 … … 78 83 } 79 84 85 /** Test panel_paint() */ 86 PCUT_TEST(paint) 87 { 88 ui_t *ui; 89 ui_window_t *window; 90 ui_wnd_params_t params; 91 panel_t *panel; 92 errno_t rc; 93 94 rc = ui_create_disp(NULL, &ui); 95 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 96 97 ui_wnd_params_init(¶ms); 98 params.caption = "Test"; 99 100 rc = ui_window_create(ui, ¶ms, &window); 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 103 rc = panel_create(window, &panel); 104 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 105 106 rc = panel_paint(panel); 107 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 108 109 panel_destroy(panel); 110 ui_window_destroy(window); 111 ui_destroy(ui); 112 } 113 80 114 /** panel_ctl() returns a valid UI control */ 81 115 PCUT_TEST(ctl) … … 90 124 control = panel_ctl(panel); 91 125 PCUT_ASSERT_NOT_NULL(control); 126 127 panel_destroy(panel); 128 } 129 130 /** Test panel_kbd_event() */ 131 PCUT_TEST(kbd_event) 132 { 133 panel_t *panel; 134 ui_control_t *control; 135 ui_evclaim_t claimed; 136 kbd_event_t event; 137 errno_t rc; 138 139 rc = panel_create(NULL, &panel); 140 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 141 142 control = panel_ctl(panel); 143 PCUT_ASSERT_NOT_NULL(control); 144 145 event.type = KEY_PRESS; 146 event.key = KC_ENTER; 147 event.mods = 0; 148 event.c = '\0'; 149 150 claimed = panel_kbd_event(panel, &event); 151 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed); 92 152 93 153 panel_destroy(panel); … … 108 168 control = panel_ctl(panel); 109 169 PCUT_ASSERT_NOT_NULL(control); 170 171 event.pos_id = 0; 172 event.type = POS_PRESS; 173 event.btn_num = 1; 174 event.hpos = 0; 175 event.vpos = 0; 110 176 111 177 claimed = panel_pos_event(panel, &event); … … 310 376 } 311 377 378 /** panel_last() returns valid entry or @c NULL as appropriate */ 379 PCUT_TEST(last) 380 { 381 panel_t *panel; 382 panel_entry_t *entry; 383 errno_t rc; 384 385 rc = panel_create(NULL, &panel); 386 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 387 388 entry = panel_last(panel); 389 PCUT_ASSERT_NULL(entry); 390 391 /* Add one entry */ 392 rc = panel_entry_append(panel, "a", 1); 393 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 394 395 /* Now try getting it */ 396 entry = panel_last(panel); 397 PCUT_ASSERT_NOT_NULL(entry); 398 PCUT_ASSERT_STR_EQUALS("a", entry->name); 399 PCUT_ASSERT_INT_EQUALS(1, entry->size); 400 401 /* Add another entry */ 402 rc = panel_entry_append(panel, "b", 2); 403 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 404 405 /* We should get new entry now */ 406 entry = panel_last(panel); 407 PCUT_ASSERT_NOT_NULL(entry); 408 PCUT_ASSERT_STR_EQUALS("b", entry->name); 409 PCUT_ASSERT_INT_EQUALS(2, entry->size); 410 411 panel_destroy(panel); 412 } 413 312 414 /** panel_next() returns the next entry or @c NULL as appropriate */ 313 415 PCUT_TEST(next) … … 347 449 } 348 450 451 /** panel_prev() returns the previous entry or @c NULL as appropriate */ 452 PCUT_TEST(prev) 453 { 454 panel_t *panel; 455 panel_entry_t *entry; 456 errno_t rc; 457 458 rc = panel_create(NULL, &panel); 459 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 460 461 /* Add one entry */ 462 rc = panel_entry_append(panel, "a", 1); 463 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 464 465 /* Now try getting its predecessor */ 466 entry = panel_last(panel); 467 PCUT_ASSERT_NOT_NULL(entry); 468 469 entry = panel_prev(entry); 470 PCUT_ASSERT_NULL(entry); 471 472 /* Add another entry */ 473 rc = panel_entry_append(panel, "b", 2); 474 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 475 476 /* Try getting the predecessor of the new entry */ 477 entry = panel_last(panel); 478 PCUT_ASSERT_NOT_NULL(entry); 479 480 entry = panel_prev(entry); 481 PCUT_ASSERT_NOT_NULL(entry); 482 PCUT_ASSERT_STR_EQUALS("a", entry->name); 483 PCUT_ASSERT_INT_EQUALS(1, entry->size); 484 485 panel_destroy(panel); 486 } 487 488 /** panel_cursor_move() ... */ 489 PCUT_TEST(cursor_move) 490 { 491 } 492 493 /** panel_cursor_up() moves cursor one entry up */ 494 PCUT_TEST(cursor_up) 495 { 496 ui_t *ui; 497 ui_window_t *window; 498 ui_wnd_params_t params; 499 panel_t *panel; 500 gfx_rect_t rect; 501 errno_t rc; 502 503 rc = ui_create_disp(NULL, &ui); 504 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 505 506 ui_wnd_params_init(¶ms); 507 params.caption = "Test"; 508 509 rc = ui_window_create(ui, ¶ms, &window); 510 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 511 512 rc = panel_create(window, &panel); 513 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 514 515 rect.p0.x = 0; 516 rect.p0.y = 0; 517 rect.p1.x = 10; 518 rect.p1.y = 4; // XXX Assuming this makes page size 2 519 panel_set_rect(panel, &rect); 520 521 /* Add tree entries (more than page size, which is 2) */ 522 rc = panel_entry_append(panel, "a", 1); 523 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 524 525 rc = panel_entry_append(panel, "b", 2); 526 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 527 528 rc = panel_entry_append(panel, "c", 3); 529 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 530 531 /* Cursor to the last entry and page start to the next-to-last entry */ 532 panel->cursor = panel_last(panel); 533 panel->cursor_idx = 2; 534 panel->page = panel_prev(panel->cursor); 535 panel->page_idx = 1; 536 537 /* Move cursor one entry up */ 538 panel_cursor_up(panel); 539 540 /* Cursor and page start should now both be at the second entry */ 541 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name); 542 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size); 543 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx); 544 PCUT_ASSERT_EQUALS(panel->cursor, panel->page); 545 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx); 546 547 /* Move cursor one entry up. This should scroll up. */ 548 panel_cursor_up(panel); 549 550 /* Cursor and page start should now both be at the first entry */ 551 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name); 552 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size); 553 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx); 554 PCUT_ASSERT_EQUALS(panel->cursor, panel->page); 555 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx); 556 557 /* Moving further up should do nothing (we are at the top). */ 558 panel_cursor_up(panel); 559 560 /* Cursor and page start should still be at the first entry */ 561 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name); 562 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size); 563 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx); 564 PCUT_ASSERT_EQUALS(panel->cursor, panel->page); 565 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx); 566 567 panel_destroy(panel); 568 ui_window_destroy(window); 569 ui_destroy(ui); 570 } 571 572 /** panel_cursor_down() moves cursor one entry down */ 573 PCUT_TEST(cursor_down) 574 { 575 ui_t *ui; 576 ui_window_t *window; 577 ui_wnd_params_t params; 578 panel_t *panel; 579 gfx_rect_t rect; 580 errno_t rc; 581 582 rc = ui_create_disp(NULL, &ui); 583 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 584 585 ui_wnd_params_init(¶ms); 586 params.caption = "Test"; 587 588 rc = ui_window_create(ui, ¶ms, &window); 589 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 590 591 rc = panel_create(window, &panel); 592 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 593 594 rect.p0.x = 0; 595 rect.p0.y = 0; 596 rect.p1.x = 10; 597 rect.p1.y = 4; // XXX Assuming this makes page size 2 598 panel_set_rect(panel, &rect); 599 600 /* Add tree entries (more than page size, which is 2) */ 601 rc = panel_entry_append(panel, "a", 1); 602 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 603 604 rc = panel_entry_append(panel, "b", 2); 605 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 606 607 rc = panel_entry_append(panel, "c", 3); 608 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 609 610 /* Cursor and page start to the first entry */ 611 panel->cursor = panel_first(panel); 612 panel->cursor_idx = 0; 613 panel->page = panel->cursor; 614 panel->page_idx = 0; 615 616 /* Move cursor one entry down */ 617 panel_cursor_down(panel); 618 619 /* Cursor should now be at the second entry, page stays the same */ 620 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name); 621 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size); 622 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx); 623 PCUT_ASSERT_EQUALS(panel_first(panel), panel->page); 624 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx); 625 626 /* Move cursor one entry down. This should scroll down. */ 627 panel_cursor_down(panel); 628 629 /* Cursor should now be at the third and page at the second entry. */ 630 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name); 631 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size); 632 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx); 633 PCUT_ASSERT_STR_EQUALS("b", panel->page->name); 634 PCUT_ASSERT_INT_EQUALS(2, panel->page->size); 635 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx); 636 637 /* Moving further down should do nothing (we are at the bottom). */ 638 panel_cursor_down(panel); 639 640 /* Cursor should still be at the third and page at the second entry. */ 641 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name); 642 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size); 643 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx); 644 PCUT_ASSERT_STR_EQUALS("b", panel->page->name); 645 PCUT_ASSERT_INT_EQUALS(2, panel->page->size); 646 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx); 647 648 panel_destroy(panel); 649 ui_window_destroy(window); 650 ui_destroy(ui); 651 } 652 653 /** panel_cursor_top() moves cursor to the first entry */ 654 PCUT_TEST(cursor_top) 655 { 656 ui_t *ui; 657 ui_window_t *window; 658 ui_wnd_params_t params; 659 panel_t *panel; 660 gfx_rect_t rect; 661 errno_t rc; 662 663 rc = ui_create_disp(NULL, &ui); 664 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 665 666 ui_wnd_params_init(¶ms); 667 params.caption = "Test"; 668 669 rc = ui_window_create(ui, ¶ms, &window); 670 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 671 672 rc = panel_create(window, &panel); 673 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 674 675 rect.p0.x = 0; 676 rect.p0.y = 0; 677 rect.p1.x = 10; 678 rect.p1.y = 4; // XXX Assuming this makes page size 2 679 panel_set_rect(panel, &rect); 680 681 /* Add tree entries (more than page size, which is 2) */ 682 rc = panel_entry_append(panel, "a", 1); 683 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 684 685 rc = panel_entry_append(panel, "b", 2); 686 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 687 688 rc = panel_entry_append(panel, "c", 3); 689 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 690 691 /* Cursor to the last entry and page start to the next-to-last entry */ 692 panel->cursor = panel_last(panel); 693 panel->cursor_idx = 2; 694 panel->page = panel_prev(panel->cursor); 695 panel->page_idx = 1; 696 697 /* Move cursor to the top. This should scroll up. */ 698 panel_cursor_top(panel); 699 700 /* Cursor and page start should now both be at the first entry */ 701 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name); 702 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size); 703 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx); 704 PCUT_ASSERT_EQUALS(panel->cursor, panel->page); 705 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx); 706 707 panel_destroy(panel); 708 ui_window_destroy(window); 709 ui_destroy(ui); 710 } 711 712 /** panel_cursor_bottom() moves cursor to the last entry */ 713 PCUT_TEST(cursor_bottom) 714 { 715 ui_t *ui; 716 ui_window_t *window; 717 ui_wnd_params_t params; 718 panel_t *panel; 719 gfx_rect_t rect; 720 errno_t rc; 721 722 rc = ui_create_disp(NULL, &ui); 723 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 724 725 ui_wnd_params_init(¶ms); 726 params.caption = "Test"; 727 728 rc = ui_window_create(ui, ¶ms, &window); 729 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 730 731 rc = panel_create(window, &panel); 732 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 733 734 rect.p0.x = 0; 735 rect.p0.y = 0; 736 rect.p1.x = 10; 737 rect.p1.y = 4; // XXX Assuming this makes page size 2 738 panel_set_rect(panel, &rect); 739 740 /* Add tree entries (more than page size, which is 2) */ 741 rc = panel_entry_append(panel, "a", 1); 742 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 743 744 rc = panel_entry_append(panel, "b", 2); 745 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 746 747 rc = panel_entry_append(panel, "c", 3); 748 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 749 750 /* Cursor and page start to the first entry */ 751 panel->cursor = panel_first(panel); 752 panel->cursor_idx = 0; 753 panel->page = panel->cursor; 754 panel->page_idx = 0; 755 756 /* Move cursor to the bottom. This should scroll down. */ 757 panel_cursor_bottom(panel); 758 759 /* Cursor should now be at the third and page at the second entry. */ 760 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name); 761 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size); 762 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx); 763 PCUT_ASSERT_STR_EQUALS("b", panel->page->name); 764 PCUT_ASSERT_INT_EQUALS(2, panel->page->size); 765 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx); 766 767 panel_destroy(panel); 768 ui_window_destroy(window); 769 ui_destroy(ui); 770 } 771 349 772 PCUT_EXPORT(panel);
Note:
See TracChangeset
for help on using the changeset viewer.