Changeset 453f9645 in mainline for uspace/lib/ui/test/filelist.c
- Timestamp:
- 2022-06-16T10:05:17Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 54ddb59
- Parents:
- fdf55a3
- git-author:
- Jiri Svoboda <jiri@…> (2022-06-15 17:05:06)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-06-16 10:05:17)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/filelist.c
rfdf55a3 r453f9645 34 34 #include <ui/ui.h> 35 35 #include <ui/filelist.h> 36 #include <ui/scrollbar.h> 36 37 #include <vfs/vfs.h> 37 38 #include "../private/filelist.h" … … 62 63 PCUT_TEST(create_destroy) 63 64 { 64 ui_file_list_t *flist; 65 errno_t rc; 66 67 rc = ui_file_list_create(NULL, true, &flist); 68 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 69 70 ui_file_list_destroy(flist); 65 ui_t *ui; 66 ui_window_t *window; 67 ui_wnd_params_t params; 68 ui_file_list_t *flist; 69 errno_t rc; 70 71 rc = ui_create_disp(NULL, &ui); 72 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 73 74 ui_wnd_params_init(¶ms); 75 params.caption = "Test"; 76 77 rc = ui_window_create(ui, ¶ms, &window); 78 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 79 80 rc = ui_file_list_create(window, true, &flist); 81 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 82 83 ui_file_list_destroy(flist); 84 ui_window_destroy(window); 85 ui_destroy(ui); 71 86 } 72 87 … … 74 89 PCUT_TEST(set_cb) 75 90 { 91 ui_t *ui; 92 ui_window_t *window; 93 ui_wnd_params_t params; 76 94 ui_file_list_t *flist; 77 95 errno_t rc; 78 96 test_resp_t resp; 79 97 80 rc = ui_file_list_create(NULL, true, &flist); 98 rc = ui_create_disp(NULL, &ui); 99 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 100 101 ui_wnd_params_init(¶ms); 102 params.caption = "Test"; 103 104 rc = ui_window_create(ui, ¶ms, &window); 105 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 106 107 rc = ui_file_list_create(window, true, &flist); 81 108 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 82 109 … … 86 113 87 114 ui_file_list_destroy(flist); 115 ui_window_destroy(window); 116 ui_destroy(ui); 88 117 } 89 118 … … 91 120 PCUT_TEST(entry_height) 92 121 { 93 // XXX 122 ui_t *ui; 123 ui_window_t *window; 124 ui_wnd_params_t params; 125 ui_file_list_t *flist; 126 errno_t rc; 127 gfx_coord_t height; 128 129 rc = ui_create_disp(NULL, &ui); 130 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 131 132 ui_wnd_params_init(¶ms); 133 params.caption = "Test"; 134 135 rc = ui_window_create(ui, ¶ms, &window); 136 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 137 138 rc = ui_file_list_create(window, true, &flist); 139 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 140 141 /* Font height is 13, padding: 2 (top) + 2 (bottom) */ 142 height = ui_file_list_entry_height(flist); 143 PCUT_ASSERT_INT_EQUALS(17, height); 144 145 ui_file_list_destroy(flist); 146 ui_window_destroy(window); 147 ui_destroy(ui); 94 148 } 95 149 … … 163 217 PCUT_TEST(ctl) 164 218 { 219 ui_t *ui; 220 ui_window_t *window; 221 ui_wnd_params_t params; 165 222 ui_file_list_t *flist; 166 223 ui_control_t *control; 167 224 errno_t rc; 168 225 169 rc = ui_file_list_create(NULL, true, &flist); 226 rc = ui_create_disp(NULL, &ui); 227 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 228 229 ui_wnd_params_init(¶ms); 230 params.caption = "Test"; 231 232 rc = ui_window_create(ui, ¶ms, &window); 233 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 234 235 rc = ui_file_list_create(window, true, &flist); 170 236 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 237 … … 174 240 175 241 ui_file_list_destroy(flist); 242 ui_window_destroy(window); 243 ui_destroy(ui); 176 244 } 177 245 … … 179 247 PCUT_TEST(kbd_event) 180 248 { 249 ui_t *ui; 250 ui_window_t *window; 251 ui_wnd_params_t params; 181 252 ui_file_list_t *flist; 182 253 ui_evclaim_t claimed; … … 186 257 /* Active file list should claim events */ 187 258 188 rc = ui_file_list_create(NULL, true, &flist); 259 rc = ui_create_disp(NULL, &ui); 260 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 261 262 ui_wnd_params_init(¶ms); 263 params.caption = "Test"; 264 265 rc = ui_window_create(ui, ¶ms, &window); 266 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 267 268 rc = ui_file_list_create(window, true, &flist); 189 269 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 190 270 … … 201 281 /* Inactive file list should not claim events */ 202 282 203 rc = ui_file_list_create(NULL, false, &flist); 283 rc = ui_create_disp(NULL, &ui); 284 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 285 286 ui_wnd_params_init(¶ms); 287 params.caption = "Test"; 288 289 rc = ui_window_create(ui, ¶ms, &window); 290 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 291 292 rc = ui_file_list_create(window, false, &flist); 204 293 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 205 294 … … 213 302 214 303 ui_file_list_destroy(flist); 304 ui_window_destroy(window); 305 ui_destroy(ui); 215 306 } 216 307 … … 242 333 rect.p0.x = 10; 243 334 rect.p0.y = 20; 244 rect.p1.x = 30;335 rect.p1.x = 50; 245 336 rect.p1.y = 220; 246 337 … … 301 392 PCUT_TEST(set_rect) 302 393 { 394 ui_t *ui; 395 ui_window_t *window; 396 ui_wnd_params_t params; 303 397 ui_file_list_t *flist; 304 398 gfx_rect_t rect; 305 399 errno_t rc; 306 400 307 rc = ui_file_list_create(NULL, true, &flist); 401 rc = ui_create_disp(NULL, &ui); 402 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 403 404 ui_wnd_params_init(¶ms); 405 params.caption = "Test"; 406 407 rc = ui_window_create(ui, ¶ms, &window); 408 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 409 410 rc = ui_file_list_create(window, true, &flist); 308 411 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 309 412 … … 320 423 321 424 ui_file_list_destroy(flist); 425 ui_window_destroy(window); 426 ui_destroy(ui); 322 427 } 323 428 … … 346 451 rect.p0.x = 10; 347 452 rect.p0.y = 20; 348 rect.p1.x = 30;453 rect.p1.x = 50; 349 454 rect.p1.y = 220; 350 455 … … 359 464 } 360 465 361 /** ui_file_list_inside_rect() ...*/466 /** ui_file_list_inside_rect() gives correct interior rectangle */ 362 467 PCUT_TEST(inside_rect) 363 468 { 364 // XXX 469 ui_t *ui; 470 ui_window_t *window; 471 ui_wnd_params_t params; 472 ui_file_list_t *flist; 473 gfx_rect_t rect; 474 gfx_rect_t irect; 475 errno_t rc; 476 477 rc = ui_create_disp(NULL, &ui); 478 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 479 480 ui_wnd_params_init(¶ms); 481 params.caption = "Test"; 482 483 rc = ui_window_create(ui, ¶ms, &window); 484 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 485 486 rc = ui_file_list_create(window, true, &flist); 487 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 488 489 rect.p0.x = 10; 490 rect.p0.y = 20; 491 rect.p1.x = 50; 492 rect.p1.y = 220; 493 494 ui_file_list_set_rect(flist, &rect); 495 496 ui_file_list_inside_rect(flist, &irect); 497 PCUT_ASSERT_INT_EQUALS(10 + 2, irect.p0.x); 498 PCUT_ASSERT_INT_EQUALS(20 + 2, irect.p0.y); 499 PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, irect.p1.x); 500 PCUT_ASSERT_INT_EQUALS(220 - 2, irect.p1.y); 501 502 ui_file_list_destroy(flist); 503 ui_window_destroy(window); 504 ui_destroy(ui); 505 } 506 507 /** ui_file_list_scrollbar_rect() gives correct scrollbar rectangle */ 508 PCUT_TEST(scrollbar_rect) 509 { 510 ui_t *ui; 511 ui_window_t *window; 512 ui_wnd_params_t params; 513 ui_file_list_t *flist; 514 gfx_rect_t rect; 515 gfx_rect_t srect; 516 errno_t rc; 517 518 rc = ui_create_disp(NULL, &ui); 519 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 520 521 ui_wnd_params_init(¶ms); 522 params.caption = "Test"; 523 524 rc = ui_window_create(ui, ¶ms, &window); 525 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 526 527 rc = ui_file_list_create(window, true, &flist); 528 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 529 530 rect.p0.x = 10; 531 rect.p0.y = 20; 532 rect.p1.x = 50; 533 rect.p1.y = 220; 534 535 ui_file_list_set_rect(flist, &rect); 536 537 ui_file_list_scrollbar_rect(flist, &srect); 538 PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, srect.p0.x); 539 PCUT_ASSERT_INT_EQUALS(20 + 2, srect.p0.y); 540 PCUT_ASSERT_INT_EQUALS(50 - 2, srect.p1.x); 541 PCUT_ASSERT_INT_EQUALS(220 - 2, srect.p1.y); 542 543 ui_file_list_destroy(flist); 544 ui_window_destroy(window); 545 ui_destroy(ui); 546 } 547 548 /** ui_file_list_scrollbar_update() updates scrollbar position */ 549 PCUT_TEST(scrollbar_update) 550 { 551 ui_t *ui; 552 ui_window_t *window; 553 ui_wnd_params_t params; 554 ui_file_list_t *flist; 555 gfx_rect_t rect; 556 ui_file_list_entry_attr_t attr; 557 ui_file_list_entry_t *entry; 558 gfx_coord_t pos; 559 gfx_coord_t move_len; 560 errno_t rc; 561 562 rc = ui_create_disp(NULL, &ui); 563 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 564 565 ui_wnd_params_init(¶ms); 566 params.caption = "Test"; 567 568 rc = ui_window_create(ui, ¶ms, &window); 569 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 570 571 rc = ui_file_list_create(window, true, &flist); 572 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 573 574 rect.p0.x = 0; 575 rect.p0.y = 0; 576 rect.p1.x = 50; 577 rect.p1.y = 38; 578 579 ui_file_list_set_rect(flist, &rect); 580 581 ui_file_list_entry_attr_init(&attr); 582 attr.name = "a"; 583 attr.size = 1; 584 rc = ui_file_list_entry_append(flist, &attr); 585 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 586 587 attr.name = "b"; 588 attr.size = 2; 589 rc = ui_file_list_entry_append(flist, &attr); 590 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 591 592 attr.name = "c"; 593 attr.size = 3; 594 rc = ui_file_list_entry_append(flist, &attr); 595 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 596 597 entry = ui_file_list_next(ui_file_list_first(flist)); 598 599 flist->cursor = entry; 600 flist->cursor_idx = 1; 601 flist->page = entry; 602 flist->page_idx = 1; 603 604 ui_file_list_scrollbar_update(flist); 605 606 /* Now scrollbar thumb should be all the way down */ 607 move_len = ui_scrollbar_move_length(flist->scrollbar); 608 pos = ui_scrollbar_get_pos(flist->scrollbar); 609 PCUT_ASSERT_INT_EQUALS(move_len, pos); 610 611 ui_file_list_destroy(flist); 612 ui_window_destroy(window); 613 ui_destroy(ui); 365 614 } 366 615 … … 368 617 PCUT_TEST(is_active) 369 618 { 370 ui_file_list_t *flist; 371 errno_t rc; 372 373 rc = ui_file_list_create(NULL, true, &flist); 619 ui_t *ui; 620 ui_window_t *window; 621 ui_wnd_params_t params; 622 ui_file_list_t *flist; 623 errno_t rc; 624 625 rc = ui_create_disp(NULL, &ui); 626 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 627 628 ui_wnd_params_init(¶ms); 629 params.caption = "Test"; 630 631 rc = ui_window_create(ui, ¶ms, &window); 632 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 633 634 rc = ui_file_list_create(window, true, &flist); 374 635 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 375 636 PCUT_ASSERT_TRUE(ui_file_list_is_active(flist)); 376 637 ui_file_list_destroy(flist); 377 638 378 rc = ui_file_list_create( NULL, false, &flist);639 rc = ui_file_list_create(window, false, &flist); 379 640 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 380 641 PCUT_ASSERT_FALSE(ui_file_list_is_active(flist)); 381 642 ui_file_list_destroy(flist); 643 ui_window_destroy(window); 644 ui_destroy(ui); 382 645 } 383 646 … … 446 709 PCUT_TEST(entry_append) 447 710 { 711 ui_t *ui; 712 ui_window_t *window; 713 ui_wnd_params_t params; 448 714 ui_file_list_t *flist; 449 715 ui_file_list_entry_attr_t attr; 450 716 errno_t rc; 451 717 452 rc = ui_file_list_create(NULL, true, &flist); 718 rc = ui_create_disp(NULL, &ui); 719 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 720 721 ui_wnd_params_init(¶ms); 722 params.caption = "Test"; 723 724 rc = ui_window_create(ui, ¶ms, &window); 725 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 726 727 rc = ui_file_list_create(window, true, &flist); 453 728 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 454 729 … … 470 745 471 746 ui_file_list_destroy(flist); 747 ui_window_destroy(window); 748 ui_destroy(ui); 472 749 } 473 750 … … 475 752 PCUT_TEST(entry_delete) 476 753 { 754 ui_t *ui; 755 ui_window_t *window; 756 ui_wnd_params_t params; 477 757 ui_file_list_t *flist; 478 758 ui_file_list_entry_t *entry; … … 480 760 errno_t rc; 481 761 482 rc = ui_file_list_create(NULL, true, &flist); 762 rc = ui_create_disp(NULL, &ui); 763 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 764 765 ui_wnd_params_init(¶ms); 766 params.caption = "Test"; 767 768 rc = ui_window_create(ui, ¶ms, &window); 769 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 770 771 rc = ui_file_list_create(window, true, &flist); 483 772 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 484 773 … … 506 795 507 796 ui_file_list_destroy(flist); 797 ui_window_destroy(window); 798 ui_destroy(ui); 508 799 } 509 800 … … 511 802 PCUT_TEST(clear_entries) 512 803 { 804 ui_t *ui; 805 ui_window_t *window; 806 ui_wnd_params_t params; 513 807 ui_file_list_t *flist; 514 808 ui_file_list_entry_attr_t attr; 515 809 errno_t rc; 516 810 517 rc = ui_file_list_create(NULL, true, &flist); 811 rc = ui_create_disp(NULL, &ui); 812 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 813 814 ui_wnd_params_init(¶ms); 815 params.caption = "Test"; 816 817 rc = ui_window_create(ui, ¶ms, &window); 818 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 819 820 rc = ui_file_list_create(window, true, &flist); 518 821 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 519 822 … … 535 838 536 839 ui_file_list_destroy(flist); 840 ui_window_destroy(window); 841 ui_destroy(ui); 537 842 } 538 843 … … 540 845 PCUT_TEST(read_dir) 541 846 { 847 ui_t *ui; 848 ui_window_t *window; 849 ui_wnd_params_t params; 542 850 ui_file_list_t *flist; 543 851 ui_file_list_entry_t *entry; … … 569 877 PCUT_ASSERT_INT_EQUALS(0, rv); 570 878 571 rc = ui_file_list_create(NULL, true, &flist); 879 rc = ui_create_disp(NULL, &ui); 880 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 881 882 ui_wnd_params_init(¶ms); 883 params.caption = "Test"; 884 885 rc = ui_window_create(ui, ¶ms, &window); 886 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 887 888 rc = ui_file_list_create(window, true, &flist); 572 889 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 573 890 … … 595 912 596 913 free(fname); 914 ui_window_destroy(window); 915 ui_destroy(ui); 597 916 } 598 917 … … 688 1007 PCUT_TEST(sort) 689 1008 { 1009 ui_t *ui; 1010 ui_window_t *window; 1011 ui_wnd_params_t params; 690 1012 ui_file_list_t *flist; 691 1013 ui_file_list_entry_t *entry; … … 693 1015 errno_t rc; 694 1016 695 rc = ui_file_list_create(NULL, true, &flist); 1017 rc = ui_create_disp(NULL, &ui); 1018 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1019 1020 ui_wnd_params_init(¶ms); 1021 params.caption = "Test"; 1022 1023 rc = ui_window_create(ui, ¶ms, &window); 1024 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1025 1026 rc = ui_file_list_create(window, true, &flist); 696 1027 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 697 1028 … … 729 1060 730 1061 ui_file_list_destroy(flist); 1062 ui_window_destroy(window); 1063 ui_destroy(ui); 731 1064 } 732 1065 … … 734 1067 PCUT_TEST(entry_ptr_cmp) 735 1068 { 1069 ui_t *ui; 1070 ui_window_t *window; 1071 ui_wnd_params_t params; 736 1072 ui_file_list_t *flist; 737 1073 ui_file_list_entry_t *a, *b; … … 740 1076 errno_t rc; 741 1077 742 rc = ui_file_list_create(NULL, true, &flist); 1078 rc = ui_create_disp(NULL, &ui); 1079 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1080 1081 ui_wnd_params_init(¶ms); 1082 params.caption = "Test"; 1083 1084 rc = ui_window_create(ui, ¶ms, &window); 1085 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1086 1087 rc = ui_file_list_create(window, true, &flist); 743 1088 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 744 1089 … … 773 1118 774 1119 ui_file_list_destroy(flist); 1120 ui_window_destroy(window); 1121 ui_destroy(ui); 775 1122 } 776 1123 … … 778 1125 PCUT_TEST(first) 779 1126 { 1127 ui_t *ui; 1128 ui_window_t *window; 1129 ui_wnd_params_t params; 780 1130 ui_file_list_t *flist; 781 1131 ui_file_list_entry_t *entry; … … 783 1133 errno_t rc; 784 1134 785 rc = ui_file_list_create(NULL, true, &flist); 1135 rc = ui_create_disp(NULL, &ui); 1136 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1137 1138 ui_wnd_params_init(¶ms); 1139 params.caption = "Test"; 1140 1141 rc = ui_window_create(ui, ¶ms, &window); 1142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1143 1144 rc = ui_file_list_create(window, true, &flist); 786 1145 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 787 1146 … … 816 1175 817 1176 ui_file_list_destroy(flist); 1177 ui_window_destroy(window); 1178 ui_destroy(ui); 818 1179 } 819 1180 … … 821 1182 PCUT_TEST(last) 822 1183 { 1184 ui_t *ui; 1185 ui_window_t *window; 1186 ui_wnd_params_t params; 823 1187 ui_file_list_t *flist; 824 1188 ui_file_list_entry_t *entry; … … 826 1190 errno_t rc; 827 1191 828 rc = ui_file_list_create(NULL, true, &flist); 1192 rc = ui_create_disp(NULL, &ui); 1193 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1194 1195 ui_wnd_params_init(¶ms); 1196 params.caption = "Test"; 1197 1198 rc = ui_window_create(ui, ¶ms, &window); 1199 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1200 1201 rc = ui_file_list_create(window, true, &flist); 829 1202 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 830 1203 … … 861 1234 862 1235 ui_file_list_destroy(flist); 1236 ui_window_destroy(window); 1237 ui_destroy(ui); 863 1238 } 864 1239 … … 866 1241 PCUT_TEST(next) 867 1242 { 1243 ui_t *ui; 1244 ui_window_t *window; 1245 ui_wnd_params_t params; 868 1246 ui_file_list_t *flist; 869 1247 ui_file_list_entry_t *entry; … … 871 1249 errno_t rc; 872 1250 873 rc = ui_file_list_create(NULL, true, &flist); 1251 rc = ui_create_disp(NULL, &ui); 1252 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1253 1254 ui_wnd_params_init(¶ms); 1255 params.caption = "Test"; 1256 1257 rc = ui_window_create(ui, ¶ms, &window); 1258 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1259 1260 rc = ui_file_list_create(window, true, &flist); 874 1261 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 875 1262 … … 905 1292 906 1293 ui_file_list_destroy(flist); 1294 ui_window_destroy(window); 1295 ui_destroy(ui); 907 1296 } 908 1297 … … 910 1299 PCUT_TEST(prev) 911 1300 { 1301 ui_t *ui; 1302 ui_window_t *window; 1303 ui_wnd_params_t params; 912 1304 ui_file_list_t *flist; 913 1305 ui_file_list_entry_t *entry; … … 915 1307 errno_t rc; 916 1308 917 rc = ui_file_list_create(NULL, true, &flist); 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 = ui_file_list_create(window, true, &flist); 918 1319 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 919 1320 … … 949 1350 950 1351 ui_file_list_destroy(flist); 1352 ui_window_destroy(window); 1353 ui_destroy(ui); 951 1354 } 952 1355 … … 1021 1424 } 1022 1425 1023 /** ui_file_list_cursor_move() ...*/1426 /** ui_file_list_cursor_move() moves cursor and scrolls */ 1024 1427 PCUT_TEST(cursor_move) 1025 1428 { 1429 ui_t *ui; 1430 ui_window_t *window; 1431 ui_wnd_params_t params; 1432 ui_file_list_t *flist; 1433 ui_file_list_entry_attr_t attr; 1434 gfx_rect_t rect; 1435 errno_t rc; 1436 rc = ui_create_disp(NULL, &ui); 1437 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1438 1439 ui_wnd_params_init(¶ms); 1440 params.caption = "Test"; 1441 1442 rc = ui_window_create(ui, ¶ms, &window); 1443 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1444 1445 rc = ui_file_list_create(window, true, &flist); 1446 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1447 1448 rect.p0.x = 0; 1449 rect.p0.y = 0; 1450 rect.p1.x = 10; 1451 rect.p1.y = 38; /* Assuming this makes page size 2 */ 1452 ui_file_list_set_rect(flist, &rect); 1453 1454 PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist)); 1455 1456 /* Add tree entries (more than page size, which is 2) */ 1457 1458 ui_file_list_entry_attr_init(&attr); 1459 1460 attr.name = "a"; 1461 attr.size = 1; 1462 rc = ui_file_list_entry_append(flist, &attr); 1463 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1464 1465 attr.name = "b"; 1466 attr.size = 2; 1467 rc = ui_file_list_entry_append(flist, &attr); 1468 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1469 1470 attr.name = "c"; 1471 attr.size = 3; 1472 rc = ui_file_list_entry_append(flist, &attr); 1473 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1474 1475 /* Cursor to the last entry and page start to the next-to-last entry */ 1476 flist->cursor = ui_file_list_last(flist); 1477 flist->cursor_idx = 2; 1478 flist->page = ui_file_list_prev(flist->cursor); 1479 flist->page_idx = 1; 1480 1481 /* Move cursor one entry up */ 1482 ui_file_list_cursor_move(flist, ui_file_list_prev(flist->cursor), 1483 flist->cursor_idx - 1); 1484 1485 /* Cursor and page start should now both be at the second entry */ 1486 PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name); 1487 PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size); 1488 PCUT_ASSERT_INT_EQUALS(1, flist->cursor_idx); 1489 PCUT_ASSERT_EQUALS(flist->cursor, flist->page); 1490 PCUT_ASSERT_INT_EQUALS(1, flist->page_idx); 1491 1492 /* Move cursor to the first entry. This should scroll up. */ 1493 ui_file_list_cursor_move(flist, ui_file_list_first(flist), 0); 1494 1495 /* Cursor and page start should now both be at the first entry */ 1496 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 1497 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 1498 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 1499 PCUT_ASSERT_EQUALS(flist->cursor, flist->page); 1500 PCUT_ASSERT_INT_EQUALS(0, flist->page_idx); 1501 1502 /* Move cursor to the last entry. */ 1503 ui_file_list_cursor_move(flist, ui_file_list_last(flist), 2); 1504 1505 /* Cursor should be on the last entry and page on the next to last */ 1506 PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name); 1507 PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size); 1508 PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx); 1509 PCUT_ASSERT_STR_EQUALS("b", flist->page->name); 1510 PCUT_ASSERT_INT_EQUALS(2, flist->page->size); 1511 PCUT_ASSERT_INT_EQUALS(1, flist->page_idx); 1512 1513 ui_file_list_destroy(flist); 1514 ui_window_destroy(window); 1515 ui_destroy(ui); 1026 1516 } 1027 1517 … … 1036 1526 gfx_rect_t rect; 1037 1527 errno_t rc; 1038 1039 1528 rc = ui_create_disp(NULL, &ui); 1040 1529 PCUT_ASSERT_ERRNO_VAL(EOK, rc); … … 1559 2048 } 1560 2049 1561 /** ui_file_list_open() opens a directory entry */ 1562 PCUT_TEST(open) 2050 /** ui_file_list_scroll_up() scrolls up by one row */ 2051 PCUT_TEST(scroll_up) 2052 { 2053 ui_t *ui; 2054 ui_window_t *window; 2055 ui_wnd_params_t params; 2056 ui_file_list_t *flist; 2057 ui_file_list_entry_attr_t attr; 2058 gfx_rect_t rect; 2059 errno_t rc; 2060 2061 rc = ui_create_disp(NULL, &ui); 2062 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2063 2064 ui_wnd_params_init(¶ms); 2065 params.caption = "Test"; 2066 2067 rc = ui_window_create(ui, ¶ms, &window); 2068 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2069 2070 rc = ui_file_list_create(window, true, &flist); 2071 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2072 2073 rect.p0.x = 0; 2074 rect.p0.y = 0; 2075 rect.p1.x = 10; 2076 rect.p1.y = 38; /* Assuming this makes page size 2 */ 2077 ui_file_list_set_rect(flist, &rect); 2078 2079 PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist)); 2080 2081 /* Add tree entries (more than page size, which is 2) */ 2082 2083 ui_file_list_entry_attr_init(&attr); 2084 2085 attr.name = "a"; 2086 attr.size = 1; 2087 rc = ui_file_list_entry_append(flist, &attr); 2088 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2089 2090 attr.name = "b"; 2091 attr.size = 2; 2092 rc = ui_file_list_entry_append(flist, &attr); 2093 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2094 2095 attr.name = "c"; 2096 attr.size = 3; 2097 rc = ui_file_list_entry_append(flist, &attr); 2098 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2099 2100 /* Cursor to the last entry, page to the second */ 2101 flist->cursor = ui_file_list_last(flist); 2102 flist->cursor_idx = 2; 2103 flist->page = ui_file_list_prev(flist->cursor); 2104 flist->page_idx = 1; 2105 2106 /* Scroll one entry up */ 2107 ui_file_list_scroll_up(flist); 2108 2109 /* Page should start on the first entry, cursor unchanged */ 2110 PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name); 2111 PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size); 2112 PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx); 2113 PCUT_ASSERT_STR_EQUALS("a", flist->page->name); 2114 PCUT_ASSERT_INT_EQUALS(1, flist->page->size); 2115 PCUT_ASSERT_INT_EQUALS(0, flist->page_idx); 2116 2117 /* Try scrolling one more entry up */ 2118 ui_file_list_scroll_up(flist); 2119 2120 /* We were at the beginning, so nothing should have changed */ 2121 PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name); 2122 PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size); 2123 PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx); 2124 PCUT_ASSERT_STR_EQUALS("a", flist->page->name); 2125 PCUT_ASSERT_INT_EQUALS(1, flist->page->size); 2126 PCUT_ASSERT_INT_EQUALS(0, flist->page_idx); 2127 2128 ui_file_list_destroy(flist); 2129 ui_window_destroy(window); 2130 ui_destroy(ui); 2131 } 2132 2133 /** ui_file_list_scroll_down() scrolls down by one row */ 2134 PCUT_TEST(scroll_down) 2135 { 2136 ui_t *ui; 2137 ui_window_t *window; 2138 ui_wnd_params_t params; 2139 ui_file_list_t *flist; 2140 ui_file_list_entry_attr_t attr; 2141 gfx_rect_t rect; 2142 errno_t rc; 2143 2144 rc = ui_create_disp(NULL, &ui); 2145 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2146 2147 ui_wnd_params_init(¶ms); 2148 params.caption = "Test"; 2149 2150 rc = ui_window_create(ui, ¶ms, &window); 2151 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2152 2153 rc = ui_file_list_create(window, true, &flist); 2154 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2155 2156 rect.p0.x = 0; 2157 rect.p0.y = 0; 2158 rect.p1.x = 10; 2159 rect.p1.y = 38; /* Assuming this makes page size 2 */ 2160 ui_file_list_set_rect(flist, &rect); 2161 2162 PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist)); 2163 2164 /* Add tree entries (more than page size, which is 2) */ 2165 2166 ui_file_list_entry_attr_init(&attr); 2167 2168 attr.name = "a"; 2169 attr.size = 1; 2170 rc = ui_file_list_entry_append(flist, &attr); 2171 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2172 2173 attr.name = "b"; 2174 attr.size = 2; 2175 rc = ui_file_list_entry_append(flist, &attr); 2176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2177 2178 attr.name = "c"; 2179 attr.size = 3; 2180 rc = ui_file_list_entry_append(flist, &attr); 2181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2182 2183 /* Cursor and page start to the first entry */ 2184 flist->cursor = ui_file_list_first(flist); 2185 flist->cursor_idx = 0; 2186 flist->page = flist->cursor; 2187 flist->page_idx = 0; 2188 2189 /* Scroll one entry down */ 2190 ui_file_list_scroll_down(flist); 2191 2192 /* Page should start on the second entry, cursor unchanged */ 2193 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 2194 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 2195 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 2196 PCUT_ASSERT_STR_EQUALS("b", flist->page->name); 2197 PCUT_ASSERT_INT_EQUALS(2, flist->page->size); 2198 PCUT_ASSERT_INT_EQUALS(1, flist->page_idx); 2199 2200 /* Try scrolling one more entry down */ 2201 ui_file_list_scroll_down(flist); 2202 2203 /* We were at the end, so nothing should have changed */ 2204 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 2205 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 2206 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 2207 PCUT_ASSERT_STR_EQUALS("b", flist->page->name); 2208 PCUT_ASSERT_INT_EQUALS(2, flist->page->size); 2209 PCUT_ASSERT_INT_EQUALS(1, flist->page_idx); 2210 2211 ui_file_list_destroy(flist); 2212 ui_window_destroy(window); 2213 ui_destroy(ui); 2214 } 2215 2216 /** ui_file_list_scroll_page_up() scrolls up by one page */ 2217 PCUT_TEST(scroll_page_up) 2218 { 2219 ui_t *ui; 2220 ui_window_t *window; 2221 ui_wnd_params_t params; 2222 ui_file_list_t *flist; 2223 ui_file_list_entry_attr_t attr; 2224 gfx_rect_t rect; 2225 errno_t rc; 2226 2227 rc = ui_create_disp(NULL, &ui); 2228 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2229 2230 ui_wnd_params_init(¶ms); 2231 params.caption = "Test"; 2232 2233 rc = ui_window_create(ui, ¶ms, &window); 2234 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2235 2236 rc = ui_file_list_create(window, true, &flist); 2237 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2238 2239 rect.p0.x = 0; 2240 rect.p0.y = 0; 2241 rect.p1.x = 10; 2242 rect.p1.y = 38; /* Assuming this makes page size 2 */ 2243 ui_file_list_set_rect(flist, &rect); 2244 2245 PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist)); 2246 2247 /* Add five entries (more than twice the page size, which is 2) */ 2248 2249 ui_file_list_entry_attr_init(&attr); 2250 2251 attr.name = "a"; 2252 attr.size = 1; 2253 rc = ui_file_list_entry_append(flist, &attr); 2254 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2255 2256 attr.name = "b"; 2257 attr.size = 2; 2258 rc = ui_file_list_entry_append(flist, &attr); 2259 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2260 2261 attr.name = "c"; 2262 attr.size = 3; 2263 rc = ui_file_list_entry_append(flist, &attr); 2264 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2265 2266 attr.name = "d"; 2267 attr.size = 4; 2268 rc = ui_file_list_entry_append(flist, &attr); 2269 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2270 2271 attr.name = "e"; 2272 attr.size = 5; 2273 rc = ui_file_list_entry_append(flist, &attr); 2274 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2275 2276 /* Cursor to the last entry, page to the second last */ 2277 flist->cursor = ui_file_list_last(flist); 2278 flist->cursor_idx = 4; 2279 flist->page = ui_file_list_prev(flist->cursor); 2280 flist->page_idx = 3; 2281 2282 /* Scroll one page up */ 2283 ui_file_list_scroll_page_up(flist); 2284 2285 /* Page should start on 'b', cursor unchanged */ 2286 PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name); 2287 PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size); 2288 PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx); 2289 PCUT_ASSERT_STR_EQUALS("b", flist->page->name); 2290 PCUT_ASSERT_INT_EQUALS(2, flist->page->size); 2291 PCUT_ASSERT_INT_EQUALS(1, flist->page_idx); 2292 2293 /* Page up again */ 2294 ui_file_list_scroll_page_up(flist); 2295 2296 /* Page should now be at the beginning, cursor unchanged */ 2297 PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name); 2298 PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size); 2299 PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx); 2300 PCUT_ASSERT_STR_EQUALS("a", flist->page->name); 2301 PCUT_ASSERT_INT_EQUALS(1, flist->page->size); 2302 PCUT_ASSERT_INT_EQUALS(0, flist->page_idx); 2303 2304 /* Page up again */ 2305 ui_file_list_scroll_page_up(flist); 2306 2307 /* We were at the beginning, nothing should have changed */ 2308 PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name); 2309 PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size); 2310 PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx); 2311 PCUT_ASSERT_STR_EQUALS("a", flist->page->name); 2312 PCUT_ASSERT_INT_EQUALS(1, flist->page->size); 2313 PCUT_ASSERT_INT_EQUALS(0, flist->page_idx); 2314 2315 ui_file_list_destroy(flist); 2316 ui_window_destroy(window); 2317 ui_destroy(ui); 2318 } 2319 2320 /** ui_file_list_scroll_page_up() scrolls down by one page */ 2321 PCUT_TEST(scroll_page_down) 2322 { 2323 ui_t *ui; 2324 ui_window_t *window; 2325 ui_wnd_params_t params; 2326 ui_file_list_t *flist; 2327 ui_file_list_entry_attr_t attr; 2328 gfx_rect_t rect; 2329 errno_t rc; 2330 2331 rc = ui_create_disp(NULL, &ui); 2332 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2333 2334 ui_wnd_params_init(¶ms); 2335 params.caption = "Test"; 2336 2337 rc = ui_window_create(ui, ¶ms, &window); 2338 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2339 2340 rc = ui_file_list_create(window, true, &flist); 2341 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2342 2343 rect.p0.x = 0; 2344 rect.p0.y = 0; 2345 rect.p1.x = 10; 2346 rect.p1.y = 38; /* Assuming this makes page size 2 */ 2347 ui_file_list_set_rect(flist, &rect); 2348 2349 PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist)); 2350 2351 /* Add five entries (more than twice the page size, which is 2) */ 2352 2353 ui_file_list_entry_attr_init(&attr); 2354 2355 attr.name = "a"; 2356 attr.size = 1; 2357 rc = ui_file_list_entry_append(flist, &attr); 2358 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2359 2360 attr.name = "b"; 2361 attr.size = 2; 2362 rc = ui_file_list_entry_append(flist, &attr); 2363 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2364 2365 attr.name = "c"; 2366 attr.size = 3; 2367 rc = ui_file_list_entry_append(flist, &attr); 2368 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2369 2370 attr.name = "d"; 2371 attr.size = 4; 2372 rc = ui_file_list_entry_append(flist, &attr); 2373 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2374 2375 attr.name = "e"; 2376 attr.size = 5; 2377 rc = ui_file_list_entry_append(flist, &attr); 2378 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2379 2380 /* Cursor and page to the first entry */ 2381 flist->cursor = ui_file_list_first(flist); 2382 flist->cursor_idx = 0; 2383 flist->page = ui_file_list_first(flist); 2384 flist->page_idx = 0; 2385 2386 /* Scroll one page down */ 2387 ui_file_list_scroll_page_down(flist); 2388 2389 /* Page should start on 'c', cursor unchanged */ 2390 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 2391 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 2392 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 2393 PCUT_ASSERT_STR_EQUALS("c", flist->page->name); 2394 PCUT_ASSERT_INT_EQUALS(3, flist->page->size); 2395 PCUT_ASSERT_INT_EQUALS(2, flist->page_idx); 2396 2397 /* Page down again */ 2398 ui_file_list_scroll_page_down(flist); 2399 2400 /* Page should now start at 'd', cursor unchanged */ 2401 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 2402 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 2403 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 2404 PCUT_ASSERT_STR_EQUALS("d", flist->page->name); 2405 PCUT_ASSERT_INT_EQUALS(4, flist->page->size); 2406 PCUT_ASSERT_INT_EQUALS(3, flist->page_idx); 2407 2408 /* Page down again */ 2409 ui_file_list_scroll_page_down(flist); 2410 2411 /* We were at the end, nothing should have changed */ 2412 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 2413 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 2414 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 2415 PCUT_ASSERT_STR_EQUALS("d", flist->page->name); 2416 PCUT_ASSERT_INT_EQUALS(4, flist->page->size); 2417 PCUT_ASSERT_INT_EQUALS(3, flist->page_idx); 2418 2419 ui_file_list_destroy(flist); 2420 ui_window_destroy(window); 2421 ui_destroy(ui); 2422 } 2423 2424 PCUT_TEST(scroll_pos) 2425 { 2426 ui_t *ui; 2427 ui_window_t *window; 2428 ui_wnd_params_t params; 2429 ui_file_list_t *flist; 2430 ui_file_list_entry_attr_t attr; 2431 gfx_rect_t rect; 2432 errno_t rc; 2433 2434 rc = ui_create_disp(NULL, &ui); 2435 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2436 2437 ui_wnd_params_init(¶ms); 2438 params.caption = "Test"; 2439 2440 rc = ui_window_create(ui, ¶ms, &window); 2441 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2442 2443 rc = ui_file_list_create(window, true, &flist); 2444 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2445 2446 rect.p0.x = 0; 2447 rect.p0.y = 0; 2448 rect.p1.x = 10; 2449 rect.p1.y = 38; /* Assuming this makes page size 2 */ 2450 ui_file_list_set_rect(flist, &rect); 2451 2452 PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist)); 2453 2454 /* Add five entries (more than twice the page size, which is 2) */ 2455 2456 ui_file_list_entry_attr_init(&attr); 2457 2458 attr.name = "a"; 2459 attr.size = 1; 2460 rc = ui_file_list_entry_append(flist, &attr); 2461 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2462 2463 attr.name = "b"; 2464 attr.size = 2; 2465 rc = ui_file_list_entry_append(flist, &attr); 2466 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2467 2468 attr.name = "c"; 2469 attr.size = 3; 2470 rc = ui_file_list_entry_append(flist, &attr); 2471 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2472 2473 attr.name = "d"; 2474 attr.size = 4; 2475 rc = ui_file_list_entry_append(flist, &attr); 2476 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2477 2478 attr.name = "e"; 2479 attr.size = 5; 2480 rc = ui_file_list_entry_append(flist, &attr); 2481 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2482 2483 /* Cursor and page to the first entry */ 2484 flist->cursor = ui_file_list_first(flist); 2485 flist->cursor_idx = 0; 2486 flist->page = ui_file_list_first(flist); 2487 flist->page_idx = 0; 2488 2489 /* Scroll to entry 1 (one down) */ 2490 ui_file_list_scroll_pos(flist, 1); 2491 2492 /* Page should start on 'b', cursor unchanged */ 2493 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 2494 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 2495 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 2496 PCUT_ASSERT_STR_EQUALS("b", flist->page->name); 2497 PCUT_ASSERT_INT_EQUALS(2, flist->page->size); 2498 PCUT_ASSERT_INT_EQUALS(1, flist->page_idx); 2499 2500 /* Scroll to entry 3 (i.e. the end) */ 2501 ui_file_list_scroll_pos(flist, 3); 2502 2503 /* Page should now start at 'd', cursor unchanged */ 2504 PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name); 2505 PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size); 2506 PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx); 2507 PCUT_ASSERT_STR_EQUALS("d", flist->page->name); 2508 PCUT_ASSERT_INT_EQUALS(4, flist->page->size); 2509 PCUT_ASSERT_INT_EQUALS(3, flist->page_idx); 2510 2511 ui_file_list_destroy(flist); 2512 ui_window_destroy(window); 2513 ui_destroy(ui); 2514 } 2515 2516 /** ui_file_list_open_dir() opens a directory entry */ 2517 PCUT_TEST(open_dir) 1563 2518 { 1564 2519 ui_t *ui; … … 1615 2570 PCUT_ASSERT_TRUE(entry->isdir); 1616 2571 1617 rc = ui_file_list_open (flist, entry);2572 rc = ui_file_list_open_dir(flist, entry); 1618 2573 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1619 2574 … … 1633 2588 } 1634 2589 1635 PCUT_TEST(open_dir) 1636 { 1637 } 1638 2590 /** ui_file_list_open_file() runs selected callback */ 1639 2591 PCUT_TEST(open_file) 1640 2592 { 2593 ui_t *ui; 2594 ui_window_t *window; 2595 ui_wnd_params_t params; 2596 ui_file_list_t *flist; 2597 ui_file_list_entry_attr_t attr; 2598 errno_t rc; 2599 test_resp_t resp; 2600 2601 rc = ui_create_disp(NULL, &ui); 2602 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2603 2604 ui_wnd_params_init(¶ms); 2605 params.caption = "Test"; 2606 2607 rc = ui_window_create(ui, ¶ms, &window); 2608 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2609 2610 rc = ui_file_list_create(window, true, &flist); 2611 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2612 2613 ui_file_list_set_cb(flist, &test_cb, &resp); 2614 2615 attr.name = "hello.txt"; 2616 attr.size = 1; 2617 rc = ui_file_list_entry_append(flist, &attr); 2618 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2619 2620 resp.selected = false; 2621 resp.selected_file_list = NULL; 2622 resp.selected_fname = NULL; 2623 2624 ui_file_list_open_file(flist, ui_file_list_first(flist)); 2625 PCUT_ASSERT_TRUE(resp.selected); 2626 PCUT_ASSERT_EQUALS(flist, resp.selected_file_list); 2627 PCUT_ASSERT_STR_EQUALS("hello.txt", resp.selected_fname); 2628 2629 ui_file_list_destroy(flist); 2630 ui_window_destroy(window); 2631 ui_destroy(ui); 1641 2632 } 1642 2633 … … 1644 2635 PCUT_TEST(activate_req) 1645 2636 { 2637 ui_t *ui; 2638 ui_window_t *window; 2639 ui_wnd_params_t params; 1646 2640 ui_file_list_t *flist; 1647 2641 errno_t rc; 1648 2642 test_resp_t resp; 1649 2643 1650 rc = ui_file_list_create(NULL, true, &flist); 2644 rc = ui_create_disp(NULL, &ui); 2645 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2646 2647 ui_wnd_params_init(¶ms); 2648 params.caption = "Test"; 2649 2650 rc = ui_window_create(ui, ¶ms, &window); 2651 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2652 2653 rc = ui_file_list_create(window, true, &flist); 1651 2654 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1652 2655 … … 1661 2664 1662 2665 ui_file_list_destroy(flist); 2666 ui_window_destroy(window); 2667 ui_destroy(ui); 1663 2668 } 1664 2669 … … 1666 2671 PCUT_TEST(selected) 1667 2672 { 2673 ui_t *ui; 2674 ui_window_t *window; 2675 ui_wnd_params_t params; 1668 2676 ui_file_list_t *flist; 1669 2677 errno_t rc; 1670 2678 test_resp_t resp; 1671 2679 1672 rc = ui_file_list_create(NULL, true, &flist); 2680 rc = ui_create_disp(NULL, &ui); 2681 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2682 2683 ui_wnd_params_init(¶ms); 2684 params.caption = "Test"; 2685 2686 rc = ui_window_create(ui, ¶ms, &window); 2687 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 2688 2689 rc = ui_file_list_create(window, true, &flist); 1673 2690 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1674 2691 … … 1685 2702 1686 2703 ui_file_list_destroy(flist); 2704 ui_window_destroy(window); 2705 ui_destroy(ui); 1687 2706 } 1688 2707
Note:
See TracChangeset
for help on using the changeset viewer.