summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop.Tests')
-rw-r--r--src/LivingVillage.Desktop.Tests/AssetPackTests.fs73
-rw-r--r--src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj1
2 files changed, 74 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/AssetPackTests.fs b/src/LivingVillage.Desktop.Tests/AssetPackTests.fs
new file mode 100644
index 0000000..fc235d0
--- /dev/null
+++ b/src/LivingVillage.Desktop.Tests/AssetPackTests.fs
@@ -0,0 +1,73 @@
+namespace LivingVillage.Desktop.Tests
+
+open System
+open System.IO
+open Microsoft.VisualStudio.TestTools.UnitTesting
+open LivingVillage.Kernel
+open LivingVillage.Kernel.Sim
+open LivingVillage.Desktop.VillageArt
+
+/// P33 vertical slice: the provenanced CC0 asset pack (Kenney Tiny Farm ground +
+/// Puny Characters) must load at the documented 32x32 / 32x48 shapes, be an exact
+/// integer 2x of the 16px / 16x24 source sprites, and stay behind the
+/// `LV_ASSET_PACK=cc0` switch so the procedural Jiangnan atlas is the fallback.
+[<TestClass>]
+type AssetPackTests () =
+
+ let assetPath (relative: string) =
+ Path.Combine(AppContext.BaseDirectory, relative)
+
+ let pngDimensions (path: string) : int * int =
+ let bytes = File.ReadAllBytes path
+ let signature = [| 0x89uy; 0x50uy; 0x4Euy; 0x47uy |]
+ for i in 0 .. 3 do
+ Assert.IsTrue(signature.[i] = bytes.[i], sprintf "%s is not a PNG" path)
+ let be32 (offset: int) =
+ (int bytes.[offset] <<< 24)
+ ||| (int bytes.[offset + 1] <<< 16)
+ ||| (int bytes.[offset + 2] <<< 8)
+ ||| int bytes.[offset + 3]
+ be32 16, be32 20
+
+ [<TestMethod>]
+ member _.Cc0GroundAtlasIsIntegerMultipleOfTheTileGrid () =
+ let width, height = pngDimensions (assetPath cc0TileAtlasRelativePath)
+ Assert.AreEqual<int>(cc0TileAtlasWidth, width)
+ Assert.AreEqual<int>(cc0TileAtlasHeight, height)
+ Assert.AreEqual<int>(0, width % Sim.tilePixels)
+ Assert.AreEqual<int>(0, height % Sim.tilePixels)
+ Assert.AreEqual<int>(4, width / Sim.tilePixels)
+ Assert.AreEqual<int>(2, Sim.tilePixels / cc0TileSourcePixels)
+ Assert.AreEqual<int>(0, Sim.tilePixels % cc0TileSourcePixels)
+
+ [<TestMethod>]
+ member _.Cc0CharacterAtlasIsIntegerMultipleOfTheCellGrid () =
+ let width, height = pngDimensions (assetPath cc0CharacterAtlasRelativePath)
+ Assert.AreEqual<int>(cc0CharacterAtlasWidth, width)
+ Assert.AreEqual<int>(cc0CharacterCellHeight, height)
+ Assert.AreEqual<int>(0, width % cc0CharacterCellWidth)
+ Assert.AreEqual<int>(0, height % cc0CharacterCellHeight)
+ Assert.AreEqual<int>(
+ cc0CharacterVariantCount * cc0CharacterDirectionCount * cc0CharacterFrameCount,
+ width / cc0CharacterCellWidth)
+ Assert.AreEqual<int>(2, cc0CharacterCellWidth / cc0CharacterSourceWidth)
+ Assert.AreEqual<int>(2, cc0CharacterCellHeight / cc0CharacterSourceHeight)
+
+ [<TestMethod>]
+ member _.AssetPackSwitchSelectsRealPackAndFallsBackToProcedural () =
+ let previous = Environment.GetEnvironmentVariable "LV_ASSET_PACK"
+ try
+ Environment.SetEnvironmentVariable("LV_ASSET_PACK", null)
+ Assert.IsFalse(useCc0Pack (), "unset switch must keep the procedural fallback")
+ Assert.IsTrue((selectedGroundAtlasRelativePath ()).IsNone, "fallback ground is procedural")
+ Assert.AreEqual<string>(characterAtlasRelativePath, selectedCharacterAtlasRelativePath ())
+
+ Environment.SetEnvironmentVariable("LV_ASSET_PACK", "cc0")
+ Assert.IsTrue(useCc0Pack (), "cc0 switch enables the real pack")
+ Assert.IsTrue(selectedGroundAtlasRelativePath () = Some cc0TileAtlasRelativePath)
+ Assert.AreEqual<string>(cc0CharacterAtlasRelativePath, selectedCharacterAtlasRelativePath ())
+
+ Environment.SetEnvironmentVariable("LV_ASSET_PACK", "kenney")
+ Assert.IsFalse(useCc0Pack (), "unknown pack value falls back to procedural")
+ finally
+ Environment.SetEnvironmentVariable("LV_ASSET_PACK", previous)
diff --git a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj
index d4fa1f5..d32a21f 100644
--- a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj
+++ b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj
@@ -15,6 +15,7 @@
<Compile Include="MapGenTests.fs" />
<Compile Include="PerformanceSummaryTests.fs" />
<Compile Include="M3BatchOutputTests.fs" />
+ <Compile Include="AssetPackTests.fs" />
<Compile Include="SampleTests.fs" />
</ItemGroup>