Changeset d884672 in mainline for uspace/lib/gfxfont/test/font.c


Ignore:
Timestamp:
2020-09-30T20:26:24Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c9748a4
Parents:
38a4b6d
Message:

Need to set rectangle/origin for new glyph

Otherwise, having unsaved glyphs would lead to corruption once another
glyph is created, edited and saved.

File:
1 edited

Legend:

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

    r38a4b6d rd884672  
    287287}
    288288
     289/** Test gfx_font_last_glyph() */
     290PCUT_TEST(last_glyph)
     291{
     292        gfx_font_props_t props;
     293        gfx_font_metrics_t metrics;
     294        gfx_glyph_metrics_t gmetrics;
     295        gfx_typeface_t *tface;
     296        gfx_font_t *font;
     297        gfx_context_t *gc;
     298        gfx_glyph_t *glyph;
     299        gfx_glyph_t *glast;
     300        test_gc_t tgc;
     301        errno_t rc;
     302
     303        rc = gfx_context_new(&test_ops, (void *)&tgc, &gc);
     304        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     305
     306        gfx_font_metrics_init(&metrics);
     307
     308        rc = gfx_typeface_create(gc, &tface);
     309        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     310
     311        gfx_font_props_init(&props);
     312        gfx_font_metrics_init(&metrics);
     313        rc = gfx_font_create(tface, &props, &metrics, &font);
     314        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     315
     316        /* Should get NULL since there is no glyph in the font */
     317        glyph = gfx_font_last_glyph(font);
     318        PCUT_ASSERT_NULL(glyph);
     319
     320        /* Now add one */
     321        gfx_glyph_metrics_init(&gmetrics);
     322        rc = gfx_glyph_create(font, &gmetrics, &glyph);
     323        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     324
     325        /* gfx_font_last_glyph() should return the same */
     326        glast = gfx_font_last_glyph(font);
     327        PCUT_ASSERT_EQUALS(glyph, glast);
     328
     329        gfx_glyph_destroy(glyph);
     330        gfx_font_close(font);
     331        gfx_typeface_destroy(tface);
     332        rc = gfx_context_delete(gc);
     333        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     334}
     335
     336/** Test gfx_font_prev_glyph() */
     337PCUT_TEST(prev_glyph)
     338{
     339        gfx_font_props_t props;
     340        gfx_font_metrics_t metrics;
     341        gfx_glyph_metrics_t gmetrics;
     342        gfx_typeface_t *tface;
     343        gfx_font_t *font;
     344        gfx_context_t *gc;
     345        gfx_glyph_t *glyph1;
     346        gfx_glyph_t *glyph2;
     347        gfx_glyph_t *gfirst;
     348        gfx_glyph_t *gsecond;
     349        test_gc_t tgc;
     350        errno_t rc;
     351
     352        rc = gfx_context_new(&test_ops, (void *)&tgc, &gc);
     353        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     354
     355        gfx_font_metrics_init(&metrics);
     356
     357        rc = gfx_typeface_create(gc, &tface);
     358        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     359
     360        gfx_font_props_init(&props);
     361        gfx_font_metrics_init(&metrics);
     362        rc = gfx_font_create(tface, &props, &metrics, &font);
     363        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     364
     365        /* Add first glyph */
     366        gfx_glyph_metrics_init(&gmetrics);
     367        rc = gfx_glyph_create(font, &gmetrics, &glyph1);
     368        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     369
     370        /* Add second glyph */
     371        gfx_glyph_metrics_init(&gmetrics);
     372        rc = gfx_glyph_create(font, &gmetrics, &glyph2);
     373        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     374
     375        /* gfx_font_last_glyph() should return glyph2 */
     376        gsecond = gfx_font_last_glyph(font);
     377        PCUT_ASSERT_EQUALS(glyph2, gsecond);
     378
     379        /* gfx_font_prev_glyph() should return glyph1 */
     380        gfirst = gfx_font_prev_glyph(gsecond);
     381        PCUT_ASSERT_EQUALS(glyph1, gfirst);
     382
     383        gfx_glyph_destroy(glyph1);
     384        gfx_glyph_destroy(glyph2);
     385        gfx_font_close(font);
     386        gfx_typeface_destroy(tface);
     387        rc = gfx_context_delete(gc);
     388        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     389}
     390
    289391/** Test gfx_font_search_glyph() */
    290392PCUT_TEST(search_glyph)
Note: See TracChangeset for help on using the changeset viewer.