A game framework written with osu! in mind.
at master 91 lines 3.2 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 osu.Framework.Allocation; 5using osu.Framework.Graphics; 6using osu.Framework.Graphics.Shapes; 7using osu.Framework.Testing; 8using osuTK; 9 10namespace osu.Framework.Tests.Visual.Drawables 11{ 12 [HeadlessTest] 13 [System.ComponentModel.Description("ensure validity of drawables when receiving certain values")] 14 public class TestScenePropertyBoundaries : FrameworkTestScene 15 { 16 [BackgroundDependencyLoader] 17 private void load() 18 { 19 testPositiveScale(); 20 testZeroScale(); 21 testNegativeScale(); 22 } 23 24 private void testPositiveScale() 25 { 26 var box = new Box 27 { 28 Size = new Vector2(100), 29 Scale = new Vector2(2) 30 }; 31 32 Add(box); 33 34 AddAssert("Box is loaded", () => box.LoadState >= LoadState.Ready); 35 AddAssert("Box is present", () => box.IsPresent); 36 AddAssert("Box has valid draw matrix", () => checkDrawInfo(box.DrawInfo)); 37 } 38 39 private void testZeroScale() 40 { 41 var box = new Box 42 { 43 Size = new Vector2(100), 44 Scale = new Vector2(0) 45 }; 46 47 Add(box); 48 49 AddAssert("Box is loaded", () => box.LoadState >= LoadState.Ready); 50 AddAssert("Box is present", () => !box.IsPresent); 51 AddAssert("Box has valid draw matrix", () => checkDrawInfo(box.DrawInfo)); 52 } 53 54 private void testNegativeScale() 55 { 56 var box = new Box 57 { 58 Size = new Vector2(100), 59 Scale = new Vector2(-2) 60 }; 61 62 Add(box); 63 64 AddAssert("Box is loaded", () => box.LoadState >= LoadState.Ready); 65 AddAssert("Box is present", () => box.IsPresent); 66 AddAssert("Box has valid draw matrix", () => checkDrawInfo(box.DrawInfo)); 67 } 68 69 private bool checkDrawInfo(DrawInfo drawInfo) => 70 checkFloat(drawInfo.Matrix.M11) 71 && checkFloat(drawInfo.Matrix.M12) 72 && checkFloat(drawInfo.Matrix.M13) 73 && checkFloat(drawInfo.Matrix.M21) 74 && checkFloat(drawInfo.Matrix.M22) 75 && checkFloat(drawInfo.Matrix.M23) 76 && checkFloat(drawInfo.Matrix.M31) 77 && checkFloat(drawInfo.Matrix.M32) 78 && checkFloat(drawInfo.Matrix.M33) 79 && checkFloat(drawInfo.MatrixInverse.M11) 80 && checkFloat(drawInfo.MatrixInverse.M12) 81 && checkFloat(drawInfo.MatrixInverse.M13) 82 && checkFloat(drawInfo.MatrixInverse.M21) 83 && checkFloat(drawInfo.MatrixInverse.M22) 84 && checkFloat(drawInfo.MatrixInverse.M23) 85 && checkFloat(drawInfo.MatrixInverse.M31) 86 && checkFloat(drawInfo.MatrixInverse.M32) 87 && checkFloat(drawInfo.MatrixInverse.M33); 88 89 private bool checkFloat(float value) => !float.IsNaN(value) && !float.IsInfinity(value) && !float.IsNegativeInfinity(value); 90 } 91}