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


Ignore:
Timestamp:
2020-11-07T22:12:12Z (5 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/wdecor.c

    rd55ab823 r8c772c4  
    3333#include <stdbool.h>
    3434#include <ui/pbutton.h>
    35 #include <ui/resource.h>
     35#include <ui/ui.h>
    3636#include <ui/wdecor.h>
    3737#include "../private/wdecor.h"
     
    4040
    4141PCUT_TEST_SUITE(wdecor);
    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 };
    5942
    6043static void test_wdecor_close(ui_wdecor_t *, void *);
     
    6851static ui_wdecor_cb_t dummy_wdecor_cb = {
    6952};
    70 
    71 typedef struct {
    72         bool bm_created;
    73         bool bm_destroyed;
    74         gfx_bitmap_params_t bm_params;
    75         void *bm_pixels;
    76         gfx_rect_t bm_srect;
    77         gfx_coord2_t bm_offs;
    78         bool bm_rendered;
    79         bool bm_got_alloc;
    80 } test_gc_t;
    81 
    82 typedef struct {
    83         test_gc_t *tgc;
    84         gfx_bitmap_alloc_t alloc;
    85         bool myalloc;
    86 } testgc_bitmap_t;
    8753
    8854typedef struct {
     
    159125{
    160126        errno_t rc;
    161         gfx_context_t *gc = NULL;
    162         test_gc_t tgc;
    163         ui_resource_t *resource = NULL;
    164         ui_wdecor_t *wdecor;
    165 
    166         memset(&tgc, 0, sizeof(tgc));
    167         rc = gfx_context_new(&ops, &tgc, &gc);
    168         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    169 
    170         rc = ui_resource_create(gc, &resource);
    171         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    172         PCUT_ASSERT_NOT_NULL(resource);
    173 
    174         rc = ui_wdecor_create(resource, "Hello", &wdecor);
     127        ui_t *ui;
     128        ui_wdecor_t *wdecor;
     129
     130        rc = ui_create_disp(NULL, &ui);
     131        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     132
     133        rc = ui_wdecor_create(ui, "Hello", &wdecor);
    175134        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    176135
     
    179138
    180139        ui_wdecor_destroy(wdecor);
    181         ui_resource_destroy(resource);
    182 
    183         rc = gfx_context_delete(gc);
    184         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     140        ui_destroy(ui);
    185141}
    186142
     
    371327}
    372328
    373 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    374 {
    375         (void) arg;
    376         (void) color;
    377         return EOK;
    378 }
    379 
    380 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    381 {
    382         (void) arg;
    383         (void) rect;
    384         return EOK;
    385 }
    386 
    387 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    388     gfx_bitmap_alloc_t *alloc, void **rbm)
    389 {
    390         test_gc_t *tgc = (test_gc_t *) arg;
    391         testgc_bitmap_t *tbm;
    392 
    393         tbm = calloc(1, sizeof(testgc_bitmap_t));
    394         if (tbm == NULL)
    395                 return ENOMEM;
    396 
    397         if (alloc == NULL) {
    398                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    399                     sizeof(uint32_t);
    400                 tbm->alloc.off0 = 0;
    401                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    402                     (params->rect.p1.x - params->rect.p0.x) *
    403                     (params->rect.p1.y - params->rect.p0.y));
    404                 tbm->myalloc = true;
    405                 if (tbm->alloc.pixels == NULL) {
    406                         free(tbm);
    407                         return ENOMEM;
    408                 }
    409         } else {
    410                 tbm->alloc = *alloc;
    411         }
    412 
    413         tbm->tgc = tgc;
    414         tgc->bm_created = true;
    415         tgc->bm_params = *params;
    416         tgc->bm_pixels = tbm->alloc.pixels;
    417         *rbm = (void *)tbm;
    418         return EOK;
    419 }
    420 
    421 static errno_t testgc_bitmap_destroy(void *bm)
    422 {
    423         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    424         if (tbm->myalloc)
    425                 free(tbm->alloc.pixels);
    426         tbm->tgc->bm_destroyed = true;
    427         free(tbm);
    428         return EOK;
    429 }
    430 
    431 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    432     gfx_coord2_t *offs)
    433 {
    434         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    435         tbm->tgc->bm_rendered = true;
    436         tbm->tgc->bm_srect = *srect;
    437         tbm->tgc->bm_offs = *offs;
    438         return EOK;
    439 }
    440 
    441 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    442 {
    443         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    444         *alloc = tbm->alloc;
    445         tbm->tgc->bm_got_alloc = true;
    446         return EOK;
    447 }
    448 
    449329static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg)
    450330{
Note: See TracChangeset for help on using the changeset viewer.