From ecae463892d8a9fea8e9d1830c40e3114d7c5d8f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 8 May 2022 15:58:39 +0200 Subject: [PATCH] Add unit tests for input description APIs --- .../D2D1InteropServicesTests.cs | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs index 3e6d1919..9b9f24c2 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs @@ -1,4 +1,5 @@ -using ComputeSharp.D2D1.Interop; +using System; +using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Tests.Effects; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -99,4 +100,70 @@ public partial class D2D1InteropServicesTests return 0; } } + + [TestMethod] + public unsafe void GetInputDescriptions_Empty() + { + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + Assert.AreEqual(D2D1PixelShader.GetInputDescriptions().Length, 0); + } + + [TestMethod] + public unsafe void GetInputDescriptions_Custom() + { + ReadOnlyMemory inputDescriptions = D2D1PixelShader.GetInputDescriptions(); + + Assert.AreEqual(inputDescriptions.Length, 5); + + ReadOnlySpan span = inputDescriptions.Span; + + Assert.AreEqual(span[0].Index, 0); + Assert.AreEqual(span[0].Filter, D2D1Filter.MinPointMagLinearMipPoint); + Assert.AreEqual(span[0].LevelOfDetail, 0); + + Assert.AreEqual(span[1].Index, 1); + Assert.AreEqual(span[1].Filter, D2D1Filter.Anisotropic); + Assert.AreEqual(span[1].LevelOfDetail, 0); + + Assert.AreEqual(span[2].Index, 2); + Assert.AreEqual(span[2].Filter, D2D1Filter.MinLinearMagPointMinLinear); + Assert.AreEqual(span[2].LevelOfDetail, 4); + + Assert.AreEqual(span[3].Index, 5); + Assert.AreEqual(span[3].Filter, D2D1Filter.MinMagPointMipLinear); + Assert.AreEqual(span[3].LevelOfDetail, 0); + + Assert.AreEqual(span[4].Index, 6); + Assert.AreEqual(span[4].Filter, D2D1Filter.MinPointMagMipLinear); + Assert.AreEqual(span[4].LevelOfDetail, 3); + } + + [D2DInputCount(7)] + [D2DInputSimple(0)] + [D2DInputSimple(2)] + [D2DInputComplex(1)] + [D2DInputComplex(3)] + [D2DInputComplex(5)] + [D2DInputSimple(6)] + [D2DInputDescription(0, D2D1Filter.MinPointMagLinearMipPoint)] + [D2DInputDescription(1, D2D1Filter.Anisotropic)] + [D2DInputDescription(2, D2D1Filter.MinLinearMagPointMinLinear, LevelOfDetail = 4)] + [D2DInputDescription(5, D2D1Filter.MinMagPointMipLinear)] + [D2DInputDescription(6, D2D1Filter.MinPointMagMipLinear, LevelOfDetail = 3)] + partial struct ShaderWithInputDescriptions : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } } \ No newline at end of file