From c5a17c6a162f4e8730f6e31341e7859e8260efcd Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 14 Jun 2024 11:56:32 +0200 Subject: [PATCH 1/4] mark all BinaryFormatter-related tests as conditional that require PlatformDetection.IsBinaryFormatterSupported to be true, fixes #103406 --- .../tests/BinaryFormatTests/Common/SerializationTest.cs | 1 + .../BinaryFormatTests/FormattedObject/BinaryFormattedTypes.cs | 1 + .../tests/BinaryFormatTests/Legacy/BinaryFormatterTests.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SerializationTest.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SerializationTest.cs index 3a7b4046058835..dc4bf6246ec28a 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SerializationTest.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SerializationTest.cs @@ -8,6 +8,7 @@ namespace System.Resources.Extensions.Tests.Common; +[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))] public abstract class SerializationTest where TSerializer : ISerializer { public static TheoryData FormatterOptions => new() diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BinaryFormattedTypes.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BinaryFormattedTypes.cs index b49320a1cadf5b..f9641ce9c86613 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BinaryFormattedTypes.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/BinaryFormattedTypes.cs @@ -8,6 +8,7 @@ namespace System.Resources.Extensions.Tests.FormattedObject; +[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))] public class BinaryFormattedTypes { [Theory] diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Legacy/BinaryFormatterTests.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Legacy/BinaryFormatterTests.cs index 9fe63ef1dd9ab3..f63d32b95264ff 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Legacy/BinaryFormatterTests.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Legacy/BinaryFormatterTests.cs @@ -15,6 +15,7 @@ namespace BinaryFormatTests.FormatterTests; +[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))] public partial class BinaryFormatterTests { [Theory] From 0e24bc787507b901ed2d8dd975721073630dd084 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 14 Jun 2024 13:52:44 +0200 Subject: [PATCH 2/4] two types in inheritance hierarchy can not use [ConditionalClass] with different conditions --- .../tests/BinaryFormatTests/Common/SystemDrawingTests.cs | 7 ++++--- .../FormattedObject/SystemDrawingTests.cs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs index 81b491e887edba..263d60641dfdf7 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs @@ -7,10 +7,11 @@ namespace System.Resources.Extensions.Tests.Common; -[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] +// This type can not be annotated with [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] +// because the base type is annotated with [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))] public abstract class SystemDrawingTests : SerializationTest where T : ISerializer { - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] [MemberData(nameof(FormatterOptions))] [SupportedOSPlatform("windows")] public void Bitmap_RoundTrip(FormatterTypeStyle typeStyle, FormatterAssemblyStyle assemblyMatching) @@ -20,7 +21,7 @@ public void Bitmap_RoundTrip(FormatterTypeStyle typeStyle, FormatterAssemblyStyl deserialized.Size.Should().Be(bitmap.Size); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] [MemberData(nameof(FormatterOptions))] [SupportedOSPlatform("windows")] public void Png_RoundTrip(FormatterTypeStyle typeStyle, FormatterAssemblyStyle assemblyMatching) diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/SystemDrawingTests.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/SystemDrawingTests.cs index ce96ceef12ea87..1cf34e7e7d5e0a 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/SystemDrawingTests.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/FormattedObject/SystemDrawingTests.cs @@ -9,7 +9,7 @@ namespace System.Resources.Extensions.Tests.FormattedObject; public class SystemDrawingTests : Common.SystemDrawingTests { - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] public void PointF_Parse() { PointF input = new() { X = 123.5f, Y = 456.1f }; @@ -25,7 +25,7 @@ public void PointF_Parse() classInfo.GetSingle("y").Should().Be(input.Y); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] public void RectangleF_Parse() { RectangleF input = new(x: 123.5f, y: 456.1f, width: 100.25f, height: 200.75f); From 1d2a1367b8b138e07ab4db29dc8e879c3253bad8 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 14 Jun 2024 16:23:52 +0200 Subject: [PATCH 3/4] Apply suggestions from code review --- .../tests/BinaryFormatTests/Common/SystemDrawingTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs index 263d60641dfdf7..9fcb7d60a6cc89 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/SystemDrawingTests.cs @@ -11,7 +11,7 @@ namespace System.Resources.Extensions.Tests.Common; // because the base type is annotated with [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))] public abstract class SystemDrawingTests : SerializationTest where T : ISerializer { - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported), nameof(PlatformDetection.SupportsComInterop))] [MemberData(nameof(FormatterOptions))] [SupportedOSPlatform("windows")] public void Bitmap_RoundTrip(FormatterTypeStyle typeStyle, FormatterAssemblyStyle assemblyMatching) @@ -21,7 +21,7 @@ public void Bitmap_RoundTrip(FormatterTypeStyle typeStyle, FormatterAssemblyStyl deserialized.Size.Should().Be(bitmap.Size); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported))] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsDrawingSupported), nameof(PlatformDetection.SupportsComInterop))] [MemberData(nameof(FormatterOptions))] [SupportedOSPlatform("windows")] public void Png_RoundTrip(FormatterTypeStyle typeStyle, FormatterAssemblyStyle assemblyMatching) From de3c046e25f25795b73fea6fd2bdffa9a1e3071b Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Mon, 17 Jun 2024 12:49:43 +0200 Subject: [PATCH 4/4] don't run BinaryFormatter tests for NativeAOT and Mobiles (they are not supported by design) --- src/libraries/tests.proj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 754ba0940ab820..9e4ac5317716fe 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -425,6 +425,11 @@ + + + + + @@ -506,8 +511,6 @@ - -