Minor refactoring to unit tests
このコミットが含まれているのは:
1 親
41b8e64da7
コミット
298614d9b9
2ファイル変更
+88
-89
検索条件に一致するファイルはありません
@@ -1,10 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Tests.Effects;
|
||||
using ComputeSharp.D2D1.Tests.Effects;
|
||||
using ComputeSharp.D2D1.Tests.Helpers;
|
||||
using ComputeSharp.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
@@ -23,19 +18,19 @@ public class EndToEndTests
|
||||
[TestMethod]
|
||||
public unsafe void Invert()
|
||||
{
|
||||
RunAndCompareShader(new InvertEffect(), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
D2D1TestRunner.RunAndCompareShader(new InvertEffect(), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void InvertWithThreshold()
|
||||
{
|
||||
RunAndCompareShader(new InvertWithThresholdEffect(1), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
D2D1TestRunner.RunAndCompareShader(new InvertWithThresholdEffect(1), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void Pixelate()
|
||||
{
|
||||
RunAndCompareShader(
|
||||
D2D1TestRunner.RunAndCompareShader(
|
||||
new PixelateEffect.Shader(new PixelateEffect.Shader.Constants(1280, 840, 16)),
|
||||
static () => new PixelateEffect(),
|
||||
"Landscape.png",
|
||||
@@ -45,88 +40,12 @@ public class EndToEndTests
|
||||
[TestMethod]
|
||||
public unsafe void ZonePlate()
|
||||
{
|
||||
RunAndCompareShader(new ZonePlateEffect(1280, 720, 800), null, 1280, 720, "ZonePlate.png");
|
||||
D2D1TestRunner.RunAndCompareShader(new ZonePlateEffect(1280, 720, 800), null, 1280, 720, "ZonePlate.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void CheckerboardClip()
|
||||
{
|
||||
RunAndCompareShader(new CheckerboardClipEffect(1280, 840, 32), null, "Landscape.png", "Landscape_CheckerboardClip.png");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="originalFileName">The name of the source image.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
private static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
string originalFileName,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string originalPath = Path.Combine(assetsPath, originalFileName);
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
D2D1TestRunner.ExecutePixelShaderAndCompareResults(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
originalPath,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="width">The resulting width.</param>
|
||||
/// <param name="height">The resulting height.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
private static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
int width,
|
||||
int height,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
D2D1TestRunner.ExecutePixelShaderAndCompareResults(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
width,
|
||||
height,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
D2D1TestRunner.RunAndCompareShader(new CheckerboardClipEffect(1280, 840, 32), null, "Landscape.png", "Landscape_CheckerboardClip.png");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.Tests.Helpers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
@@ -10,6 +14,82 @@ namespace ComputeSharp.D2D1.Tests.Helpers;
|
||||
/// </summary>
|
||||
internal static class D2D1TestRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="originalFileName">The name of the source image.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
public static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
string originalFileName,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string originalPath = Path.Combine(assetsPath, originalFileName);
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
ExecutePixelShaderAndSaveToFile(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
originalPath,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="width">The resulting width.</param>
|
||||
/// <param name="height">The resulting height.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
public static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
int width,
|
||||
int height,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
ExecutePixelShaderAndSaveToFile(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
width,
|
||||
height,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader to produce an image.
|
||||
/// </summary>
|
||||
@@ -18,7 +98,7 @@ internal static class D2D1TestRunner
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="sourcePath">The source path for the image to run the shader on.</param>
|
||||
/// <param name="destinationPath">The destination path for the result.</param>
|
||||
public static unsafe void ExecutePixelShaderAndCompareResults<T>(
|
||||
public static unsafe void ExecutePixelShaderAndSaveToFile<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
string sourcePath,
|
||||
@@ -58,7 +138,7 @@ internal static class D2D1TestRunner
|
||||
/// <param name="height">The resulting height.</param>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="destinationPath">The destination path for the result.</param>
|
||||
public static unsafe void ExecutePixelShaderAndCompareResults<T>(
|
||||
public static unsafe void ExecutePixelShaderAndSaveToFile<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
int width,
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする