Changeset 1fa6292 in mainline for uspace/lib/ui/test/rbutton.c


Ignore:
Timestamp:
2025-01-28T14:48:04Z (3 weeks ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
56210a7
Parents:
97116a2
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-01-28 14:46:24)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-01-28 14:48:04)
Message:

Remove a ton of duplicated code in libui/libgfxfont tests

File:
1 edited

Legend:

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

    r97116a2 r1fa6292  
    3636#include <ui/resource.h>
    3737#include "../private/rbutton.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(rbutton);
    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_rbutton_select(ui_rbutton_group_t *, void *, void *);
     
    7050static ui_rbutton_group_cb_t dummy_rbutton_group_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 {
     
    592555}
    593556
    594 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    595 {
    596         (void) arg;
    597         (void) rect;
    598         return EOK;
    599 }
    600 
    601 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    602 {
    603         (void) arg;
    604         (void) color;
    605         return EOK;
    606 }
    607 
    608 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    609 {
    610         (void) arg;
    611         (void) rect;
    612         return EOK;
    613 }
    614 
    615 static errno_t testgc_update(void *arg)
    616 {
    617         (void) arg;
    618         return EOK;
    619 }
    620 
    621 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    622     gfx_bitmap_alloc_t *alloc, void **rbm)
    623 {
    624         test_gc_t *tgc = (test_gc_t *) arg;
    625         testgc_bitmap_t *tbm;
    626 
    627         tbm = calloc(1, sizeof(testgc_bitmap_t));
    628         if (tbm == NULL)
    629                 return ENOMEM;
    630 
    631         if (alloc == NULL) {
    632                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    633                     sizeof(uint32_t);
    634                 tbm->alloc.off0 = 0;
    635                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    636                     (params->rect.p1.x - params->rect.p0.x) *
    637                     (params->rect.p1.y - params->rect.p0.y));
    638                 tbm->myalloc = true;
    639                 if (tbm->alloc.pixels == NULL) {
    640                         free(tbm);
    641                         return ENOMEM;
    642                 }
    643         } else {
    644                 tbm->alloc = *alloc;
    645         }
    646 
    647         tbm->tgc = tgc;
    648         tgc->bm_created = true;
    649         tgc->bm_params = *params;
    650         tgc->bm_pixels = tbm->alloc.pixels;
    651         *rbm = (void *)tbm;
    652         return EOK;
    653 }
    654 
    655 static errno_t testgc_bitmap_destroy(void *bm)
    656 {
    657         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    658         if (tbm->myalloc)
    659                 free(tbm->alloc.pixels);
    660         tbm->tgc->bm_destroyed = true;
    661         free(tbm);
    662         return EOK;
    663 }
    664 
    665 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    666     gfx_coord2_t *offs)
    667 {
    668         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    669         tbm->tgc->bm_rendered = true;
    670         tbm->tgc->bm_srect = *srect;
    671         tbm->tgc->bm_offs = *offs;
    672         return EOK;
    673 }
    674 
    675 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    676 {
    677         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    678         *alloc = tbm->alloc;
    679         tbm->tgc->bm_got_alloc = true;
    680         return EOK;
    681 }
    682 
    683557static void test_rbutton_select(ui_rbutton_group_t *group, void *arg,
    684558    void *barg)
Note: See TracChangeset for help on using the changeset viewer.