Ignore:
File:
1 edited

Legend:

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

    r297b1b3 r1fa6292  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <ui/resource.h>
    3737#include "../private/checkbox.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(checkbox);
    42 
    43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    44 static errno_t testgc_set_color(void *, gfx_color_t *);
    45 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    46 static errno_t testgc_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static gfx_context_ops_t ops = {
    54         .set_clip_rect = testgc_set_clip_rect,
    55         .set_color = testgc_set_color,
    56         .fill_rect = testgc_fill_rect,
    57         .update = testgc_update,
    58         .bitmap_create = testgc_bitmap_create,
    59         .bitmap_destroy = testgc_bitmap_destroy,
    60         .bitmap_render = testgc_bitmap_render,
    61         .bitmap_get_alloc = testgc_bitmap_get_alloc
    62 };
    6343
    6444static void test_checkbox_switched(ui_checkbox_t *, void *, bool);
     
    7050static ui_checkbox_cb_t dummy_checkbox_cb = {
    7151};
    72 
    73 typedef struct {
    74         bool bm_created;
    75         bool bm_destroyed;
    76         gfx_bitmap_params_t bm_params;
    77         void *bm_pixels;
    78         gfx_rect_t bm_srect;
    79         gfx_coord2_t bm_offs;
    80         bool bm_rendered;
    81         bool bm_got_alloc;
    82 } test_gc_t;
    83 
    84 typedef struct {
    85         test_gc_t *tgc;
    86         gfx_bitmap_alloc_t alloc;
    87         bool myalloc;
    88 } testgc_bitmap_t;
    8952
    9053typedef struct {
     
    151114}
    152115
     116/** Get check box checked returns internal field */
     117PCUT_TEST(get_checked)
     118{
     119        ui_checkbox_t *checkbox;
     120        errno_t rc;
     121
     122        rc = ui_checkbox_create(NULL, "Hello", &checkbox);
     123        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     124
     125        checkbox->checked = false;
     126        PCUT_ASSERT_FALSE(ui_checkbox_get_checked(checkbox));
     127        checkbox->checked = true;
     128        PCUT_ASSERT_TRUE(ui_checkbox_get_checked(checkbox));
     129
     130        ui_checkbox_destroy(checkbox);
     131}
     132
     133/** Set check box checked sets internal field */
     134PCUT_TEST(set_checked)
     135{
     136        ui_checkbox_t *checkbox;
     137        errno_t rc;
     138
     139        rc = ui_checkbox_create(NULL, "Hello", &checkbox);
     140        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     141
     142        ui_checkbox_set_checked(checkbox, true);
     143        PCUT_ASSERT_TRUE(checkbox->checked);
     144        ui_checkbox_set_checked(checkbox, false);
     145        PCUT_ASSERT_FALSE(checkbox->checked);
     146
     147        ui_checkbox_destroy(checkbox);
     148}
     149
    153150/** Paint check box in graphics mode */
    154151PCUT_TEST(paint_gfx)
     
    515512}
    516513
    517 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    518 {
    519         (void) arg;
    520         (void) rect;
    521         return EOK;
    522 }
    523 
    524 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    525 {
    526         (void) arg;
    527         (void) color;
    528         return EOK;
    529 }
    530 
    531 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    532 {
    533         (void) arg;
    534         (void) rect;
    535         return EOK;
    536 }
    537 
    538 static errno_t testgc_update(void *arg)
    539 {
    540         (void) arg;
    541         return EOK;
    542 }
    543 
    544 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    545     gfx_bitmap_alloc_t *alloc, void **rbm)
    546 {
    547         test_gc_t *tgc = (test_gc_t *) arg;
    548         testgc_bitmap_t *tbm;
    549 
    550         tbm = calloc(1, sizeof(testgc_bitmap_t));
    551         if (tbm == NULL)
    552                 return ENOMEM;
    553 
    554         if (alloc == NULL) {
    555                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    556                     sizeof(uint32_t);
    557                 tbm->alloc.off0 = 0;
    558                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    559                     (params->rect.p1.x - params->rect.p0.x) *
    560                     (params->rect.p1.y - params->rect.p0.y));
    561                 tbm->myalloc = true;
    562                 if (tbm->alloc.pixels == NULL) {
    563                         free(tbm);
    564                         return ENOMEM;
    565                 }
    566         } else {
    567                 tbm->alloc = *alloc;
    568         }
    569 
    570         tbm->tgc = tgc;
    571         tgc->bm_created = true;
    572         tgc->bm_params = *params;
    573         tgc->bm_pixels = tbm->alloc.pixels;
    574         *rbm = (void *)tbm;
    575         return EOK;
    576 }
    577 
    578 static errno_t testgc_bitmap_destroy(void *bm)
    579 {
    580         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    581         if (tbm->myalloc)
    582                 free(tbm->alloc.pixels);
    583         tbm->tgc->bm_destroyed = true;
    584         free(tbm);
    585         return EOK;
    586 }
    587 
    588 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    589     gfx_coord2_t *offs)
    590 {
    591         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    592         tbm->tgc->bm_rendered = true;
    593         tbm->tgc->bm_srect = *srect;
    594         tbm->tgc->bm_offs = *offs;
    595         return EOK;
    596 }
    597 
    598 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    599 {
    600         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    601         *alloc = tbm->alloc;
    602         tbm->tgc->bm_got_alloc = true;
    603         return EOK;
    604 }
    605 
    606514static void test_checkbox_switched(ui_checkbox_t *checkbox, void *arg,
    607515    bool checked)
Note: See TracChangeset for help on using the changeset viewer.