A game framework written with osu! in mind.
at master 4.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 NUnit.Framework; 5using osu.Framework.Graphics; 6using osu.Framework.Graphics.Containers; 7using osu.Framework.Graphics.Shapes; 8using osu.Framework.Testing; 9using osu.Framework.Tests.Visual; 10using osu.Framework.Utils; 11using osuTK; 12 13namespace osu.Framework.Tests.Layout 14{ 15 [HeadlessTest] 16 public class TestSceneGridContainerLayout : FrameworkTestScene 17 { 18 /// <summary> 19 /// Tests that a grid's auto-size is updated when a child becomes alive. 20 /// </summary> 21 [Test] 22 public void TestGridContainerAutoSizeUpdatesWhenChildBecomesAlive() 23 { 24 Box box = null; 25 GridContainer parent = null; 26 27 AddStep("create test", () => 28 { 29 Child = parent = new GridContainer 30 { 31 AutoSizeAxes = Axes.Both, 32 RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, 33 ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, 34 Content = new[] 35 { 36 new Drawable[] 37 { 38 box = new Box 39 { 40 Size = new Vector2(200), 41 LifetimeStart = double.MaxValue 42 } 43 }, 44 } 45 }; 46 }); 47 48 AddStep("make child alive", () => box.LifetimeStart = double.MinValue); 49 50 AddAssert("parent has size 200", () => Precision.AlmostEquals(new Vector2(200), parent.DrawSize)); 51 } 52 53 /// <summary> 54 /// Tests that a grid's auto-size is updated when a child is removed through death. 55 /// </summary> 56 [Test] 57 public void TestGridContainerAutoSizeUpdatesWhenChildBecomesDead() 58 { 59 Box box = null; 60 GridContainer parent = null; 61 62 AddStep("create test", () => 63 { 64 Child = parent = new GridContainer 65 { 66 AutoSizeAxes = Axes.Both, 67 RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, 68 ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, 69 Content = new[] 70 { 71 new Drawable[] 72 { 73 box = new Box { Size = new Vector2(200) } 74 }, 75 } 76 }; 77 }); 78 79 AddStep("make child dead", () => box.Expire()); 80 81 AddAssert("parent has size 0", () => Precision.AlmostEquals(Vector2.Zero, parent.DrawSize)); 82 } 83 84 /// <summary> 85 /// Tests that a grid's auto-size is updated when a child becomes dead and doesn't get removed. 86 /// </summary> 87 [Test] 88 public void TestGridContainerAutoSizeUpdatesWhenChildBecomesDeadWithoutRemoval() 89 { 90 Box box = null; 91 GridContainer parent = null; 92 93 AddStep("create test", () => 94 { 95 Child = parent = new GridContainer 96 { 97 AutoSizeAxes = Axes.Both, 98 RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, 99 ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, 100 Content = new[] 101 { 102 new Drawable[] 103 { 104 box = new TestBox1 { Size = new Vector2(200) } 105 }, 106 } 107 }; 108 }); 109 110 AddStep("make child dead", () => box.Expire()); 111 112 AddAssert("parent has size 0", () => Precision.AlmostEquals(Vector2.Zero, parent.DrawSize)); 113 } 114 115 private class TestBox1 : Box 116 { 117 public override bool RemoveWhenNotAlive => false; 118 } 119 } 120}