From 15e801dc7bf654ce5591f4f4f2f19d1d3bfdb65c Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Mon, 25 Jan 2016 20:19:23 +0300 Subject: [PATCH] More Font tests --- tests/test_font.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_font.cc b/tests/test_font.cc index 9b5a058..ccc3fa0 100644 --- a/tests/test_font.cc +++ b/tests/test_font.cc @@ -2,6 +2,7 @@ #include #include +#include #include "testing.h" @@ -99,4 +100,36 @@ BEGIN_TEST(int, char*[]) EXPECT_TRUE(family && *family == "Bitstream Vera Sans"); EXPECT_TRUE(style && *style == "Roman"); } + + { + // Glyphs provided + EXPECT_TRUE(font.IsGlyphProvided(u'A')); + EXPECT_TRUE(font.IsGlyphProvided(u'¼')); + EXPECT_TRUE(!font.IsGlyphProvided(u'л')); + EXPECT_TRUE(!font.IsGlyphProvided(u'Ы')); + } + + { + // Glyph metrics + int minx, maxx, miny, maxy, advance; + + // Why doesn't TTF_GlyphMetrics on non-existing glyph not return -1?! + //EXPECT_EXCEPTION(font.GetGlyphMetrics(u'л', minx, maxx, miny, maxy, advance), Exception); + + EXPECT_NO_EXCEPTION(font.GetGlyphMetrics(u'A', minx, maxx, miny, maxy, advance)); + + EXPECT_EQUAL(minx, 0); + EXPECT_EQUAL(maxx, 20); + EXPECT_EQUAL(miny, 0); + EXPECT_EQUAL(maxy, 22); + EXPECT_EQUAL(advance, 21); + + EXPECT_EQUAL(font.GetGlyphRect(u'A'), Rect(0, 0, 20, 22)); + EXPECT_EQUAL(font.GetGlyphAdvance(u'A'), 21); + + // Text size + EXPECT_EQUAL(font.GetSizeText("AA"), Point(43, 36)); + EXPECT_EQUAL(font.GetSizeUTF8(u8"AA"), Point(43, 36)); + EXPECT_EQUAL(font.GetSizeUNICODE(u"AA"), Point(43, 36)); + } END_TEST()