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


Ignore:
Timestamp:
2021-06-30T16:48:54Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d63623f
Parents:
5d1ff11
Message:

Seeking in entry text (using keyboard)

Seek using Home, End, Left Arrow and Right Arrow keys, delete character
after cursor using Delete key.

File:
1 edited

Legend:

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

    r5d1ff11 r61bf9dd9  
    214214        PCUT_ASSERT_STR_EQUALS("A", entry->text);
    215215
     216        /* This moves the cursor to the end of the text */
     217        ui_entry_activate(entry);
     218
    216219        rc = ui_entry_insert_str(entry, "B");
    217220        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     
    219222        PCUT_ASSERT_STR_EQUALS("AB", entry->text);
    220223
     224        rc = ui_entry_insert_str(entry, "EF");
     225        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     226
     227        PCUT_ASSERT_STR_EQUALS("ABEF", entry->text);
     228
     229        entry->pos = 2;
    221230        rc = ui_entry_insert_str(entry, "CD");
    222231        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    223232
    224         PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
     233        PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text);
    225234
    226235        ui_entry_destroy(entry);
     
    248257        PCUT_ASSERT_NOT_NULL(window);
    249258
    250         rc = ui_entry_create(window, "ABC", &entry);
    251         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    252 
    253         PCUT_ASSERT_STR_EQUALS("ABC", entry->text);
     259        rc = ui_entry_create(window, "ABCD", &entry);
     260        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     261
     262        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
     263        entry->pos = 3;
    254264
    255265        ui_entry_backspace(entry);
    256         PCUT_ASSERT_STR_EQUALS("AB", entry->text);
     266        PCUT_ASSERT_STR_EQUALS("ABD", entry->text);
    257267
    258268        ui_entry_backspace(entry);
     269        PCUT_ASSERT_STR_EQUALS("AD", entry->text);
     270
     271        ui_entry_backspace(entry);
     272        PCUT_ASSERT_STR_EQUALS("D", entry->text);
     273
     274        ui_entry_backspace(entry);
     275        PCUT_ASSERT_STR_EQUALS("D", entry->text);
     276
     277        ui_entry_destroy(entry);
     278        ui_window_destroy(window);
     279        ui_destroy(ui);
     280}
     281
     282/** ui_entry_delete() deletes character after cursor. */
     283PCUT_TEST(delete)
     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, "ABCD", &entry);
     302        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     303
     304        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
     305        entry->pos = 1;
     306
     307        ui_entry_delete(entry);
     308        PCUT_ASSERT_STR_EQUALS("ACD", entry->text);
     309
     310        ui_entry_delete(entry);
     311        PCUT_ASSERT_STR_EQUALS("AD", entry->text);
     312
     313        ui_entry_delete(entry);
    259314        PCUT_ASSERT_STR_EQUALS("A", entry->text);
    260315
    261         ui_entry_backspace(entry);
    262         PCUT_ASSERT_STR_EQUALS("", entry->text);
    263 
    264         ui_entry_backspace(entry);
    265         PCUT_ASSERT_STR_EQUALS("", entry->text);
     316        ui_entry_delete(entry);
     317        PCUT_ASSERT_STR_EQUALS("A", entry->text);
     318
     319        ui_entry_destroy(entry);
     320        ui_window_destroy(window);
     321        ui_destroy(ui);
     322}
     323
     324/** ui_entry_seek_start() moves cursor to beginning of text */
     325PCUT_TEST(seek_start)
     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(&params);
     337        params.caption = "Hello";
     338
     339        rc = ui_window_create(ui, &params, &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 = 2;
     348
     349        ui_entry_seek_start(entry);
     350        PCUT_ASSERT_INT_EQUALS(0, entry->pos);
     351
     352        ui_entry_destroy(entry);
     353        ui_window_destroy(window);
     354        ui_destroy(ui);
     355}
     356
     357/** ui_entry_seek_end() moves cursor to the end of text */
     358PCUT_TEST(seek_end)
     359{
     360        errno_t rc;
     361        ui_t *ui = NULL;
     362        ui_window_t *window = NULL;
     363        ui_wnd_params_t params;
     364        ui_entry_t *entry;
     365
     366        rc = ui_create_disp(NULL, &ui);
     367        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     368
     369        ui_wnd_params_init(&params);
     370        params.caption = "Hello";
     371
     372        rc = ui_window_create(ui, &params, &window);
     373        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     374        PCUT_ASSERT_NOT_NULL(window);
     375
     376        rc = ui_entry_create(window, "ABCD", &entry);
     377        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     378
     379        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
     380        entry->pos = 2;
     381
     382        ui_entry_seek_end(entry);
     383        PCUT_ASSERT_INT_EQUALS(4, entry->pos);
     384
     385        ui_entry_destroy(entry);
     386        ui_window_destroy(window);
     387        ui_destroy(ui);
     388}
     389
     390/** ui_entry_seek_prev_char() moves cursor to the previous character */
     391PCUT_TEST(seek_prev_char)
     392{
     393        errno_t rc;
     394        ui_t *ui = NULL;
     395        ui_window_t *window = NULL;
     396        ui_wnd_params_t params;
     397        ui_entry_t *entry;
     398
     399        rc = ui_create_disp(NULL, &ui);
     400        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     401
     402        ui_wnd_params_init(&params);
     403        params.caption = "Hello";
     404
     405        rc = ui_window_create(ui, &params, &window);
     406        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     407        PCUT_ASSERT_NOT_NULL(window);
     408
     409        rc = ui_entry_create(window, "ABCD", &entry);
     410        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     411
     412        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
     413        entry->pos = 2;
     414
     415        ui_entry_seek_prev_char(entry);
     416        PCUT_ASSERT_INT_EQUALS(1, entry->pos);
     417
     418        ui_entry_destroy(entry);
     419        ui_window_destroy(window);
     420        ui_destroy(ui);
     421}
     422
     423/** ui_entry_seek_prev_char() moves cursor to the next character */
     424PCUT_TEST(seek_next_char)
     425{
     426        errno_t rc;
     427        ui_t *ui = NULL;
     428        ui_window_t *window = NULL;
     429        ui_wnd_params_t params;
     430        ui_entry_t *entry;
     431
     432        rc = ui_create_disp(NULL, &ui);
     433        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     434
     435        ui_wnd_params_init(&params);
     436        params.caption = "Hello";
     437
     438        rc = ui_window_create(ui, &params, &window);
     439        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     440        PCUT_ASSERT_NOT_NULL(window);
     441
     442        rc = ui_entry_create(window, "ABCD", &entry);
     443        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     444
     445        PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
     446        entry->pos = 2;
     447
     448        ui_entry_seek_next_char(entry);
     449        PCUT_ASSERT_INT_EQUALS(3, entry->pos);
    266450
    267451        ui_entry_destroy(entry);
Note: See TracChangeset for help on using the changeset viewer.