using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnitTestSharp; namespace Glass.UnitTests { public class SpriteFontDefinitionTests : TestFixture { static SpriteFontDefinition MakeFont(char glyph, int xAdvance) { var font = new SpriteFontDefinition(); font.GlyphDefinitions[glyph] = new SpriteFontDefinition.GlyphDefinition { XAdvance = xAdvance }; return font; } public class GlyphWidthTests : TestFixture { public void GlyphWidthReturnsXAdvance() { var font = MakeFont('A', xAdvance: 7); CheckEqual(7, font.GlyphWidth('A')); } public void GlyphWidthIsZeroForMissingGlyph() { var font = MakeFont('B', xAdvance: 7); CheckEqual(0, font.GlyphWidth('A')); } public void GlyphWidthIsNotSizeX() { var font = new SpriteFontDefinition(); font.GlyphDefinitions['A'] = new SpriteFontDefinition.GlyphDefinition { XAdvance = 7, Size = new Point(99, 99) }; CheckEqual(7, font.GlyphWidth('A')); } } public class SpaceBetweenGlyphsTests : TestFixture { public void SpaceBetweenGlyphsReturnsKerning() { var font = new SpriteFontDefinition(); font.Kernings[((short)'A', (short)'V')] = -2; CheckEqual(-2, font.SpaceBetweenGlyphs('A', 'V')); } public void SpaceBetweenGlyphsIsZeroWithNoKerningEntry() { var font = new SpriteFontDefinition(); CheckEqual(0, font.SpaceBetweenGlyphs('A', 'V')); } public void SpaceBetweenGlyphsIsZeroWhenLeftGlyphIsNull() { var font = new SpriteFontDefinition(); font.Kernings[((short)'A', (short)'V')] = -2; CheckEqual(0, font.SpaceBetweenGlyphs(null, 'V')); } public void SpaceBetweenGlyphsIsZeroWhenRightGlyphIsNull() { var font = new SpriteFontDefinition(); font.Kernings[((short)'A', (short)'V')] = -2; CheckEqual(0, font.SpaceBetweenGlyphs('A', null)); } public void SpaceBetweenGlyphsIsZeroWhenBothGlyphsAreNull() { var font = new SpriteFontDefinition(); CheckEqual(0, font.SpaceBetweenGlyphs(null, null)); } public void SpaceBetweenGlyphsIsDirectional() { var font = new SpriteFontDefinition(); font.Kernings[((short)'A', (short)'V')] = -2; // No entry for (V, A), so only one direction has kerning. CheckEqual(-2, font.SpaceBetweenGlyphs('A', 'V')); CheckEqual(0, font.SpaceBetweenGlyphs('V', 'A')); } } } }