-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
d6ff983
commit 97a5fa6
Showing
8 changed files
with
165 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace kanimal_tests | ||
{ | ||
public static class EmbeddedUtilities | ||
{ | ||
private static Assembly assembly = Assembly.GetExecutingAssembly(); | ||
public static Stream GetResource(string resourceName) | ||
{ | ||
return assembly.GetManifestResourceStream(resourceName); | ||
} | ||
} | ||
} |
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,45 @@ | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using kanimal; | ||
|
||
namespace kanimal_tests | ||
{ | ||
// A virtual scenario of memorystreams to substitute for actual files | ||
public class KTestContext | ||
{ | ||
|
||
} | ||
|
||
public class ScmlContext : KTestContext | ||
{ | ||
public Stream Scml; | ||
public Dictionary<string, Bitmap> Sprites; | ||
|
||
// Construct an ScmlContext given a directory (aka namespace) for | ||
// files embedded into the assembly. | ||
public ScmlContext(string namespaceName) | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var files = assembly.GetManifestResourceNames() | ||
.Where(name => name.EndsWith("scml") || name.EndsWith("png")); | ||
Sprites = new Dictionary<string, Bitmap>(); | ||
foreach (var filename in files) | ||
{ | ||
if (filename.EndsWith("scml")) | ||
{ | ||
Scml = EmbeddedUtilities.GetResource(filename); | ||
} | ||
else | ||
{ | ||
// Need to get the base filename by chopping off the namespace | ||
var realName = filename.Substring("kanimal_tests.".Length + namespaceName.Length + 1); | ||
Sprites[Utilities.WithoutExtension(realName)] = | ||
new Bitmap(EmbeddedUtilities.GetResource(filename)); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,42 @@ | ||
using System.Linq; | ||
using kanimal; | ||
using Microsoft.VisualStudio.TestPlatform.Common.Utilities; | ||
using NUnit.Framework; | ||
|
||
namespace kanimal_tests | ||
{ | ||
public class ScmlReaderTests | ||
{ | ||
private static ScmlContext Minimal; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
Minimal = new ScmlContext("testcases.minimal"); | ||
} | ||
|
||
[Test] | ||
// The minimal case has a simple build content and thus a known state. | ||
public void TestMinimalBuildCorrect() | ||
{ | ||
var reader = new ScmlReader(Minimal.Scml, Minimal.Sprites); | ||
reader.Read(); | ||
|
||
var buildData = reader.BuildData; | ||
Assert.AreEqual(1, buildData.SymbolCount); | ||
Assert.AreEqual(1, buildData.FrameCount); | ||
Assert.AreEqual(1696137821, buildData.Symbols[0].Hash); | ||
var frames = buildData.Symbols[0].Frames; | ||
Assert.AreEqual(1, frames.Count); | ||
Assert.AreEqual(1, frames[0].Duration); | ||
Assert.AreEqual(0, frames[0].BuildImageIndex); | ||
Assert.AreEqual(100, frames[0].PivotX); | ||
Assert.AreEqual(100, frames[0].PivotY); | ||
|
||
var hashtable = reader.BuildHashes; | ||
Assert.AreEqual(1, hashtable.Count); | ||
Assert.AreEqual(1696137821, hashtable.Keys.First()); | ||
Assert.AreEqual("square", hashtable.Values.First()); | ||
} | ||
} | ||
} |
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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<RootNamespace>kanimal_tests</RootNamespace> | ||
|
||
<IsPackable>false</IsPackable> | ||
<DebugType>full</DebugType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="nunit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> | ||
<PackageReference Include="System.Drawing.Common" Version="4.7.0-preview1.19504.10" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="testcases\minimal\square_0.png" /> | ||
<EmbeddedResource Include="testcases\minimal\square_0.png" /> | ||
<None Remove="testcases\minimal\test_minimal.scml" /> | ||
<EmbeddedResource Include="testcases\minimal\test_minimal.scml" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\kanimal\kanimal.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<spriter_data scml_version="1.0" generator="BrashMonkey Spriter" generator_version="r11"> | ||
<folder id="0"> | ||
<file id="0" name="square_0.png" width="100" height="100" pivot_x="0" pivot_y="1"/> | ||
</folder> | ||
<entity id="0" name="test"> | ||
<animation id="0" name="place" length="400" interval="100"> | ||
<mainline> | ||
<key id="0"> | ||
<object_ref id="0" timeline="0" key="0" z_index="0"/> | ||
</key> | ||
<key id="1" time="100"> | ||
<object_ref id="0" timeline="0" key="0" z_index="0"/> | ||
</key> | ||
<key id="2" time="200"> | ||
<object_ref id="0" timeline="0" key="0" z_index="0"/> | ||
</key> | ||
<key id="3" time="300"> | ||
<object_ref id="0" timeline="0" key="0" z_index="0"/> | ||
</key> | ||
</mainline> | ||
<timeline id="0" name="square_0"> | ||
<key id="0" spin="0"> | ||
<object folder="0" file="0" x="-49" y="100" angle="0"/> | ||
</key> | ||
</timeline> | ||
</animation> | ||
</entity> | ||
</spriter_data> |
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