Changeset 1fa6292 in mainline for uspace/lib/gfxfont/test/typeface.c


Ignore:
Timestamp:
2025-01-28T14:48:04Z (3 months 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/gfxfont/test/typeface.c

    r97116a2 r1fa6292  
    3232#include <pcut/pcut.h>
    3333#include "../private/typeface.h"
     34#include "../private/testgc.h"
    3435
    3536PCUT_INIT;
    3637
    3738PCUT_TEST_SUITE(typeface);
    38 
    39 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    40 static errno_t testgc_set_color(void *, gfx_color_t *);
    41 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    42 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    43     gfx_bitmap_alloc_t *, void **);
    44 static errno_t testgc_bitmap_destroy(void *);
    45 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    46 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    47 
    48 static gfx_context_ops_t test_ops = {
    49         .set_clip_rect = testgc_set_clip_rect,
    50         .set_color = testgc_set_color,
    51         .fill_rect = testgc_fill_rect,
    52         .bitmap_create = testgc_bitmap_create,
    53         .bitmap_destroy = testgc_bitmap_destroy,
    54         .bitmap_render = testgc_bitmap_render,
    55         .bitmap_get_alloc = testgc_bitmap_get_alloc
    56 };
    57 
    58 typedef struct {
    59         gfx_bitmap_params_t bm_params;
    60         void *bm_pixels;
    61         gfx_rect_t bm_srect;
    62         gfx_coord2_t bm_offs;
    63 } test_gc_t;
    64 
    65 typedef struct {
    66         test_gc_t *tgc;
    67         gfx_bitmap_alloc_t alloc;
    68         bool myalloc;
    69 } testgc_bitmap_t;
    7039
    7140/** Test creating and destroying typeface */
     
    9867}
    9968
    100 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    101 {
    102         return EOK;
    103 }
    104 
    105 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    106 {
    107         return EOK;
    108 }
    109 
    110 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    111 {
    112         return EOK;
    113 }
    114 
    115 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    116     gfx_bitmap_alloc_t *alloc, void **rbm)
    117 {
    118         test_gc_t *tgc = (test_gc_t *) arg;
    119         testgc_bitmap_t *tbm;
    120 
    121         tbm = calloc(1, sizeof(testgc_bitmap_t));
    122         if (tbm == NULL)
    123                 return ENOMEM;
    124 
    125         if (alloc == NULL) {
    126                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    127                     sizeof(uint32_t);
    128                 tbm->alloc.off0 = 0;
    129                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    130                     tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
    131                 tbm->myalloc = true;
    132                 if (tbm->alloc.pixels == NULL) {
    133                         free(tbm);
    134                         return ENOMEM;
    135                 }
    136         } else {
    137                 tbm->alloc = *alloc;
    138         }
    139 
    140         tbm->tgc = tgc;
    141         tgc->bm_params = *params;
    142         tgc->bm_pixels = tbm->alloc.pixels;
    143         *rbm = (void *)tbm;
    144         return EOK;
    145 }
    146 
    147 static errno_t testgc_bitmap_destroy(void *bm)
    148 {
    149         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    150         if (tbm->myalloc)
    151                 free(tbm->alloc.pixels);
    152         free(tbm);
    153         return EOK;
    154 }
    155 
    156 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    157     gfx_coord2_t *offs)
    158 {
    159         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    160         tbm->tgc->bm_srect = *srect;
    161         tbm->tgc->bm_offs = *offs;
    162         return EOK;
    163 }
    164 
    165 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    166 {
    167         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    168         *alloc = tbm->alloc;
    169         return EOK;
    170 }
    171 
    17269PCUT_EXPORT(typeface);
Note: See TracChangeset for help on using the changeset viewer.