Changeset 8a9a41e in mainline for uspace/lib/ui/test/entry.c
- Timestamp:
- 2021-10-24T08:28:43Z (2 years ago)
- Children:
- f628215
- Parents:
- 2ce943a (diff), cd981f2a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Erik Kučák <35500848+Riko196@…> (2021-10-24 08:28:43)
- git-committer:
- GitHub <noreply@…> (2021-10-24 08:28:43)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/entry.c
r2ce943a r8a9a41e 27 27 */ 28 28 29 #include <clipboard.h> 29 30 #include <gfx/context.h> 30 31 #include <gfx/coord.h> … … 119 120 } 120 121 122 /** Set entry read only flag sets internal field */ 123 PCUT_TEST(set_read_only) 124 { 125 ui_entry_t *entry; 126 errno_t rc; 127 128 rc = ui_entry_create(NULL, "Hello", &entry); 129 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 130 131 ui_entry_set_read_only(entry, true); 132 PCUT_ASSERT_TRUE(entry->read_only); 133 ui_entry_set_read_only(entry, false); 134 PCUT_ASSERT_FALSE(entry->read_only); 135 136 ui_entry_destroy(entry); 137 } 138 121 139 /** Set text entry rectangle sets internal field */ 122 140 PCUT_TEST(set_text) … … 173 191 } 174 192 193 /** ui_entry_delete_sel() deletes selected text */ 194 PCUT_TEST(delete_sel) 195 { 196 errno_t rc; 197 ui_t *ui = NULL; 198 ui_window_t *window = NULL; 199 ui_wnd_params_t params; 200 ui_entry_t *entry; 201 202 rc = ui_create_disp(NULL, &ui); 203 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 204 205 ui_wnd_params_init(¶ms); 206 params.caption = "Hello"; 207 208 rc = ui_window_create(ui, ¶ms, &window); 209 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 210 PCUT_ASSERT_NOT_NULL(window); 211 212 rc = ui_entry_create(window, "ABCDEF", &entry); 213 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 214 215 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text); 216 217 ui_entry_activate(entry); 218 219 /* Select all but first and last character */ 220 ui_entry_seek_start(entry, false); 221 ui_entry_seek_next_char(entry, false); 222 ui_entry_seek_end(entry, true); 223 ui_entry_seek_prev_char(entry, true); 224 225 ui_entry_delete_sel(entry); 226 227 PCUT_ASSERT_STR_EQUALS("AF", entry->text); 228 229 ui_entry_destroy(entry); 230 ui_window_destroy(window); 231 ui_destroy(ui); 232 } 233 234 /** ui_entry_insert_str() inserts string at cursor. */ 235 PCUT_TEST(insert_str) 236 { 237 errno_t rc; 238 ui_t *ui = NULL; 239 ui_window_t *window = NULL; 240 ui_wnd_params_t params; 241 ui_entry_t *entry; 242 243 rc = ui_create_disp(NULL, &ui); 244 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 245 246 ui_wnd_params_init(¶ms); 247 params.caption = "Hello"; 248 249 rc = ui_window_create(ui, ¶ms, &window); 250 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 251 PCUT_ASSERT_NOT_NULL(window); 252 253 rc = ui_entry_create(window, "A", &entry); 254 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 255 256 PCUT_ASSERT_STR_EQUALS("A", entry->text); 257 258 ui_entry_activate(entry); 259 ui_entry_seek_end(entry, false); 260 261 rc = ui_entry_insert_str(entry, "B"); 262 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 263 264 PCUT_ASSERT_STR_EQUALS("AB", entry->text); 265 266 rc = ui_entry_insert_str(entry, "EF"); 267 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 268 269 PCUT_ASSERT_STR_EQUALS("ABEF", entry->text); 270 271 entry->pos = 2; 272 entry->sel_start = 2; 273 rc = ui_entry_insert_str(entry, "CD"); 274 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 275 276 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text); 277 278 ui_entry_destroy(entry); 279 ui_window_destroy(window); 280 ui_destroy(ui); 281 } 282 283 /** ui_entry_insert_str() deletes selection before inserting string */ 284 PCUT_TEST(insert_str_with_sel) 285 { 286 errno_t rc; 287 ui_t *ui = NULL; 288 ui_window_t *window = NULL; 289 ui_wnd_params_t params; 290 ui_entry_t *entry; 291 292 rc = ui_create_disp(NULL, &ui); 293 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 294 295 ui_wnd_params_init(¶ms); 296 params.caption = "Hello"; 297 298 rc = ui_window_create(ui, ¶ms, &window); 299 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 300 PCUT_ASSERT_NOT_NULL(window); 301 302 rc = ui_entry_create(window, "ABCDE", &entry); 303 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 304 305 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text); 306 307 /* Select all but the first and last character */ 308 ui_entry_activate(entry); 309 ui_entry_seek_start(entry, false); 310 ui_entry_seek_next_char(entry, false); 311 ui_entry_seek_end(entry, true); 312 ui_entry_seek_prev_char(entry, true); 313 314 rc = ui_entry_insert_str(entry, "123"); 315 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 316 317 PCUT_ASSERT_STR_EQUALS("A123E", entry->text); 318 319 ui_entry_destroy(entry); 320 ui_window_destroy(window); 321 ui_destroy(ui); 322 } 323 324 /** ui_entry_backspace() deletes character before cursor. */ 325 PCUT_TEST(backspace) 326 { 327 errno_t rc; 328 ui_t *ui = NULL; 329 ui_window_t *window = NULL; 330 ui_wnd_params_t params; 331 ui_entry_t *entry; 332 333 rc = ui_create_disp(NULL, &ui); 334 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 335 336 ui_wnd_params_init(¶ms); 337 params.caption = "Hello"; 338 339 rc = ui_window_create(ui, ¶ms, &window); 340 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 341 PCUT_ASSERT_NOT_NULL(window); 342 343 rc = ui_entry_create(window, "ABCD", &entry); 344 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 345 346 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 347 entry->pos = 3; 348 entry->sel_start = 3; 349 350 ui_entry_backspace(entry); 351 PCUT_ASSERT_STR_EQUALS("ABD", entry->text); 352 353 ui_entry_backspace(entry); 354 PCUT_ASSERT_STR_EQUALS("AD", entry->text); 355 356 ui_entry_backspace(entry); 357 PCUT_ASSERT_STR_EQUALS("D", entry->text); 358 359 ui_entry_backspace(entry); 360 PCUT_ASSERT_STR_EQUALS("D", entry->text); 361 362 ui_entry_destroy(entry); 363 ui_window_destroy(window); 364 ui_destroy(ui); 365 } 366 367 /** ui_entry_backspace() with selected text deletes selection. */ 368 PCUT_TEST(backspace_with_sel) 369 { 370 errno_t rc; 371 ui_t *ui = NULL; 372 ui_window_t *window = NULL; 373 ui_wnd_params_t params; 374 ui_entry_t *entry; 375 376 rc = ui_create_disp(NULL, &ui); 377 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 378 379 ui_wnd_params_init(¶ms); 380 params.caption = "Hello"; 381 382 rc = ui_window_create(ui, ¶ms, &window); 383 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 384 PCUT_ASSERT_NOT_NULL(window); 385 386 rc = ui_entry_create(window, "ABCDE", &entry); 387 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 388 389 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text); 390 391 /* Select all but the first and last character */ 392 ui_entry_activate(entry); 393 ui_entry_seek_start(entry, false); 394 ui_entry_seek_next_char(entry, false); 395 ui_entry_seek_end(entry, true); 396 ui_entry_seek_prev_char(entry, true); 397 398 ui_entry_backspace(entry); 399 400 PCUT_ASSERT_STR_EQUALS("AE", entry->text); 401 402 ui_entry_destroy(entry); 403 ui_window_destroy(window); 404 ui_destroy(ui); 405 } 406 407 /** ui_entry_delete() deletes character after cursor. */ 408 PCUT_TEST(delete) 409 { 410 errno_t rc; 411 ui_t *ui = NULL; 412 ui_window_t *window = NULL; 413 ui_wnd_params_t params; 414 ui_entry_t *entry; 415 416 rc = ui_create_disp(NULL, &ui); 417 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 418 419 ui_wnd_params_init(¶ms); 420 params.caption = "Hello"; 421 422 rc = ui_window_create(ui, ¶ms, &window); 423 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 424 PCUT_ASSERT_NOT_NULL(window); 425 426 rc = ui_entry_create(window, "ABCD", &entry); 427 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 428 429 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 430 entry->pos = 1; 431 entry->sel_start = 1; 432 433 ui_entry_delete(entry); 434 PCUT_ASSERT_STR_EQUALS("ACD", entry->text); 435 436 ui_entry_delete(entry); 437 PCUT_ASSERT_STR_EQUALS("AD", entry->text); 438 439 ui_entry_delete(entry); 440 PCUT_ASSERT_STR_EQUALS("A", entry->text); 441 442 ui_entry_delete(entry); 443 PCUT_ASSERT_STR_EQUALS("A", entry->text); 444 445 ui_entry_destroy(entry); 446 ui_window_destroy(window); 447 ui_destroy(ui); 448 } 449 450 /** ui_entry_delete() with selected text deletes selection. */ 451 PCUT_TEST(delete_with_sel) 452 { 453 errno_t rc; 454 ui_t *ui = NULL; 455 ui_window_t *window = NULL; 456 ui_wnd_params_t params; 457 ui_entry_t *entry; 458 459 rc = ui_create_disp(NULL, &ui); 460 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 461 462 ui_wnd_params_init(¶ms); 463 params.caption = "Hello"; 464 465 rc = ui_window_create(ui, ¶ms, &window); 466 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 467 PCUT_ASSERT_NOT_NULL(window); 468 469 rc = ui_entry_create(window, "ABCDE", &entry); 470 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 471 472 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text); 473 474 /* Select all but the first and last character */ 475 ui_entry_activate(entry); 476 ui_entry_seek_start(entry, false); 477 ui_entry_seek_next_char(entry, false); 478 ui_entry_seek_end(entry, true); 479 ui_entry_seek_prev_char(entry, true); 480 481 ui_entry_delete(entry); 482 483 PCUT_ASSERT_STR_EQUALS("AE", entry->text); 484 485 ui_entry_destroy(entry); 486 ui_window_destroy(window); 487 ui_destroy(ui); 488 } 489 490 /** ui_entry_copy() copies selected text to clipboard. */ 491 PCUT_TEST(copy) 492 { 493 errno_t rc; 494 ui_t *ui = NULL; 495 ui_window_t *window = NULL; 496 ui_wnd_params_t params; 497 ui_entry_t *entry; 498 char *str; 499 500 rc = ui_create_disp(NULL, &ui); 501 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 502 503 ui_wnd_params_init(¶ms); 504 params.caption = "Hello"; 505 506 rc = ui_window_create(ui, ¶ms, &window); 507 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 508 PCUT_ASSERT_NOT_NULL(window); 509 510 rc = ui_entry_create(window, "ABCDEF", &entry); 511 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 512 513 ui_entry_activate(entry); 514 ui_entry_seek_start(entry, false); 515 ui_entry_seek_next_char(entry, false); 516 ui_entry_seek_end(entry, true); 517 ui_entry_seek_prev_char(entry, true); 518 519 // FIXME: This is not safe unless we could create a private 520 // test clipboard 521 522 ui_entry_copy(entry); 523 rc = clipboard_get_str(&str); 524 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 525 PCUT_ASSERT_STR_EQUALS("BCDE", str); 526 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text); 527 free(str); 528 529 ui_entry_destroy(entry); 530 ui_window_destroy(window); 531 ui_destroy(ui); 532 } 533 534 /** ui_entry_cut() cuts selected text to clipboard. */ 535 PCUT_TEST(cut) 536 { 537 errno_t rc; 538 ui_t *ui = NULL; 539 ui_window_t *window = NULL; 540 ui_wnd_params_t params; 541 ui_entry_t *entry; 542 char *str; 543 544 rc = ui_create_disp(NULL, &ui); 545 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 546 547 ui_wnd_params_init(¶ms); 548 params.caption = "Hello"; 549 550 rc = ui_window_create(ui, ¶ms, &window); 551 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 552 PCUT_ASSERT_NOT_NULL(window); 553 554 rc = ui_entry_create(window, "ABCDEF", &entry); 555 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 556 557 ui_entry_activate(entry); 558 ui_entry_seek_start(entry, false); 559 ui_entry_seek_next_char(entry, false); 560 ui_entry_seek_end(entry, true); 561 ui_entry_seek_prev_char(entry, true); 562 563 // FIXME: This is not safe unless we could create a private 564 // test clipboard 565 566 ui_entry_cut(entry); 567 rc = clipboard_get_str(&str); 568 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 569 PCUT_ASSERT_STR_EQUALS("BCDE", str); 570 PCUT_ASSERT_STR_EQUALS("AF", entry->text); 571 free(str); 572 573 ui_entry_destroy(entry); 574 ui_window_destroy(window); 575 ui_destroy(ui); 576 } 577 578 /** ui_entry_paste() pastes text from clipboard. */ 579 PCUT_TEST(paste) 580 { 581 errno_t rc; 582 ui_t *ui = NULL; 583 ui_window_t *window = NULL; 584 ui_wnd_params_t params; 585 ui_entry_t *entry; 586 587 rc = ui_create_disp(NULL, &ui); 588 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 589 590 ui_wnd_params_init(¶ms); 591 params.caption = "Hello"; 592 593 rc = ui_window_create(ui, ¶ms, &window); 594 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 595 PCUT_ASSERT_NOT_NULL(window); 596 597 rc = ui_entry_create(window, "AB", &entry); 598 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 599 600 ui_entry_activate(entry); 601 ui_entry_seek_start(entry, false); 602 ui_entry_seek_next_char(entry, false); 603 604 // FIXME: This is not safe unless we could create a private 605 // test clipboard 606 607 rc = clipboard_put_str("123"); 608 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 609 610 ui_entry_paste(entry); 611 PCUT_ASSERT_STR_EQUALS("A123B", entry->text); 612 613 ui_entry_destroy(entry); 614 ui_window_destroy(window); 615 ui_destroy(ui); 616 } 617 618 /** ui_entry_seek_start() moves cursor to beginning of text */ 619 PCUT_TEST(seek_start) 620 { 621 errno_t rc; 622 ui_t *ui = NULL; 623 ui_window_t *window = NULL; 624 ui_wnd_params_t params; 625 ui_entry_t *entry; 626 627 rc = ui_create_disp(NULL, &ui); 628 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 629 630 ui_wnd_params_init(¶ms); 631 params.caption = "Hello"; 632 633 rc = ui_window_create(ui, ¶ms, &window); 634 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 635 PCUT_ASSERT_NOT_NULL(window); 636 637 rc = ui_entry_create(window, "ABCDEF", &entry); 638 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 639 640 ui_entry_activate(entry); 641 642 entry->pos = 2; 643 entry->sel_start = 2; 644 645 ui_entry_seek_start(entry, true); 646 PCUT_ASSERT_INT_EQUALS(0, entry->pos); 647 PCUT_ASSERT_INT_EQUALS(2, entry->sel_start); 648 649 ui_entry_seek_start(entry, false); 650 PCUT_ASSERT_INT_EQUALS(0, entry->pos); 651 PCUT_ASSERT_INT_EQUALS(0, entry->sel_start); 652 653 ui_entry_destroy(entry); 654 ui_window_destroy(window); 655 ui_destroy(ui); 656 } 657 658 /** ui_entry_seek_end() moves cursor to the end of text */ 659 PCUT_TEST(seek_end) 660 { 661 errno_t rc; 662 ui_t *ui = NULL; 663 ui_window_t *window = NULL; 664 ui_wnd_params_t params; 665 ui_entry_t *entry; 666 667 rc = ui_create_disp(NULL, &ui); 668 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 669 670 ui_wnd_params_init(¶ms); 671 params.caption = "Hello"; 672 673 rc = ui_window_create(ui, ¶ms, &window); 674 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 675 PCUT_ASSERT_NOT_NULL(window); 676 677 rc = ui_entry_create(window, "ABCD", &entry); 678 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 679 680 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 681 entry->pos = 2; 682 entry->sel_start = 2; 683 684 ui_entry_seek_end(entry, true); 685 PCUT_ASSERT_INT_EQUALS(4, entry->pos); 686 PCUT_ASSERT_INT_EQUALS(2, entry->sel_start); 687 ui_entry_seek_end(entry, false); 688 PCUT_ASSERT_INT_EQUALS(4, entry->pos); 689 PCUT_ASSERT_INT_EQUALS(4, entry->sel_start); 690 691 ui_entry_destroy(entry); 692 ui_window_destroy(window); 693 ui_destroy(ui); 694 } 695 696 /** ui_entry_seek_prev_char() moves cursor to the previous character */ 697 PCUT_TEST(seek_prev_char) 698 { 699 errno_t rc; 700 ui_t *ui = NULL; 701 ui_window_t *window = NULL; 702 ui_wnd_params_t params; 703 ui_entry_t *entry; 704 705 rc = ui_create_disp(NULL, &ui); 706 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 707 708 ui_wnd_params_init(¶ms); 709 params.caption = "Hello"; 710 711 rc = ui_window_create(ui, ¶ms, &window); 712 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 713 PCUT_ASSERT_NOT_NULL(window); 714 715 rc = ui_entry_create(window, "ABCD", &entry); 716 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 717 718 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 719 entry->pos = 3; 720 entry->sel_start = 3; 721 722 ui_entry_seek_prev_char(entry, true); 723 PCUT_ASSERT_INT_EQUALS(2, entry->pos); 724 PCUT_ASSERT_INT_EQUALS(3, entry->sel_start); 725 726 ui_entry_seek_prev_char(entry, false); 727 PCUT_ASSERT_INT_EQUALS(1, entry->pos); 728 PCUT_ASSERT_INT_EQUALS(1, entry->sel_start); 729 730 ui_entry_destroy(entry); 731 ui_window_destroy(window); 732 ui_destroy(ui); 733 } 734 735 /** ui_entry_seek_prev_char() moves cursor to the next character */ 736 PCUT_TEST(seek_next_char) 737 { 738 errno_t rc; 739 ui_t *ui = NULL; 740 ui_window_t *window = NULL; 741 ui_wnd_params_t params; 742 ui_entry_t *entry; 743 744 rc = ui_create_disp(NULL, &ui); 745 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 746 747 ui_wnd_params_init(¶ms); 748 params.caption = "Hello"; 749 750 rc = ui_window_create(ui, ¶ms, &window); 751 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 752 PCUT_ASSERT_NOT_NULL(window); 753 754 rc = ui_entry_create(window, "ABCD", &entry); 755 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 756 757 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 758 entry->pos = 1; 759 entry->sel_start = 1; 760 761 ui_entry_seek_next_char(entry, true); 762 PCUT_ASSERT_INT_EQUALS(2, entry->pos); 763 PCUT_ASSERT_INT_EQUALS(1, entry->sel_start); 764 ui_entry_seek_next_char(entry, false); 765 PCUT_ASSERT_INT_EQUALS(3, entry->pos); 766 PCUT_ASSERT_INT_EQUALS(3, entry->sel_start); 767 768 ui_entry_destroy(entry); 769 ui_window_destroy(window); 770 ui_destroy(ui); 771 } 772 773 /** ui_entry_activate() / ui_entry_deactivate() */ 774 PCUT_TEST(activate_deactivate) 775 { 776 errno_t rc; 777 ui_t *ui = NULL; 778 ui_window_t *window = NULL; 779 ui_wnd_params_t params; 780 ui_entry_t *entry; 781 782 rc = ui_create_disp(NULL, &ui); 783 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 784 785 ui_wnd_params_init(¶ms); 786 params.caption = "Hello"; 787 788 rc = ui_window_create(ui, ¶ms, &window); 789 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 790 PCUT_ASSERT_NOT_NULL(window); 791 792 rc = ui_entry_create(window, "ABC", &entry); 793 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 794 795 PCUT_ASSERT_FALSE(entry->active); 796 797 ui_entry_activate(entry); 798 PCUT_ASSERT_TRUE(entry->active); 799 800 ui_entry_deactivate(entry); 801 PCUT_ASSERT_FALSE(entry->active); 802 803 ui_entry_destroy(entry); 804 ui_window_destroy(window); 805 ui_destroy(ui); 806 } 807 175 808 PCUT_EXPORT(entry);
Note:
See TracChangeset
for help on using the changeset viewer.