From 6ae36696ac6d724e4c492ed6639ba066b9b31617 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 16 Aug 2022 17:16:48 +0200 Subject: [PATCH] Add D2D1EffectRegistrationData unit test --- .../D2D1EffectRegistrationDataTests.cs | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs new file mode 100644 index 00000000..6e63f1a8 --- /dev/null +++ b/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs @@ -0,0 +1,120 @@ +using System; +using ComputeSharp.D2D1.Interop; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.D2D1.Tests; + +[TestClass] +[TestCategory("D2D1EffectRegistrationData")] +public partial class D2D1EffectRegistrationDataTests +{ + [TestMethod] + public unsafe void EffectRegistrationData_Validate() + { + ReadOnlyMemory blob = D2D1PixelShaderEffect.GetRegistrationBlob(out Guid effectId); + D2D1EffectRegistrationData.V1 data = D2D1EffectRegistrationData.V1.Load(blob); + + Assert.AreEqual(effectId, data.ClassId); + Assert.AreEqual(2, data.NumberOfInputs); + Assert.IsTrue(data.EffectFactory is not null); + Assert.AreEqual(17, data.PropertyBindings.Length); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ConstantBuffer), data.PropertyBindings.Span[0].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager0), data.PropertyBindings.Span[1].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager1), data.PropertyBindings.Span[2].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager2), data.PropertyBindings.Span[3].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager3), data.PropertyBindings.Span[4].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager4), data.PropertyBindings.Span[5].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager5), data.PropertyBindings.Span[6].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager6), data.PropertyBindings.Span[7].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager7), data.PropertyBindings.Span[8].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager8), data.PropertyBindings.Span[9].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager9), data.PropertyBindings.Span[10].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager10), data.PropertyBindings.Span[11].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager11), data.PropertyBindings.Span[12].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager12), data.PropertyBindings.Span[13].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager13), data.PropertyBindings.Span[14].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager14), data.PropertyBindings.Span[15].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager15), data.PropertyBindings.Span[16].PropertyName); + + foreach (ref readonly D2D1PropertyBinding propertyBinding in data.PropertyBindings.Span) + { + Assert.IsTrue(propertyBinding.SetFunction is not null); + Assert.IsTrue(propertyBinding.GetFunction is not null); + } + + Assert.AreEqual(@" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +", data.PropertyXml); + } + + [D2DInputCount(2)] + [D2DRequiresScenePosition] + [AutoConstructor] + private partial struct TestRegistrationBlobShader : ID2D1PixelShader + { + private float a; + + public float4 Execute() + { + return a; + } + } +} \ No newline at end of file