From 4407d78c91e6d9407a328c2aff6cf342dfa79aa4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 20 Sep 2023 14:12:43 +0200 Subject: [PATCH] Update unit tests for new custom metadata --- .../D2D1EffectRegistrationDataTests.cs | 100 +++++++++++++++++- .../D2D1PixelShaderEffectTests.cs | 40 ++++--- 2 files changed, 120 insertions(+), 20 deletions(-) diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs index 19069545..ef833251 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs @@ -14,6 +14,7 @@ public partial class D2D1EffectRegistrationDataTests ReadOnlyMemory blob = D2D1PixelShaderEffect.GetRegistrationBlob(out Guid effectId); D2D1EffectRegistrationData.V1 data = D2D1EffectRegistrationData.V1.Load(blob); + Assert.AreEqual(Guid.Parse("8AA3BDF3-5EC8-34D9-CFBC-97A2B4068FFD"), effectId); Assert.AreEqual(effectId, data.ClassId); Assert.AreEqual(2, data.NumberOfInputs); Assert.IsTrue(data.EffectFactory is not null); @@ -47,9 +48,9 @@ public partial class D2D1EffectRegistrationDataTests - - - + + + @@ -124,4 +125,97 @@ public partial class D2D1EffectRegistrationDataTests return this.a; } } + + [TestMethod] + public unsafe void EffectRegistrationData_WithCustomMetadata_Validate() + { + ReadOnlyMemory blob = D2D1PixelShaderEffect.GetRegistrationBlob(out Guid effectId); + D2D1EffectRegistrationData.V1 data = D2D1EffectRegistrationData.V1.Load(blob); + + Assert.AreEqual(Guid.Parse("ABF58390-91D2-4F58-AA2B-22D0F6AC069C"), effectId); + Assert.AreEqual(""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """, data.PropertyXml); + } + + [D2DInputCount(2)] + [D2DEffectId("ABF58390-91D2-4F58-AA2B-22D0F6AC069C")] + [D2DEffectDisplayName("EffectWithCustomMetadata")] + [D2DEffectDescription("A test effect with some custom metadata")] + [D2DEffectCategory("Test effects")] + [D2DEffectAuthor("Bob Ross")] + [AutoConstructor] + private readonly partial struct TestRegistrationBlobWithCustomMetadataShader : ID2D1PixelShader + { + private readonly float a; + + public float4 Execute() + { + return this.a; + } + } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs index 8a9ea8a1..7dd2fe16 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderEffectTests.cs @@ -226,9 +226,12 @@ public partial class D2D1PixelShaderEffectTests } [TestMethod] - public unsafe void DefaultEffectDisplayName_MatchesValue() + public unsafe void DefaultEffectMetadata_MatchesValue() { Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), null); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), null); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), null); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), null); } [D2DInputCount(0)] @@ -241,16 +244,17 @@ public partial class D2D1PixelShaderEffectTests } [TestMethod] - public unsafe void ExplicitEffectDisplayName_MatchesValue() + public unsafe void ExplicitEffectMetadata1_MatchesValue() { - Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), "Fancy blur"); - Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), "Fancy"<"); - Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), "FancyBlurEffect"); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), "Fancy blur"); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDescription(), null); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectCategory(), null); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectAuthor(), null); } [D2DInputCount(0)] [D2DEffectDisplayName("Fancy blur")] - private partial struct ShaderWithExplicitEffectDisplayName : ID2D1PixelShader + private partial struct ShaderWithExplicitEffectDisplayName1 : ID2D1PixelShader { public float4 Execute() { @@ -258,8 +262,20 @@ public partial class D2D1PixelShaderEffectTests } } + [TestMethod] + public unsafe void ExplicitEffectMetadata2_MatchesValue() + { + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDisplayName(), "Fancy"<"); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectDescription(), "A test effect with some custom metadata"); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectCategory(), "Test effects!"); + Assert.AreEqual(D2D1PixelShaderEffect.GetEffectAuthor(), "Bob Ross"); + } + [D2DInputCount(0)] - [D2DEffectDisplayName("Fancy\"<")] + [D2DEffectDisplayName("F\r\na\nncy\"<")] + [D2DEffectDescription("A test effect with \nsome custom metadata")] + [D2DEffectCategory("Test effects!")] + [D2DEffectAuthor("Bob \r\nRoss")] private partial struct ShaderWithExplicitEffectDisplayName2 : ID2D1PixelShader { public float4 Execute() @@ -267,14 +283,4 @@ public partial class D2D1PixelShaderEffectTests return 0; } } - - [D2DInputCount(0)] - [D2DEffectDisplayName("Fancy\r\nBlur\nEffect")] - private partial struct ShaderWithExplicitEffectDisplayName3 : ID2D1PixelShader - { - public float4 Execute() - { - return 0; - } - } } \ No newline at end of file