Ignore:
File:
1 edited

Legend:

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

    rcde067e r3d10a2f  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4545PCUT_TEST_SUITE(window);
    4646
    47 static void test_window_sysmenu(ui_window_t *, void *, sysarg_t);
    48 static void test_window_minimize(ui_window_t *, void *);
    49 static void test_window_maximize(ui_window_t *, void *);
    50 static void test_window_unmaximize(ui_window_t *, void *);
    5147static void test_window_close(ui_window_t *, void *);
    52 static void test_window_focus(ui_window_t *, void *, unsigned);
     48static void test_window_focus(ui_window_t *, void *);
    5349static void test_window_kbd(ui_window_t *, void *, kbd_event_t *);
    5450static errno_t test_window_paint(ui_window_t *, void *);
    5551static void test_window_pos(ui_window_t *, void *, pos_event_t *);
    56 static void test_window_unfocus(ui_window_t *, void *, unsigned);
    57 static void test_window_resize(ui_window_t *, void *);
     52static void test_window_unfocus(ui_window_t *, void *);
    5853
    5954static 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,
    6455        .close = test_window_close,
    6556        .focus = test_window_focus,
     
    6758        .paint = test_window_paint,
    6859        .pos = test_window_pos,
    69         .unfocus = test_window_unfocus,
    70         .resize = test_window_resize
     60        .unfocus = test_window_unfocus
    7161};
    7262
     
    7666static errno_t test_ctl_paint(void *);
    7767static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    78 static void test_ctl_unfocus(void *, unsigned);
     68static void test_ctl_unfocus(void *);
    7969
    8070static ui_control_ops_t test_ctl_ops = {
     
    8676typedef struct {
    8777        errno_t rc;
    88         bool sysmenu;
    89         sysarg_t sysmenu_idev_id;
    90         bool minimize;
    91         bool maximize;
    92         bool unmaximize;
    9378        bool close;
    9479        bool focus;
    95         unsigned focus_nfocus;
    9680        bool kbd;
    9781        kbd_event_t kbd_event;
     
    10084        pos_event_t pos_event;
    10185        bool unfocus;
    102         unsigned unfocus_nfocus;
    103         bool resize;
    10486} test_cb_resp_t;
    10587
     
    11193        pos_event_t pos_event;
    11294        bool unfocus;
    113         unsigned unfocus_nfocus;
    11495} test_ctl_resp_t;
    11596
     
    540521        resp.unfocus = false;
    541522
    542         ui_window_def_unfocus(window, 42);
     523        ui_window_def_unfocus(window);
    543524        PCUT_ASSERT_TRUE(resp.unfocus);
    544         PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    545525
    546526        /* Need to remove first because we didn't implement the destructor */
    547527        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() */
    554 PCUT_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() */
    592 PCUT_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() */
    628 PCUT_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() */
    664 PCUT_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);
    694528
    695529        ui_window_destroy(window);
     
    753587
    754588        /* Focus callback with no callbacks set */
    755         ui_window_send_focus(window, 42);
     589        ui_window_send_focus(window);
    756590
    757591        /* Focus callback with focus callback not implemented */
    758592        ui_window_set_cb(window, &dummy_window_cb, NULL);
    759         ui_window_send_focus(window, 42);
     593        ui_window_send_focus(window);
    760594
    761595        /* Focus callback with real callback set */
    762596        resp.focus = false;
    763597        ui_window_set_cb(window, &test_window_cb, &resp);
    764         ui_window_send_focus(window, 42);
     598        ui_window_send_focus(window);
    765599        PCUT_ASSERT_TRUE(resp.focus);
    766         PCUT_ASSERT_INT_EQUALS(42, resp.focus_nfocus);
    767600
    768601        ui_window_destroy(window);
     
    790623        PCUT_ASSERT_NOT_NULL(window);
    791624
    792         kbd_event.type = KEY_PRESS;
     625        kbd_event.type = POS_PRESS;
    793626        kbd_event.key = KC_X;
    794627        kbd_event.mods = 0;
     
    922755
    923756        /* Unfocus callback with no callbacks set */
    924         ui_window_send_unfocus(window, 42);
     757        ui_window_send_unfocus(window);
    925758
    926759        /* Unfocus callback with unfocus callback not implemented */
    927760        ui_window_set_cb(window, &dummy_window_cb, NULL);
    928         ui_window_send_unfocus(window, 42);
     761        ui_window_send_unfocus(window);
    929762
    930763        /* Unfocus callback with real callback set */
    931764        resp.close = false;
    932765        ui_window_set_cb(window, &test_window_cb, &resp);
    933         ui_window_send_unfocus(window, 42);
     766        ui_window_send_unfocus(window);
    934767        PCUT_ASSERT_TRUE(resp.unfocus);
    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() */
    942 PCUT_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 
    977 static void test_window_sysmenu(ui_window_t *window, void *arg, sysarg_t idev_id)
     768
     769        ui_window_destroy(window);
     770        ui_destroy(ui);
     771}
     772
     773static void test_window_close(ui_window_t *window, void *arg)
    978774{
    979775        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    980776
    981         resp->sysmenu = true;
    982         resp->sysmenu_idev_id = idev_id;
    983 }
    984 
    985 static void test_window_minimize(ui_window_t *window, void *arg)
     777        resp->close = true;
     778}
     779
     780static void test_window_focus(ui_window_t *window, void *arg)
    986781{
    987782        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    988783
    989         resp->minimize = true;
    990 }
    991 
    992 static 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 
    999 static 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;
    1004 }
    1005 
    1006 static void test_window_close(ui_window_t *window, void *arg)
    1007 {
    1008         test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    1009 
    1010         resp->close = true;
    1011 }
    1012 
    1013 static void test_window_focus(ui_window_t *window, void *arg, unsigned nfocus)
    1014 {
    1015         test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    1016 
    1017784        resp->focus = true;
    1018         resp->focus_nfocus = nfocus;
    1019785}
    1020786
     
    1045811}
    1046812
    1047 static void test_window_unfocus(ui_window_t *window, void *arg, unsigned nfocus)
     813static void test_window_unfocus(ui_window_t *window, void *arg)
    1048814{
    1049815        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    1050816
    1051817        resp->unfocus = true;
    1052         resp->unfocus_nfocus = nfocus;
    1053 }
    1054 
    1055 static 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;
    1060818}
    1061819
     
    1078836}
    1079837
    1080 static void test_ctl_unfocus(void *arg, unsigned nfocus)
     838static void test_ctl_unfocus(void *arg)
    1081839{
    1082840        test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
    1083841
    1084842        resp->unfocus = true;
    1085         resp->unfocus_nfocus = nfocus;
    1086843}
    1087844
Note: See TracChangeset for help on using the changeset viewer.