Changeset e0377075 in mainline for uspace/app/nav/test/panel.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (3 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9ee55cd
Parents:
39ab17c
git-author:
Jiri Svoboda <jiri@…> (2021-10-22 18:25:44)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

Select entry using the mouse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/test/panel.c

    r39ab17c re0377075  
    205205PCUT_TEST(pos_event)
    206206{
     207        ui_t *ui;
     208        ui_window_t *window;
     209        ui_wnd_params_t params;
    207210        panel_t *panel;
    208211        ui_evclaim_t claimed;
    209212        pos_event_t event;
    210         errno_t rc;
    211 
    212         rc = panel_create(NULL, true, &panel);
    213         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     213        gfx_rect_t rect;
     214        panel_entry_attr_t attr;
     215        errno_t rc;
     216
     217        rc = ui_create_disp(NULL, &ui);
     218        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     219
     220        ui_wnd_params_init(&params);
     221        params.caption = "Test";
     222
     223        rc = ui_window_create(ui, &params, &window);
     224        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     225
     226        rc = panel_create(window, true, &panel);
     227        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     228
     229        rect.p0.x = 0;
     230        rect.p0.y = 0;
     231        rect.p1.x = 10;
     232        rect.p1.y = 10;
     233        panel_set_rect(panel, &rect);
     234
     235        panel_entry_attr_init(&attr);
     236        attr.name = "a";
     237        attr.size = 1;
     238        rc = panel_entry_append(panel, &attr);
     239        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     240
     241        attr.name = "b";
     242        attr.size = 2;
     243        rc = panel_entry_append(panel, &attr);
     244        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     245
     246        attr.name = "c";
     247        attr.size = 3;
     248        rc = panel_entry_append(panel, &attr);
     249        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     250
     251        panel->cursor = panel_first(panel);
     252        panel->cursor_idx = 0;
     253        panel->page = panel_first(panel);
     254        panel->page_idx = 0;
    214255
    215256        event.pos_id = 0;
    216257        event.type = POS_PRESS;
    217258        event.btn_num = 1;
    218         event.hpos = 0;
    219         event.vpos = 0;
     259
     260        /* Clicking on the middle entry should select it */
     261        event.hpos = 1;
     262        event.vpos = 2;
    220263
    221264        claimed = panel_pos_event(panel, &event);
    222         PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
    223 
    224         panel_destroy(panel);
     265        PCUT_ASSERT_EQUALS(ui_claimed, claimed);
     266
     267        PCUT_ASSERT_NOT_NULL(panel->cursor);
     268        PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name);
     269        PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size);
     270
     271        /* Clicking below the last entry should select it */
     272        event.hpos = 1;
     273        event.vpos = 4;
     274        claimed = panel_pos_event(panel, &event);
     275        PCUT_ASSERT_EQUALS(ui_claimed, claimed);
     276
     277        PCUT_ASSERT_NOT_NULL(panel->cursor);
     278        PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name);
     279        PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size);
     280
     281        panel_destroy(panel);
     282        ui_window_destroy(window);
     283        ui_destroy(ui);
    225284}
    226285
     
    839898        PCUT_ASSERT_STR_EQUALS("a", entry->name);
    840899        PCUT_ASSERT_INT_EQUALS(1, entry->size);
     900
     901        panel_destroy(panel);
     902}
     903
     904/** panel_page_nth_entry() .. */
     905PCUT_TEST(page_nth_entry)
     906{
     907        panel_t *panel;
     908        panel_entry_t *entry;
     909        panel_entry_attr_t attr;
     910        size_t idx;
     911        errno_t rc;
     912
     913        rc = panel_create(NULL, true, &panel);
     914        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     915
     916        panel_entry_attr_init(&attr);
     917
     918        /* Add some entries */
     919        attr.name = "a";
     920        attr.size = 1;
     921        rc = panel_entry_append(panel, &attr);
     922        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     923
     924        attr.name = "b";
     925        attr.size = 2;
     926        rc = panel_entry_append(panel, &attr);
     927        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     928
     929        attr.name = "c";
     930        attr.size = 3;
     931        rc = panel_entry_append(panel, &attr);
     932        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     933
     934        panel->page = panel_next(panel_first(panel));
     935        panel->page_idx = 1;
     936
     937        entry = panel_page_nth_entry(panel, 0, &idx);
     938        PCUT_ASSERT_STR_EQUALS("b", entry->name);
     939        PCUT_ASSERT_INT_EQUALS(1, idx);
     940
     941        entry = panel_page_nth_entry(panel, 1, &idx);
     942        PCUT_ASSERT_STR_EQUALS("c", entry->name);
     943        PCUT_ASSERT_INT_EQUALS(2, idx);
     944
     945        entry = panel_page_nth_entry(panel, 2, &idx);
     946        PCUT_ASSERT_STR_EQUALS("c", entry->name);
     947        PCUT_ASSERT_INT_EQUALS(2, idx);
     948
     949        entry = panel_page_nth_entry(panel, 3, &idx);
     950        PCUT_ASSERT_STR_EQUALS("c", entry->name);
     951        PCUT_ASSERT_INT_EQUALS(2, idx);
    841952
    842953        panel_destroy(panel);
Note: See TracChangeset for help on using the changeset viewer.