using System.Drawing; using NUnit.Framework; namespace Developpez.Dotnet.Drawing.Tests { [TestFixture] public class FontCacheTests { [Test] public void Test_GetFont_ByPrototype() { FontCache cache = new FontCache(); Font prototype = SystemFonts.DefaultFont; Font first = cache.GetFont(prototype, FontStyle.Bold); Font second = cache.GetFont(prototype, FontStyle.Bold); Assert.IsTrue(object.ReferenceEquals(first, second)); } [Test] public void Test_GetFont_ByFamilyAndSize() { FontCache cache = new FontCache(); Font first = cache.GetFont("Arial", 10); Font second = cache.GetFont("Arial", 10); Font third = cache.GetFont(new FontFamily("Arial"), 10); Assert.IsTrue(object.ReferenceEquals(first, second)); Assert.IsTrue(object.ReferenceEquals(first, third)); } [Test] public void Test_GetFont_ByFamilySizeAndUnit() { FontCache cache = new FontCache(); Font first = cache.GetFont("Arial", 10, GraphicsUnit.Pixel); Font second = cache.GetFont("Arial", 10, GraphicsUnit.Pixel); Font third = cache.GetFont(new FontFamily("Arial"), 10, GraphicsUnit.Pixel); Assert.IsTrue(object.ReferenceEquals(first, second)); Assert.IsTrue(object.ReferenceEquals(first, third)); } [Test] public void Test_GetFont_ByFamilySizeAndStyle() { FontCache cache = new FontCache(); Font first = cache.GetFont("Arial", 10, FontStyle.Bold); Font second = cache.GetFont("Arial", 10, FontStyle.Bold); Font third = cache.GetFont(new FontFamily("Arial"), 10, FontStyle.Bold); Assert.IsTrue(object.ReferenceEquals(first, second)); Assert.IsTrue(object.ReferenceEquals(first, third)); } [Test] public void Test_GetFont_ByFamilySizeStyleAndUnit() { FontCache cache = new FontCache(); Font first = cache.GetFont("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel); Font second = cache.GetFont("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel); Font third = cache.GetFont(new FontFamily("Arial"), 10, FontStyle.Bold, GraphicsUnit.Pixel); Assert.IsTrue(object.ReferenceEquals(first, second)); Assert.IsTrue(object.ReferenceEquals(first, third)); } [Test] public void Test_GetFont_ByFamilySizeStyleUnitAndGdiCharset() { FontCache cache = new FontCache(); Font first = cache.GetFont("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel, 2); Font second = cache.GetFont("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel, 2); Font third = cache.GetFont(new FontFamily("Arial"), 10, FontStyle.Bold, GraphicsUnit.Pixel, 2); Assert.IsTrue(object.ReferenceEquals(first, second)); Assert.IsTrue(object.ReferenceEquals(first, third)); } [Test] public void Test_GetFont_ByFamilySizeStyleUnitGdiCharsetAndGdiVerticalFont() { FontCache cache = new FontCache(); Font first = cache.GetFont("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel, 2, true); Font second = cache.GetFont("@Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel, 2); Font third = cache.GetFont(new FontFamily("Arial"), 10, FontStyle.Bold, GraphicsUnit.Pixel, 2, true); Assert.IsTrue(object.ReferenceEquals(first, second)); Assert.IsTrue(object.ReferenceEquals(first, third)); } [Test] public void Test_Clear() { FontCache cache = new FontCache(); Font first = cache.GetFont("Arial", 10); cache.Clear(); Font second = cache.GetFont("Arial", 10); Assert.IsFalse(object.ReferenceEquals(first, second)); } } }