Browse Source

Added resolution tests

Krzysztof Krysiński 3 months ago
parent
commit
4a8e9fd15d

+ 4 - 0
tests/PixiEditor.Tests/PixiEditor.Tests.csproj

@@ -36,5 +36,9 @@
     <ItemGroup>
         <Content Include="TestFiles\**" CopyToOutputDirectory="PreserveNewest" />
     </ItemGroup>
+    
+    <ItemGroup>
+      <Folder Include="TestFiles\ResolutionTests\" />
+    </ItemGroup>
 
 </Project>

+ 44 - 0
tests/PixiEditor.Tests/RenderTests.cs

@@ -1,8 +1,13 @@
 using Avalonia.Headless.XUnit;
+using ChunkyImageLib;
+using ChunkyImageLib.DataHolders;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core.Bridge;
+using Drawie.Backend.Core.ColorsImpl;
+using Drawie.Numerics;
 using PixiEditor.Models.IO;
 using Xunit.Abstractions;
+using Color = Drawie.Backend.Core.ColorsImpl.Color;
 
 namespace PixiEditor.Tests;
 
@@ -49,6 +54,26 @@ public class RenderTests : FullPixiEditorTest
         Assert.True(PixelCompare(image, toCompareTo));
     }
 
+    [AvaloniaTheory]
+    [InlineData("SingleLayer")]
+    [InlineData("SingleLayerWithMask")]
+    [InlineData("LayerWithMaskClipped")]
+    [InlineData("LayerWithMaskClippedHighDpiPresent")]
+    [InlineData("LayerWithMaskClippedInFolder")]
+    [InlineData("LayerWithMaskClippedInFolderWithMask")]
+    public void TestThatHalfResolutionScalesRenderCorrectly(string pixiName)
+    {
+        string pixiFile = Path.Combine("TestFiles", "ResolutionTests", pixiName + ".pixi");
+
+        var document = Importer.ImportDocument(pixiFile);
+        using Surface output = Surface.ForDisplay(document.SizeBindable);
+        document.SceneRenderer.RenderScene(output.DrawingSurface, ChunkResolution.Half);
+
+        Color expectedColor = Colors.Yellow;
+
+        Assert.True(AllPixelsAreColor(output, expectedColor));
+    }
+
     private static bool PixelCompare(Surface image, Surface compareTo)
     {
         if (image.Size != compareTo.Size)
@@ -86,4 +111,23 @@ public class RenderTests : FullPixiEditorTest
 
         return true;
     }
+
+    private static bool AllPixelsAreColor(Surface image, Color color)
+    {
+        var imageData = image.PeekPixels();
+
+        for (int y = 0; y < imageData.Height; y++)
+        {
+            for (int x = 0; x < imageData.Width; x++)
+            {
+                var pixel = imageData.GetPixelColor(x, y);
+                if (pixel != color)
+                {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
 }

BIN
tests/PixiEditor.Tests/TestFiles/ResolutionTests/LayerWithMaskClipped.pixi


BIN
tests/PixiEditor.Tests/TestFiles/ResolutionTests/LayerWithMaskClippedHighDpiPresent.pixi


BIN
tests/PixiEditor.Tests/TestFiles/ResolutionTests/LayerWithMaskClippedInFolder.pixi


BIN
tests/PixiEditor.Tests/TestFiles/ResolutionTests/LayerWithMaskClippedInFolderWithMask.pixi


BIN
tests/PixiEditor.Tests/TestFiles/ResolutionTests/SingleLayer.pixi


BIN
tests/PixiEditor.Tests/TestFiles/ResolutionTests/SingleLayerWithMask.pixi