Changeset d2100e2 in mainline for uspace/lib/gfxfont/test/font.c
- Timestamp:
- 2020-08-09T18:40:28Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 06b8383
- Parents:
- 5592c56
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/font.c
r5592c56 rd2100e2 29 29 #include <gfx/context.h> 30 30 #include <gfx/font.h> 31 #include <gfx/glyph.h> 31 32 #include <pcut/pcut.h> 33 #include "../private/font.h" 32 34 33 35 PCUT_INIT; … … 37 39 static errno_t testgc_set_color(void *, gfx_color_t *); 38 40 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 41 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *, 42 gfx_bitmap_alloc_t *, void **); 43 static errno_t testgc_bitmap_destroy(void *); 44 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 45 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 39 46 40 47 static gfx_context_ops_t test_ops = { 41 48 .set_color = testgc_set_color, 42 .fill_rect = testgc_fill_rect 49 .fill_rect = testgc_fill_rect, 50 .bitmap_create = testgc_bitmap_create, 51 .bitmap_destroy = testgc_bitmap_destroy, 52 .bitmap_render = testgc_bitmap_render, 53 .bitmap_get_alloc = testgc_bitmap_get_alloc 43 54 }; 55 56 typedef struct { 57 gfx_bitmap_params_t bm_params; 58 void *bm_pixels; 59 gfx_rect_t bm_srect; 60 gfx_coord2_t bm_offs; 61 } test_gc_t; 62 63 typedef struct { 64 test_gc_t *tgc; 65 gfx_bitmap_alloc_t alloc; 66 bool myalloc; 67 } testgc_bitmap_t; 44 68 45 69 /** Test creating and destroying font */ … … 49 73 gfx_font_t *font; 50 74 gfx_context_t *gc; 51 errno_t rc; 52 53 rc = gfx_context_new(&test_ops, NULL, &gc); 75 test_gc_t tgc; 76 errno_t rc; 77 78 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 54 79 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 55 80 … … 70 95 gfx_font_t *font; 71 96 gfx_context_t *gc; 72 errno_t rc; 73 74 rc = gfx_context_new(&test_ops, NULL, &gc); 97 test_gc_t tgc; 98 errno_t rc; 99 100 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 75 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 76 102 … … 101 127 gfx_font_t *font; 102 128 gfx_context_t *gc; 103 errno_t rc; 104 105 rc = gfx_context_new(&test_ops, NULL, &gc); 129 test_gc_t tgc; 130 errno_t rc; 131 132 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 106 133 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 107 134 … … 136 163 { 137 164 gfx_font_metrics_t metrics; 165 gfx_glyph_metrics_t gmetrics; 138 166 gfx_font_t *font; 139 167 gfx_context_t *gc; 140 168 gfx_glyph_t *glyph; 141 errno_t rc; 142 143 rc = gfx_context_new(&test_ops, NULL, &gc); 144 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 146 gfx_font_metrics_init(&metrics); 147 148 rc = gfx_font_create(gc, &metrics, &font); 149 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 150 169 gfx_glyph_t *gfirst; 170 test_gc_t tgc; 171 errno_t rc; 172 173 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 174 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 175 176 gfx_font_metrics_init(&metrics); 177 178 rc = gfx_font_create(gc, &metrics, &font); 179 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 180 181 /* Should get NULL since there is no glyph in the font */ 151 182 glyph = gfx_font_first_glyph(font); 152 183 PCUT_ASSERT_NULL(glyph); 153 184 185 /* Now add one */ 186 gfx_glyph_metrics_init(&gmetrics); 187 rc = gfx_glyph_create(font, &gmetrics, &glyph); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 190 /* gfx_font_first_glyph() should return the same */ 191 gfirst = gfx_font_first_glyph(font); 192 PCUT_ASSERT_EQUALS(glyph, gfirst); 193 194 gfx_glyph_destroy(glyph); 154 195 gfx_font_destroy(font); 155 196 rc = gfx_context_delete(gc); … … 160 201 PCUT_TEST(next_glyph) 161 202 { 162 /* TODO */ 203 gfx_font_metrics_t metrics; 204 gfx_glyph_metrics_t gmetrics; 205 gfx_font_t *font; 206 gfx_context_t *gc; 207 gfx_glyph_t *glyph1; 208 gfx_glyph_t *glyph2; 209 gfx_glyph_t *gfirst; 210 gfx_glyph_t *gsecond; 211 test_gc_t tgc; 212 errno_t rc; 213 214 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 215 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 216 217 gfx_font_metrics_init(&metrics); 218 219 rc = gfx_font_create(gc, &metrics, &font); 220 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 221 222 /* Add first glyph */ 223 gfx_glyph_metrics_init(&gmetrics); 224 rc = gfx_glyph_create(font, &gmetrics, &glyph1); 225 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 226 227 /* Add second glyph */ 228 gfx_glyph_metrics_init(&gmetrics); 229 rc = gfx_glyph_create(font, &gmetrics, &glyph2); 230 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 231 232 /* gfx_font_first_glyph() should return glyph1 */ 233 gfirst = gfx_font_first_glyph(font); 234 PCUT_ASSERT_EQUALS(glyph1, gfirst); 235 236 /* gfx_font_next_glyph() should return glyph2 */ 237 gsecond = gfx_font_next_glyph(gfirst); 238 PCUT_ASSERT_EQUALS(glyph2, gsecond); 239 240 gfx_glyph_destroy(glyph1); 241 gfx_glyph_destroy(glyph2); 242 gfx_font_destroy(font); 243 rc = gfx_context_delete(gc); 244 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 163 245 } 164 246 … … 171 253 gfx_glyph_t *glyph; 172 254 size_t bytes; 173 errno_t rc; 174 175 rc = gfx_context_new(&test_ops, NULL, &gc); 255 test_gc_t tgc; 256 errno_t rc; 257 258 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 176 259 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 177 260 … … 189 272 } 190 273 274 /** Test gfx_font_splice_at_glyph() */ 275 PCUT_TEST(splice_at_glyph) 276 { 277 gfx_font_metrics_t fmetrics; 278 gfx_font_t *font; 279 gfx_glyph_metrics_t gmetrics; 280 gfx_glyph_t *glyph; 281 gfx_context_t *gc; 282 test_gc_t tgc; 283 errno_t rc; 284 285 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 286 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 287 288 gfx_font_metrics_init(&fmetrics); 289 rc = gfx_font_create(gc, &fmetrics, &font); 290 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 291 292 gfx_glyph_metrics_init(&gmetrics); 293 rc = gfx_glyph_create(font, &gmetrics, &glyph); 294 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 295 296 rc = gfx_font_splice_at_glyph(font, glyph, 10, 10); 297 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 298 299 gfx_glyph_destroy(glyph); 300 301 gfx_font_destroy(font); 302 rc = gfx_context_delete(gc); 303 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 304 } 305 191 306 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 192 307 { … … 199 314 } 200 315 316 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 317 gfx_bitmap_alloc_t *alloc, void **rbm) 318 { 319 test_gc_t *tgc = (test_gc_t *) arg; 320 testgc_bitmap_t *tbm; 321 322 tbm = calloc(1, sizeof(testgc_bitmap_t)); 323 if (tbm == NULL) 324 return ENOMEM; 325 326 if (alloc == NULL) { 327 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) * 328 sizeof(uint32_t); 329 tbm->alloc.off0 = 0; 330 tbm->alloc.pixels = calloc(sizeof(uint32_t), 331 tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y)); 332 tbm->myalloc = true; 333 if (tbm->alloc.pixels == NULL) { 334 free(tbm); 335 return ENOMEM; 336 } 337 } else { 338 tbm->alloc = *alloc; 339 } 340 341 tbm->tgc = tgc; 342 tgc->bm_params = *params; 343 tgc->bm_pixels = tbm->alloc.pixels; 344 *rbm = (void *)tbm; 345 return EOK; 346 } 347 348 static errno_t testgc_bitmap_destroy(void *bm) 349 { 350 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 351 if (tbm->myalloc) 352 free(tbm->alloc.pixels); 353 free(tbm); 354 return EOK; 355 } 356 357 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 358 gfx_coord2_t *offs) 359 { 360 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 361 tbm->tgc->bm_srect = *srect; 362 tbm->tgc->bm_offs = *offs; 363 return EOK; 364 } 365 366 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 367 { 368 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 369 *alloc = tbm->alloc; 370 return EOK; 371 } 372 201 373 PCUT_EXPORT(font);
Note:
See TracChangeset
for help on using the changeset viewer.