Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfx/test/render.c

    r7470d97 r9259d20  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2019 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3232#include <pcut/pcut.h>
    3333#include <mem.h>
    34 #include <stdbool.h>
    3534
    3635PCUT_INIT;
     
    3837PCUT_TEST_SUITE(render);
    3938
    40 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    4139static errno_t testgc_set_color(void *, gfx_color_t *);
    4240static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    43 static errno_t testgc_update(void *);
    4441
    4542static gfx_context_ops_t ops = {
    46         .set_clip_rect = testgc_set_clip_rect,
    4743        .set_color = testgc_set_color,
    48         .fill_rect = testgc_fill_rect,
    49         .update = testgc_update
     44        .fill_rect = testgc_fill_rect
    5045};
    5146
    5247/** Test graphics context data */
    5348typedef struct {
    54         errno_t rc;
    55 
    56         bool set_clip_rect;
    57         gfx_rect_t crect;
    58         bool do_clip;
    59 
    60         bool set_color;
    6149        gfx_color_t *dclr;
    62 
    63         bool fill_rect;
    64         gfx_rect_t frect;
    65 
    66         bool update;
     50        gfx_rect_t *rect;
    6751} test_gc_t;
    6852
    69 /** Set clipping rectangle */
    70 PCUT_TEST(set_clip_rect)
    71 {
    72         errno_t rc;
    73         gfx_rect_t rect;
    74         gfx_context_t *gc = NULL;
    75         test_gc_t tgc;
    76 
    77         memset(&tgc, 0, sizeof(tgc));
    78 
    79         rc = gfx_context_new(&ops, &tgc, &gc);
    80         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    81 
    82         rect.p0.x = 1;
    83         rect.p0.y = 2;
    84         rect.p1.x = 3;
    85         rect.p1.y = 4;
    86 
    87         tgc.rc = EOK;
    88 
    89         rc = gfx_set_clip_rect(gc, &rect);
    90         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    91 
    92         PCUT_ASSERT_TRUE(tgc.set_clip_rect);
    93         PCUT_ASSERT_TRUE(tgc.do_clip);
    94         PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc.crect.p0.x);
    95         PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc.crect.p0.y);
    96         PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc.crect.p1.x);
    97         PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc.crect.p1.y);
    98 
    99         rc = gfx_context_delete(gc);
    100         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    101 }
    102 
    103 /** Set null clipping rectangle */
    104 PCUT_TEST(set_clip_rect_null)
    105 {
    106         errno_t rc;
    107         gfx_context_t *gc = NULL;
    108         test_gc_t tgc;
    109 
    110         memset(&tgc, 0, sizeof(tgc));
    111 
    112         rc = gfx_context_new(&ops, &tgc, &gc);
    113         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    114 
    115         tgc.rc = EOK;
    116 
    117         rc = gfx_set_clip_rect(gc, NULL);
    118         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    119 
    120         PCUT_ASSERT_TRUE(tgc.set_clip_rect);
    121         PCUT_ASSERT_FALSE(tgc.do_clip);
    122 
    123         rc = gfx_context_delete(gc);
    124         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    125 }
    126 
    127 /** Set clipping rectangle with error return */
    128 PCUT_TEST(set_clip_rect_failure)
    129 {
    130         errno_t rc;
    131         gfx_rect_t rect;
    132         gfx_context_t *gc = NULL;
    133         test_gc_t tgc;
    134 
    135         memset(&tgc, 0, sizeof(tgc));
    136 
    137         rc = gfx_context_new(&ops, &tgc, &gc);
    138         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    139 
    140         tgc.rc = EIO;
    141 
    142         rc = gfx_set_clip_rect(gc, &rect);
    143         PCUT_ASSERT_ERRNO_VAL(EIO, rc);
    144 
    145         rc = gfx_context_delete(gc);
    146         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    147 }
    148 
    149 /** Set drawing color */
    15053PCUT_TEST(set_color)
    151 {
    152         errno_t rc;
    153         gfx_color_t *color;
    154         gfx_context_t *gc = NULL;
    155         uint16_t r, g, b;
    156         test_gc_t tgc;
    157 
    158         memset(&tgc, 0, sizeof(tgc));
    159 
    160         rc = gfx_context_new(&ops, &tgc, &gc);
    161         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    162 
    163         rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
    164         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    165 
    166         PCUT_ASSERT_FALSE(tgc.set_color);
    167 
    168         tgc.rc = EOK;
    169 
    170         rc = gfx_set_color(gc, color);
    171         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    172 
    173         PCUT_ASSERT_TRUE(tgc.set_color);
    174 
    175         gfx_color_get_rgb_i16(tgc.dclr, &r, &g, &b);
    176 
    177         PCUT_ASSERT_INT_EQUALS(0xffff, r);
    178         PCUT_ASSERT_INT_EQUALS(0xffff, g);
    179         PCUT_ASSERT_INT_EQUALS(0xffff, b);
    180 
    181         rc = gfx_context_delete(gc);
    182         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    183 }
    184 
    185 /** Set drawing color with error return */
    186 PCUT_TEST(set_color_failure)
    18754{
    18855        errno_t rc;
     
    19966        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    20067
    201         PCUT_ASSERT_FALSE(tgc.set_color);
    202 
    203         tgc.rc = EIO;
    204 
    20568        rc = gfx_set_color(gc, color);
    206         PCUT_ASSERT_ERRNO_VAL(EIO, rc);
     69        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     70        PCUT_ASSERT_EQUALS(color, tgc.dclr);
     71        PCUT_ASSERT_NULL(tgc.rect);
    20772
    20873        gfx_color_delete(color);
     
    21277}
    21378
    214 /** Fill rectangle */
    21579PCUT_TEST(fill_rect)
    21680{
    21781        errno_t rc;
     82        gfx_color_t *color;
    21883        gfx_rect_t rect;
    21984        gfx_context_t *gc = NULL;
     
    22590        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    22691
    227         rect.p0.x = 1;
    228         rect.p0.y = 2;
    229         rect.p1.x = 3;
    230         rect.p1.y = 4;
     92        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     93        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    23194
    232         PCUT_ASSERT_FALSE(tgc.fill_rect);
    233 
    234         tgc.rc = EOK;
     95        rc = gfx_set_color(gc, color);
     96        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     97        PCUT_ASSERT_EQUALS(color, tgc.dclr);
    23598
    23699        rc = gfx_fill_rect(gc, &rect);
    237100        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     101        PCUT_ASSERT_EQUALS(&rect, tgc.rect);
    238102
    239         PCUT_ASSERT_TRUE(tgc.fill_rect);
    240         PCUT_ASSERT_INT_EQUALS(rect.p0.x, tgc.frect.p0.x);
    241         PCUT_ASSERT_INT_EQUALS(rect.p0.y, tgc.frect.p0.y);
    242         PCUT_ASSERT_INT_EQUALS(rect.p1.x, tgc.frect.p1.x);
    243         PCUT_ASSERT_INT_EQUALS(rect.p1.y, tgc.frect.p1.y);
     103        gfx_color_delete(color);
    244104
    245105        rc = gfx_context_delete(gc);
    246106        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    247 }
    248 
    249 /** Fill rectangle with error return */
    250 PCUT_TEST(fill_rect_failure)
    251 {
    252         errno_t rc;
    253         gfx_rect_t rect;
    254         gfx_context_t *gc = NULL;
    255         test_gc_t tgc;
    256 
    257         memset(&tgc, 0, sizeof(tgc));
    258 
    259         rc = gfx_context_new(&ops, &tgc, &gc);
    260         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    261 
    262         rect.p0.x = 1;
    263         rect.p0.y = 2;
    264         rect.p1.x = 3;
    265         rect.p1.y = 4;
    266 
    267         PCUT_ASSERT_FALSE(tgc.fill_rect);
    268 
    269         tgc.rc = EIO;
    270 
    271         rc = gfx_fill_rect(gc, &rect);
    272         PCUT_ASSERT_ERRNO_VAL(EIO, rc);
    273 
    274         rc = gfx_context_delete(gc);
    275         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    276 }
    277 
    278 /** Update GC */
    279 PCUT_TEST(update)
    280 {
    281         errno_t rc;
    282         gfx_context_t *gc = NULL;
    283         test_gc_t tgc;
    284 
    285         memset(&tgc, 0, sizeof(tgc));
    286 
    287         rc = gfx_context_new(&ops, &tgc, &gc);
    288         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    289 
    290         tgc.rc = EOK;
    291 
    292         PCUT_ASSERT_FALSE(tgc.update);
    293         rc = gfx_update(gc);
    294         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    295         PCUT_ASSERT_TRUE(tgc.update);
    296 
    297         rc = gfx_context_delete(gc);
    298         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    299 }
    300 
    301 /** Update GC with error return */
    302 PCUT_TEST(update_failure)
    303 {
    304         errno_t rc;
    305         gfx_context_t *gc = NULL;
    306         test_gc_t tgc;
    307 
    308         memset(&tgc, 0, sizeof(tgc));
    309 
    310         rc = gfx_context_new(&ops, &tgc, &gc);
    311         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    312 
    313         tgc.rc = EIO;
    314         rc = gfx_update(gc);
    315 
    316         PCUT_ASSERT_ERRNO_VAL(EIO, rc);
    317 
    318         rc = gfx_context_delete(gc);
    319         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    320 }
    321 
    322 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    323 {
    324         test_gc_t *tgc = (test_gc_t *) arg;
    325 
    326         tgc->set_clip_rect = true;
    327         if (rect != NULL) {
    328                 tgc->do_clip = true;
    329                 tgc->crect = *rect;
    330         } else {
    331                 tgc->do_clip = false;
    332         }
    333 
    334         return tgc->rc;
    335107}
    336108
     
    339111        test_gc_t *tgc = (test_gc_t *) arg;
    340112
    341         tgc->set_color = true;
    342 
    343113        /* Technically we should copy the data */
    344114        tgc->dclr = color;
    345         return tgc->rc;
     115        return EOK;
    346116}
    347117
     
    350120        test_gc_t *tgc = (test_gc_t *) arg;
    351121
    352         tgc->fill_rect = true;
    353         tgc->frect = *rect;
    354         return tgc->rc;
    355 }
    356 
    357 static errno_t testgc_update(void *arg)
    358 {
    359         test_gc_t *tgc = (test_gc_t *) arg;
    360 
    361         tgc->update = true;
    362         return tgc->rc;
     122        /* Technically we should copy the data */
     123        tgc->rect = rect;
     124        return EOK;
    363125}
    364126
Note: See TracChangeset for help on using the changeset viewer.