Changeset f03d1308 in mainline for uspace/lib/ui/test/window.c


Ignore:
Timestamp:
2020-10-28T12:42:11Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8009dc27
Parents:
d284ce9
git-author:
Jiri Svoboda <jiri@…> (2020-10-28 12:41:11)
git-committer:
Jiri Svoboda <jiri@…> (2020-10-28 12:42:11)
Message:

Convert terminal to using ui_window

File:
1 edited

Legend:

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

    rd284ce9 rf03d1308  
    2929#include <gfx/context.h>
    3030#include <gfx/coord.h>
     31#include <io/kbd_event.h>
    3132#include <io/pos_event.h>
    3233#include <mem.h>
     
    4344
    4445static void test_window_close(ui_window_t *, void *);
     46static void test_window_focus(ui_window_t *, void *);
     47static void test_window_kbd(ui_window_t *, void *, kbd_event_t *);
    4548static void test_window_pos(ui_window_t *, void *, pos_event_t *);
     49static void test_window_unfocus(ui_window_t *, void *);
    4650
    4751static ui_window_cb_t test_window_cb = {
    4852        .close = test_window_close,
    49         .pos = test_window_pos
     53        .focus = test_window_focus,
     54        .kbd = test_window_kbd,
     55        .pos = test_window_pos,
     56        .unfocus = test_window_unfocus
    5057};
    5158
     
    5562typedef struct {
    5663        bool close;
     64        bool focus;
     65        bool kbd;
     66        kbd_event_t kbd_event;
    5767        bool pos;
    5868        pos_event_t pos_event;
     69        bool unfocus;
    5970} test_cb_resp_t;
    6071
     
    151162        ui_window_close(window);
    152163        PCUT_ASSERT_TRUE(resp.close);
     164
     165        ui_window_destroy(window);
     166        ui_destroy(ui);
     167}
     168
     169/** ui_window_focus() calls focus callback set via ui_window_set_cb() */
     170PCUT_TEST(focus)
     171{
     172        errno_t rc;
     173        ui_t *ui = NULL;
     174        ui_wnd_params_t params;
     175        ui_window_t *window = NULL;
     176        test_cb_resp_t resp;
     177
     178        rc = ui_create_disp(NULL, &ui);
     179        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     180
     181        ui_wnd_params_init(&params);
     182        params.caption = "Hello";
     183
     184        rc = ui_window_create(ui, &params, &window);
     185        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     186        PCUT_ASSERT_NOT_NULL(window);
     187
     188        /* Focus callback with no callbacks set */
     189        ui_window_focus(window);
     190
     191        /* Focus callback with focus callback not implemented */
     192        ui_window_set_cb(window, &dummy_window_cb, NULL);
     193        ui_window_focus(window);
     194
     195        /* Focus callback with real callback set */
     196        resp.close = false;
     197        ui_window_set_cb(window, &test_window_cb, &resp);
     198        ui_window_focus(window);
     199        PCUT_ASSERT_TRUE(resp.focus);
     200
     201        ui_window_destroy(window);
     202        ui_destroy(ui);
     203}
     204
     205/** ui_window_kbd() calls kbd callback set via ui_window_set_cb() */
     206PCUT_TEST(kbd)
     207{
     208        errno_t rc;
     209        ui_t *ui = NULL;
     210        ui_wnd_params_t params;
     211        ui_window_t *window = NULL;
     212        kbd_event_t kbd_event;
     213        test_cb_resp_t resp;
     214
     215        rc = ui_create_disp(NULL, &ui);
     216        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     217
     218        ui_wnd_params_init(&params);
     219        params.caption = "Hello";
     220
     221        rc = ui_window_create(ui, &params, &window);
     222        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     223        PCUT_ASSERT_NOT_NULL(window);
     224
     225        kbd_event.type = POS_PRESS;
     226        kbd_event.key = KC_X;
     227        kbd_event.mods = 0;
     228        kbd_event.c = 'x';
     229
     230        /* Kbd callback with no callbacks set */
     231        ui_window_kbd(window, &kbd_event);
     232
     233        /* Kbd callback with kbd callback not implemented */
     234        ui_window_set_cb(window, &dummy_window_cb, NULL);
     235        ui_window_kbd(window, &kbd_event);
     236
     237        /* Kbd callback with real callback set */
     238        resp.kbd = false;
     239        ui_window_set_cb(window, &test_window_cb, &resp);
     240        ui_window_kbd(window, &kbd_event);
     241        PCUT_ASSERT_TRUE(resp.kbd);
     242        PCUT_ASSERT_EQUALS(kbd_event.type, resp.kbd_event.type);
     243        PCUT_ASSERT_INT_EQUALS(kbd_event.key, resp.kbd_event.key);
     244        PCUT_ASSERT_INT_EQUALS(kbd_event.mods, resp.kbd_event.mods);
     245        PCUT_ASSERT_INT_EQUALS(kbd_event.c, resp.kbd_event.c);
    153246
    154247        ui_window_destroy(window);
     
    204297}
    205298
     299/** ui_window_unfocus() calls unfocus callback set via ui_window_set_cb() */
     300PCUT_TEST(unfocus)
     301{
     302        errno_t rc;
     303        ui_t *ui = NULL;
     304        ui_wnd_params_t params;
     305        ui_window_t *window = NULL;
     306        test_cb_resp_t resp;
     307
     308        rc = ui_create_disp(NULL, &ui);
     309        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     310
     311        ui_wnd_params_init(&params);
     312        params.caption = "Hello";
     313
     314        rc = ui_window_create(ui, &params, &window);
     315        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     316        PCUT_ASSERT_NOT_NULL(window);
     317
     318        /* Unfocus callback with no callbacks set */
     319        ui_window_unfocus(window);
     320
     321        /* Unfocus callback with unfocus callback not implemented */
     322        ui_window_set_cb(window, &dummy_window_cb, NULL);
     323        ui_window_unfocus(window);
     324
     325        /* Unfocus callback with real callback set */
     326        resp.close = false;
     327        ui_window_set_cb(window, &test_window_cb, &resp);
     328        ui_window_unfocus(window);
     329        PCUT_ASSERT_TRUE(resp.unfocus);
     330
     331        ui_window_destroy(window);
     332        ui_destroy(ui);
     333}
     334
    206335static void test_window_close(ui_window_t *window, void *arg)
    207336{
     
    209338
    210339        resp->close = true;
     340}
     341
     342static void test_window_focus(ui_window_t *window, void *arg)
     343{
     344        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     345
     346        resp->focus = true;
     347}
     348
     349static void test_window_kbd(ui_window_t *window, void *arg,
     350    kbd_event_t *event)
     351{
     352        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     353
     354        resp->kbd = true;
     355        resp->kbd_event = *event;
    211356}
    212357
     
    220365}
    221366
     367static void test_window_unfocus(ui_window_t *window, void *arg)
     368{
     369        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     370
     371        resp->unfocus = true;
     372}
     373
    222374PCUT_EXPORT(window);
Note: See TracChangeset for help on using the changeset viewer.