Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/test/text.c

    r9eb8d12 r1fa6292  
    3636#include "../private/font.h"
    3737#include "../private/typeface.h"
     38#include "../private/testgc.h"
    3839
    3940PCUT_INIT;
    4041
    4142PCUT_TEST_SUITE(text);
    42 
    43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    44 static errno_t testgc_set_color(void *, gfx_color_t *);
    45 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    46 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    47     gfx_bitmap_alloc_t *, void **);
    48 static errno_t testgc_bitmap_destroy(void *);
    49 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    50 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    51 
    52 static gfx_context_ops_t test_ops = {
    53         .set_clip_rect = testgc_set_clip_rect,
    54         .set_color = testgc_set_color,
    55         .fill_rect = testgc_fill_rect,
    56         .bitmap_create = testgc_bitmap_create,
    57         .bitmap_destroy = testgc_bitmap_destroy,
    58         .bitmap_render = testgc_bitmap_render,
    59         .bitmap_get_alloc = testgc_bitmap_get_alloc
    60 };
    61 
    62 typedef struct {
    63         gfx_bitmap_params_t bm_params;
    64         void *bm_pixels;
    65         gfx_rect_t bm_srect;
    66         gfx_coord2_t bm_offs;
    67 } test_gc_t;
    68 
    69 typedef struct {
    70         test_gc_t *tgc;
    71         gfx_bitmap_alloc_t alloc;
    72         bool myalloc;
    73 } testgc_bitmap_t;
    7443
    7544/** Test text width computation with a dummy font */
     
    135104
    136105        gfx_text_fmt_init(&fmt);
     106        fmt.font = font;
    137107        fmt.color = color;
    138108        pos.x = 0;
    139109        pos.y = 0;
    140110
    141         rc = gfx_puttext(font, &pos, &fmt, "Hello world!");
     111        rc = gfx_puttext(&pos, &fmt, "Hello world!");
    142112        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    143113
     
    181151
    182152        gfx_text_fmt_init(&fmt);
     153        fmt.font = font;
    183154        fmt.color = color;
    184155        pos.x = 0;
    185156        pos.y = 0;
    186157
    187         rc = gfx_puttext(font, &pos, &fmt, "Hello world!");
     158        rc = gfx_puttext(&pos, &fmt, "Hello world!");
    188159        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    189160
     
    245216
    246217        gfx_text_fmt_init(&fmt);
     218        fmt.font = font;
    247219        anchor.x = 10;
    248220        anchor.y = 0;
     
    250222        fpos.x = 9;
    251223        fpos.y = 0;
    252         off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
     224        off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
    253225        PCUT_ASSERT_INT_EQUALS(0, off);
    254226
    255227        fpos.x = 10;
    256228        fpos.y = 0;
    257         off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
     229        off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
    258230        PCUT_ASSERT_INT_EQUALS(0, off);
    259231
    260232        fpos.x = 11;
    261233        fpos.y = 0;
    262         off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
     234        off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
    263235        PCUT_ASSERT_INT_EQUALS(0, off);
    264236
    265237        fpos.x = 19;
    266238        fpos.y = 0;
    267         off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
     239        off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
    268240        PCUT_ASSERT_INT_EQUALS(1, off);
    269241
    270242        fpos.x = 20;
    271243        fpos.y = 0;
    272         off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
     244        off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
    273245        PCUT_ASSERT_INT_EQUALS(2, off);
    274246
    275247        fpos.x = 21;
    276248        fpos.y = 0;
    277         off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
     249        off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
    278250        PCUT_ASSERT_INT_EQUALS(3, off);
    279251
    280252        fpos.x = 22;
    281253        fpos.y = 0;
    282         off = gfx_text_find_pos(font, &anchor, &fmt, "Aii", &fpos);
     254        off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos);
    283255        PCUT_ASSERT_INT_EQUALS(3, off);
    284256
     
    318290        anchor.y = 0;
    319291        gfx_text_fmt_init(&fmt);
     292        fmt.font = font;
    320293
    321294        fpos.x = 9;
    322295        fpos.y = 0;
    323         off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
     296        off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
    324297        PCUT_ASSERT_INT_EQUALS(0, off);
    325298
    326299        fpos.x = 10;
    327300        fpos.y = 0;
    328         off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
     301        off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
    329302        PCUT_ASSERT_INT_EQUALS(0, off);
    330303
    331304        fpos.x = 11;
    332305        fpos.y = 0;
    333         off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
     306        off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
    334307        PCUT_ASSERT_INT_EQUALS(1, off);
    335308
    336309        fpos.x = 12;
    337310        fpos.y = 0;
    338         off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
     311        off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
    339312        PCUT_ASSERT_INT_EQUALS(2, off);
    340313
    341314        fpos.x = 13;
    342315        fpos.y = 0;
    343         off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
     316        off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
    344317        PCUT_ASSERT_INT_EQUALS(3, off);
    345318
    346319        fpos.x = 14;
    347320        fpos.y = 0;
    348         off = gfx_text_find_pos(font, &anchor, &fmt, "Abc", &fpos);
     321        off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos);
    349322        PCUT_ASSERT_INT_EQUALS(3, off);
    350323
     
    385358        anchor.y = 20;
    386359        gfx_text_fmt_init(&fmt);
     360        fmt.font = font;
    387361        fmt.color = color;
    388362
    389         gfx_text_cont(font, &anchor, &fmt, "Abc", &cpos, &cfmt);
     363        gfx_text_cont(&anchor, &fmt, "Abc", &cpos, &cfmt);
    390364
    391365        PCUT_ASSERT_INT_EQUALS(13, cpos.x);
     
    431405        anchor.y = 20;
    432406        gfx_text_fmt_init(&fmt);
     407        fmt.font = font;
    433408        fmt.color = color;
    434409
    435         gfx_text_rect(font, &anchor, &fmt, "Abc", &rect);
     410        gfx_text_rect(&anchor, &fmt, "Abc", &rect);
    436411
    437412        PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
     
    448423}
    449424
    450 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    451 {
    452         return EOK;
    453 }
    454 
    455 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    456 {
    457         return EOK;
    458 }
    459 
    460 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    461 {
    462         return EOK;
    463 }
    464 
    465 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    466     gfx_bitmap_alloc_t *alloc, void **rbm)
    467 {
    468         test_gc_t *tgc = (test_gc_t *) arg;
    469         testgc_bitmap_t *tbm;
    470 
    471         tbm = calloc(1, sizeof(testgc_bitmap_t));
    472         if (tbm == NULL)
    473                 return ENOMEM;
    474 
    475         if (alloc == NULL) {
    476                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    477                     sizeof(uint32_t);
    478                 tbm->alloc.off0 = 0;
    479                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    480                     tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
    481                 tbm->myalloc = true;
    482                 if (tbm->alloc.pixels == NULL) {
    483                         free(tbm);
    484                         return ENOMEM;
    485                 }
    486         } else {
    487                 tbm->alloc = *alloc;
    488         }
    489 
    490         tbm->tgc = tgc;
    491         tgc->bm_params = *params;
    492         tgc->bm_pixels = tbm->alloc.pixels;
    493         *rbm = (void *)tbm;
    494         return EOK;
    495 }
    496 
    497 static errno_t testgc_bitmap_destroy(void *bm)
    498 {
    499         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    500         if (tbm->myalloc)
    501                 free(tbm->alloc.pixels);
    502         free(tbm);
    503         return EOK;
    504 }
    505 
    506 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    507     gfx_coord2_t *offs)
    508 {
    509         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    510         tbm->tgc->bm_srect = *srect;
    511         tbm->tgc->bm_offs = *offs;
    512         return EOK;
    513 }
    514 
    515 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    516 {
    517         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    518         *alloc = tbm->alloc;
    519         return EOK;
    520 }
    521 
    522425PCUT_EXPORT(text);
Note: See TracChangeset for help on using the changeset viewer.