Changeset c9722c1 in mainline for uspace/lib/ui/test/entry.c


Ignore:
Timestamp:
2021-07-20T00:18:59Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
282c86d
Parents:
9eb8d12
Message:

Cut, copy and paste entry text

Using Ctrl-X, Ctrl-C and Ctrl-V.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/test/entry.c

    r9eb8d12 rc9722c1  
    2727 */
    2828
     29#include <clipboard.h>
    2930#include <gfx/context.h>
    3031#include <gfx/coord.h>
     
    487488}
    488489
     490/** ui_entry_copy() copies selected text to clipboard. */
     491PCUT_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(&params);
     504        params.caption = "Hello";
     505
     506        rc = ui_window_create(ui, &params, &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. */
     535PCUT_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(&params);
     548        params.caption = "Hello";
     549
     550        rc = ui_window_create(ui, &params, &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. */
     579PCUT_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(&params);
     591        params.caption = "Hello";
     592
     593        rc = ui_window_create(ui, &params, &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
    489618/** ui_entry_seek_start() moves cursor to beginning of text */
    490619PCUT_TEST(seek_start)
     
    506635        PCUT_ASSERT_NOT_NULL(window);
    507636
    508         rc = ui_entry_create(window, "ABCD", &entry);
    509         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    510 
    511         PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
     637        rc = ui_entry_create(window, "ABCDEF", &entry);
     638        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     639
     640        ui_entry_activate(entry);
     641
    512642        entry->pos = 2;
    513643        entry->sel_start = 2;
Note: See TracChangeset for help on using the changeset viewer.