Ignore:
File:
1 edited

Legend:

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

    r95a9cbc r1fa6292  
    3333#include <ui/resource.h>
    3434#include "../private/resource.h"
     35#include "../private/testgc.h"
    3536
    3637PCUT_INIT;
     
    3839PCUT_TEST_SUITE(resource);
    3940
    40 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    41     gfx_bitmap_alloc_t *, void **);
    42 static errno_t testgc_bitmap_destroy(void *);
    43 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    44 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    45 
    4641static void test_expose(void *);
    47 
    48 static gfx_context_ops_t ops = {
    49         .bitmap_create = testgc_bitmap_create,
    50         .bitmap_destroy = testgc_bitmap_destroy,
    51         .bitmap_render = testgc_bitmap_render,
    52         .bitmap_get_alloc = testgc_bitmap_get_alloc
    53 };
    54 
    55 typedef struct {
    56         bool bm_created;
    57         bool bm_destroyed;
    58         gfx_bitmap_params_t bm_params;
    59         void *bm_pixels;
    60         gfx_rect_t bm_srect;
    61         gfx_coord2_t bm_offs;
    62         bool bm_rendered;
    63         bool bm_got_alloc;
    64 } test_gc_t;
    65 
    66 typedef struct {
    67         test_gc_t *tgc;
    68         gfx_bitmap_alloc_t alloc;
    69         bool myalloc;
    70 } testgc_bitmap_t;
    7142
    7243typedef struct {
     
    134105}
    135106
    136 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    137     gfx_bitmap_alloc_t *alloc, void **rbm)
    138 {
    139         test_gc_t *tgc = (test_gc_t *) arg;
    140         testgc_bitmap_t *tbm;
    141 
    142         tbm = calloc(1, sizeof(testgc_bitmap_t));
    143         if (tbm == NULL)
    144                 return ENOMEM;
    145 
    146         if (alloc == NULL) {
    147                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    148                     sizeof(uint32_t);
    149                 tbm->alloc.off0 = 0;
    150                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    151                     (params->rect.p1.x - params->rect.p0.x) *
    152                     (params->rect.p1.y - params->rect.p0.y));
    153                 tbm->myalloc = true;
    154                 if (tbm->alloc.pixels == NULL) {
    155                         free(tbm);
    156                         return ENOMEM;
    157                 }
    158         } else {
    159                 tbm->alloc = *alloc;
    160         }
    161 
    162         tbm->tgc = tgc;
    163         tgc->bm_created = true;
    164         tgc->bm_params = *params;
    165         tgc->bm_pixels = tbm->alloc.pixels;
    166         *rbm = (void *)tbm;
    167         return EOK;
    168 }
    169 
    170 static errno_t testgc_bitmap_destroy(void *bm)
    171 {
    172         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    173         if (tbm->myalloc)
    174                 free(tbm->alloc.pixels);
    175         tbm->tgc->bm_destroyed = true;
    176         free(tbm);
    177         return EOK;
    178 }
    179 
    180 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    181     gfx_coord2_t *offs)
    182 {
    183         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    184         tbm->tgc->bm_rendered = true;
    185         tbm->tgc->bm_srect = *srect;
    186         tbm->tgc->bm_offs = *offs;
    187         return EOK;
    188 }
    189 
    190 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    191 {
    192         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    193         *alloc = tbm->alloc;
    194         tbm->tgc->bm_got_alloc = true;
    195         return EOK;
     107/** ui_resource_get_font() returns the font */
     108PCUT_TEST(get_font)
     109{
     110        errno_t rc;
     111        gfx_context_t *gc = NULL;
     112        test_gc_t tgc;
     113        ui_resource_t *resource = NULL;
     114        gfx_font_t *font;
     115
     116        memset(&tgc, 0, sizeof(tgc));
     117        rc = gfx_context_new(&ops, &tgc, &gc);
     118        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     119
     120        rc = ui_resource_create(gc, false, &resource);
     121        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     122        PCUT_ASSERT_NOT_NULL(resource);
     123
     124        font = ui_resource_get_font(resource);
     125        PCUT_ASSERT_EQUALS(resource->font, font);
     126
     127        ui_resource_destroy(resource);
     128
     129        rc = gfx_context_delete(gc);
     130        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     131}
     132
     133/** ui_resource_is_textmode() returns the textmode flag */
     134PCUT_TEST(is_textmode)
     135{
     136        errno_t rc;
     137        gfx_context_t *gc = NULL;
     138        test_gc_t tgc;
     139        ui_resource_t *resource = NULL;
     140
     141        memset(&tgc, 0, sizeof(tgc));
     142        rc = gfx_context_new(&ops, &tgc, &gc);
     143        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     144
     145        rc = ui_resource_create(gc, false, &resource);
     146        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     147        PCUT_ASSERT_NOT_NULL(resource);
     148
     149        /* To make sure let's test both true and false case */
     150        resource->textmode = true;
     151        PCUT_ASSERT_TRUE(ui_resource_is_textmode(resource));
     152        resource->textmode = false;
     153        PCUT_ASSERT_FALSE(ui_resource_is_textmode(resource));
     154
     155        ui_resource_destroy(resource);
     156
     157        rc = gfx_context_delete(gc);
     158        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     159}
     160
     161/** ui_resource_get_wnd_face_color() returns window face color */
     162PCUT_TEST(get_wnd_face_color)
     163{
     164        errno_t rc;
     165        gfx_context_t *gc = NULL;
     166        test_gc_t tgc;
     167        ui_resource_t *resource = NULL;
     168        gfx_color_t *color;
     169
     170        memset(&tgc, 0, sizeof(tgc));
     171        rc = gfx_context_new(&ops, &tgc, &gc);
     172        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     173
     174        rc = ui_resource_create(gc, false, &resource);
     175        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     176        PCUT_ASSERT_NOT_NULL(resource);
     177
     178        color = ui_resource_get_wnd_face_color(resource);
     179        PCUT_ASSERT_EQUALS(resource->wnd_face_color, color);
     180
     181        ui_resource_destroy(resource);
     182
     183        rc = gfx_context_delete(gc);
     184        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     185}
     186
     187/** ui_resource_get_wnd_text_color() returns window text color */
     188PCUT_TEST(get_wnd_text_color)
     189{
     190        errno_t rc;
     191        gfx_context_t *gc = NULL;
     192        test_gc_t tgc;
     193        ui_resource_t *resource = NULL;
     194        gfx_color_t *color;
     195
     196        memset(&tgc, 0, sizeof(tgc));
     197        rc = gfx_context_new(&ops, &tgc, &gc);
     198        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     199
     200        rc = ui_resource_create(gc, false, &resource);
     201        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     202        PCUT_ASSERT_NOT_NULL(resource);
     203
     204        color = ui_resource_get_wnd_text_color(resource);
     205        PCUT_ASSERT_EQUALS(resource->wnd_text_color, color);
     206
     207        ui_resource_destroy(resource);
     208
     209        rc = gfx_context_delete(gc);
     210        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    196211}
    197212
Note: See TracChangeset for help on using the changeset viewer.