Changeset 54ddb59 in mainline for uspace/app/nav/test/panel.c
- Timestamp:
- 2022-06-20T13:10:08Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 52214a2
- Parents:
- 453f9645
- git-author:
- Jiri Svoboda <jiri@…> (2022-06-19 18:09:49)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-06-20 13:10:08)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/test/panel.c
r453f9645 r54ddb59 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 81 81 } 82 82 83 /** Test panel_entry_paint() */84 PCUT_TEST(entry_paint)85 {86 ui_t *ui;87 ui_window_t *window;88 ui_wnd_params_t params;89 panel_t *panel;90 panel_entry_attr_t attr;91 errno_t rc;92 93 rc = ui_create_disp(NULL, &ui);94 PCUT_ASSERT_ERRNO_VAL(EOK, rc);95 96 ui_wnd_params_init(¶ms);97 params.caption = "Test";98 99 rc = ui_window_create(ui, ¶ms, &window);100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);101 102 rc = panel_create(window, true, &panel);103 PCUT_ASSERT_ERRNO_VAL(EOK, rc);104 105 panel_entry_attr_init(&attr);106 attr.name = "a";107 attr.size = 1;108 109 rc = panel_entry_append(panel, &attr);110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);111 112 rc = panel_entry_paint(panel_first(panel), 0);113 PCUT_ASSERT_ERRNO_VAL(EOK, rc);114 115 panel_destroy(panel);116 ui_window_destroy(window);117 ui_destroy(ui);118 }119 120 83 /** Test panel_paint() */ 121 84 PCUT_TEST(paint) … … 205 168 PCUT_TEST(pos_event) 206 169 { 207 ui_t *ui;208 ui_window_t *window;209 ui_wnd_params_t params;210 panel_t *panel;211 ui_evclaim_t claimed;212 pos_event_t event;213 gfx_rect_t rect;214 panel_entry_attr_t attr;215 errno_t rc;216 217 rc = ui_create_disp(NULL, &ui);218 PCUT_ASSERT_ERRNO_VAL(EOK, rc);219 220 ui_wnd_params_init(¶ms);221 params.caption = "Test";222 223 rc = ui_window_create(ui, ¶ms, &window);224 PCUT_ASSERT_ERRNO_VAL(EOK, rc);225 226 rc = panel_create(window, true, &panel);227 PCUT_ASSERT_ERRNO_VAL(EOK, rc);228 229 rect.p0.x = 0;230 rect.p0.y = 0;231 rect.p1.x = 10;232 rect.p1.y = 10;233 panel_set_rect(panel, &rect);234 235 panel_entry_attr_init(&attr);236 attr.name = "a";237 attr.size = 1;238 rc = panel_entry_append(panel, &attr);239 PCUT_ASSERT_ERRNO_VAL(EOK, rc);240 241 attr.name = "b";242 attr.size = 2;243 rc = panel_entry_append(panel, &attr);244 PCUT_ASSERT_ERRNO_VAL(EOK, rc);245 246 attr.name = "c";247 attr.size = 3;248 rc = panel_entry_append(panel, &attr);249 PCUT_ASSERT_ERRNO_VAL(EOK, rc);250 251 panel->cursor = panel_first(panel);252 panel->cursor_idx = 0;253 panel->page = panel_first(panel);254 panel->page_idx = 0;255 256 event.pos_id = 0;257 event.type = POS_PRESS;258 event.btn_num = 1;259 260 /* Clicking on the middle entry should select it */261 event.hpos = 1;262 event.vpos = 2;263 264 claimed = panel_pos_event(panel, &event);265 PCUT_ASSERT_EQUALS(ui_claimed, claimed);266 267 PCUT_ASSERT_NOT_NULL(panel->cursor);268 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);269 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);270 271 /* Clicking below the last entry should select it */272 event.hpos = 1;273 event.vpos = 4;274 claimed = panel_pos_event(panel, &event);275 PCUT_ASSERT_EQUALS(ui_claimed, claimed);276 277 PCUT_ASSERT_NOT_NULL(panel->cursor);278 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);279 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);280 281 /* Clicking on the top edge should do a page-up */282 event.hpos = 1;283 event.vpos = 0;284 claimed = panel_pos_event(panel, &event);285 PCUT_ASSERT_EQUALS(ui_claimed, claimed);286 287 PCUT_ASSERT_NOT_NULL(panel->cursor);288 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);289 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);290 291 panel_destroy(panel);292 ui_window_destroy(window);293 ui_destroy(ui);294 170 } 295 171 … … 318 194 } 319 195 320 /** panel_page_size() returns correct size */321 PCUT_TEST(page_size)322 {323 panel_t *panel;324 gfx_rect_t rect;325 errno_t rc;326 327 rc = panel_create(NULL, true, &panel);328 PCUT_ASSERT_ERRNO_VAL(EOK, rc);329 330 rect.p0.x = 10;331 rect.p0.y = 20;332 rect.p1.x = 30;333 rect.p1.y = 40;334 335 panel_set_rect(panel, &rect);336 337 /* NOTE If page size changes, we have problems elsewhere in the tests */338 PCUT_ASSERT_INT_EQUALS(18, panel_page_size(panel));339 340 panel_destroy(panel);341 }342 343 196 /** panel_is_active() returns panel activity state */ 344 197 PCUT_TEST(is_active) … … 419 272 } 420 273 421 /** panel_entry_append() appends new entry */422 PCUT_TEST(entry_append)423 {424 panel_t *panel;425 panel_entry_attr_t attr;426 errno_t rc;427 428 rc = panel_create(NULL, true, &panel);429 PCUT_ASSERT_ERRNO_VAL(EOK, rc);430 431 panel_entry_attr_init(&attr);432 433 attr.name = "a";434 attr.size = 1;435 rc = panel_entry_append(panel, &attr);436 PCUT_ASSERT_ERRNO_VAL(EOK, rc);437 438 PCUT_ASSERT_INT_EQUALS(1, list_count(&panel->entries));439 440 attr.name = "b";441 attr.size = 2;442 rc = panel_entry_append(panel, &attr);443 PCUT_ASSERT_ERRNO_VAL(EOK, rc);444 445 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));446 447 panel_destroy(panel);448 }449 450 /** panel_entry_delete() deletes entry */451 PCUT_TEST(entry_delete)452 {453 panel_t *panel;454 panel_entry_t *entry;455 panel_entry_attr_t attr;456 errno_t rc;457 458 rc = panel_create(NULL, true, &panel);459 PCUT_ASSERT_ERRNO_VAL(EOK, rc);460 461 attr.name = "a";462 attr.size = 1;463 rc = panel_entry_append(panel, &attr);464 PCUT_ASSERT_ERRNO_VAL(EOK, rc);465 466 attr.name = "b";467 attr.size = 2;468 rc = panel_entry_append(panel, &attr);469 PCUT_ASSERT_ERRNO_VAL(EOK, rc);470 471 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));472 473 entry = panel_first(panel);474 panel_entry_delete(entry);475 476 PCUT_ASSERT_INT_EQUALS(1, list_count(&panel->entries));477 478 entry = panel_first(panel);479 panel_entry_delete(entry);480 481 PCUT_ASSERT_INT_EQUALS(0, list_count(&panel->entries));482 483 panel_destroy(panel);484 }485 486 /** panel_clear_entries() removes all entries from panel */487 PCUT_TEST(clear_entries)488 {489 panel_t *panel;490 panel_entry_attr_t attr;491 errno_t rc;492 493 rc = panel_create(NULL, true, &panel);494 PCUT_ASSERT_ERRNO_VAL(EOK, rc);495 496 panel_entry_attr_init(&attr);497 attr.name = "a";498 attr.size = 1;499 rc = panel_entry_append(panel, &attr);500 PCUT_ASSERT_ERRNO_VAL(EOK, rc);501 502 attr.name = "a";503 attr.size = 2;504 rc = panel_entry_append(panel, &attr);505 PCUT_ASSERT_ERRNO_VAL(EOK, rc);506 507 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));508 509 panel_clear_entries(panel);510 PCUT_ASSERT_INT_EQUALS(0, list_count(&panel->entries));511 512 panel_destroy(panel);513 }514 515 /** panel_read_dir() reads the contents of a directory */516 PCUT_TEST(read_dir)517 {518 panel_t *panel;519 panel_entry_t *entry;520 char buf[L_tmpnam];521 char *fname;522 char *p;523 errno_t rc;524 FILE *f;525 int rv;526 527 /* Create name for temporary directory */528 p = tmpnam(buf);529 PCUT_ASSERT_NOT_NULL(p);530 531 /* Create temporary directory */532 rc = vfs_link_path(p, KIND_DIRECTORY, NULL);533 PCUT_ASSERT_ERRNO_VAL(EOK, rc);534 535 rv = asprintf(&fname, "%s/%s", p, "a");536 PCUT_ASSERT_TRUE(rv >= 0);537 538 f = fopen(fname, "wb");539 PCUT_ASSERT_NOT_NULL(f);540 541 rv = fprintf(f, "X");542 PCUT_ASSERT_TRUE(rv >= 0);543 544 rv = fclose(f);545 PCUT_ASSERT_INT_EQUALS(0, rv);546 547 rc = panel_create(NULL, true, &panel);548 PCUT_ASSERT_ERRNO_VAL(EOK, rc);549 550 rc = panel_read_dir(panel, p);551 PCUT_ASSERT_ERRNO_VAL(EOK, rc);552 553 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));554 555 entry = panel_first(panel);556 PCUT_ASSERT_NOT_NULL(entry);557 PCUT_ASSERT_STR_EQUALS("..", entry->name);558 559 entry = panel_next(entry);560 PCUT_ASSERT_NOT_NULL(entry);561 PCUT_ASSERT_STR_EQUALS("a", entry->name);562 PCUT_ASSERT_INT_EQUALS(1, entry->size);563 564 panel_destroy(panel);565 566 rv = remove(fname);567 PCUT_ASSERT_INT_EQUALS(0, rv);568 569 rv = remove(p);570 PCUT_ASSERT_INT_EQUALS(0, rv);571 572 free(fname);573 }574 575 /** When moving to parent directory from a subdir, we seek to the576 * coresponding entry577 */578 PCUT_TEST(read_dir_up)579 {580 panel_t *panel;581 char buf[L_tmpnam];582 char *subdir_a;583 char *subdir_b;584 char *subdir_c;585 char *p;586 errno_t rc;587 int rv;588 589 /* Create name for temporary directory */590 p = tmpnam(buf);591 PCUT_ASSERT_NOT_NULL(p);592 593 /* Create temporary directory */594 rc = vfs_link_path(p, KIND_DIRECTORY, NULL);595 PCUT_ASSERT_ERRNO_VAL(EOK, rc);596 597 /* Create some subdirectories */598 599 rv = asprintf(&subdir_a, "%s/%s", p, "a");600 PCUT_ASSERT_TRUE(rv >= 0);601 rc = vfs_link_path(subdir_a, KIND_DIRECTORY, NULL);602 PCUT_ASSERT_ERRNO_VAL(EOK, rc);603 604 rv = asprintf(&subdir_b, "%s/%s", p, "b");605 PCUT_ASSERT_TRUE(rv >= 0);606 rc = vfs_link_path(subdir_b, KIND_DIRECTORY, NULL);607 PCUT_ASSERT_ERRNO_VAL(EOK, rc);608 609 rv = asprintf(&subdir_c, "%s/%s", p, "c");610 PCUT_ASSERT_TRUE(rv >= 0);611 rc = vfs_link_path(subdir_c, KIND_DIRECTORY, NULL);612 PCUT_ASSERT_ERRNO_VAL(EOK, rc);613 614 rc = panel_create(NULL, true, &panel);615 PCUT_ASSERT_ERRNO_VAL(EOK, rc);616 617 /* Start in subdirectory "b" */618 rc = panel_read_dir(panel, subdir_b);619 PCUT_ASSERT_ERRNO_VAL(EOK, rc);620 621 /* Now go up (into p) */622 623 rc = panel_read_dir(panel, "..");624 PCUT_ASSERT_ERRNO_VAL(EOK, rc);625 626 PCUT_ASSERT_NOT_NULL(panel->cursor);627 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);628 629 panel_destroy(panel);630 631 rv = remove(subdir_a);632 PCUT_ASSERT_INT_EQUALS(0, rv);633 634 rv = remove(subdir_b);635 PCUT_ASSERT_INT_EQUALS(0, rv);636 637 rv = remove(subdir_c);638 PCUT_ASSERT_INT_EQUALS(0, rv);639 640 rv = remove(p);641 PCUT_ASSERT_INT_EQUALS(0, rv);642 643 free(subdir_a);644 free(subdir_b);645 free(subdir_c);646 }647 648 /** panel_sort() sorts panel entries */649 PCUT_TEST(sort)650 {651 panel_t *panel;652 panel_entry_t *entry;653 panel_entry_attr_t attr;654 errno_t rc;655 656 rc = panel_create(NULL, true, &panel);657 PCUT_ASSERT_ERRNO_VAL(EOK, rc);658 659 panel_entry_attr_init(&attr);660 661 attr.name = "b";662 attr.size = 1;663 rc = panel_entry_append(panel, &attr);664 PCUT_ASSERT_ERRNO_VAL(EOK, rc);665 666 attr.name = "c";667 attr.size = 3;668 rc = panel_entry_append(panel, &attr);669 PCUT_ASSERT_ERRNO_VAL(EOK, rc);670 671 attr.name = "a";672 attr.size = 2;673 rc = panel_entry_append(panel, &attr);674 PCUT_ASSERT_ERRNO_VAL(EOK, rc);675 676 rc = panel_sort(panel);677 PCUT_ASSERT_ERRNO_VAL(EOK, rc);678 679 entry = panel_first(panel);680 PCUT_ASSERT_STR_EQUALS("a", entry->name);681 PCUT_ASSERT_INT_EQUALS(2, entry->size);682 683 entry = panel_next(entry);684 PCUT_ASSERT_STR_EQUALS("b", entry->name);685 PCUT_ASSERT_INT_EQUALS(1, entry->size);686 687 entry = panel_next(entry);688 PCUT_ASSERT_STR_EQUALS("c", entry->name);689 PCUT_ASSERT_INT_EQUALS(3, entry->size);690 691 panel_destroy(panel);692 }693 694 /** panel_entry_ptr_cmp compares two indirectly referenced entries */695 PCUT_TEST(entry_ptr_cmp)696 {697 panel_t *panel;698 panel_entry_t *a, *b;699 panel_entry_attr_t attr;700 int rel;701 errno_t rc;702 703 rc = panel_create(NULL, true, &panel);704 PCUT_ASSERT_ERRNO_VAL(EOK, rc);705 706 panel_entry_attr_init(&attr);707 708 attr.name = "a";709 attr.size = 2;710 rc = panel_entry_append(panel, &attr);711 PCUT_ASSERT_ERRNO_VAL(EOK, rc);712 713 attr.name = "b";714 attr.size = 1;715 rc = panel_entry_append(panel, &attr);716 PCUT_ASSERT_ERRNO_VAL(EOK, rc);717 718 a = panel_first(panel);719 PCUT_ASSERT_NOT_NULL(a);720 b = panel_next(a);721 PCUT_ASSERT_NOT_NULL(b);722 723 /* a < b */724 rel = panel_entry_ptr_cmp(&a, &b);725 PCUT_ASSERT_TRUE(rel < 0);726 727 /* b > a */728 rel = panel_entry_ptr_cmp(&b, &a);729 PCUT_ASSERT_TRUE(rel > 0);730 731 /* a == a */732 rel = panel_entry_ptr_cmp(&a, &a);733 PCUT_ASSERT_INT_EQUALS(0, rel);734 735 panel_destroy(panel);736 }737 738 /** panel_first() returns valid entry or @c NULL as appropriate */739 PCUT_TEST(first)740 {741 panel_t *panel;742 panel_entry_t *entry;743 panel_entry_attr_t attr;744 errno_t rc;745 746 rc = panel_create(NULL, true, &panel);747 PCUT_ASSERT_ERRNO_VAL(EOK, rc);748 749 panel_entry_attr_init(&attr);750 751 entry = panel_first(panel);752 PCUT_ASSERT_NULL(entry);753 754 /* Add one entry */755 attr.name = "a";756 attr.size = 1;757 rc = panel_entry_append(panel, &attr);758 PCUT_ASSERT_ERRNO_VAL(EOK, rc);759 760 /* Now try getting it */761 entry = panel_first(panel);762 PCUT_ASSERT_NOT_NULL(entry);763 PCUT_ASSERT_STR_EQUALS("a", entry->name);764 PCUT_ASSERT_INT_EQUALS(1, entry->size);765 766 /* Add another entry */767 attr.name = "b";768 attr.size = 2;769 rc = panel_entry_append(panel, &attr);770 PCUT_ASSERT_ERRNO_VAL(EOK, rc);771 772 /* We should still get the first entry */773 entry = panel_first(panel);774 PCUT_ASSERT_NOT_NULL(entry);775 PCUT_ASSERT_STR_EQUALS("a", entry->name);776 PCUT_ASSERT_INT_EQUALS(1, entry->size);777 778 panel_destroy(panel);779 }780 781 /** panel_last() returns valid entry or @c NULL as appropriate */782 PCUT_TEST(last)783 {784 panel_t *panel;785 panel_entry_t *entry;786 panel_entry_attr_t attr;787 errno_t rc;788 789 rc = panel_create(NULL, true, &panel);790 PCUT_ASSERT_ERRNO_VAL(EOK, rc);791 792 panel_entry_attr_init(&attr);793 794 entry = panel_last(panel);795 PCUT_ASSERT_NULL(entry);796 797 /* Add one entry */798 attr.name = "a";799 attr.size = 1;800 rc = panel_entry_append(panel, &attr);801 PCUT_ASSERT_ERRNO_VAL(EOK, rc);802 803 /* Now try getting it */804 entry = panel_last(panel);805 PCUT_ASSERT_NOT_NULL(entry);806 PCUT_ASSERT_STR_EQUALS("a", entry->name);807 PCUT_ASSERT_INT_EQUALS(1, entry->size);808 809 /* Add another entry */810 attr.name = "b";811 attr.size = 2;812 rc = panel_entry_append(panel, &attr);813 PCUT_ASSERT_ERRNO_VAL(EOK, rc);814 815 /* We should get new entry now */816 entry = panel_last(panel);817 PCUT_ASSERT_NOT_NULL(entry);818 attr.name = "b";819 attr.size = 2;820 PCUT_ASSERT_STR_EQUALS("b", entry->name);821 PCUT_ASSERT_INT_EQUALS(2, entry->size);822 823 panel_destroy(panel);824 }825 826 /** panel_next() returns the next entry or @c NULL as appropriate */827 PCUT_TEST(next)828 {829 panel_t *panel;830 panel_entry_t *entry;831 panel_entry_attr_t attr;832 errno_t rc;833 834 rc = panel_create(NULL, true, &panel);835 PCUT_ASSERT_ERRNO_VAL(EOK, rc);836 837 panel_entry_attr_init(&attr);838 839 /* Add one entry */840 attr.name = "a";841 attr.size = 1;842 rc = panel_entry_append(panel, &attr);843 PCUT_ASSERT_ERRNO_VAL(EOK, rc);844 845 /* Now try getting its successor */846 entry = panel_first(panel);847 PCUT_ASSERT_NOT_NULL(entry);848 849 entry = panel_next(entry);850 PCUT_ASSERT_NULL(entry);851 852 /* Add another entry */853 attr.name = "b";854 attr.size = 2;855 rc = panel_entry_append(panel, &attr);856 PCUT_ASSERT_ERRNO_VAL(EOK, rc);857 858 /* Try getting the successor of first entry again */859 entry = panel_first(panel);860 PCUT_ASSERT_NOT_NULL(entry);861 862 entry = panel_next(entry);863 PCUT_ASSERT_NOT_NULL(entry);864 PCUT_ASSERT_STR_EQUALS("b", entry->name);865 PCUT_ASSERT_INT_EQUALS(2, entry->size);866 867 panel_destroy(panel);868 }869 870 /** panel_prev() returns the previous entry or @c NULL as appropriate */871 PCUT_TEST(prev)872 {873 panel_t *panel;874 panel_entry_t *entry;875 panel_entry_attr_t attr;876 errno_t rc;877 878 rc = panel_create(NULL, true, &panel);879 PCUT_ASSERT_ERRNO_VAL(EOK, rc);880 881 panel_entry_attr_init(&attr);882 883 /* Add one entry */884 attr.name = "a";885 attr.size = 1;886 rc = panel_entry_append(panel, &attr);887 PCUT_ASSERT_ERRNO_VAL(EOK, rc);888 889 /* Now try getting its predecessor */890 entry = panel_last(panel);891 PCUT_ASSERT_NOT_NULL(entry);892 893 entry = panel_prev(entry);894 PCUT_ASSERT_NULL(entry);895 896 /* Add another entry */897 attr.name = "b";898 attr.size = 2;899 rc = panel_entry_append(panel, &attr);900 PCUT_ASSERT_ERRNO_VAL(EOK, rc);901 902 /* Try getting the predecessor of the new entry */903 entry = panel_last(panel);904 PCUT_ASSERT_NOT_NULL(entry);905 906 entry = panel_prev(entry);907 PCUT_ASSERT_NOT_NULL(entry);908 PCUT_ASSERT_STR_EQUALS("a", entry->name);909 PCUT_ASSERT_INT_EQUALS(1, entry->size);910 911 panel_destroy(panel);912 }913 914 /** panel_page_nth_entry() .. */915 PCUT_TEST(page_nth_entry)916 {917 panel_t *panel;918 panel_entry_t *entry;919 panel_entry_attr_t attr;920 size_t idx;921 errno_t rc;922 923 rc = panel_create(NULL, true, &panel);924 PCUT_ASSERT_ERRNO_VAL(EOK, rc);925 926 panel_entry_attr_init(&attr);927 928 /* Add some entries */929 attr.name = "a";930 attr.size = 1;931 rc = panel_entry_append(panel, &attr);932 PCUT_ASSERT_ERRNO_VAL(EOK, rc);933 934 attr.name = "b";935 attr.size = 2;936 rc = panel_entry_append(panel, &attr);937 PCUT_ASSERT_ERRNO_VAL(EOK, rc);938 939 attr.name = "c";940 attr.size = 3;941 rc = panel_entry_append(panel, &attr);942 PCUT_ASSERT_ERRNO_VAL(EOK, rc);943 944 panel->page = panel_next(panel_first(panel));945 panel->page_idx = 1;946 947 entry = panel_page_nth_entry(panel, 0, &idx);948 PCUT_ASSERT_STR_EQUALS("b", entry->name);949 PCUT_ASSERT_INT_EQUALS(1, idx);950 951 entry = panel_page_nth_entry(panel, 1, &idx);952 PCUT_ASSERT_STR_EQUALS("c", entry->name);953 PCUT_ASSERT_INT_EQUALS(2, idx);954 955 entry = panel_page_nth_entry(panel, 2, &idx);956 PCUT_ASSERT_STR_EQUALS("c", entry->name);957 PCUT_ASSERT_INT_EQUALS(2, idx);958 959 entry = panel_page_nth_entry(panel, 3, &idx);960 PCUT_ASSERT_STR_EQUALS("c", entry->name);961 PCUT_ASSERT_INT_EQUALS(2, idx);962 963 panel_destroy(panel);964 }965 966 /** panel_cursor_move() ... */967 PCUT_TEST(cursor_move)968 {969 }970 971 /** panel_cursor_up() moves cursor one entry up */972 PCUT_TEST(cursor_up)973 {974 ui_t *ui;975 ui_window_t *window;976 ui_wnd_params_t params;977 panel_t *panel;978 panel_entry_attr_t attr;979 gfx_rect_t rect;980 errno_t rc;981 982 rc = ui_create_disp(NULL, &ui);983 PCUT_ASSERT_ERRNO_VAL(EOK, rc);984 985 ui_wnd_params_init(¶ms);986 params.caption = "Test";987 988 rc = ui_window_create(ui, ¶ms, &window);989 PCUT_ASSERT_ERRNO_VAL(EOK, rc);990 991 rc = panel_create(window, true, &panel);992 PCUT_ASSERT_ERRNO_VAL(EOK, rc);993 994 rect.p0.x = 0;995 rect.p0.y = 0;996 rect.p1.x = 10;997 rect.p1.y = 4; // XXX Assuming this makes page size 2998 panel_set_rect(panel, &rect);999 1000 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));1001 1002 /* Add tree entries (more than page size, which is 2) */1003 1004 panel_entry_attr_init(&attr);1005 1006 attr.name = "a";1007 attr.size = 1;1008 rc = panel_entry_append(panel, &attr);1009 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1010 1011 attr.name = "b";1012 attr.size = 2;1013 rc = panel_entry_append(panel, &attr);1014 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1015 1016 attr.name = "c";1017 attr.size = 3;1018 rc = panel_entry_append(panel, &attr);1019 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1020 1021 /* Cursor to the last entry and page start to the next-to-last entry */1022 panel->cursor = panel_last(panel);1023 panel->cursor_idx = 2;1024 panel->page = panel_prev(panel->cursor);1025 panel->page_idx = 1;1026 1027 /* Move cursor one entry up */1028 panel_cursor_up(panel);1029 1030 /* Cursor and page start should now both be at the second entry */1031 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);1032 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);1033 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx);1034 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);1035 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);1036 1037 /* Move cursor one entry up. This should scroll up. */1038 panel_cursor_up(panel);1039 1040 /* Cursor and page start should now both be at the first entry */1041 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);1042 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);1043 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);1044 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);1045 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);1046 1047 /* Moving further up should do nothing (we are at the top). */1048 panel_cursor_up(panel);1049 1050 /* Cursor and page start should still be at the first entry */1051 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);1052 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);1053 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);1054 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);1055 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);1056 1057 panel_destroy(panel);1058 ui_window_destroy(window);1059 ui_destroy(ui);1060 }1061 1062 /** panel_cursor_down() moves cursor one entry down */1063 PCUT_TEST(cursor_down)1064 {1065 ui_t *ui;1066 ui_window_t *window;1067 ui_wnd_params_t params;1068 panel_t *panel;1069 panel_entry_attr_t attr;1070 gfx_rect_t rect;1071 errno_t rc;1072 1073 rc = ui_create_disp(NULL, &ui);1074 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1075 1076 ui_wnd_params_init(¶ms);1077 params.caption = "Test";1078 1079 rc = ui_window_create(ui, ¶ms, &window);1080 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1081 1082 rc = panel_create(window, true, &panel);1083 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1084 1085 rect.p0.x = 0;1086 rect.p0.y = 0;1087 rect.p1.x = 10;1088 rect.p1.y = 4; // XXX Assuming this makes page size 21089 panel_set_rect(panel, &rect);1090 1091 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));1092 1093 /* Add tree entries (more than page size, which is 2) */1094 1095 panel_entry_attr_init(&attr);1096 1097 attr.name = "a";1098 attr.size = 1;1099 rc = panel_entry_append(panel, &attr);1100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1101 1102 attr.name = "b";1103 attr.size = 2;1104 rc = panel_entry_append(panel, &attr);1105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1106 1107 attr.name = "c";1108 attr.size = 3;1109 rc = panel_entry_append(panel, &attr);1110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1111 1112 /* Cursor and page start to the first entry */1113 panel->cursor = panel_first(panel);1114 panel->cursor_idx = 0;1115 panel->page = panel->cursor;1116 panel->page_idx = 0;1117 1118 /* Move cursor one entry down */1119 panel_cursor_down(panel);1120 1121 /* Cursor should now be at the second entry, page stays the same */1122 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);1123 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);1124 PCUT_ASSERT_INT_EQUALS(1, panel->cursor_idx);1125 PCUT_ASSERT_EQUALS(panel_first(panel), panel->page);1126 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);1127 1128 /* Move cursor one entry down. This should scroll down. */1129 panel_cursor_down(panel);1130 1131 /* Cursor should now be at the third and page at the second entry. */1132 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);1133 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);1134 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);1135 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);1136 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);1137 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);1138 1139 /* Moving further down should do nothing (we are at the bottom). */1140 panel_cursor_down(panel);1141 1142 /* Cursor should still be at the third and page at the second entry. */1143 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);1144 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);1145 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);1146 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);1147 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);1148 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);1149 1150 panel_destroy(panel);1151 ui_window_destroy(window);1152 ui_destroy(ui);1153 }1154 1155 /** panel_cursor_top() moves cursor to the first entry */1156 PCUT_TEST(cursor_top)1157 {1158 ui_t *ui;1159 ui_window_t *window;1160 ui_wnd_params_t params;1161 panel_t *panel;1162 panel_entry_attr_t attr;1163 gfx_rect_t rect;1164 errno_t rc;1165 1166 rc = ui_create_disp(NULL, &ui);1167 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1168 1169 ui_wnd_params_init(¶ms);1170 params.caption = "Test";1171 1172 rc = ui_window_create(ui, ¶ms, &window);1173 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1174 1175 rc = panel_create(window, true, &panel);1176 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1177 1178 rect.p0.x = 0;1179 rect.p0.y = 0;1180 rect.p1.x = 10;1181 rect.p1.y = 4; // XXX Assuming this makes page size 21182 panel_set_rect(panel, &rect);1183 1184 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));1185 1186 /* Add tree entries (more than page size, which is 2) */1187 1188 panel_entry_attr_init(&attr);1189 1190 attr.name = "a";1191 attr.size = 1;1192 rc = panel_entry_append(panel, &attr);1193 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1194 1195 attr.name = "b";1196 attr.size = 2;1197 rc = panel_entry_append(panel, &attr);1198 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1199 1200 attr.name = "c";1201 attr.size = 3;1202 rc = panel_entry_append(panel, &attr);1203 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1204 1205 /* Cursor to the last entry and page start to the next-to-last entry */1206 panel->cursor = panel_last(panel);1207 panel->cursor_idx = 2;1208 panel->page = panel_prev(panel->cursor);1209 panel->page_idx = 1;1210 1211 /* Move cursor to the top. This should scroll up. */1212 panel_cursor_top(panel);1213 1214 /* Cursor and page start should now both be at the first entry */1215 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);1216 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);1217 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);1218 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);1219 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);1220 1221 panel_destroy(panel);1222 ui_window_destroy(window);1223 ui_destroy(ui);1224 }1225 1226 /** panel_cursor_bottom() moves cursor to the last entry */1227 PCUT_TEST(cursor_bottom)1228 {1229 ui_t *ui;1230 ui_window_t *window;1231 ui_wnd_params_t params;1232 panel_t *panel;1233 panel_entry_attr_t attr;1234 gfx_rect_t rect;1235 errno_t rc;1236 1237 rc = ui_create_disp(NULL, &ui);1238 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1239 1240 ui_wnd_params_init(¶ms);1241 params.caption = "Test";1242 1243 rc = ui_window_create(ui, ¶ms, &window);1244 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1245 1246 rc = panel_create(window, true, &panel);1247 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1248 1249 rect.p0.x = 0;1250 rect.p0.y = 0;1251 rect.p1.x = 10;1252 rect.p1.y = 4; // XXX Assuming this makes page size 21253 panel_set_rect(panel, &rect);1254 1255 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));1256 1257 /* Add tree entries (more than page size, which is 2) */1258 1259 panel_entry_attr_init(&attr);1260 1261 attr.name = "a";1262 attr.size = 1;1263 rc = panel_entry_append(panel, &attr);1264 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1265 1266 attr.name = "b";1267 attr.size = 2;1268 rc = panel_entry_append(panel, &attr);1269 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1270 1271 attr.name = "c";1272 attr.size = 3;1273 rc = panel_entry_append(panel, &attr);1274 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1275 1276 /* Cursor and page start to the first entry */1277 panel->cursor = panel_first(panel);1278 panel->cursor_idx = 0;1279 panel->page = panel->cursor;1280 panel->page_idx = 0;1281 1282 /* Move cursor to the bottom. This should scroll down. */1283 panel_cursor_bottom(panel);1284 1285 /* Cursor should now be at the third and page at the second entry. */1286 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);1287 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);1288 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);1289 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);1290 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);1291 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);1292 1293 panel_destroy(panel);1294 ui_window_destroy(window);1295 ui_destroy(ui);1296 }1297 1298 /** panel_page_up() moves one page up */1299 PCUT_TEST(page_up)1300 {1301 ui_t *ui;1302 ui_window_t *window;1303 ui_wnd_params_t params;1304 panel_t *panel;1305 panel_entry_attr_t attr;1306 gfx_rect_t rect;1307 errno_t rc;1308 1309 rc = ui_create_disp(NULL, &ui);1310 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1311 1312 ui_wnd_params_init(¶ms);1313 params.caption = "Test";1314 1315 rc = ui_window_create(ui, ¶ms, &window);1316 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1317 1318 rc = panel_create(window, true, &panel);1319 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1320 1321 rect.p0.x = 0;1322 rect.p0.y = 0;1323 rect.p1.x = 10;1324 rect.p1.y = 4; // XXX Assuming this makes page size 21325 panel_set_rect(panel, &rect);1326 1327 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));1328 1329 /* Add five entries (2 full pages, one partial) */1330 1331 panel_entry_attr_init(&attr);1332 1333 attr.name = "a";1334 attr.size = 1;1335 rc = panel_entry_append(panel, &attr);1336 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1337 1338 attr.name = "b";1339 attr.size = 2;1340 rc = panel_entry_append(panel, &attr);1341 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1342 1343 attr.name = "c";1344 attr.size = 3;1345 rc = panel_entry_append(panel, &attr);1346 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1347 1348 attr.name = "d";1349 attr.size = 4;1350 rc = panel_entry_append(panel, &attr);1351 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1352 1353 attr.name = "e";1354 attr.size = 5;1355 rc = panel_entry_append(panel, &attr);1356 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1357 1358 /* Cursor to the last entry and page start to the next-to-last entry */1359 panel->cursor = panel_last(panel);1360 panel->cursor_idx = 4;1361 panel->page = panel_prev(panel->cursor);1362 panel->page_idx = 3;1363 1364 /* Move one page up */1365 panel_page_up(panel);1366 1367 /* Page should now start at second entry and cursor at third */1368 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);1369 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);1370 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);1371 PCUT_ASSERT_STR_EQUALS("b", panel->page->name);1372 PCUT_ASSERT_INT_EQUALS(2, panel->page->size);1373 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx);1374 1375 /* Move one page up again. */1376 panel_page_up(panel);1377 1378 /* Cursor and page start should now both be at the first entry */1379 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);1380 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);1381 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);1382 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);1383 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);1384 1385 /* Moving further up should do nothing (we are at the top). */1386 panel_page_up(panel);1387 1388 /* Cursor and page start should still be at the first entry */1389 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name);1390 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size);1391 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx);1392 PCUT_ASSERT_EQUALS(panel->cursor, panel->page);1393 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx);1394 1395 panel_destroy(panel);1396 ui_window_destroy(window);1397 ui_destroy(ui);1398 }1399 1400 /** panel_page_up() moves one page down */1401 PCUT_TEST(page_down)1402 {1403 ui_t *ui;1404 ui_window_t *window;1405 ui_wnd_params_t params;1406 panel_t *panel;1407 panel_entry_attr_t attr;1408 gfx_rect_t rect;1409 errno_t rc;1410 1411 rc = ui_create_disp(NULL, &ui);1412 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1413 1414 ui_wnd_params_init(¶ms);1415 params.caption = "Test";1416 1417 rc = ui_window_create(ui, ¶ms, &window);1418 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1419 1420 rc = panel_create(window, true, &panel);1421 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1422 1423 rect.p0.x = 0;1424 rect.p0.y = 0;1425 rect.p1.x = 10;1426 rect.p1.y = 4; // XXX Assuming this makes page size 21427 panel_set_rect(panel, &rect);1428 1429 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel));1430 1431 /* Add five entries (2 full pages, one partial) */1432 1433 panel_entry_attr_init(&attr);1434 1435 attr.name = "a";1436 attr.size = 1;1437 rc = panel_entry_append(panel, &attr);1438 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1439 1440 attr.name = "b";1441 attr.size = 2;1442 rc = panel_entry_append(panel, &attr);1443 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1444 1445 attr.name = "c";1446 attr.size = 3;1447 rc = panel_entry_append(panel, &attr);1448 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1449 1450 attr.name = "d";1451 attr.size = 4;1452 rc = panel_entry_append(panel, &attr);1453 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1454 1455 attr.name = "e";1456 attr.size = 5;1457 rc = panel_entry_append(panel, &attr);1458 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1459 1460 /* Cursor and page to the first entry */1461 panel->cursor = panel_first(panel);1462 panel->cursor_idx = 0;1463 panel->page = panel->cursor;1464 panel->page_idx = 0;1465 1466 /* Move one page down */1467 panel_page_down(panel);1468 1469 /* Page and cursor should point to the third entry */1470 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);1471 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);1472 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx);1473 PCUT_ASSERT_STR_EQUALS("c", panel->page->name);1474 PCUT_ASSERT_INT_EQUALS(3, panel->page->size);1475 PCUT_ASSERT_INT_EQUALS(2, panel->page_idx);1476 1477 /* Move one page down again. */1478 panel_page_down(panel);1479 1480 /* Cursor should point to last and page to next-to-last entry */1481 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name);1482 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size);1483 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx);1484 PCUT_ASSERT_STR_EQUALS("d", panel->page->name);1485 PCUT_ASSERT_INT_EQUALS(4, panel->page->size);1486 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx);1487 1488 /* Moving further down should do nothing (we are at the bottom). */1489 panel_page_down(panel);1490 1491 /* Cursor should still point to last and page to next-to-last entry */1492 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name);1493 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size);1494 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx);1495 PCUT_ASSERT_STR_EQUALS("d", panel->page->name);1496 PCUT_ASSERT_INT_EQUALS(4, panel->page->size);1497 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx);1498 1499 panel_destroy(panel);1500 ui_window_destroy(window);1501 ui_destroy(ui);1502 }1503 1504 /** panel_open() opens a directory entry */1505 PCUT_TEST(open)1506 {1507 ui_t *ui;1508 ui_window_t *window;1509 ui_wnd_params_t params;1510 panel_t *panel;1511 panel_entry_t *entry;1512 char buf[L_tmpnam];1513 char *sdname;1514 char *p;1515 errno_t rc;1516 int rv;1517 1518 rc = ui_create_disp(NULL, &ui);1519 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1520 1521 ui_wnd_params_init(¶ms);1522 params.caption = "Test";1523 1524 rc = ui_window_create(ui, ¶ms, &window);1525 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1526 1527 /* Create name for temporary directory */1528 p = tmpnam(buf);1529 PCUT_ASSERT_NOT_NULL(p);1530 1531 /* Create temporary directory */1532 rc = vfs_link_path(p, KIND_DIRECTORY, NULL);1533 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1534 1535 rv = asprintf(&sdname, "%s/%s", p, "a");1536 PCUT_ASSERT_TRUE(rv >= 0);1537 1538 /* Create sub-directory */1539 rc = vfs_link_path(sdname, KIND_DIRECTORY, NULL);1540 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1541 1542 rc = panel_create(window, true, &panel);1543 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1544 1545 rc = panel_read_dir(panel, p);1546 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1547 PCUT_ASSERT_STR_EQUALS(p, panel->dir);1548 1549 PCUT_ASSERT_INT_EQUALS(2, list_count(&panel->entries));1550 1551 entry = panel_first(panel);1552 PCUT_ASSERT_NOT_NULL(entry);1553 PCUT_ASSERT_STR_EQUALS("..", entry->name);1554 1555 entry = panel_next(entry);1556 PCUT_ASSERT_NOT_NULL(entry);1557 PCUT_ASSERT_STR_EQUALS("a", entry->name);1558 PCUT_ASSERT_TRUE(entry->isdir);1559 1560 rc = panel_open(panel, entry);1561 PCUT_ASSERT_ERRNO_VAL(EOK, rc);1562 1563 PCUT_ASSERT_STR_EQUALS(sdname, panel->dir);1564 1565 panel_destroy(panel);1566 ui_window_destroy(window);1567 ui_destroy(ui);1568 1569 rv = remove(sdname);1570 PCUT_ASSERT_INT_EQUALS(0, rv);1571 1572 rv = remove(p);1573 PCUT_ASSERT_INT_EQUALS(0, rv);1574 1575 free(sdname);1576 }1577 1578 274 /** panel_activate_req() sends activation request */ 1579 275 PCUT_TEST(activate_req)
Note:
See TracChangeset
for help on using the changeset viewer.