Changeset 3e6c51f in mainline for uspace/app/nav/test/panel.c
- Timestamp:
- 2021-10-13T07:41:33Z (3 years ago)
- Children:
- b9d689b
- Parents:
- af2ea83
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-12 19:41:17)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-10-13 07:41:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/test/panel.c
raf2ea83 r3e6c51f 209 209 } 210 210 211 /** panel_page_size() returns correct size */ 212 PCUT_TEST(page_size) 213 { 214 panel_t *panel; 215 ui_control_t *control; 216 gfx_rect_t rect; 217 errno_t rc; 218 219 rc = panel_create(NULL, &panel); 220 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 221 222 control = panel_ctl(panel); 223 PCUT_ASSERT_NOT_NULL(control); 224 225 rect.p0.x = 10; 226 rect.p0.y = 20; 227 rect.p1.x = 30; 228 rect.p1.y = 40; 229 230 panel_set_rect(panel, &rect); 231 232 /* NOTE If page size changes, we have problems elsewhere in the tests */ 233 PCUT_ASSERT_INT_EQUALS(18, panel_page_size(panel)); 234 235 panel_destroy(panel); 236 } 237 211 238 /** panel_entry_append() appends new entry */ 212 239 PCUT_TEST(entry_append) … … 518 545 rect.p1.y = 4; // XXX Assuming this makes page size 2 519 546 panel_set_rect(panel, &rect); 547 548 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel)); 520 549 521 550 /* Add tree entries (more than page size, which is 2) */ … … 597 626 rect.p1.y = 4; // XXX Assuming this makes page size 2 598 627 panel_set_rect(panel, &rect); 628 629 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel)); 599 630 600 631 /* Add tree entries (more than page size, which is 2) */ … … 679 710 panel_set_rect(panel, &rect); 680 711 712 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel)); 713 681 714 /* Add tree entries (more than page size, which is 2) */ 682 715 rc = panel_entry_append(panel, "a", 1); … … 737 770 rect.p1.y = 4; // XXX Assuming this makes page size 2 738 771 panel_set_rect(panel, &rect); 772 773 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel)); 739 774 740 775 /* Add tree entries (more than page size, which is 2) */ … … 770 805 } 771 806 807 /** panel_page_up() moves one page up */ 808 PCUT_TEST(page_up) 809 { 810 ui_t *ui; 811 ui_window_t *window; 812 ui_wnd_params_t params; 813 panel_t *panel; 814 gfx_rect_t rect; 815 errno_t rc; 816 817 rc = ui_create_disp(NULL, &ui); 818 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 819 820 ui_wnd_params_init(¶ms); 821 params.caption = "Test"; 822 823 rc = ui_window_create(ui, ¶ms, &window); 824 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 825 826 rc = panel_create(window, &panel); 827 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 828 829 rect.p0.x = 0; 830 rect.p0.y = 0; 831 rect.p1.x = 10; 832 rect.p1.y = 4; // XXX Assuming this makes page size 2 833 panel_set_rect(panel, &rect); 834 835 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel)); 836 837 /* Add five entries (2 full pages, one partial) */ 838 rc = panel_entry_append(panel, "a", 1); 839 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 840 841 rc = panel_entry_append(panel, "b", 2); 842 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 843 844 rc = panel_entry_append(panel, "c", 3); 845 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 846 847 rc = panel_entry_append(panel, "d", 4); 848 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 849 850 rc = panel_entry_append(panel, "e", 5); 851 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 852 853 /* Cursor to the last entry and page start to the next-to-last entry */ 854 panel->cursor = panel_last(panel); 855 panel->cursor_idx = 4; 856 panel->page = panel_prev(panel->cursor); 857 panel->page_idx = 3; 858 859 /* Move one page up */ 860 panel_page_up(panel); 861 862 /* Page should now start at second entry and cursor at third */ 863 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name); 864 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size); 865 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx); 866 PCUT_ASSERT_STR_EQUALS("b", panel->page->name); 867 PCUT_ASSERT_INT_EQUALS(2, panel->page->size); 868 PCUT_ASSERT_INT_EQUALS(1, panel->page_idx); 869 870 /* Move one page up again. */ 871 panel_page_up(panel); 872 873 /* Cursor and page start should now both be at the first entry */ 874 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name); 875 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size); 876 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx); 877 PCUT_ASSERT_EQUALS(panel->cursor, panel->page); 878 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx); 879 880 /* Moving further up should do nothing (we are at the top). */ 881 panel_page_up(panel); 882 883 /* Cursor and page start should still be at the first entry */ 884 PCUT_ASSERT_STR_EQUALS("a", panel->cursor->name); 885 PCUT_ASSERT_INT_EQUALS(1, panel->cursor->size); 886 PCUT_ASSERT_INT_EQUALS(0, panel->cursor_idx); 887 PCUT_ASSERT_EQUALS(panel->cursor, panel->page); 888 PCUT_ASSERT_INT_EQUALS(0, panel->page_idx); 889 890 panel_destroy(panel); 891 ui_window_destroy(window); 892 ui_destroy(ui); 893 } 894 895 /** panel_page_up() moves one page down */ 896 PCUT_TEST(page_down) 897 { 898 ui_t *ui; 899 ui_window_t *window; 900 ui_wnd_params_t params; 901 panel_t *panel; 902 gfx_rect_t rect; 903 errno_t rc; 904 905 rc = ui_create_disp(NULL, &ui); 906 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 907 908 ui_wnd_params_init(¶ms); 909 params.caption = "Test"; 910 911 rc = ui_window_create(ui, ¶ms, &window); 912 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 913 914 rc = panel_create(window, &panel); 915 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 916 917 rect.p0.x = 0; 918 rect.p0.y = 0; 919 rect.p1.x = 10; 920 rect.p1.y = 4; // XXX Assuming this makes page size 2 921 panel_set_rect(panel, &rect); 922 923 PCUT_ASSERT_INT_EQUALS(2, panel_page_size(panel)); 924 925 /* Add five entries (2 full pages, one partial) */ 926 rc = panel_entry_append(panel, "a", 1); 927 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 928 929 rc = panel_entry_append(panel, "b", 2); 930 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 931 932 rc = panel_entry_append(panel, "c", 3); 933 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 934 935 rc = panel_entry_append(panel, "d", 4); 936 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 937 938 rc = panel_entry_append(panel, "e", 5); 939 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 940 941 /* Cursor and page to the first entry */ 942 panel->cursor = panel_first(panel); 943 panel->cursor_idx = 0; 944 panel->page = panel->cursor; 945 panel->page_idx = 0; 946 947 /* Move one page down */ 948 panel_page_down(panel); 949 950 /* Page and cursor should point to the third entry */ 951 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name); 952 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size); 953 PCUT_ASSERT_INT_EQUALS(2, panel->cursor_idx); 954 PCUT_ASSERT_STR_EQUALS("c", panel->page->name); 955 PCUT_ASSERT_INT_EQUALS(3, panel->page->size); 956 PCUT_ASSERT_INT_EQUALS(2, panel->page_idx); 957 958 /* Move one page down again. */ 959 panel_page_down(panel); 960 961 /* Cursor should point to last and page to next-to-last entry */ 962 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name); 963 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size); 964 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx); 965 PCUT_ASSERT_STR_EQUALS("d", panel->page->name); 966 PCUT_ASSERT_INT_EQUALS(4, panel->page->size); 967 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx); 968 969 /* Moving further down should do nothing (we are at the bottom). */ 970 panel_page_down(panel); 971 972 /* Cursor should still point to last and page to next-to-last entry */ 973 PCUT_ASSERT_STR_EQUALS("e", panel->cursor->name); 974 PCUT_ASSERT_INT_EQUALS(5, panel->cursor->size); 975 PCUT_ASSERT_INT_EQUALS(4, panel->cursor_idx); 976 PCUT_ASSERT_STR_EQUALS("d", panel->page->name); 977 PCUT_ASSERT_INT_EQUALS(4, panel->page->size); 978 PCUT_ASSERT_INT_EQUALS(3, panel->page_idx); 979 980 panel_destroy(panel); 981 ui_window_destroy(window); 982 ui_destroy(ui); 983 } 984 772 985 PCUT_EXPORT(panel);
Note:
See TracChangeset
for help on using the changeset viewer.