A game framework written with osu! in mind.
at master 63 lines 2.3 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using NUnit.Framework; 5using osu.Framework.Graphics; 6using osu.Framework.IO.Stores; 7using osu.Framework.Testing; 8using osu.Framework.Text; 9 10namespace osu.Framework.Tests.IO 11{ 12 [TestFixture] 13 public class FontStoreTest 14 { 15 private ResourceStore<byte[]> fontResourceStore; 16 private TemporaryNativeStorage storage; 17 18 [OneTimeSetUp] 19 public void OneTimeSetUp() 20 { 21 storage = new TemporaryNativeStorage("fontstore-test"); 22 fontResourceStore = new NamespacedResourceStore<byte[]>(new DllResourceStore(typeof(Drawable).Assembly), "Resources.Fonts.Roboto"); 23 } 24 25 [Test] 26 public void TestNestedScaleAdjust() 27 { 28 using (var fontStore = new FontStore(new RawCachingGlyphStore(fontResourceStore, "Roboto-Regular") { CacheStorage = storage }, scaleAdjust: 100)) 29 using (var nestedFontStore = new FontStore(new RawCachingGlyphStore(fontResourceStore, "Roboto-Bold") { CacheStorage = storage }, 10)) 30 { 31 fontStore.AddStore(nestedFontStore); 32 33 var normalGlyph = (TexturedCharacterGlyph)fontStore.Get("Roboto-Regular", 'a'); 34 Assert.That(normalGlyph, Is.Not.Null); 35 36 var boldGlyph = (TexturedCharacterGlyph)fontStore.Get("Roboto-Bold", 'a'); 37 Assert.That(boldGlyph, Is.Not.Null); 38 39 Assert.That(normalGlyph.Scale, Is.EqualTo(1f / 100)); 40 Assert.That(boldGlyph.Scale, Is.EqualTo(1f / 10)); 41 } 42 } 43 44 [Test] 45 public void TestNoCrashOnMissingResources() 46 { 47 using (var glyphStore = new RawCachingGlyphStore(fontResourceStore, "DoesntExist") { CacheStorage = storage }) 48 using (var fontStore = new FontStore(glyphStore, 100)) 49 { 50 Assert.That(glyphStore.Get('a'), Is.Null); 51 52 Assert.That(fontStore.Get("DoesntExist", 'a'), Is.Null); 53 Assert.That(fontStore.Get("OtherAttempt", 'a'), Is.Null); 54 } 55 } 56 57 [OneTimeTearDown] 58 public void TearDown() 59 { 60 storage.Dispose(); 61 } 62 } 63}