using UnitTestSharp; using Azimuth; using Annulus; using System.Collections.Generic; namespace Glass.UnitTests.Materials { public class TextMaterialTests : TestFixture { public static SpriteFontDefinition CreateMonospaceTestFont(int glyphWidth, int glyphHeight) { var font = new SpriteFontDefinition { Name = "TestMonospace", LineHeight = (ushort)glyphHeight, Baseline = (ushort)(glyphHeight * 0.8f), Pages = new List { "test" }, InvalidGlyph = new SpriteFontDefinition.GlyphDefinition { Size = new Point(glyphWidth, glyphHeight), XAdvance = glyphWidth } }; // populate printable ASCII for (char c = ' '; c <= '~'; c++) { font.GlyphDefinitions[c] = new SpriteFontDefinition.GlyphDefinition { Size = new Point(glyphWidth, glyphHeight), XAdvance = glyphWidth }; } return font; } public void CalculateLayoutSizeEmptyString() { var material = new TextMaterial { Text = "", Font = CreateMonospaceTestFont(3, 4), }; CheckEqual(Vector.Zero, material.CalculateLayoutSize(Vector.PositiveInfinity)); } public void CalculateLayoutSizeSimpleString() { var material = new TextMaterial { Text = "test", Font = CreateMonospaceTestFont(3, 4), }; CheckEqual(new Vector(12, 4), material.CalculateLayoutSize(Vector.PositiveInfinity)); } public void CalculateLayoutSizeMultilineString() { var material = new TextMaterial { Text = "test", Font = CreateMonospaceTestFont(3, 4), }; CheckEqual(new Vector(3, 16), material.CalculateLayoutSize(new Vector(3, Scalar.PositiveInfinity))); } public void CalculateLayoutSizeTooSmall() { var material = new TextMaterial { Text = "test", Font = CreateMonospaceTestFont(3, 4), }; CheckEqual(new Vector(3, 4), material.CalculateLayoutSize(new Vector(3, 4))); } public void CalculateLayoutSizeZeroSize() { var material = new TextMaterial { Text = "test", Font = CreateMonospaceTestFont(3, 4), }; CheckEqual(Vector.Zero, material.CalculateLayoutSize(Vector.Zero)); } } }