Ignore:
File:
1 edited

Legend:

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

    r3c54869 r7470d97  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6363
    6464static void test_pbutton_clicked(ui_pbutton_t *, void *);
    65 static void test_pbutton_down(ui_pbutton_t *, void *);
    66 static void test_pbutton_up(ui_pbutton_t *, void *);
    6765
    6866static ui_pbutton_cb_t test_pbutton_cb = {
    69         .clicked = test_pbutton_clicked,
    70         .down = test_pbutton_down,
    71         .up = test_pbutton_up
     67        .clicked = test_pbutton_clicked
    7268};
    7369
     
    9490typedef struct {
    9591        bool clicked;
    96         bool down;
    97         bool up;
    9892} test_cb_resp_t;
    9993
     
    131125
    132126        ui_control_destroy(control);
    133 }
    134 
    135 /** Set flags sets internal field */
    136 PCUT_TEST(set_flags)
    137 {
    138         ui_pbutton_t *pbutton;
    139         errno_t rc;
    140 
    141         rc = ui_pbutton_create(NULL, "Hello", &pbutton);
    142         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    143 
    144         ui_pbutton_set_flags(pbutton, ui_pbf_no_text_depress);
    145         PCUT_ASSERT_INT_EQUALS(ui_pbf_no_text_depress, pbutton->flags);
    146 
    147         ui_pbutton_destroy(pbutton);
    148127}
    149128
     
    190169}
    191170
    192 /** Get light gets internal field */
    193 PCUT_TEST(get_light)
    194 {
    195         ui_pbutton_t *pbutton;
    196         errno_t rc;
    197 
    198         rc = ui_pbutton_create(NULL, "Hello", &pbutton);
    199         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    200 
    201         pbutton->light = true;
    202         PCUT_ASSERT_TRUE(ui_pbutton_get_light(pbutton));
    203 
    204         pbutton->light = false;
    205         PCUT_ASSERT_FALSE(ui_pbutton_get_light(pbutton));
    206 
    207         ui_pbutton_destroy(pbutton);
    208 }
    209 
    210 /** Set light sets internal field */
    211 PCUT_TEST(set_light)
    212 {
    213         ui_pbutton_t *pbutton;
    214         errno_t rc;
    215 
    216         rc = ui_pbutton_create(NULL, "Hello", &pbutton);
    217         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    218 
    219         ui_pbutton_set_light(pbutton, true);
    220         PCUT_ASSERT_TRUE(pbutton->light);
    221 
    222         ui_pbutton_set_light(pbutton, false);
    223         PCUT_ASSERT_FALSE(pbutton->light);
    224 
    225         ui_pbutton_destroy(pbutton);
    226 }
    227 
    228 /** Set caption sets internal field */
    229 PCUT_TEST(set_caption)
    230 {
    231         ui_pbutton_t *pbutton;
    232         errno_t rc;
    233 
    234         rc = ui_pbutton_create(NULL, "Hello", &pbutton);
    235         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    236 
    237         PCUT_ASSERT_STR_EQUALS("Hello", pbutton->caption);
    238 
    239         rc = ui_pbutton_set_caption(pbutton, "World");
    240         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    241 
    242         PCUT_ASSERT_STR_EQUALS("World", pbutton->caption);
    243 
    244         ui_pbutton_destroy(pbutton);
    245 }
    246 
    247171/** Paint button */
    248172PCUT_TEST(paint)
     
    301225}
    302226
    303 /** Test ui_pbutton_down() */
    304 PCUT_TEST(down)
    305 {
    306         errno_t rc;
    307         ui_pbutton_t *pbutton;
    308         test_cb_resp_t resp;
    309 
    310         rc = ui_pbutton_create(NULL, "Hello", &pbutton);
    311         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    312 
    313         /* Down with no callbacks set */
    314         ui_pbutton_clicked(pbutton);
    315 
    316         /* Down with callback not implementing down */
    317         ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
    318         ui_pbutton_down(pbutton);
    319 
    320         /* Down with real callback set */
    321         resp.down = false;
    322         ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
    323         ui_pbutton_down(pbutton);
    324         PCUT_ASSERT_TRUE(resp.down);
    325 
    326         ui_pbutton_destroy(pbutton);
    327 }
    328 
    329 /** Test ui_pbutton_up() */
    330 PCUT_TEST(up)
    331 {
    332         errno_t rc;
    333         ui_pbutton_t *pbutton;
    334         test_cb_resp_t resp;
    335 
    336         rc = ui_pbutton_create(NULL, "Hello", &pbutton);
    337         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    338 
    339         /* Up with no callbacks set */
    340         ui_pbutton_clicked(pbutton);
    341 
    342         /* Up with callback not implementing up */
    343         ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
    344         ui_pbutton_up(pbutton);
    345 
    346         /* Up with real callback set */
    347         resp.up = false;
    348         ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
    349         ui_pbutton_up(pbutton);
    350         PCUT_ASSERT_TRUE(resp.up);
    351 
    352         ui_pbutton_destroy(pbutton);
    353 }
    354 
    355227/** Press and release button */
    356228PCUT_TEST(press_release)
     
    375247
    376248        resp.clicked = false;
    377         resp.down = false;
    378         resp.up = false;
    379249        ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
    380250
     
    385255        PCUT_ASSERT_TRUE(pbutton->held);
    386256        PCUT_ASSERT_TRUE(pbutton->inside);
    387         PCUT_ASSERT_TRUE(resp.down);
    388         PCUT_ASSERT_FALSE(resp.up);
    389257        PCUT_ASSERT_FALSE(resp.clicked);
    390258
     
    392260        PCUT_ASSERT_FALSE(pbutton->held);
    393261        PCUT_ASSERT_TRUE(pbutton->inside);
    394         PCUT_ASSERT_TRUE(resp.up);
    395262        PCUT_ASSERT_TRUE(resp.clicked);
    396263
     
    721588}
    722589
    723 static void test_pbutton_down(ui_pbutton_t *pbutton, void *arg)
    724 {
    725         test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    726 
    727         resp->down = true;
    728 }
    729 
    730 static void test_pbutton_up(ui_pbutton_t *pbutton, void *arg)
    731 {
    732         test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    733 
    734         resp->up = true;
    735 }
    736 
    737590PCUT_EXPORT(pbutton);
Note: See TracChangeset for help on using the changeset viewer.