()
| 8 | |
| 9 | public class FontTest implements Executable { |
| 10 | @Override |
| 11 | public void execute() throws Exception { |
| 12 | try (Typeface jbMono = FontMgr.getDefault().makeFromFile("fonts/JetBrainsMono-Regular.ttf"); |
| 13 | Font font = new Font(jbMono, 12f); ) { |
| 14 | |
| 15 | float advance = font.measureTextWidth("a"); |
| 16 | |
| 17 | // Empty strings |
| 18 | assertEquals(0.0f, font.measureTextWidth("")); |
| 19 | assertEquals(0, font.getStringGlyphs("").length); |
| 20 | assertEquals(0, font.getStringGlyphsCount("")); |
| 21 | assertEquals(Rect.makeLTRB(0, 0, 0, 0), font.measureText("")); |
| 22 | |
| 23 | // ASCII |
| 24 | assertClose(3 * advance, font.measureTextWidth("abc"), 0.01f); |
| 25 | |
| 26 | // Cyrillic (multi-byte UTF-8, single UTF-16 code unit each) |
| 27 | assertClose(3 * advance, font.measureTextWidth("абв"), 0.01f); |
| 28 | |
| 29 | // Valid surrogate pair (U+1D400) |
| 30 | float wPair = font.measureTextWidth("\ud835\udc00"); |
| 31 | assertEquals(true, wPair >= 0 && Float.isFinite(wPair)); |
| 32 | |
| 33 | // Malformed UTF-16 must throw IllegalArgumentException. |
| 34 | String[] invalid = { |
| 35 | "\udc00", // lone low surrogate (first) |
| 36 | "A\udc00B", // lone low surrogate (middle) |
| 37 | "\ud835", // lone high surrogate (truncated) |
| 38 | "hello\ud83d", // lone high surrogate (at end) |
| 39 | "\ud835X\ud835", // high surrogate not followed by low |
| 40 | "\ud83d\ud83d", // high surrogate followed by high surrogate |
| 41 | "\ud835\u0041", // high surrogate followed by BMP char |
| 42 | }; |
| 43 | for (String s : invalid) { |
| 44 | assertThrows(IllegalArgumentException.class, () -> font.measureTextWidth(s)); |
| 45 | assertThrows(IllegalArgumentException.class, () -> font.measureText(s)); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
nothing calls this directly
no test coverage detected