Changes in uspace/lib/gfxfont/test/font.c [d884672:1fa6292] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/font.c
rd884672 r1fa6292 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 #include "../private/font.h" 35 35 #include "../private/typeface.h" 36 #include "../private/testgc.h" 36 37 37 38 PCUT_INIT; 38 39 39 40 PCUT_TEST_SUITE(font); 40 41 static errno_t testgc_set_color(void *, gfx_color_t *);42 static errno_t testgc_fill_rect(void *, gfx_rect_t *);43 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,44 gfx_bitmap_alloc_t *, void **);45 static errno_t testgc_bitmap_destroy(void *);46 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);47 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);48 49 static gfx_context_ops_t test_ops = {50 .set_color = testgc_set_color,51 .fill_rect = testgc_fill_rect,52 .bitmap_create = testgc_bitmap_create,53 .bitmap_destroy = testgc_bitmap_destroy,54 .bitmap_render = testgc_bitmap_render,55 .bitmap_get_alloc = testgc_bitmap_get_alloc56 };57 58 typedef struct {59 gfx_bitmap_params_t bm_params;60 void *bm_pixels;61 gfx_rect_t bm_srect;62 gfx_coord2_t bm_offs;63 } test_gc_t;64 65 typedef struct {66 test_gc_t *tgc;67 gfx_bitmap_alloc_t alloc;68 bool myalloc;69 } testgc_bitmap_t;70 41 71 42 /** Test creating and destroying font */ … … 89 60 gfx_font_metrics_init(&metrics); 90 61 rc = gfx_font_create(tface, &props, &metrics, &font); 62 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 63 64 gfx_font_close(font); 65 gfx_typeface_destroy(tface); 66 67 rc = gfx_context_delete(gc); 68 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 69 } 70 71 /** Test creating and destroying text-mode font */ 72 PCUT_TEST(create_textmode_destroy) 73 { 74 gfx_typeface_t *tface; 75 gfx_font_t *font; 76 gfx_context_t *gc; 77 test_gc_t tgc; 78 errno_t rc; 79 80 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 81 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 82 83 rc = gfx_typeface_create(gc, &tface); 84 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 85 86 rc = gfx_font_create_textmode(tface, &font); 91 87 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 92 88 … … 482 478 height = 10; 483 479 484 pixels = calloc( sizeof(uint32_t), width * height);480 pixels = calloc(width * height, sizeof(uint32_t)); 485 481 PCUT_ASSERT_NOT_NULL(pixels); 486 482 … … 529 525 } 530 526 531 pixels = calloc( sizeof(uint32_t), width * height);527 pixels = calloc(width * height, sizeof(uint32_t)); 532 528 PCUT_ASSERT_NOT_NULL(pixels); 533 529 … … 545 541 } 546 542 547 static errno_t testgc_set_color(void *arg, gfx_color_t *color)548 {549 return EOK;550 }551 552 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)553 {554 return EOK;555 }556 557 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,558 gfx_bitmap_alloc_t *alloc, void **rbm)559 {560 test_gc_t *tgc = (test_gc_t *) arg;561 testgc_bitmap_t *tbm;562 563 tbm = calloc(1, sizeof(testgc_bitmap_t));564 if (tbm == NULL)565 return ENOMEM;566 567 if (alloc == NULL) {568 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *569 sizeof(uint32_t);570 tbm->alloc.off0 = 0;571 tbm->alloc.pixels = calloc(sizeof(uint32_t),572 tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));573 tbm->myalloc = true;574 if (tbm->alloc.pixels == NULL) {575 free(tbm);576 return ENOMEM;577 }578 } else {579 tbm->alloc = *alloc;580 }581 582 tbm->tgc = tgc;583 tgc->bm_params = *params;584 tgc->bm_pixels = tbm->alloc.pixels;585 *rbm = (void *)tbm;586 return EOK;587 }588 589 static errno_t testgc_bitmap_destroy(void *bm)590 {591 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;592 if (tbm->myalloc)593 free(tbm->alloc.pixels);594 free(tbm);595 return EOK;596 }597 598 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,599 gfx_coord2_t *offs)600 {601 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;602 tbm->tgc->bm_srect = *srect;603 tbm->tgc->bm_offs = *offs;604 return EOK;605 }606 607 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)608 {609 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;610 *alloc = tbm->alloc;611 return EOK;612 }613 614 543 PCUT_EXPORT(font);
Note:
See TracChangeset
for help on using the changeset viewer.