Ignore:
File:
1 edited

Legend:

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

    rdb3895d rcde067e  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4545PCUT_TEST_SUITE(window);
    4646
     47static void test_window_sysmenu(ui_window_t *, void *, sysarg_t);
     48static void test_window_minimize(ui_window_t *, void *);
     49static void test_window_maximize(ui_window_t *, void *);
     50static void test_window_unmaximize(ui_window_t *, void *);
    4751static void test_window_close(ui_window_t *, void *);
    48 static void test_window_focus(ui_window_t *, void *);
     52static void test_window_focus(ui_window_t *, void *, unsigned);
    4953static void test_window_kbd(ui_window_t *, void *, kbd_event_t *);
    5054static errno_t test_window_paint(ui_window_t *, void *);
    5155static void test_window_pos(ui_window_t *, void *, pos_event_t *);
    52 static void test_window_unfocus(ui_window_t *, void *);
     56static void test_window_unfocus(ui_window_t *, void *, unsigned);
     57static void test_window_resize(ui_window_t *, void *);
    5358
    5459static ui_window_cb_t test_window_cb = {
     60        .sysmenu = test_window_sysmenu,
     61        .minimize = test_window_minimize,
     62        .maximize = test_window_maximize,
     63        .unmaximize = test_window_unmaximize,
    5564        .close = test_window_close,
    5665        .focus = test_window_focus,
     
    5867        .paint = test_window_paint,
    5968        .pos = test_window_pos,
    60         .unfocus = test_window_unfocus
     69        .unfocus = test_window_unfocus,
     70        .resize = test_window_resize
    6171};
    6272
     
    6676static errno_t test_ctl_paint(void *);
    6777static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    68 static void test_ctl_unfocus(void *);
     78static void test_ctl_unfocus(void *, unsigned);
    6979
    7080static ui_control_ops_t test_ctl_ops = {
     
    7686typedef struct {
    7787        errno_t rc;
     88        bool sysmenu;
     89        sysarg_t sysmenu_idev_id;
     90        bool minimize;
     91        bool maximize;
     92        bool unmaximize;
    7893        bool close;
    7994        bool focus;
     95        unsigned focus_nfocus;
    8096        bool kbd;
    8197        kbd_event_t kbd_event;
     
    84100        pos_event_t pos_event;
    85101        bool unfocus;
     102        unsigned unfocus_nfocus;
     103        bool resize;
    86104} test_cb_resp_t;
    87105
     
    93111        pos_event_t pos_event;
    94112        bool unfocus;
     113        unsigned unfocus_nfocus;
    95114} test_ctl_resp_t;
    96115
     
    258277}
    259278
     279/** ui_window_get_ui() returns containing UI */
     280PCUT_TEST(get_ui)
     281{
     282        errno_t rc;
     283        ui_t *ui = NULL;
     284        ui_t *rui;
     285        ui_wnd_params_t params;
     286        ui_window_t *window = NULL;
     287
     288        rc = ui_create_disp(NULL, &ui);
     289        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     290
     291        ui_wnd_params_init(&params);
     292        params.caption = "Hello";
     293
     294        rc = ui_window_create(ui, &params, &window);
     295        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     296        PCUT_ASSERT_NOT_NULL(window);
     297
     298        rui = ui_window_get_ui(window);
     299        PCUT_ASSERT_EQUALS(ui, rui);
     300
     301        ui_window_destroy(window);
     302        ui_destroy(ui);
     303}
     304
    260305/** ui_window_get_res/gc/rect() return valid objects */
    261306PCUT_TEST(get_res_gc_rect)
     
    495540        resp.unfocus = false;
    496541
    497         ui_window_def_unfocus(window);
     542        ui_window_def_unfocus(window, 42);
    498543        PCUT_ASSERT_TRUE(resp.unfocus);
     544        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    499545
    500546        /* Need to remove first because we didn't implement the destructor */
    501547        ui_window_remove(window, control);
     548
     549        ui_window_destroy(window);
     550        ui_destroy(ui);
     551}
     552
     553/** ui_window_send_sysmenu() calls sysmenu callback set via ui_window_set_cb() */
     554PCUT_TEST(send_sysmenu)
     555{
     556        errno_t rc;
     557        ui_t *ui = NULL;
     558        ui_wnd_params_t params;
     559        ui_window_t *window = NULL;
     560        test_cb_resp_t resp;
     561
     562        rc = ui_create_disp(NULL, &ui);
     563        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     564
     565        ui_wnd_params_init(&params);
     566        params.caption = "Hello";
     567
     568        rc = ui_window_create(ui, &params, &window);
     569        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     570        PCUT_ASSERT_NOT_NULL(window);
     571
     572        /* Sysmenu callback with no callbacks set */
     573        ui_window_send_sysmenu(window, 42);
     574
     575        /* Sysmenu callback with sysmenu callback not implemented */
     576        ui_window_set_cb(window, &dummy_window_cb, NULL);
     577        ui_window_send_sysmenu(window, 42);
     578
     579        /* Sysmenu callback with real callback set */
     580        resp.sysmenu = false;
     581        resp.sysmenu_idev_id = 0;
     582        ui_window_set_cb(window, &test_window_cb, &resp);
     583        ui_window_send_sysmenu(window, 42);
     584        PCUT_ASSERT_TRUE(resp.sysmenu);
     585        PCUT_ASSERT_INT_EQUALS(42, resp.sysmenu_idev_id);
     586
     587        ui_window_destroy(window);
     588        ui_destroy(ui);
     589}
     590
     591/** ui_window_send_minimize() calls minimize callback set via ui_window_set_cb() */
     592PCUT_TEST(send_minimize)
     593{
     594        errno_t rc;
     595        ui_t *ui = NULL;
     596        ui_wnd_params_t params;
     597        ui_window_t *window = NULL;
     598        test_cb_resp_t resp;
     599
     600        rc = ui_create_disp(NULL, &ui);
     601        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     602
     603        ui_wnd_params_init(&params);
     604        params.caption = "Hello";
     605
     606        rc = ui_window_create(ui, &params, &window);
     607        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     608        PCUT_ASSERT_NOT_NULL(window);
     609
     610        /* Minimize callback with no callbacks set */
     611        ui_window_send_minimize(window);
     612
     613        /* Minimize callback with minimize callback not implemented */
     614        ui_window_set_cb(window, &dummy_window_cb, NULL);
     615        ui_window_send_minimize(window);
     616
     617        /* Minimize callback with real callback set */
     618        resp.minimize = false;
     619        ui_window_set_cb(window, &test_window_cb, &resp);
     620        ui_window_send_minimize(window);
     621        PCUT_ASSERT_TRUE(resp.minimize);
     622
     623        ui_window_destroy(window);
     624        ui_destroy(ui);
     625}
     626
     627/** ui_window_send_maximize() calls maximize callback set via ui_window_set_cb() */
     628PCUT_TEST(send_maximize)
     629{
     630        errno_t rc;
     631        ui_t *ui = NULL;
     632        ui_wnd_params_t params;
     633        ui_window_t *window = NULL;
     634        test_cb_resp_t resp;
     635
     636        rc = ui_create_disp(NULL, &ui);
     637        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     638
     639        ui_wnd_params_init(&params);
     640        params.caption = "Hello";
     641
     642        rc = ui_window_create(ui, &params, &window);
     643        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     644        PCUT_ASSERT_NOT_NULL(window);
     645
     646        /* Maximize callback with no callbacks set */
     647        ui_window_send_maximize(window);
     648
     649        /* Maximize callback with maximize callback not implemented */
     650        ui_window_set_cb(window, &dummy_window_cb, NULL);
     651        ui_window_send_maximize(window);
     652
     653        /* Maximize callback with real callback set */
     654        resp.maximize = false;
     655        ui_window_set_cb(window, &test_window_cb, &resp);
     656        ui_window_send_maximize(window);
     657        PCUT_ASSERT_TRUE(resp.maximize);
     658
     659        ui_window_destroy(window);
     660        ui_destroy(ui);
     661}
     662
     663/** ui_window_send_unmaximize() calls unmaximize callback set via ui_window_set_cb() */
     664PCUT_TEST(send_unmaximize)
     665{
     666        errno_t rc;
     667        ui_t *ui = NULL;
     668        ui_wnd_params_t params;
     669        ui_window_t *window = NULL;
     670        test_cb_resp_t resp;
     671
     672        rc = ui_create_disp(NULL, &ui);
     673        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     674
     675        ui_wnd_params_init(&params);
     676        params.caption = "Hello";
     677
     678        rc = ui_window_create(ui, &params, &window);
     679        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     680        PCUT_ASSERT_NOT_NULL(window);
     681
     682        /* Unmaximize callback with no callbacks set */
     683        ui_window_send_unmaximize(window);
     684
     685        /* Unmaximize callback with unmaximize callback not implemented */
     686        ui_window_set_cb(window, &dummy_window_cb, NULL);
     687        ui_window_send_unmaximize(window);
     688
     689        /* Unmaximize callback with real callback set */
     690        resp.unmaximize = false;
     691        ui_window_set_cb(window, &test_window_cb, &resp);
     692        ui_window_send_unmaximize(window);
     693        PCUT_ASSERT_TRUE(resp.unmaximize);
    502694
    503695        ui_window_destroy(window);
     
    561753
    562754        /* Focus callback with no callbacks set */
    563         ui_window_send_focus(window);
     755        ui_window_send_focus(window, 42);
    564756
    565757        /* Focus callback with focus callback not implemented */
    566758        ui_window_set_cb(window, &dummy_window_cb, NULL);
    567         ui_window_send_focus(window);
     759        ui_window_send_focus(window, 42);
    568760
    569761        /* Focus callback with real callback set */
    570762        resp.focus = false;
    571763        ui_window_set_cb(window, &test_window_cb, &resp);
    572         ui_window_send_focus(window);
     764        ui_window_send_focus(window, 42);
    573765        PCUT_ASSERT_TRUE(resp.focus);
     766        PCUT_ASSERT_INT_EQUALS(42, resp.focus_nfocus);
    574767
    575768        ui_window_destroy(window);
     
    597790        PCUT_ASSERT_NOT_NULL(window);
    598791
    599         kbd_event.type = POS_PRESS;
     792        kbd_event.type = KEY_PRESS;
    600793        kbd_event.key = KC_X;
    601794        kbd_event.mods = 0;
     
    729922
    730923        /* Unfocus callback with no callbacks set */
    731         ui_window_send_unfocus(window);
     924        ui_window_send_unfocus(window, 42);
    732925
    733926        /* Unfocus callback with unfocus callback not implemented */
    734927        ui_window_set_cb(window, &dummy_window_cb, NULL);
    735         ui_window_send_unfocus(window);
     928        ui_window_send_unfocus(window, 42);
    736929
    737930        /* Unfocus callback with real callback set */
    738931        resp.close = false;
    739932        ui_window_set_cb(window, &test_window_cb, &resp);
    740         ui_window_send_unfocus(window);
     933        ui_window_send_unfocus(window, 42);
    741934        PCUT_ASSERT_TRUE(resp.unfocus);
    742 
    743         ui_window_destroy(window);
    744         ui_destroy(ui);
     935        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
     936
     937        ui_window_destroy(window);
     938        ui_destroy(ui);
     939}
     940
     941/** ui_window_send_resize() calls resize callback set via ui_window_set_cb() */
     942PCUT_TEST(send_resize)
     943{
     944        errno_t rc;
     945        ui_t *ui = NULL;
     946        ui_wnd_params_t params;
     947        ui_window_t *window = NULL;
     948        test_cb_resp_t resp;
     949
     950        rc = ui_create_disp(NULL, &ui);
     951        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     952
     953        ui_wnd_params_init(&params);
     954        params.caption = "Hello";
     955
     956        rc = ui_window_create(ui, &params, &window);
     957        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     958        PCUT_ASSERT_NOT_NULL(window);
     959
     960        /* Resize callback with no callbacks set */
     961        ui_window_send_resize(window);
     962
     963        /* Resize callback with resize callback not implemented */
     964        ui_window_set_cb(window, &dummy_window_cb, NULL);
     965        ui_window_send_resize(window);
     966
     967        /* Resize callback with real callback set */
     968        resp.close = false;
     969        ui_window_set_cb(window, &test_window_cb, &resp);
     970        ui_window_send_resize(window);
     971        PCUT_ASSERT_TRUE(resp.resize);
     972
     973        ui_window_destroy(window);
     974        ui_destroy(ui);
     975}
     976
     977static void test_window_sysmenu(ui_window_t *window, void *arg, sysarg_t idev_id)
     978{
     979        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     980
     981        resp->sysmenu = true;
     982        resp->sysmenu_idev_id = idev_id;
     983}
     984
     985static void test_window_minimize(ui_window_t *window, void *arg)
     986{
     987        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     988
     989        resp->minimize = true;
     990}
     991
     992static void test_window_maximize(ui_window_t *window, void *arg)
     993{
     994        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     995
     996        resp->maximize = true;
     997}
     998
     999static void test_window_unmaximize(ui_window_t *window, void *arg)
     1000{
     1001        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     1002
     1003        resp->unmaximize = true;
    7451004}
    7461005
     
    7521011}
    7531012
    754 static void test_window_focus(ui_window_t *window, void *arg)
     1013static void test_window_focus(ui_window_t *window, void *arg, unsigned nfocus)
    7551014{
    7561015        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    7571016
    7581017        resp->focus = true;
     1018        resp->focus_nfocus = nfocus;
    7591019}
    7601020
     
    7851045}
    7861046
    787 static void test_window_unfocus(ui_window_t *window, void *arg)
     1047static void test_window_unfocus(ui_window_t *window, void *arg, unsigned nfocus)
    7881048{
    7891049        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    7901050
    7911051        resp->unfocus = true;
     1052        resp->unfocus_nfocus = nfocus;
     1053}
     1054
     1055static void test_window_resize(ui_window_t *window, void *arg)
     1056{
     1057        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     1058
     1059        resp->resize = true;
    7921060}
    7931061
     
    8101078}
    8111079
    812 static void test_ctl_unfocus(void *arg)
     1080static void test_ctl_unfocus(void *arg, unsigned nfocus)
    8131081{
    8141082        test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
    8151083
    8161084        resp->unfocus = true;
     1085        resp->unfocus_nfocus = nfocus;
    8171086}
    8181087
Note: See TracChangeset for help on using the changeset viewer.