Changeset 8c772c4 in mainline for uspace/lib/ui/test/label.c


Ignore:
Timestamp:
2020-11-07T22:12:12Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3583ffb
Parents:
d55ab823
Message:

Create UI controls based on UI object instead of based on UI resource

We want to be a bit more generic. Better not expose UI resource
(at least not in this particular case).

File:
1 edited

Legend:

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

    rd55ab823 r8c772c4  
    3434#include <ui/control.h>
    3535#include <ui/label.h>
    36 #include <ui/resource.h>
     36#include <ui/ui.h>
    3737#include "../private/label.h"
    3838
     
    4040
    4141PCUT_TEST_SUITE(label);
    42 
    43 static errno_t testgc_set_color(void *, gfx_color_t *);
    44 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    45 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    46     gfx_bitmap_alloc_t *, void **);
    47 static errno_t testgc_bitmap_destroy(void *);
    48 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    49 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    50 
    51 static gfx_context_ops_t ops = {
    52         .set_color = testgc_set_color,
    53         .fill_rect = testgc_fill_rect,
    54         .bitmap_create = testgc_bitmap_create,
    55         .bitmap_destroy = testgc_bitmap_destroy,
    56         .bitmap_render = testgc_bitmap_render,
    57         .bitmap_get_alloc = testgc_bitmap_get_alloc
    58 };
    59 
    60 typedef struct {
    61         bool bm_created;
    62         bool bm_destroyed;
    63         gfx_bitmap_params_t bm_params;
    64         void *bm_pixels;
    65         gfx_rect_t bm_srect;
    66         gfx_coord2_t bm_offs;
    67         bool bm_rendered;
    68         bool bm_got_alloc;
    69 } test_gc_t;
    70 
    71 typedef struct {
    72         test_gc_t *tgc;
    73         gfx_bitmap_alloc_t alloc;
    74         bool myalloc;
    75 } testgc_bitmap_t;
    7642
    7743typedef struct {
     
    183149{
    184150        errno_t rc;
    185         gfx_context_t *gc = NULL;
    186         test_gc_t tgc;
    187         ui_resource_t *resource = NULL;
     151        ui_t *ui;
    188152        ui_label_t *label;
    189153
    190         memset(&tgc, 0, sizeof(tgc));
    191         rc = gfx_context_new(&ops, &tgc, &gc);
     154        rc = ui_create_disp(NULL, &ui);
    192155        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    193156
    194         rc = ui_resource_create(gc, &resource);
    195         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    196         PCUT_ASSERT_NOT_NULL(resource);
    197 
    198         rc = ui_label_create(resource, "Hello", &label);
     157        rc = ui_label_create(ui, "Hello", &label);
    199158        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    200159
     
    203162
    204163        ui_label_destroy(label);
    205         ui_resource_destroy(resource);
    206 
    207         rc = gfx_context_delete(gc);
    208         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    209 }
    210 
    211 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    212 {
    213         (void) arg;
    214         (void) color;
    215         return EOK;
    216 }
    217 
    218 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    219 {
    220         (void) arg;
    221         (void) rect;
    222         return EOK;
    223 }
    224 
    225 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    226     gfx_bitmap_alloc_t *alloc, void **rbm)
    227 {
    228         test_gc_t *tgc = (test_gc_t *) arg;
    229         testgc_bitmap_t *tbm;
    230 
    231         tbm = calloc(1, sizeof(testgc_bitmap_t));
    232         if (tbm == NULL)
    233                 return ENOMEM;
    234 
    235         if (alloc == NULL) {
    236                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    237                     sizeof(uint32_t);
    238                 tbm->alloc.off0 = 0;
    239                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    240                     (params->rect.p1.x - params->rect.p0.x) *
    241                     (params->rect.p1.y - params->rect.p0.y));
    242                 tbm->myalloc = true;
    243                 if (tbm->alloc.pixels == NULL) {
    244                         free(tbm);
    245                         return ENOMEM;
    246                 }
    247         } else {
    248                 tbm->alloc = *alloc;
    249         }
    250 
    251         tbm->tgc = tgc;
    252         tgc->bm_created = true;
    253         tgc->bm_params = *params;
    254         tgc->bm_pixels = tbm->alloc.pixels;
    255         *rbm = (void *)tbm;
    256         return EOK;
    257 }
    258 
    259 static errno_t testgc_bitmap_destroy(void *bm)
    260 {
    261         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    262         if (tbm->myalloc)
    263                 free(tbm->alloc.pixels);
    264         tbm->tgc->bm_destroyed = true;
    265         free(tbm);
    266         return EOK;
    267 }
    268 
    269 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    270     gfx_coord2_t *offs)
    271 {
    272         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    273         tbm->tgc->bm_rendered = true;
    274         tbm->tgc->bm_srect = *srect;
    275         tbm->tgc->bm_offs = *offs;
    276         return EOK;
    277 }
    278 
    279 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    280 {
    281         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    282         *alloc = tbm->alloc;
    283         tbm->tgc->bm_got_alloc = true;
    284         return EOK;
     164        ui_destroy(ui);
    285165}
    286166
Note: See TracChangeset for help on using the changeset viewer.