Changeset 7481ee19 in mainline for uspace/lib/ui/test/control.c


Ignore:
Timestamp:
2021-06-23T08:15:00Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a977e37
Parents:
034ce6bb
git-author:
Jiri Svoboda <jiri@…> (2021-06-22 17:14:40)
git-committer:
Jiri Svoboda <jiri@…> (2021-06-23 08:15:00)
Message:

Basic editable text entry

File:
1 edited

Legend:

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

    r034ce6bb r7481ee19  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2929#include <errno.h>
    3030#include <mem.h>
     31#include <io/kbd_event.h>
    3132#include <io/pos_event.h>
    3233#include <pcut/pcut.h>
     
    4142static void test_ctl_destroy(void *);
    4243static errno_t test_ctl_paint(void *);
     44static ui_evclaim_t test_ctl_kbd_event(void *, kbd_event_t *);
    4345static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    4446static void test_ctl_unfocus(void *);
     
    4749        .destroy = test_ctl_destroy,
    4850        .paint = test_ctl_paint,
     51        .kbd_event = test_ctl_kbd_event,
    4952        .pos_event = test_ctl_pos_event,
    5053        .unfocus = test_ctl_unfocus
     
    6467        bool paint;
    6568
     69        /** @c true iff kbd_event was called */
     70        bool kbd;
     71        /** Keyboard event that was sent */
     72        kbd_event_t kevent;
     73
    6674        /** @c true iff pos_event was called */
    6775        bool pos;
     
    134142        PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
    135143        PCUT_ASSERT_TRUE(resp.paint);
     144
     145        ui_control_delete(control);
     146}
     147
     148/** Test sending keyboard event to control */
     149PCUT_TEST(kbd_event)
     150{
     151        ui_control_t *control = NULL;
     152        test_resp_t resp;
     153        kbd_event_t event;
     154        ui_evclaim_t claim;
     155        errno_t rc;
     156
     157        rc = ui_control_new(&test_ctl_ops, &resp, &control);
     158        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     159        PCUT_ASSERT_NOT_NULL(control);
     160
     161        resp.claim = ui_claimed;
     162        resp.kbd = false;
     163        event.type = KEY_PRESS;
     164        event.key = KC_2;
     165        event.mods = KM_LSHIFT;
     166        event.c = '@';
     167
     168        claim = ui_control_kbd_event(control, &event);
     169        PCUT_ASSERT_EQUALS(resp.claim, claim);
     170        PCUT_ASSERT_TRUE(resp.kbd);
     171        PCUT_ASSERT_EQUALS(resp.kevent.type, event.type);
     172        PCUT_ASSERT_INT_EQUALS(resp.kevent.key, event.key);
     173        PCUT_ASSERT_INT_EQUALS(resp.kevent.mods, event.mods);
     174        PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c);
    136175
    137176        ui_control_delete(control);
     
    205244}
    206245
     246static ui_evclaim_t test_ctl_kbd_event(void *arg, kbd_event_t *event)
     247{
     248        test_resp_t *resp = (test_resp_t *) arg;
     249
     250        resp->kbd = true;
     251        resp->kevent = *event;
     252
     253        return resp->claim;
     254}
     255
    207256static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event)
    208257{
Note: See TracChangeset for help on using the changeset viewer.