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


Ignore:
Timestamp:
2021-07-19T22:35:19Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c9722c1
Parents:
ead72f2
Message:

Entry text selection (using keyboard)

Text can be selected with movement keys while holding down Shift.
Selection can be deleted by pressing Backspace, Delete or typing
in replacement text.

File:
1 edited

Legend:

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

    read72f2 r9eb8d12  
    190190}
    191191
     192/** ui_entry_delete_sel() deletes selected text */
     193PCUT_TEST(delete_sel)
     194{
     195        errno_t rc;
     196        ui_t *ui = NULL;
     197        ui_window_t *window = NULL;
     198        ui_wnd_params_t params;
     199        ui_entry_t *entry;
     200
     201        rc = ui_create_disp(NULL, &ui);
     202        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     203
     204        ui_wnd_params_init(&params);
     205        params.caption = "Hello";
     206
     207        rc = ui_window_create(ui, &params, &window);
     208        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     209        PCUT_ASSERT_NOT_NULL(window);
     210
     211        rc = ui_entry_create(window, "ABCDEF", &entry);
     212        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     213
     214        PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text);
     215
     216        ui_entry_activate(entry);
     217
     218        /* Select all but first and last character */
     219        ui_entry_seek_start(entry, false);
     220        ui_entry_seek_next_char(entry, false);
     221        ui_entry_seek_end(entry, true);
     222        ui_entry_seek_prev_char(entry, true);
     223
     224        ui_entry_delete_sel(entry);
     225
     226        PCUT_ASSERT_STR_EQUALS("AF", entry->text);
     227
     228        ui_entry_destroy(entry);
     229        ui_window_destroy(window);
     230        ui_destroy(ui);
     231}
     232
    192233/** ui_entry_insert_str() inserts string at cursor. */
    193234PCUT_TEST(insert_str)
     
    214255        PCUT_ASSERT_STR_EQUALS("A", entry->text);
    215256
    216         /* This moves the cursor to the end of the text */
    217257        ui_entry_activate(entry);
     258        ui_entry_seek_end(entry, false);
    218259
    219260        rc = ui_entry_insert_str(entry, "B");
     
    228269
    229270        entry->pos = 2;
     271        entry->sel_start = 2;
    230272        rc = ui_entry_insert_str(entry, "CD");
    231273        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    232274
    233275        PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text);
     276
     277        ui_entry_destroy(entry);
     278        ui_window_destroy(window);
     279        ui_destroy(ui);
     280}
     281
     282/** ui_entry_insert_str() deletes selection before inserting string */
     283PCUT_TEST(insert_str_with_sel)
     284{
     285        errno_t rc;
     286        ui_t *ui = NULL;
     287        ui_window_t *window = NULL;
     288        ui_wnd_params_t params;
     289        ui_entry_t *entry;
     290
     291        rc = ui_create_disp(NULL, &ui);
     292        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     293
     294        ui_wnd_params_init(&params);
     295        params.caption = "Hello";
     296
     297        rc = ui_window_create(ui, &params, &window);
     298        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     299        PCUT_ASSERT_NOT_NULL(window);
     300
     301        rc = ui_entry_create(window, "ABCDE", &entry);
     302        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     303
     304        PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text);
     305
     306        /* Select all but the first and last character */
     307        ui_entry_activate(entry);
     308        ui_entry_seek_start(entry, false);
     309        ui_entry_seek_next_char(entry, false);
     310        ui_entry_seek_end(entry, true);
     311        ui_entry_seek_prev_char(entry, true);
     312
     313        rc = ui_entry_insert_str(entry, "123");
     314        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     315
     316        PCUT_ASSERT_STR_EQUALS("A123E", entry->text);
    234317
    235318        ui_entry_destroy(entry);
     
    262345        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
    263346        entry->pos = 3;
     347        entry->sel_start = 3;
    264348
    265349        ui_entry_backspace(entry);
     
    280364}
    281365
     366/** ui_entry_backspace() with selected text deletes selection. */
     367PCUT_TEST(backspace_with_sel)
     368{
     369        errno_t rc;
     370        ui_t *ui = NULL;
     371        ui_window_t *window = NULL;
     372        ui_wnd_params_t params;
     373        ui_entry_t *entry;
     374
     375        rc = ui_create_disp(NULL, &ui);
     376        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     377
     378        ui_wnd_params_init(&params);
     379        params.caption = "Hello";
     380
     381        rc = ui_window_create(ui, &params, &window);
     382        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     383        PCUT_ASSERT_NOT_NULL(window);
     384
     385        rc = ui_entry_create(window, "ABCDE", &entry);
     386        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     387
     388        PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text);
     389
     390        /* Select all but the first and last character */
     391        ui_entry_activate(entry);
     392        ui_entry_seek_start(entry, false);
     393        ui_entry_seek_next_char(entry, false);
     394        ui_entry_seek_end(entry, true);
     395        ui_entry_seek_prev_char(entry, true);
     396
     397        ui_entry_backspace(entry);
     398
     399        PCUT_ASSERT_STR_EQUALS("AE", entry->text);
     400
     401        ui_entry_destroy(entry);
     402        ui_window_destroy(window);
     403        ui_destroy(ui);
     404}
     405
    282406/** ui_entry_delete() deletes character after cursor. */
    283407PCUT_TEST(delete)
     
    304428        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
    305429        entry->pos = 1;
     430        entry->sel_start = 1;
    306431
    307432        ui_entry_delete(entry);
     
    322447}
    323448
     449/** ui_entry_delete() with selected text deletes selection. */
     450PCUT_TEST(delete_with_sel)
     451{
     452        errno_t rc;
     453        ui_t *ui = NULL;
     454        ui_window_t *window = NULL;
     455        ui_wnd_params_t params;
     456        ui_entry_t *entry;
     457
     458        rc = ui_create_disp(NULL, &ui);
     459        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     460
     461        ui_wnd_params_init(&params);
     462        params.caption = "Hello";
     463
     464        rc = ui_window_create(ui, &params, &window);
     465        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     466        PCUT_ASSERT_NOT_NULL(window);
     467
     468        rc = ui_entry_create(window, "ABCDE", &entry);
     469        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     470
     471        PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text);
     472
     473        /* Select all but the first and last character */
     474        ui_entry_activate(entry);
     475        ui_entry_seek_start(entry, false);
     476        ui_entry_seek_next_char(entry, false);
     477        ui_entry_seek_end(entry, true);
     478        ui_entry_seek_prev_char(entry, true);
     479
     480        ui_entry_delete(entry);
     481
     482        PCUT_ASSERT_STR_EQUALS("AE", entry->text);
     483
     484        ui_entry_destroy(entry);
     485        ui_window_destroy(window);
     486        ui_destroy(ui);
     487}
     488
    324489/** ui_entry_seek_start() moves cursor to beginning of text */
    325490PCUT_TEST(seek_start)
     
    346511        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
    347512        entry->pos = 2;
    348 
    349         ui_entry_seek_start(entry);
     513        entry->sel_start = 2;
     514
     515        ui_entry_seek_start(entry, true);
    350516        PCUT_ASSERT_INT_EQUALS(0, entry->pos);
     517        PCUT_ASSERT_INT_EQUALS(2, entry->sel_start);
     518
     519        ui_entry_seek_start(entry, false);
     520        PCUT_ASSERT_INT_EQUALS(0, entry->pos);
     521        PCUT_ASSERT_INT_EQUALS(0, entry->sel_start);
    351522
    352523        ui_entry_destroy(entry);
     
    379550        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
    380551        entry->pos = 2;
    381 
    382         ui_entry_seek_end(entry);
     552        entry->sel_start = 2;
     553
     554        ui_entry_seek_end(entry, true);
    383555        PCUT_ASSERT_INT_EQUALS(4, entry->pos);
     556        PCUT_ASSERT_INT_EQUALS(2, entry->sel_start);
     557        ui_entry_seek_end(entry, false);
     558        PCUT_ASSERT_INT_EQUALS(4, entry->pos);
     559        PCUT_ASSERT_INT_EQUALS(4, entry->sel_start);
    384560
    385561        ui_entry_destroy(entry);
     
    411587
    412588        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
    413         entry->pos = 2;
    414 
    415         ui_entry_seek_prev_char(entry);
     589        entry->pos = 3;
     590        entry->sel_start = 3;
     591
     592        ui_entry_seek_prev_char(entry, true);
     593        PCUT_ASSERT_INT_EQUALS(2, entry->pos);
     594        PCUT_ASSERT_INT_EQUALS(3, entry->sel_start);
     595
     596        ui_entry_seek_prev_char(entry, false);
    416597        PCUT_ASSERT_INT_EQUALS(1, entry->pos);
     598        PCUT_ASSERT_INT_EQUALS(1, entry->sel_start);
    417599
    418600        ui_entry_destroy(entry);
     
    444626
    445627        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
    446         entry->pos = 2;
    447 
    448         ui_entry_seek_next_char(entry);
     628        entry->pos = 1;
     629        entry->sel_start = 1;
     630
     631        ui_entry_seek_next_char(entry, true);
     632        PCUT_ASSERT_INT_EQUALS(2, entry->pos);
     633        PCUT_ASSERT_INT_EQUALS(1, entry->sel_start);
     634        ui_entry_seek_next_char(entry, false);
    449635        PCUT_ASSERT_INT_EQUALS(3, entry->pos);
     636        PCUT_ASSERT_INT_EQUALS(3, entry->sel_start);
    450637
    451638        ui_entry_destroy(entry);
Note: See TracChangeset for help on using the changeset viewer.