A game framework written with osu! in mind.
at master 120 lines 4.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.Extensions.Color4Extensions; 6using osu.Framework.Graphics; 7using osu.Framework.Graphics.Containers; 8using osu.Framework.Graphics.Shapes; 9using osu.Framework.Graphics.Sprites; 10using osu.Framework.Utils; 11using osu.Framework.Testing; 12using osu.Framework.Tests.Visual; 13using osuTK.Graphics; 14 15namespace osu.Framework.Tests.Sprites 16{ 17 [HeadlessTest] 18 public class TestSceneSpriteTextPresence : FrameworkTestScene 19 { 20 /// <summary> 21 /// Tests with a normal <see cref="SpriteText"/> which changes presence based on whether text is empty. 22 /// </summary> 23 [Test] 24 public void TestNormalSpriteText() 25 { 26 Container container = null; 27 SpriteText text = null; 28 29 AddStep("reset", () => 30 { 31 Child = container = new Container 32 { 33 Anchor = Anchor.Centre, 34 Origin = Anchor.Centre, 35 AutoSizeAxes = Axes.Both, 36 Children = new Drawable[] 37 { 38 new Box 39 { 40 RelativeSizeAxes = Axes.Both, 41 Colour = Color4.Red.Opacity(0.3f) 42 }, 43 text = new SpriteText 44 { 45 Text = "Hello world!", 46 Font = new FontUsage(size: 12), 47 } 48 } 49 }; 50 }); 51 52 AddAssert("is present", () => text.IsPresent); 53 AddAssert("height == 12", () => Precision.AlmostEquals(12, container.Height)); 54 AddStep("empty text", () => text.Text = string.Empty); 55 AddAssert("not present", () => !text.IsPresent); 56 AddAssert("height == 0", () => Precision.AlmostEquals(0, container.Height)); 57 } 58 59 /// <summary> 60 /// Tests with a special <see cref="SpriteText"/> that always remains present regardless of whether text is empty. 61 /// </summary> 62 [Test] 63 public void TestAlwaysPresentSpriteText() 64 { 65 Container container = null; 66 SpriteText text = null; 67 68 AddStep("reset", () => 69 { 70 Child = container = new Container 71 { 72 Anchor = Anchor.Centre, 73 Origin = Anchor.Centre, 74 AutoSizeAxes = Axes.Both, 75 Children = new Drawable[] 76 { 77 new Box 78 { 79 RelativeSizeAxes = Axes.Both, 80 Colour = Color4.Red.Opacity(0.3f) 81 }, 82 text = new AlwaysPresentSpriteText 83 { 84 Text = "Hello world!", 85 Font = new FontUsage(size: 12), 86 } 87 } 88 }; 89 }); 90 91 AddAssert("is present", () => text.IsPresent); 92 AddAssert("height == 12", () => Precision.AlmostEquals(12, container.Height)); 93 AddStep("empty text", () => text.Text = string.Empty); 94 AddAssert("is present", () => text.IsPresent); 95 AddAssert("height == 0", () => Precision.AlmostEquals(0, container.Height)); 96 } 97 98 /// <summary> 99 /// Tests that the <see cref="Drawable.IsPresent"/> state of the <see cref="SpriteText"/> doesn't change during flow layout. 100 /// </summary> 101 [Test] 102 public void TestPresenceRemainsTheSameDuringFlow() 103 { 104 AddStep("reset", () => 105 { 106 Child = new FillFlowContainer 107 { 108 Child = new SpriteText() 109 }; 110 }); 111 112 AddWaitStep("wait for some update frames", 2); 113 } 114 115 private class AlwaysPresentSpriteText : SpriteText 116 { 117 public override bool IsPresent => true; 118 } 119 } 120}