-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.Xna.Framework; | ||
using Myra.Graphics2D.UI; | ||
using NUnit.Framework; | ||
|
||
namespace Myra.Tests | ||
{ | ||
[TestFixture] | ||
public class GridTests | ||
{ | ||
private static Project LoadFromResource(string name) | ||
{ | ||
var xml = typeof(GridTests).Assembly.ReadResourceAsString("Resources.GridTests." + name); | ||
|
||
return Project.LoadFromXml(xml); | ||
} | ||
|
||
[Test] | ||
public static void TestSimpleProportionsPart() | ||
{ | ||
var project = LoadFromResource("SimpleProportionsPart.xmmp"); | ||
var grid = (Grid)project.Root; | ||
|
||
grid.Arrange(new Rectangle(0, 0, 400, 400)); | ||
|
||
Assert.AreEqual(100, grid.Widgets[0].ContainerBounds.Width); | ||
Assert.AreEqual(200, grid.Widgets[0].ContainerBounds.Height); | ||
Assert.AreEqual(300, grid.Widgets[1].ContainerBounds.Width); | ||
Assert.AreEqual(200, grid.Widgets[1].ContainerBounds.Height); | ||
Assert.AreEqual(100, grid.Widgets[2].ContainerBounds.Width); | ||
Assert.AreEqual(200, grid.Widgets[2].ContainerBounds.Height); | ||
Assert.AreEqual(300, grid.Widgets[3].ContainerBounds.Width); | ||
Assert.AreEqual(200, grid.Widgets[3].ContainerBounds.Height); | ||
} | ||
|
||
[Test] | ||
public static void TestSimpleAutoFill() | ||
{ | ||
var project = LoadFromResource("SimpleAutoFill.xmmp"); | ||
var grid = (Grid)project.Root; | ||
|
||
grid.Arrange(new Rectangle(0, 0, 400, 500)); | ||
|
||
Assert.AreEqual(100, grid.Widgets[0].ContainerBounds.Width); | ||
Assert.AreEqual(450, grid.Widgets[0].ContainerBounds.Height); | ||
Assert.AreEqual(300, grid.Widgets[1].ContainerBounds.Width); | ||
Assert.AreEqual(450, grid.Widgets[1].ContainerBounds.Height); | ||
Assert.AreEqual(100, grid.Widgets[2].ContainerBounds.Width); | ||
Assert.AreEqual(50, grid.Widgets[2].ContainerBounds.Height); | ||
Assert.AreEqual(300, grid.Widgets[3].ContainerBounds.Width); | ||
Assert.AreEqual(50, grid.Widgets[3].ContainerBounds.Height); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
using System; | ||
|
||
namespace Myra.Tests | ||
{ | ||
internal static class Res | ||
{ | ||
/// <summary> | ||
/// Open assembly resource stream by relative name | ||
/// </summary> | ||
/// <param name="assembly"></param> | ||
/// <param name="path"></param> | ||
/// <returns></returns> | ||
public static Stream OpenResourceStream(this Assembly assembly, string path) | ||
{ | ||
// Once you figure out the name, pass it in as the argument here. | ||
path = assembly.GetName().Name + "." + path; | ||
var stream = assembly.GetManifestResourceStream(path); | ||
if (stream == null) | ||
{ | ||
throw new Exception($"Could not find resource at path '{path}'"); | ||
} | ||
|
||
return stream; | ||
} | ||
|
||
/// <summary> | ||
/// Reads assembly resource as byte array by relative name | ||
/// </summary> | ||
/// <param name="assembly"></param> | ||
/// <param name="path"></param> | ||
/// <returns></returns> | ||
public static byte[] ReadResourceAsBytes(this Assembly assembly, string path) | ||
{ | ||
var ms = new MemoryStream(); | ||
using (var input = assembly.OpenResourceStream(path)) | ||
{ | ||
input.CopyTo(ms); | ||
|
||
return ms.ToArray(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Reads assembly resource as string by relative name | ||
/// </summary> | ||
/// <param name="assembly"></param> | ||
/// <param name="path"></param> | ||
/// <returns></returns> | ||
public static string ReadResourceAsString(this Assembly assembly, string path) | ||
{ | ||
string result; | ||
using (var input = assembly.OpenResourceStream(path)) | ||
{ | ||
using (var textReader = new StreamReader(input)) | ||
{ | ||
result = textReader.ReadToEnd(); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project> | ||
<Grid> | ||
<Grid.ColumnsProportions> | ||
<Proportion Type="Auto" /> | ||
<Proportion Type="Fill" /> | ||
</Grid.ColumnsProportions> | ||
<Grid.RowsProportions> | ||
<Proportion Type="Fill" /> | ||
<Proportion Type="Auto" /> | ||
</Grid.RowsProportions> | ||
<Label Text="Test" Width="100" Height="50" /> | ||
<Label Text="Test" Width="100" Height="50" Grid.Column="1" /> | ||
<Label Text="Test" Width="100" Height="50" Grid.Row="1" /> | ||
<Label Text="Test" Width="100" Height="50" Grid.Column="1" Grid.Row="1" /> | ||
</Grid> | ||
</Project> |
16 changes: 16 additions & 0 deletions
16
src/Myra.Tests/Resources/GridTests/SimpleProportionsPart.xmmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project> | ||
<Grid> | ||
<Grid.ColumnsProportions> | ||
<Proportion Type="Part" Value="1" /> | ||
<Proportion Type="Part" Value="3" /> | ||
</Grid.ColumnsProportions> | ||
<Grid.RowsProportions> | ||
<Proportion Type="Part" Value="1" /> | ||
<Proportion Type="Part" Value="1" /> | ||
</Grid.RowsProportions> | ||
<Label Text="Test" /> | ||
<Label Text="Test" Grid.Column="1" /> | ||
<Label Text="Test" Grid.Row="1" /> | ||
<Label Text="Test" Grid.Column="1" Grid.Row="1" /> | ||
</Grid> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters