From 21b4a8585362c1bc12d545b63e62a0d9dd4e8673 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sun, 7 Jan 2024 11:11:24 -0500 Subject: [PATCH] Remove defunct netfx tests (#96435) --- .../Generic/Dictionary/Dictionary.Tests.cs | 4 +- ...t.Generic.Tests.AsNonGenericIEnumerable.cs | 4 +- .../Generic/HashSet/HashSet.Generic.Tests.cs | 4 +- .../AssociationAttributeTests.cs | 20 +- .../CustomValidationAttributeTests.cs | 12 +- .../DataAnnotations/DataTypeAttributeTests.cs | 2 +- .../DataAnnotations/PhoneAttributeTests.cs | 12 - .../ComponentModel/CategoryAttributeTests.cs | 18 +- .../DescriptionAttributeTests.cs | 18 +- .../DesignerCategoryAttributeTests.cs | 18 +- .../DisplayNameAttributeTests.cs | 18 +- .../tests/WindowAndCursorProps.cs | 10 +- .../tests/Lambda/LambdaTests.cs | 4 +- .../tests/FunctionalTests/CookieTest.cs | 9 +- .../FunctionalTests/CredentialCacheTest.cs | 36 +- .../tests/FunctionalTests/IPAddressParsing.cs | 4 +- .../tests/FunctionalTests/IPAddressTest.cs | 2 +- .../tests/UnitTests/CookieContainerTest.cs | 17 +- .../SslStreamStreamToStreamTest.cs | 2 +- .../tests/AbortTest.cs | 5 +- .../tests/ConnectTest.cs | 9 +- .../tests/WebSocketTests.cs | 5 +- .../XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs | 4 +- .../XsltArgumentList.cs | 2 +- .../tests/AssemblyBuilderTests.cs | 9 +- .../Marshal/GenerateGuidForTypeTests.cs | 11 +- .../GetObjectForNativeVariantTests.Windows.cs | 2 +- .../Marshal/ThrowExceptionForHRTests.cs | 8 +- .../CultureInfo/GetCultureInfo.cs | 2 +- .../DirectoryInfo/ToString.cs | 8 +- .../FileStream/ctor_str_fm.cs | 2 +- .../StreamWriter/StreamWriter.CloseTests.cs | 5 +- .../NegativeEncodingTests.cs | 9 +- .../UTF8Encoding/UTF8EncodingDecode.cs | 325 ++++++------------ .../tests/RegisteredWaitTests.cs | 14 +- .../tests/ThreadPoolTests.cs | 2 +- 36 files changed, 190 insertions(+), 446 deletions(-) diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs index 1a0845a352986..d7674f24de7eb 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs @@ -20,9 +20,9 @@ protected override IDictionary NonGenericIDictionaryFactory() return new Dictionary(); } - protected override ModifyOperation ModifyEnumeratorThrows => PlatformDetection.IsNetFramework ? base.ModifyEnumeratorThrows : ModifyOperation.Add | ModifyOperation.Insert; + protected override ModifyOperation ModifyEnumeratorThrows => ModifyOperation.Add | ModifyOperation.Insert; - protected override ModifyOperation ModifyEnumeratorAllowed => PlatformDetection.IsNetFramework ? base.ModifyEnumeratorAllowed : ModifyOperation.Overwrite | ModifyOperation.Remove | ModifyOperation.Clear; + protected override ModifyOperation ModifyEnumeratorAllowed => ModifyOperation.Overwrite | ModifyOperation.Remove | ModifyOperation.Clear; /// /// Creates an object that is dependent on the seed given. The object may be either diff --git a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs index 70671721d338a..e6bd50ac091f9 100644 --- a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs +++ b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.AsNonGenericIEnumerable.cs @@ -19,9 +19,9 @@ protected override IEnumerable NonGenericIEnumerableFactory(int count) protected override bool Enumerator_Empty_UsesSingletonInstance => true; protected override bool Enumerator_Current_UndefinedOperation_Throws => true; - protected override ModifyOperation ModifyEnumeratorThrows => PlatformDetection.IsNetFramework ? base.ModifyEnumeratorThrows : (base.ModifyEnumeratorAllowed & ~ModifyOperation.Remove); + protected override ModifyOperation ModifyEnumeratorThrows => base.ModifyEnumeratorAllowed & ~ModifyOperation.Remove; - protected override ModifyOperation ModifyEnumeratorAllowed => PlatformDetection.IsNetFramework ? base.ModifyEnumeratorAllowed : ModifyOperation.Overwrite | ModifyOperation.Remove; + protected override ModifyOperation ModifyEnumeratorAllowed => ModifyOperation.Overwrite | ModifyOperation.Remove; /// /// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them. diff --git a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs index 038bbbdb960c3..05dec6a7689cc 100644 --- a/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/HashSet/HashSet.Generic.Tests.cs @@ -20,9 +20,9 @@ public abstract class HashSet_Generic_Tests : ISet_Generic_Tests protected override bool ResetImplemented => true; - protected override ModifyOperation ModifyEnumeratorThrows => PlatformDetection.IsNetFramework ? base.ModifyEnumeratorThrows : (base.ModifyEnumeratorAllowed & ~(ModifyOperation.Remove | ModifyOperation.Clear)); + protected override ModifyOperation ModifyEnumeratorThrows => base.ModifyEnumeratorAllowed & ~(ModifyOperation.Remove | ModifyOperation.Clear); - protected override ModifyOperation ModifyEnumeratorAllowed => PlatformDetection.IsNetFramework ? base.ModifyEnumeratorAllowed : ModifyOperation.Overwrite | ModifyOperation.Remove | ModifyOperation.Clear; + protected override ModifyOperation ModifyEnumeratorAllowed => ModifyOperation.Overwrite | ModifyOperation.Remove | ModifyOperation.Clear; protected override ISet GenericISetFactory() { diff --git a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/AssociationAttributeTests.cs b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/AssociationAttributeTests.cs index 1b9f2e41870e6..c6f987d9f2f71 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/AssociationAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/AssociationAttributeTests.cs @@ -12,29 +12,15 @@ public class AssociationAttributeTests [InlineData("TestName", "TestThisKey", "TestOtherKey", new string[] { "TestThisKey" }, new string[] { "TestOtherKey" })] [InlineData(null, "", " \t \r \n", new string[] { "" }, new string[] { "\t\r\n" })] [InlineData(null, null, null, new string[0], new string[0])] - [InlineData("Name", "ThisKey1, ThisKey2, ThisKey3", "OtherKey1, OtherKey2",new string[] { "ThisKey1", "ThisKey2", "ThisKey3" }, new string[] { "OtherKey1", "OtherKey2" })] + [InlineData("Name", "ThisKey1, ThisKey2, ThisKey3", "OtherKey1, OtherKey2", new string[] { "ThisKey1", "ThisKey2", "ThisKey3" }, new string[] { "OtherKey1", "OtherKey2" })] public void Ctor_String_String_String(string name, string thisKey, string otherKey, string[] expectedThisKeyMembers, string[] expectedOtherKeyMembers) { var attribute = new AssociationAttribute(name, thisKey, otherKey); Assert.Equal(name, attribute.Name); Assert.Equal(thisKey, attribute.ThisKey); Assert.Equal(otherKey, attribute.OtherKey); - if (PlatformDetection.IsNetFramework && thisKey == null) - { - Assert.Throws(() => attribute.ThisKeyMembers); - } - else - { - Assert.Equal(expectedThisKeyMembers, attribute.ThisKeyMembers); - } - if (PlatformDetection.IsNetFramework && otherKey == null) - { - Assert.Throws(() => attribute.OtherKeyMembers); - } - else - { - Assert.Equal(expectedOtherKeyMembers, attribute.OtherKeyMembers); - } + Assert.Equal(expectedThisKeyMembers, attribute.ThisKeyMembers); + Assert.Equal(expectedOtherKeyMembers, attribute.OtherKeyMembers); } [Fact] diff --git a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/CustomValidationAttributeTests.cs b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/CustomValidationAttributeTests.cs index 2e84dae593940..a5c4b16a07d49 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/CustomValidationAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/CustomValidationAttributeTests.cs @@ -101,17 +101,7 @@ public void FormatErrorMessage_PerformedValidation_DoesNotContainName() public static void RequiresValidationContext_Get_ReturnsExpected(string method, bool expected) { CustomValidationAttribute attribute = GetAttribute(method); - - // The .NET Framework has a bug where CustomValidationAttribute doesn't - // validate the context. See https://github.com/dotnet/runtime/issues/21100. - if (PlatformDetection.IsNetFramework) - { - Assert.False(attribute.RequiresValidationContext); - } - else - { - Assert.Equal(expected, attribute.RequiresValidationContext); - } + Assert.Equal(expected, attribute.RequiresValidationContext); } public static IEnumerable BadlyFormed_TestData() diff --git a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/DataTypeAttributeTests.cs b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/DataTypeAttributeTests.cs index 8114fe084aab0..46eb797988036 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/DataTypeAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/DataTypeAttributeTests.cs @@ -72,7 +72,7 @@ public static IEnumerable Ctor_String_TestData() // .NET Core fixed a bug where whitespace strings were allowed as CustomDataType. // See https://github.com/dotnet/runtime/issues/15690. - yield return new object[] { " ", PlatformDetection.IsNetFramework }; + yield return new object[] { " ", false }; } [Theory] diff --git a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/PhoneAttributeTests.cs b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/PhoneAttributeTests.cs index 48c82d042d792..9894e35efdd98 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/PhoneAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/PhoneAttributeTests.cs @@ -39,18 +39,6 @@ protected override IEnumerable InvalidValues() yield return new TestCase(new PhoneAttribute(), "425-555-1212 ext. xyz"); yield return new TestCase(new PhoneAttribute(), "-.()"); yield return new TestCase(new PhoneAttribute(), "ext.123 1"); - - // By design, certain phone numbers are reported as valid with .NET Core, whereas .NET Framework - // considers them invalid. See https://github.com/dotnet/runtime/issues/20884. - if (PlatformDetection.IsNetFramework) - { - yield return new TestCase(new PhoneAttribute(), "+4+2+5+-+5+5+5+-+1+2++1+2++"); - yield return new TestCase(new PhoneAttribute(), "425-555-1212 "); - yield return new TestCase(new PhoneAttribute(), " \r \n 1 \t "); - yield return new TestCase(new PhoneAttribute(), "1-.()"); - yield return new TestCase(new PhoneAttribute(), "(425555-1212"); - yield return new TestCase(new PhoneAttribute(), ")425555-1212"); - } } [Fact] diff --git a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/CategoryAttributeTests.cs b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/CategoryAttributeTests.cs index 2caa78f88e931..a30c2d80edfe0 100644 --- a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/CategoryAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/CategoryAttributeTests.cs @@ -36,20 +36,10 @@ public static IEnumerable Equals_TestData() yield return new object[] { attribute, new CategoryAttribute("category"), true }; yield return new object[] { attribute, new CategoryAttribute("category2"), false }; yield return new object[] { attribute, new CategoryAttribute(string.Empty), false }; - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { attribute, new CategoryAttribute(null), false }; - } - - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { new CategoryAttribute(null), new CategoryAttribute(null), true }; - yield return new object[] { new CategoryAttribute(null), new CategoryAttribute("category"), false }; - yield return new object[] { new CategoryAttribute(null), new CategoryAttribute(string.Empty), false }; - } - + yield return new object[] { attribute, new CategoryAttribute(null), false }; + yield return new object[] { new CategoryAttribute(null), new CategoryAttribute(null), true }; + yield return new object[] { new CategoryAttribute(null), new CategoryAttribute("category"), false }; + yield return new object[] { new CategoryAttribute(null), new CategoryAttribute(string.Empty), false }; yield return new object[] { new CategoryAttribute("category"), new object(), false }; yield return new object[] { new CategoryAttribute("category"), null, false }; yield return new object[] { new CategoryAttribute(null), new object(), false }; diff --git a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DescriptionAttributeTests.cs b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DescriptionAttributeTests.cs index 744d20ed82ddc..cc1ba193cd090 100644 --- a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DescriptionAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DescriptionAttributeTests.cs @@ -54,20 +54,10 @@ public static IEnumerable Equals_TestData() yield return new object[] { attribute, new DescriptionAttribute("description"), true }; yield return new object[] { attribute, new DescriptionAttribute("description2"), false }; yield return new object[] { attribute, new DescriptionAttribute(""), false }; - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { attribute, new DescriptionAttribute(null), false }; - } - - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { new DescriptionAttribute(null), new DescriptionAttribute(null), true }; - yield return new object[] { new DescriptionAttribute(null), new DescriptionAttribute("description"), false }; - yield return new object[] { new DescriptionAttribute(null), new DescriptionAttribute(""), false }; - } - + yield return new object[] { attribute, new DescriptionAttribute(null), false }; + yield return new object[] { new DescriptionAttribute(null), new DescriptionAttribute(null), true }; + yield return new object[] { new DescriptionAttribute(null), new DescriptionAttribute("description"), false }; + yield return new object[] { new DescriptionAttribute(null), new DescriptionAttribute(""), false }; yield return new object[] { new DescriptionAttribute("description"), new object(), false }; yield return new object[] { new DescriptionAttribute("description"), null, false }; yield return new object[] { new DescriptionAttribute(null), new object(), false }; diff --git a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DesignerCategoryAttributeTests.cs b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DesignerCategoryAttributeTests.cs index c4ebcc4a09994..f51ef8eeabe62 100644 --- a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DesignerCategoryAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DesignerCategoryAttributeTests.cs @@ -36,20 +36,10 @@ public static IEnumerable Equals_TestData() yield return new object[] { attribute, new DesignerCategoryAttribute("category"), true }; yield return new object[] { attribute, new DesignerCategoryAttribute("category2"), false }; yield return new object[] { attribute, new DesignerCategoryAttribute(string.Empty), false }; - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { attribute, new DesignerCategoryAttribute(null), false }; - } - - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { new DesignerCategoryAttribute(null), new DesignerCategoryAttribute(null), true }; - yield return new object[] { new DesignerCategoryAttribute(null), new DesignerCategoryAttribute("category"), false }; - yield return new object[] { new DesignerCategoryAttribute(null), new DesignerCategoryAttribute(string.Empty), false }; - } - + yield return new object[] { attribute, new DesignerCategoryAttribute(null), false }; + yield return new object[] { new DesignerCategoryAttribute(null), new DesignerCategoryAttribute(null), true }; + yield return new object[] { new DesignerCategoryAttribute(null), new DesignerCategoryAttribute("category"), false }; + yield return new object[] { new DesignerCategoryAttribute(null), new DesignerCategoryAttribute(string.Empty), false }; yield return new object[] { new DesignerCategoryAttribute("category"), new object(), false }; yield return new object[] { new DesignerCategoryAttribute("category"), null, false }; yield return new object[] { new DesignerCategoryAttribute(null), new object(), false }; diff --git a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DisplayNameAttributeTests.cs b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DisplayNameAttributeTests.cs index 6fa1f9daaac81..c9dd2b9081b54 100644 --- a/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DisplayNameAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Primitives/tests/System/ComponentModel/DisplayNameAttributeTests.cs @@ -53,20 +53,10 @@ public static IEnumerable Equals_TestData() yield return new object[] { attribute, new DisplayNameAttribute("name"), true }; yield return new object[] { attribute, new DisplayNameAttribute("name2"), false }; yield return new object[] { attribute, new DisplayNameAttribute(""), false }; - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { attribute, new DisplayNameAttribute(null), false }; - } - - // .NET Framework throws a NullReferenceException. - if (!PlatformDetection.IsNetFramework) - { - yield return new object[] { new DisplayNameAttribute(null), new DisplayNameAttribute(null), true }; - yield return new object[] { new DisplayNameAttribute(null), new DisplayNameAttribute(""), false }; - yield return new object[] { new DisplayNameAttribute(null), new DisplayNameAttribute("name"), false }; - } - + yield return new object[] { attribute, new DisplayNameAttribute(null), false }; + yield return new object[] { new DisplayNameAttribute(null), new DisplayNameAttribute(null), true }; + yield return new object[] { new DisplayNameAttribute(null), new DisplayNameAttribute(""), false }; + yield return new object[] { new DisplayNameAttribute(null), new DisplayNameAttribute("name"), false }; yield return new object[] { new DisplayNameAttribute("name"), new object(), false }; yield return new object[] { new DisplayNameAttribute("name"), null, false }; yield return new object[] { new DisplayNameAttribute(null), new object(), false }; diff --git a/src/libraries/System.Console/tests/WindowAndCursorProps.cs b/src/libraries/System.Console/tests/WindowAndCursorProps.cs index 7ea07511594c4..c54fa87f0e361 100644 --- a/src/libraries/System.Console/tests/WindowAndCursorProps.cs +++ b/src/libraries/System.Console/tests/WindowAndCursorProps.cs @@ -258,15 +258,7 @@ public static void Title_Set_Windows(int lengthOfTitle) string newTitle = new string('a', int.Parse(lengthOfTitleString)); Console.Title = newTitle; - if (newTitle.Length >= 511 && !PlatformDetection.IsNetCore && PlatformDetection.IsWindows10Version1703OrGreater && !PlatformDetection.IsWindows10Version1709OrGreater) - { - // RS2 has a bug when getting the window title when the title length is longer than 513 character - Assert.Throws(() => Console.Title); - } - else - { - Assert.Equal(newTitle, Console.Title); - } + Assert.Equal(newTitle, Console.Title); }, lengthOfTitle.ToString()).Dispose(); } diff --git a/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs b/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs index 36f09b31543ed..6a14476a1a6bf 100644 --- a/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs @@ -941,7 +941,7 @@ public void PrivateDelegate(bool useInterpreter) Assert.Equal(42, del.DynamicInvoke()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] public void ValidateThatInterpreterWithSimpleTypeUsesNonDynamicThunk() { Expression action = () => Console.WriteLine(""); @@ -959,7 +959,7 @@ public void ValidateThatInterpreterWithSimpleTypeUsesNonDynamicThunk() Assert.True(func2.Compile(preferInterpretation:true).Method.GetType().Name == "RuntimeMethodInfo"); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] public void ValidateThatInterpreterWithSimpleTypeUsesDynamicThunk() { Expression> complexaction = (object o1, object o2, object o3) => Console.WriteLine(""); diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/CookieTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/CookieTest.cs index d2c44d4ef8427..1ba710d4f46e8 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/CookieTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/CookieTest.cs @@ -149,12 +149,9 @@ public static void Name_GetSet_Success() c1.Name = "hello"; Assert.Equal("hello", c1.Name); - if (!PlatformDetection.IsNetFramework) - { - Cookie c2 = new Cookie(); - c2.Name = "hello world"; - Assert.Equal("hello world", c2.Name); - } + Cookie c2 = new Cookie(); + c2.Name = "hello world"; + Assert.Equal("hello world", c2.Name); } [Theory] diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs index e06771ab57bfd..a67967b36811c 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs @@ -448,20 +448,10 @@ public static void Add_UriAuthenticationType_Success(string authType, NetworkCre // .NET Framework and .NET Core have different behaviors for Digest when default NetworkCredential is used. if (string.Equals(authType, authenticationTypeDigest, StringComparison.OrdinalIgnoreCase) && (nc == CredentialCache.DefaultNetworkCredentials)) { - if (PlatformDetection.IsNetFramework) - { - // In .NET Framework, when authType == Digest, if WDigestAvailable == true, it will pass the validation. - // if WDigestAvailable == false, it will throw ArgumentException. - // It is not possible to easily determine if Digest is supported or not on .NET Framework. So, we will skip the test. - return; - } - else - { - // In .NET Core, WDigestAvailable will always be false (we don't support it). - // It will always throw ArgumentException. - AssertExtensions.Throws("authType", () => cc.Add(uriPrefix1, authType, nc)); - return; - } + // In .NET Core, WDigestAvailable will always be false (we don't support it). + // It will always throw ArgumentException. + AssertExtensions.Throws("authType", () => cc.Add(uriPrefix1, authType, nc)); + return; } cc.Add(uriPrefix1, authType, nc); @@ -492,20 +482,10 @@ public static void Add_HostPortAuthenticationType_Success(string authType, Netwo // .NET Framework and .NET Core have different behaviors for Digest when default NetworkCredential is used. if (string.Equals(authType, authenticationTypeDigest, StringComparison.OrdinalIgnoreCase) && (nc == CredentialCache.DefaultNetworkCredentials)) { - if (PlatformDetection.IsNetFramework) - { - // In .NET Framework, when authType == Digest, if WDigestAvailable == true, it will pass the validation. - // if WDigestAvailable == false, it will throw ArgumentException. - // It is not possible to easily determine if Digest is supported or not on .NET Framework. So, we will skip the test. - return; - } - else - { - // In .NET Core, WDigestAvailable will always be false (we don't support it). - // It will always throw ArgumentException. - AssertExtensions.Throws("authenticationType", () => cc.Add(host1, port1, authType, nc)); - return; - } + // In .NET Core, WDigestAvailable will always be false (we don't support it). + // It will always throw ArgumentException. + AssertExtensions.Throws("authenticationType", () => cc.Add(host1, port1, authType, nc)); + return; } cc.Add(host1, port1, authType, nc); diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs index db786a5d11dcd..956c895d1ab8c 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressParsing.cs @@ -256,7 +256,7 @@ public void ParseIPv4_ValidAddress_Success(string address, string expected) [MemberData(nameof(InvalidIpv4AddressesStandalone))] public void ParseIPv4_InvalidAddress_Failure(string address) { - ParseInvalidAddress(address, hasInnerSocketException: !PlatformDetection.IsNetFramework); + ParseInvalidAddress(address, hasInnerSocketException: true); } @@ -587,7 +587,7 @@ public void ParseIPv6_InvalidAddress_ThrowsFormatException(string invalidAddress [MemberData(nameof(InvalidIpv6AddressesNoInner))] public void ParseIPv6_InvalidAddress_ThrowsFormatExceptionWithNoInnerExceptionInNetfx(string invalidAddress) { - ParseInvalidAddress(invalidAddress, hasInnerSocketException: !PlatformDetection.IsNetFramework); + ParseInvalidAddress(invalidAddress, hasInnerSocketException: true); } private void ParseInvalidAddress(string invalidAddress, bool hasInnerSocketException) diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressTest.cs index 8e232ced3a163..6175d76415975 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPAddressTest.cs @@ -209,7 +209,7 @@ public static void IsLoopback_Get_Success() Assert.True(IPAddress.IsLoopback(ip)); ip = new IPAddress(IPAddress.Loopback.MapToIPv6().GetAddressBytes()); // IPv4 loopback mapped to IPv6 - Assert.Equal(!PlatformDetection.IsNetFramework, IPAddress.IsLoopback(ip)); // https://github.com/dotnet/runtime/issues/28740 + Assert.True(IPAddress.IsLoopback(ip)); // https://github.com/dotnet/runtime/issues/28740 } [Fact] diff --git a/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs b/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs index 0a06c197c993c..06ee2c214ee85 100644 --- a/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs +++ b/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs @@ -344,18 +344,15 @@ public static IEnumerable SetCookiesData() } }; // Empty header followed by another empty header at the end - if (!PlatformDetection.IsNetFramework) + yield return new object[] { - yield return new object[] + uSecure, + "hello world=value", + new Cookie[] { - uSecure, - "hello world=value", - new Cookie[] - { - new Cookie("hello world", "value"), - } - }; // Name with space in it - } + new Cookie("hello world", "value"), + } + }; // Name with space in it } [Theory] diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs index 01bdea2da2b6d..13613df3a2479 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs @@ -263,7 +263,7 @@ public async Task SslStream_StreamToStream_Dispose_Throws() // We're inconsistent as to whether the ObjectDisposedException is thrown directly // or wrapped in an IOException. For Begin/End, it's always wrapped; for Async, // it's only wrapped on .NET Framework. - if (this is SslStreamStreamToStreamTest_BeginEnd || PlatformDetection.IsNetFramework) + if (this is SslStreamStreamToStreamTest_BeginEnd) { await Assert.ThrowsAsync(() => serverReadTask); } diff --git a/src/libraries/System.Net.WebSockets.Client/tests/AbortTest.cs b/src/libraries/System.Net.WebSockets.Client/tests/AbortTest.cs index d81baa53e4639..85f6e875a824c 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/AbortTest.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/AbortTest.cs @@ -48,10 +48,7 @@ public async Task Abort_ConnectAndAbort_ThrowsWebSocketExceptionWithmessage(Uri Assert.Equal(ResourceHelper.GetExceptionMessage("net_webstatus_ConnectFailure"), ex.Message); - if (PlatformDetection.IsNetCore) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960 - { - Assert.Equal(WebSocketError.Faulted, ex.WebSocketErrorCode); - } + Assert.Equal(WebSocketError.Faulted, ex.WebSocketErrorCode); Assert.Equal(WebSocketState.Closed, cws.State); } } diff --git a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.cs b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.cs index b3e0b6cfb4fca..7f44a7a69349a 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.cs @@ -112,7 +112,7 @@ public async Task ConnectAsync_NotWebSocketServer_ThrowsWebSocketExceptionWithMe WebSocketException ex = await Assert.ThrowsAsync(() => ConnectAsync(cws, server, cts.Token)); - if (PlatformDetection.IsNetCore && !PlatformDetection.IsInAppContainer) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960 + if (!PlatformDetection.IsInAppContainer) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960 { Assert.Equal(errorCode, ex.WebSocketErrorCode); } @@ -268,11 +268,8 @@ public async Task ConnectAsync_PassNoSubProtocol_ServerRequires_ThrowsWebSocketE WebSocketException ex = await Assert.ThrowsAsync(() => ConnectAsync(cws, ub.Uri, cts.Token)); _output.WriteLine(ex.Message); - if (PlatformDetection.IsNetCore) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960 - { - Assert.True(ex.WebSocketErrorCode == WebSocketError.Faulted || - ex.WebSocketErrorCode == WebSocketError.NotAWebSocket, $"Actual WebSocketErrorCode {ex.WebSocketErrorCode} {ex.InnerException?.Message} \n {ex}"); - } + Assert.True(ex.WebSocketErrorCode == WebSocketError.Faulted || + ex.WebSocketErrorCode == WebSocketError.NotAWebSocket, $"Actual WebSocketErrorCode {ex.WebSocketErrorCode} {ex.InnerException?.Message} \n {ex}"); Assert.Equal(WebSocketState.Closed, cws.State); } } diff --git a/src/libraries/System.Net.WebSockets/tests/WebSocketTests.cs b/src/libraries/System.Net.WebSockets/tests/WebSocketTests.cs index 3d0b54bd8ea5b..21a9ea7d27a47 100644 --- a/src/libraries/System.Net.WebSockets/tests/WebSocketTests.cs +++ b/src/libraries/System.Net.WebSockets/tests/WebSocketTests.cs @@ -132,10 +132,7 @@ public static void IsStateTerminal_TerminalReturnsTrue(WebSocketState state) public static void ThrowOnInvalidState_ThrowsIfNotInValidList(WebSocketState state, WebSocketState[] validStates) { WebSocketException wse = Assert.Throws(() => ExposeProtectedWebSocket.ThrowOnInvalidState(state, validStates)); - if (PlatformDetection.IsNetCore) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960 - { - Assert.Equal(WebSocketError.InvalidState, wse.WebSocketErrorCode); - } + Assert.Equal(WebSocketError.InvalidState, wse.WebSocketErrorCode); } [Theory] diff --git a/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs b/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs index 007bb6baf8baa..905d8c4495cd6 100644 --- a/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs +++ b/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs @@ -176,7 +176,7 @@ public void v1(string ns1, string ns2, string attrNs, int expectedError, string Assert.Equal(expectedError, _errorCount); // .NET Framework does not set the namespace property for intersections and unions - if (!PlatformDetection.IsNetFramework && expectedNs != null) + if (expectedNs != null) { XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t", attrNs)]).AttributeWildcard; CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace); @@ -211,7 +211,7 @@ public void v2(string ns1, string ns2, string attrNs, int expectedError, string Assert.Equal(expectedError, _errorCount); // .NET Framework does not set the namespace property for intersections and unions - if (!PlatformDetection.IsNetFramework && expectedNs != null) + if (expectedNs != null) { XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t1", attrNs)]).AttributeWildcard; CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace); diff --git a/src/libraries/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltArgumentList.cs b/src/libraries/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltArgumentList.cs index d28d2bf7a840f..21603113f5cec 100644 --- a/src/libraries/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltArgumentList.cs +++ b/src/libraries/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltArgumentList.cs @@ -2988,7 +2988,7 @@ public void TC_ExtensionObj_Function_Mismatch_IncorrectCasing(XslInputType xslIn m_xsltArg.AddExtensionObject(szDefaultNS, obj); LoadXSL("MyObject_CaseSensitive.xsl", xslInputType, readerType); var e = Assert.ThrowsAny(() => Transform_ArgList("fruits.xml", outputType, navType)); - var exceptionSourceAssembly = PlatformDetection.IsNetFramework ? "System.Data.SqlXml" : "System.Xml"; + var exceptionSourceAssembly = "System.Xml"; CheckExpectedError(e, exceptionSourceAssembly, "XmlIl_NoExtensionMethod", new[] { "urn:my-object", "FN3", "0" }); } diff --git a/src/libraries/System.Reflection.Emit/tests/AssemblyBuilderTests.cs b/src/libraries/System.Reflection.Emit/tests/AssemblyBuilderTests.cs index f0ffed8a72fcc..7a6d835fa63b6 100644 --- a/src/libraries/System.Reflection.Emit/tests/AssemblyBuilderTests.cs +++ b/src/libraries/System.Reflection.Emit/tests/AssemblyBuilderTests.cs @@ -145,14 +145,7 @@ public void DefineDynamicModule(string name) Assert.Equal("", module.Name); // The coreclr ignores the name passed to AssemblyBuilder.DefineDynamicModule - if (PlatformDetection.IsNetFramework) - { - Assert.Equal(name, module.FullyQualifiedName); - } - else - { - Assert.Equal("RefEmit_InMemoryManifestModule", module.FullyQualifiedName); - } + Assert.Equal("RefEmit_InMemoryManifestModule", module.FullyQualifiedName); Assert.Equal(module, assembly.GetDynamicModule(module.FullyQualifiedName)); } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs index 0e06d9c1adaef..cf2eae00ebc11 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.cs @@ -50,15 +50,8 @@ public void GenerateGuidForType_ValidType_ReturnsExpected(Type type) { if (type.HasElementType) { - if (PlatformDetection.IsNetCore) - { - Assert.Equal(Guid.Empty, type.GUID); - Assert.Equal(type.GUID, Marshal.GenerateGuidForType(type)); - } - else - { - Assert.NotEqual(type.GUID, Marshal.GenerateGuidForType(type)); - } + Assert.Equal(Guid.Empty, type.GUID); + Assert.Equal(type.GUID, Marshal.GenerateGuidForType(type)); } else { diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs index b7a3b8e398e58..a10836c1a9500 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForNativeVariantTests.Windows.cs @@ -243,7 +243,7 @@ public static IEnumerable GetObjectForNativeVariant_PrimitivesByRef_Te }; var obj = new Common.IDispatchComObject(); - if (!PlatformDetection.IsNetCore || PlatformDetection.IsWindows) + if (PlatformDetection.IsWindows) { IntPtr dispatch = Marshal.GetIDispatchForObject(obj); yield return new object[] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ThrowExceptionForHRTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ThrowExceptionForHRTests.cs index c364da559b2dc..68c87a4b8effb 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ThrowExceptionForHRTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ThrowExceptionForHRTests.cs @@ -33,9 +33,7 @@ public void ThrowExceptionForHR_NoErrorInfo_ReturnsValidException(int errorCode) Assert.Null(ex.HelpLink); Assert.NotEmpty(ex.Message); - string sourceMaybe = PlatformDetection.IsNetCore - ? "System.Private.CoreLib" - : "mscorlib"; + string sourceMaybe = "System.Private.CoreLib"; // If the ThrowExceptionForHR is inlined by the JIT, the source could be the test assembly Assert.Contains(ex.Source, new string[]{ sourceMaybe, Assembly.GetExecutingAssembly().GetName().Name }); @@ -76,9 +74,7 @@ public void ThrowExceptionForHR_ErrorInfo_ReturnsValidException(int errorCode, I Assert.Null(ex.HelpLink); Assert.NotEmpty(ex.Message); - string sourceMaybe = PlatformDetection.IsNetCore - ? "System.Private.CoreLib" - : "mscorlib"; + string sourceMaybe = "System.Private.CoreLib"; // If the ThrowExceptionForHR is inlined by the JIT, the source could be the test assembly Assert.Contains(ex.Source, new string[]{ sourceMaybe, Assembly.GetExecutingAssembly().GetName().Name }); diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/GetCultureInfo.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/GetCultureInfo.cs index a1dc7c2c9c7a8..75191ba8b4451 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/GetCultureInfo.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/GetCultureInfo.cs @@ -11,7 +11,7 @@ namespace System.Globalization.Tests { public class GetCultureInfoTests { - public static bool PlatformSupportsFakeCulture => (!PlatformDetection.IsWindows || (PlatformDetection.WindowsVersion >= 10 && !PlatformDetection.IsNetFramework)) && PlatformDetection.IsNotBrowser; + public static bool PlatformSupportsFakeCulture => (!PlatformDetection.IsWindows || PlatformDetection.WindowsVersion >= 10) && PlatformDetection.IsNotBrowser; public static bool PlatformSupportsFakeCultureAndRemoteExecutor => PlatformSupportsFakeCulture && RemoteExecutor.IsSupported; public static IEnumerable GetCultureInfoTestData() diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/DirectoryInfo/ToString.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/DirectoryInfo/ToString.cs index c9fffd7ef042d..d5df0fa2ee1d3 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/DirectoryInfo/ToString.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/DirectoryInfo/ToString.cs @@ -45,13 +45,7 @@ public void DriveOnlyReturnsDrive_Windows() Assert.Equal(path, info.ToString()); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNetFramework))] - public void ParentToString_Framework() - { - ParentToString(false); - } - - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNetCore))] + [Fact] public void ParentToString_Core() { ParentToString(true); diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_str_fm.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_str_fm.cs index 44cafb53a891c..5239b6a0345e3 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_str_fm.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_str_fm.cs @@ -62,7 +62,7 @@ public static TheoryData StreamSpecifiers TheoryData data = new TheoryData(); data.Add(""); - if (PlatformDetection.IsWindows && PlatformDetection.IsNetCore) + if (PlatformDetection.IsWindows) { data.Add("::$DATA"); // Same as default stream (e.g. main file) data.Add(":bar"); // $DATA isn't necessary diff --git a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.CloseTests.cs b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.CloseTests.cs index af4d612ce330a..f9f72367b7a5f 100644 --- a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.CloseTests.cs +++ b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.CloseTests.cs @@ -40,10 +40,7 @@ public void AfterCloseThrows() private void ValidateDisposedExceptions(StreamWriter sw) { - if (PlatformDetection.IsNetCore) - { - Assert.NotNull(sw.BaseStream); - } + Assert.NotNull(sw.BaseStream); Assert.Throws(() => sw.Write('A')); Assert.Throws(() => sw.Write("hello")); Assert.Throws(() => sw.Flush()); diff --git a/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/NegativeEncodingTests.cs b/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/NegativeEncodingTests.cs index d0e1e5a51cfa6..3eb90f87286fa 100644 --- a/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/NegativeEncodingTests.cs +++ b/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/NegativeEncodingTests.cs @@ -43,14 +43,7 @@ public static IEnumerable Encodings_TestData() public static unsafe void GetByteCount_Invalid(Encoding encoding) { // Chars is null - if (PlatformDetection.IsNetCore) - { - AssertExtensions.Throws((encoding is ASCIIEncoding || encoding is UTF8Encoding) ? "chars" : "s", () => encoding.GetByteCount((string)null)); - } - else - { - AssertExtensions.Throws((encoding is ASCIIEncoding) ? "chars" : "s", () => encoding.GetByteCount((string)null)); - } + AssertExtensions.Throws((encoding is ASCIIEncoding || encoding is UTF8Encoding) ? "chars" : "s", () => encoding.GetByteCount((string)null)); AssertExtensions.Throws("chars", () => encoding.GetByteCount((char[])null)); AssertExtensions.Throws("chars", () => encoding.GetByteCount((char[])null, 0, 0)); diff --git a/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/UTF8Encoding/UTF8EncodingDecode.cs b/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/UTF8Encoding/UTF8EncodingDecode.cs index 4225c91577301..a72de64b7e641 100644 --- a/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/UTF8Encoding/UTF8EncodingDecode.cs +++ b/src/libraries/System.Runtime/tests/System.Text.Encoding.Tests/UTF8Encoding/UTF8EncodingDecode.cs @@ -125,217 +125,120 @@ public static IEnumerable Decode_InvalidBytes_TestData() yield return new object[] { validSurrogateBytes, 2, 2, "\uFFFD\uFFFD" }; yield return new object[] { validSurrogateBytes, 2, 1, "\uFFFD" }; - if (PlatformDetection.IsNetCore) - { - // Overlong 2-byte sequences - yield return new object[] { new byte[] { 0xC0, 0x80 }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xC1, 0x80 }, 0, 2, "\uFFFD\uFFFD" }; - - // Incomplete 2-byte sequences - yield return new object[] { new byte[] { 0xC2, 0x41 }, 0, 2, "\uFFFD\u0041" }; - yield return new object[] { new byte[] { 0xC2, 0x41 }, 0, 2, "\uFFFD\u0041" }; - - // Overlong 3-byte sequences - yield return new object[] { new byte[] { 0xE0, 0x80, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0x9F, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - - // Truncated 3-byte sequences - yield return new object[] { new byte[] { 0xE0, 0xA0, 0x41 }, 0, 3, "\uFFFD\u0041" }; - yield return new object[] { new byte[] { 0xED, 0x9F, 0x41 }, 0, 3, "\uFFFD\u0041" }; - - // UTF-16 surrogate code points (invalid to be encoded in UTF-8) - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xAF, 0xBF }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xB0, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xBF, 0xBF }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xED, 0xAF, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xB0, 0x80, 0xED, 0xB0, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xED, 0xA0, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - - // Overlong 4-byte sequences - yield return new object[] { new byte[] { 0xF0, 0x80, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x8F, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - - // Truncated 4-byte sequences - yield return new object[] { new byte[] { 0xF0, 0x90, 0x41, 0x42 }, 0, 4, "\uFFFD\u0041\u0042" }; - yield return new object[] { new byte[] { 0xF0, 0x90, 0x80, 0x42 }, 0, 4, "\uFFFD\u0042" }; - - // Too high scalar value in surrogates - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xEE, 0x80, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uE000" }; - yield return new object[] { new byte[] { 0xF4, 0x90, 0x80, 0x80 }, 0, 4, "\uFFFD\uFFFD\uFFFD\uFFFD" }; - - // More examples of overlong sequences. This can cause security - // vulnerabilities (e.g. MS00-078) so it is important we parse these as invalid. - yield return new object[] { new byte[] { 0xC0 }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xC0, 0xAF }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0x80, 0xBF }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x80, 0x80, 0xBF }, 0, 4, "\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF8, 0x80, 0x80, 0x80, 0xBF }, 0, 5, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xFC, 0x80, 0x80, 0x80, 0x80, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xC0, 0xBF }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0x9C, 0x90 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x8F, 0xA4, 0x80 }, 0, 4, "\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xEF, 0x41 }, 0, 2, "\uFFFD\u0041" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0xAE }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0x41 }, 0, 3, "\uFFFD\u0041" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0x61 }, 0, 3, "\uFFFD\u0061" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0xEF, 0xBF, 0xAE }, 0, 5, "\uFFFD\uFFEE" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0xC0, 0xBF }, 0, 4, "\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF0, 0xC4, 0x80 }, 0, 3, "\uFFFD\u0100" }; - - yield return new object[] { new byte[] { 176 }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 196 }, 0, 1, "\uFFFD" }; - - yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0x52, 0x7C, 0x7B, 0x41, 0x6E, 0x47, 0x65, 0xA3, 0xA4 }, 0, 12, "\uFFFD\uFFFD\u0061\u0052\u007C\u007B\u0041\u006E\u0047\u0065\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xA3 }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xA3, 0xA4 }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x65, 0xA3, 0xA4 }, 0, 3, "\u0065\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x47, 0x65, 0xA3, 0xA4 }, 0, 4, "\u0047\u0065\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0xA3, 0xA4 }, 0, 5, "\uFFFD\uFFFD\u0061\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0xA3 }, 0, 4, "\uFFFD\uFFFD\u0061\uFFFD" }; - yield return new object[] { new byte[] { 0xD0, 0x61, 0xA3 }, 0, 3, "\uFFFD\u0061\uFFFD" }; - yield return new object[] { new byte[] { 0xA4, 0x61, 0xA3 }, 0, 3, "\uFFFD\u0061\uFFFD" }; - yield return new object[] { new byte[] { 0xD0, 0x61, 0x52, 0xA3 }, 0, 4, "\uFFFD\u0061\u0052\uFFFD" }; - - yield return new object[] { new byte[] { 0xAA }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xAA, 0x41 }, 0, 2, "\uFFFD\u0041" }; - - yield return new object[] { new byte[] { 0xEF, 0xFF, 0xEE }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xEF, 0xFF, 0xAE }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0x80, 0x90, 0xA0, 0xB0, 0xC1 }, 0, 5, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x90, 0xA0, 0xB0, 0xC1 }, 0, 15, "\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x80, 0x90, 0xA0, 0xB0, 0xC1, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F }, 0, 15, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F" }; - - yield return new object[] { new byte[] { 0xC2, 0x7F, 0xC2, 0xC0, 0xDF, 0x7F, 0xDF, 0xC0 }, 0, 8, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xC2, 0xDF }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x80, 0x80, 0xC1, 0x80, 0xC1, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xC2, 0x7F, 0xC2, 0xC0, 0x7F, 0x7F, 0x7F, 0x7F, 0xC3, 0xA1, 0xDF, 0x7F, 0xDF, 0xC0 }, 0, 14, "\uFFFD\u007F\uFFFD\uFFFD\u007F\u007F\u007F\u007F\u00E1\uFFFD\u007F\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xE0, 0xA0, 0x7F, 0xE0, 0xA0, 0xC0, 0xE0, 0xBF, 0x7F, 0xE0, 0xBF, 0xC0 }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0x9F, 0x80, 0xE0, 0xC0, 0x80, 0xE0, 0x9F, 0xBF, 0xE0, 0xC0, 0xBF }, 0, 12, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0xA0, 0x7F, 0xE0, 0xA0, 0xC0, 0x7F, 0xE0, 0xBF, 0x7F, 0xC3, 0xA1, 0xE0, 0xBF, 0xC0 }, 0, 15, "\uFFFD\u007F\uFFFD\uFFFD\u007F\uFFFD\u007F\u00E1\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xE1, 0x80, 0x7F, 0xE1, 0x80, 0xC0, 0xE1, 0xBF, 0x7F, 0xE1, 0xBF, 0xC0, 0xEC, 0x80, 0x7F, 0xEC, 0x80, 0xC0, 0xEC, 0xBF, 0x7F, 0xEC, 0xBF, 0xC0 }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE1, 0x7F, 0x80, 0xE1, 0xC0, 0x80, 0xE1, 0x7F, 0xBF, 0xE1, 0xC0, 0xBF, 0xEC, 0x7F, 0x80, 0xEC, 0xC0, 0x80, 0xEC, 0x7F, 0xBF, 0xEC, 0xC0, 0xBF }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xED, 0x80, 0x7F, 0xED, 0x80, 0xC0, 0xED, 0x9F, 0x7F, 0xED, 0x9F, 0xC0 }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0x7F, 0x80, 0xED, 0xA0, 0x80, 0xED, 0x7F, 0xBF, 0xED, 0xA0, 0xBF }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0x7F, 0x80, 0xED, 0xA0, 0x80, 0xE8, 0x80, 0x80, 0xED, 0x7F, 0xBF, 0xED, 0xA0, 0xBF }, 0, 15, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\u8000\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xEE, 0x80, 0x7F, 0xEE, 0x80, 0xC0, 0xEE, 0xBF, 0x7F, 0xEE, 0xBF, 0xC0, 0xEF, 0x80, 0x7F, 0xEF, 0x80, 0xC0, 0xEF, 0xBF, 0x7F, 0xEF, 0xBF, 0xC0 }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xEE, 0x7F, 0x80, 0xEE, 0xC0, 0x80, 0xEE, 0x7F, 0xBF, 0xEE, 0xC0, 0xBF, 0xEF, 0x7F, 0x80, 0xEF, 0xC0, 0x80, 0xEF, 0x7F, 0xBF, 0xEF, 0xC0, 0xBF }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF0, 0x90, 0x80, 0x7F, 0xF0, 0x90, 0x80, 0xC0, 0xF0, 0xBF, 0xBF, 0x7F, 0xF0, 0xBF, 0xBF, 0xC0 }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x90, 0x7F, 0x80, 0xF0, 0x90, 0xC0, 0x80, 0xF0, 0x90, 0x7F, 0xBF, 0xF0, 0x90, 0xC0, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x8F, 0x80, 0x80, 0xF0, 0xC0, 0x80, 0x80, 0xF0, 0x8F, 0xBF, 0xBF, 0xF0, 0xC0, 0xBF, 0xBF }, 0, 16, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF1, 0x80, 0x80, 0x7F, 0xF1, 0x80, 0x80, 0xC0, 0xF1, 0xBF, 0xBF, 0x7F, 0xF1, 0xBF, 0xBF, 0xC0, 0xF3, 0x80, 0x80, 0x7F, 0xF3, 0x80, 0x80, 0xC0, 0xF3, 0xBF, 0xBF, 0x7F, 0xF3, 0xBF, 0xBF, 0xC0 }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF1, 0x80, 0x7F, 0x80, 0xF1, 0x80, 0xC0, 0x80, 0xF1, 0x80, 0x7F, 0xBF, 0xF1, 0x80, 0xC0, 0xBF, 0xF3, 0x80, 0x7F, 0x80, 0xF3, 0x80, 0xC0, 0x80, 0xF3, 0x80, 0x7F, 0xBF, 0xF3, 0x80, 0xC0, 0xBF }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF1, 0x7F, 0x80, 0x80, 0xF1, 0xC0, 0x80, 0x80, 0xF1, 0x7F, 0xBF, 0xBF, 0xF1, 0xC0, 0xBF, 0xBF, 0xF3, 0x7F, 0x80, 0x80, 0xF3, 0xC0, 0x80, 0x80, 0xF3, 0x7F, 0xBF, 0xBF, 0xF3, 0xC0, 0xBF, 0xBF }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF4, 0x80, 0x80, 0x7F, 0xF4, 0x80, 0x80, 0xC0, 0xF4, 0x8F, 0xBF, 0x7F, 0xF4, 0x8F, 0xBF, 0xC0 }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF4, 0x80, 0x7F, 0x80, 0xF4, 0x80, 0xC0, 0x80, 0xF4, 0x80, 0x7F, 0xBF, 0xF4, 0x80, 0xC0, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF4, 0x7F, 0x80, 0x80, 0xF4, 0x90, 0x80, 0x80, 0xF4, 0x7F, 0xBF, 0xBF, 0xF4, 0x90, 0xBF, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - } - else - { - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80 }, 0, 3, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xAF, 0xBF }, 0, 3, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xB0, 0x80 }, 0, 3, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xBF, 0xBF }, 0, 3, "\uFFFD\uFFFD" }; - - // Invalid surrogate pair (low/low, high/high, low/high) - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xED, 0xAF, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xB0, 0x80, 0xED, 0xB0, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xED, 0xA0, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD" }; - - // Too high scalar value in surrogates - yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xEE, 0x80, 0x80 }, 0, 6, "\uFFFD\uFFFD\uE000" }; - yield return new object[] { new byte[] { 0xF4, 0x90, 0x80, 0x80 }, 0, 4, "\uFFFD\uFFFD\uFFFD" }; - - // These are examples of overlong sequences. This can cause security - // vulnerabilities (e.g. MS00-078) so it is important we parse these as invalid. - yield return new object[] { new byte[] { 0xC0 }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xC0, 0xAF }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0x80, 0xBF }, 0, 3, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x80, 0x80, 0xBF }, 0, 4, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF8, 0x80, 0x80, 0x80, 0xBF }, 0, 5, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xFC, 0x80, 0x80, 0x80, 0x80, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xC0, 0xBF }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0x9C, 0x90 }, 0, 3, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x8F, 0xA4, 0x80 }, 0, 4, "\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xEF, 0x41 }, 0, 2, "\uFFFD\u0041" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0xAE }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0x41 }, 0, 3, "\uFFFD\u0041" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0x61 }, 0, 3, "\uFFFD\u0061" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0xEF, 0xBF, 0xAE }, 0, 5, "\uFFFD\uFFEE" }; - yield return new object[] { new byte[] { 0xEF, 0xBF, 0xC0, 0xBF }, 0, 4, "\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF0, 0xC4, 0x80 }, 0, 3, "\uFFFD\u0100" }; - - yield return new object[] { new byte[] { 176 }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 196 }, 0, 1, "\uFFFD" }; - - yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0x52, 0x7C, 0x7B, 0x41, 0x6E, 0x47, 0x65, 0xA3, 0xA4 }, 0, 12, "\uFFFD\uFFFD\u0061\u0052\u007C\u007B\u0041\u006E\u0047\u0065\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xA3 }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xA3, 0xA4 }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x65, 0xA3, 0xA4 }, 0, 3, "\u0065\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x47, 0x65, 0xA3, 0xA4 }, 0, 4, "\u0047\u0065\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0xA3, 0xA4 }, 0, 5, "\uFFFD\uFFFD\u0061\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0xA3 }, 0, 4, "\uFFFD\uFFFD\u0061\uFFFD" }; - yield return new object[] { new byte[] { 0xD0, 0x61, 0xA3 }, 0, 3, "\uFFFD\u0061\uFFFD" }; - yield return new object[] { new byte[] { 0xA4, 0x61, 0xA3 }, 0, 3, "\uFFFD\u0061\uFFFD" }; - yield return new object[] { new byte[] { 0xD0, 0x61, 0x52, 0xA3 }, 0, 4, "\uFFFD\u0061\u0052\uFFFD" }; - - yield return new object[] { new byte[] { 0xAA }, 0, 1, "\uFFFD" }; - yield return new object[] { new byte[] { 0xAA, 0x41 }, 0, 2, "\uFFFD\u0041" }; - - yield return new object[] { new byte[] { 0xEF, 0xFF, 0xEE }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xEF, 0xFF, 0xAE }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0x80, 0x90, 0xA0, 0xB0, 0xC1 }, 0, 5, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x90, 0xA0, 0xB0, 0xC1 }, 0, 15, "\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x80, 0x90, 0xA0, 0xB0, 0xC1, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F }, 0, 15, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F" }; - - yield return new object[] { new byte[] { 0xC2, 0x7F, 0xC2, 0xC0, 0xDF, 0x7F, 0xDF, 0xC0 }, 0, 8, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xC2, 0xDF }, 0, 2, "\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0x80, 0x80, 0xC1, 0x80, 0xC1, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xC2, 0x7F, 0xC2, 0xC0, 0x7F, 0x7F, 0x7F, 0x7F, 0xC3, 0xA1, 0xDF, 0x7F, 0xDF, 0xC0 }, 0, 14, "\uFFFD\u007F\uFFFD\uFFFD\u007F\u007F\u007F\u007F\u00E1\uFFFD\u007F\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xE0, 0xA0, 0x7F, 0xE0, 0xA0, 0xC0, 0xE0, 0xBF, 0x7F, 0xE0, 0xBF, 0xC0 }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0x9F, 0x80, 0xE0, 0xC0, 0x80, 0xE0, 0x9F, 0xBF, 0xE0, 0xC0, 0xBF }, 0, 12, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE0, 0xA0, 0x7F, 0xE0, 0xA0, 0xC0, 0x7F, 0xE0, 0xBF, 0x7F, 0xC3, 0xA1, 0xE0, 0xBF, 0xC0 }, 0, 15, "\uFFFD\u007F\uFFFD\uFFFD\u007F\uFFFD\u007F\u00E1\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xE1, 0x80, 0x7F, 0xE1, 0x80, 0xC0, 0xE1, 0xBF, 0x7F, 0xE1, 0xBF, 0xC0, 0xEC, 0x80, 0x7F, 0xEC, 0x80, 0xC0, 0xEC, 0xBF, 0x7F, 0xEC, 0xBF, 0xC0 }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xE1, 0x7F, 0x80, 0xE1, 0xC0, 0x80, 0xE1, 0x7F, 0xBF, 0xE1, 0xC0, 0xBF, 0xEC, 0x7F, 0x80, 0xEC, 0xC0, 0x80, 0xEC, 0x7F, 0xBF, 0xEC, 0xC0, 0xBF }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xED, 0x80, 0x7F, 0xED, 0x80, 0xC0, 0xED, 0x9F, 0x7F, 0xED, 0x9F, 0xC0 }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0x7F, 0x80, 0xED, 0xA0, 0x80, 0xED, 0x7F, 0xBF, 0xED, 0xA0, 0xBF }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xED, 0x7F, 0x80, 0xED, 0xA0, 0x80, 0xE8, 0x80, 0x80, 0xED, 0x7F, 0xBF, 0xED, 0xA0, 0xBF }, 0, 15, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u8000\uFFFD\u007F\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xEE, 0x80, 0x7F, 0xEE, 0x80, 0xC0, 0xEE, 0xBF, 0x7F, 0xEE, 0xBF, 0xC0, 0xEF, 0x80, 0x7F, 0xEF, 0x80, 0xC0, 0xEF, 0xBF, 0x7F, 0xEF, 0xBF, 0xC0 }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xEE, 0x7F, 0x80, 0xEE, 0xC0, 0x80, 0xEE, 0x7F, 0xBF, 0xEE, 0xC0, 0xBF, 0xEF, 0x7F, 0x80, 0xEF, 0xC0, 0x80, 0xEF, 0x7F, 0xBF, 0xEF, 0xC0, 0xBF }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF0, 0x90, 0x80, 0x7F, 0xF0, 0x90, 0x80, 0xC0, 0xF0, 0xBF, 0xBF, 0x7F, 0xF0, 0xBF, 0xBF, 0xC0 }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x90, 0x7F, 0x80, 0xF0, 0x90, 0xC0, 0x80, 0xF0, 0x90, 0x7F, 0xBF, 0xF0, 0x90, 0xC0, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF0, 0x8F, 0x80, 0x80, 0xF0, 0xC0, 0x80, 0x80, 0xF0, 0x8F, 0xBF, 0xBF, 0xF0, 0xC0, 0xBF, 0xBF }, 0, 16, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF1, 0x80, 0x80, 0x7F, 0xF1, 0x80, 0x80, 0xC0, 0xF1, 0xBF, 0xBF, 0x7F, 0xF1, 0xBF, 0xBF, 0xC0, 0xF3, 0x80, 0x80, 0x7F, 0xF3, 0x80, 0x80, 0xC0, 0xF3, 0xBF, 0xBF, 0x7F, 0xF3, 0xBF, 0xBF, 0xC0 }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF1, 0x80, 0x7F, 0x80, 0xF1, 0x80, 0xC0, 0x80, 0xF1, 0x80, 0x7F, 0xBF, 0xF1, 0x80, 0xC0, 0xBF, 0xF3, 0x80, 0x7F, 0x80, 0xF3, 0x80, 0xC0, 0x80, 0xF3, 0x80, 0x7F, 0xBF, 0xF3, 0x80, 0xC0, 0xBF }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF1, 0x7F, 0x80, 0x80, 0xF1, 0xC0, 0x80, 0x80, 0xF1, 0x7F, 0xBF, 0xBF, 0xF1, 0xC0, 0xBF, 0xBF, 0xF3, 0x7F, 0x80, 0x80, 0xF3, 0xC0, 0x80, 0x80, 0xF3, 0x7F, 0xBF, 0xBF, 0xF3, 0xC0, 0xBF, 0xBF }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - - yield return new object[] { new byte[] { 0xF4, 0x80, 0x80, 0x7F, 0xF4, 0x80, 0x80, 0xC0, 0xF4, 0x8F, 0xBF, 0x7F, 0xF4, 0x8F, 0xBF, 0xC0 }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF4, 0x80, 0x7F, 0x80, 0xF4, 0x80, 0xC0, 0x80, 0xF4, 0x80, 0x7F, 0xBF, 0xF4, 0x80, 0xC0, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; - yield return new object[] { new byte[] { 0xF4, 0x7F, 0x80, 0x80, 0xF4, 0x90, 0x80, 0x80, 0xF4, 0x7F, 0xBF, 0xBF, 0xF4, 0x90, 0xBF, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; - } + // Overlong 2-byte sequences + yield return new object[] { new byte[] { 0xC0, 0x80 }, 0, 2, "\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xC1, 0x80 }, 0, 2, "\uFFFD\uFFFD" }; + + // Incomplete 2-byte sequences + yield return new object[] { new byte[] { 0xC2, 0x41 }, 0, 2, "\uFFFD\u0041" }; + yield return new object[] { new byte[] { 0xC2, 0x41 }, 0, 2, "\uFFFD\u0041" }; + + // Overlong 3-byte sequences + yield return new object[] { new byte[] { 0xE0, 0x80, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xE0, 0x9F, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + + // Truncated 3-byte sequences + yield return new object[] { new byte[] { 0xE0, 0xA0, 0x41 }, 0, 3, "\uFFFD\u0041" }; + yield return new object[] { new byte[] { 0xED, 0x9F, 0x41 }, 0, 3, "\uFFFD\u0041" }; + + // UTF-16 surrogate code points (invalid to be encoded in UTF-8) + yield return new object[] { new byte[] { 0xED, 0xA0, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0xAF, 0xBF }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0xB0, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0xBF, 0xBF }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xED, 0xAF, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0xB0, 0x80, 0xED, 0xB0, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xED, 0xA0, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + + // Overlong 4-byte sequences + yield return new object[] { new byte[] { 0xF0, 0x80, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF0, 0x8F, 0x80 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + + // Truncated 4-byte sequences + yield return new object[] { new byte[] { 0xF0, 0x90, 0x41, 0x42 }, 0, 4, "\uFFFD\u0041\u0042" }; + yield return new object[] { new byte[] { 0xF0, 0x90, 0x80, 0x42 }, 0, 4, "\uFFFD\u0042" }; + + // Too high scalar value in surrogates + yield return new object[] { new byte[] { 0xED, 0xA0, 0x80, 0xEE, 0x80, 0x80 }, 0, 6, "\uFFFD\uFFFD\uFFFD\uE000" }; + yield return new object[] { new byte[] { 0xF4, 0x90, 0x80, 0x80 }, 0, 4, "\uFFFD\uFFFD\uFFFD\uFFFD" }; + + // More examples of overlong sequences. This can cause security + // vulnerabilities (e.g. MS00-078) so it is important we parse these as invalid. + yield return new object[] { new byte[] { 0xC0 }, 0, 1, "\uFFFD" }; + yield return new object[] { new byte[] { 0xC0, 0xAF }, 0, 2, "\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xE0, 0x80, 0xBF }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF0, 0x80, 0x80, 0xBF }, 0, 4, "\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF8, 0x80, 0x80, 0x80, 0xBF }, 0, 5, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xFC, 0x80, 0x80, 0x80, 0x80, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xC0, 0xBF }, 0, 2, "\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xE0, 0x9C, 0x90 }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF0, 0x8F, 0xA4, 0x80 }, 0, 4, "\uFFFD\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xEF, 0x41 }, 0, 2, "\uFFFD\u0041" }; + yield return new object[] { new byte[] { 0xEF, 0xBF, 0xAE }, 0, 1, "\uFFFD" }; + yield return new object[] { new byte[] { 0xEF, 0xBF, 0x41 }, 0, 3, "\uFFFD\u0041" }; + yield return new object[] { new byte[] { 0xEF, 0xBF, 0x61 }, 0, 3, "\uFFFD\u0061" }; + yield return new object[] { new byte[] { 0xEF, 0xBF, 0xEF, 0xBF, 0xAE }, 0, 5, "\uFFFD\uFFEE" }; + yield return new object[] { new byte[] { 0xEF, 0xBF, 0xC0, 0xBF }, 0, 4, "\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xF0, 0xC4, 0x80 }, 0, 3, "\uFFFD\u0100" }; + + yield return new object[] { new byte[] { 176 }, 0, 1, "\uFFFD" }; + yield return new object[] { new byte[] { 196 }, 0, 1, "\uFFFD" }; + + yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0x52, 0x7C, 0x7B, 0x41, 0x6E, 0x47, 0x65, 0xA3, 0xA4 }, 0, 12, "\uFFFD\uFFFD\u0061\u0052\u007C\u007B\u0041\u006E\u0047\u0065\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xA3 }, 0, 1, "\uFFFD" }; + yield return new object[] { new byte[] { 0xA3, 0xA4 }, 0, 2, "\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0x65, 0xA3, 0xA4 }, 0, 3, "\u0065\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0x47, 0x65, 0xA3, 0xA4 }, 0, 4, "\u0047\u0065\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0xA3, 0xA4 }, 0, 5, "\uFFFD\uFFFD\u0061\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xA4, 0xD0, 0x61, 0xA3 }, 0, 4, "\uFFFD\uFFFD\u0061\uFFFD" }; + yield return new object[] { new byte[] { 0xD0, 0x61, 0xA3 }, 0, 3, "\uFFFD\u0061\uFFFD" }; + yield return new object[] { new byte[] { 0xA4, 0x61, 0xA3 }, 0, 3, "\uFFFD\u0061\uFFFD" }; + yield return new object[] { new byte[] { 0xD0, 0x61, 0x52, 0xA3 }, 0, 4, "\uFFFD\u0061\u0052\uFFFD" }; + + yield return new object[] { new byte[] { 0xAA }, 0, 1, "\uFFFD" }; + yield return new object[] { new byte[] { 0xAA, 0x41 }, 0, 2, "\uFFFD\u0041" }; + + yield return new object[] { new byte[] { 0xEF, 0xFF, 0xEE }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xEF, 0xFF, 0xAE }, 0, 3, "\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0x80, 0x90, 0xA0, 0xB0, 0xC1 }, 0, 5, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x90, 0xA0, 0xB0, 0xC1 }, 0, 15, "\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0x80, 0x90, 0xA0, 0xB0, 0xC1, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F }, 0, 15, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F\u007F" }; + + yield return new object[] { new byte[] { 0xC2, 0x7F, 0xC2, 0xC0, 0xDF, 0x7F, 0xDF, 0xC0 }, 0, 8, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xC2, 0xDF }, 0, 2, "\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0x80, 0x80, 0xC1, 0x80, 0xC1, 0xBF }, 0, 6, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xC2, 0x7F, 0xC2, 0xC0, 0x7F, 0x7F, 0x7F, 0x7F, 0xC3, 0xA1, 0xDF, 0x7F, 0xDF, 0xC0 }, 0, 14, "\uFFFD\u007F\uFFFD\uFFFD\u007F\u007F\u007F\u007F\u00E1\uFFFD\u007F\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xE0, 0xA0, 0x7F, 0xE0, 0xA0, 0xC0, 0xE0, 0xBF, 0x7F, 0xE0, 0xBF, 0xC0 }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xE0, 0x9F, 0x80, 0xE0, 0xC0, 0x80, 0xE0, 0x9F, 0xBF, 0xE0, 0xC0, 0xBF }, 0, 12, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xE0, 0xA0, 0x7F, 0xE0, 0xA0, 0xC0, 0x7F, 0xE0, 0xBF, 0x7F, 0xC3, 0xA1, 0xE0, 0xBF, 0xC0 }, 0, 15, "\uFFFD\u007F\uFFFD\uFFFD\u007F\uFFFD\u007F\u00E1\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xE1, 0x80, 0x7F, 0xE1, 0x80, 0xC0, 0xE1, 0xBF, 0x7F, 0xE1, 0xBF, 0xC0, 0xEC, 0x80, 0x7F, 0xEC, 0x80, 0xC0, 0xEC, 0xBF, 0x7F, 0xEC, 0xBF, 0xC0 }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xE1, 0x7F, 0x80, 0xE1, 0xC0, 0x80, 0xE1, 0x7F, 0xBF, 0xE1, 0xC0, 0xBF, 0xEC, 0x7F, 0x80, 0xEC, 0xC0, 0x80, 0xEC, 0x7F, 0xBF, 0xEC, 0xC0, 0xBF }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xED, 0x80, 0x7F, 0xED, 0x80, 0xC0, 0xED, 0x9F, 0x7F, 0xED, 0x9F, 0xC0 }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0x7F, 0x80, 0xED, 0xA0, 0x80, 0xED, 0x7F, 0xBF, 0xED, 0xA0, 0xBF }, 0, 12, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xED, 0x7F, 0x80, 0xED, 0xA0, 0x80, 0xE8, 0x80, 0x80, 0xED, 0x7F, 0xBF, 0xED, 0xA0, 0xBF }, 0, 15, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\u8000\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xEE, 0x80, 0x7F, 0xEE, 0x80, 0xC0, 0xEE, 0xBF, 0x7F, 0xEE, 0xBF, 0xC0, 0xEF, 0x80, 0x7F, 0xEF, 0x80, 0xC0, 0xEF, 0xBF, 0x7F, 0xEF, 0xBF, 0xC0 }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xEE, 0x7F, 0x80, 0xEE, 0xC0, 0x80, 0xEE, 0x7F, 0xBF, 0xEE, 0xC0, 0xBF, 0xEF, 0x7F, 0x80, 0xEF, 0xC0, 0x80, 0xEF, 0x7F, 0xBF, 0xEF, 0xC0, 0xBF }, 0, 24, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xF0, 0x90, 0x80, 0x7F, 0xF0, 0x90, 0x80, 0xC0, 0xF0, 0xBF, 0xBF, 0x7F, 0xF0, 0xBF, 0xBF, 0xC0 }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF0, 0x90, 0x7F, 0x80, 0xF0, 0x90, 0xC0, 0x80, 0xF0, 0x90, 0x7F, 0xBF, 0xF0, 0x90, 0xC0, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF0, 0x8F, 0x80, 0x80, 0xF0, 0xC0, 0x80, 0x80, 0xF0, 0x8F, 0xBF, 0xBF, 0xF0, 0xC0, 0xBF, 0xBF }, 0, 16, "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xF1, 0x80, 0x80, 0x7F, 0xF1, 0x80, 0x80, 0xC0, 0xF1, 0xBF, 0xBF, 0x7F, 0xF1, 0xBF, 0xBF, 0xC0, 0xF3, 0x80, 0x80, 0x7F, 0xF3, 0x80, 0x80, 0xC0, 0xF3, 0xBF, 0xBF, 0x7F, 0xF3, 0xBF, 0xBF, 0xC0 }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF1, 0x80, 0x7F, 0x80, 0xF1, 0x80, 0xC0, 0x80, 0xF1, 0x80, 0x7F, 0xBF, 0xF1, 0x80, 0xC0, 0xBF, 0xF3, 0x80, 0x7F, 0x80, 0xF3, 0x80, 0xC0, 0x80, 0xF3, 0x80, 0x7F, 0xBF, 0xF3, 0x80, 0xC0, 0xBF }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF1, 0x7F, 0x80, 0x80, 0xF1, 0xC0, 0x80, 0x80, 0xF1, 0x7F, 0xBF, 0xBF, 0xF1, 0xC0, 0xBF, 0xBF, 0xF3, 0x7F, 0x80, 0x80, 0xF3, 0xC0, 0x80, 0x80, 0xF3, 0x7F, 0xBF, 0xBF, 0xF3, 0xC0, 0xBF, 0xBF }, 0, 32, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; + + yield return new object[] { new byte[] { 0xF4, 0x80, 0x80, 0x7F, 0xF4, 0x80, 0x80, 0xC0, 0xF4, 0x8F, 0xBF, 0x7F, 0xF4, 0x8F, 0xBF, 0xC0 }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF4, 0x80, 0x7F, 0x80, 0xF4, 0x80, 0xC0, 0x80, 0xF4, 0x80, 0x7F, 0xBF, 0xF4, 0x80, 0xC0, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD" }; + yield return new object[] { new byte[] { 0xF4, 0x7F, 0x80, 0x80, 0xF4, 0x90, 0x80, 0x80, 0xF4, 0x7F, 0xBF, 0xBF, 0xF4, 0x90, 0xBF, 0xBF }, 0, 16, "\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u007F\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD" }; } [Theory] diff --git a/src/libraries/System.Threading.ThreadPool/tests/RegisteredWaitTests.cs b/src/libraries/System.Threading.ThreadPool/tests/RegisteredWaitTests.cs index 0e3534c38704d..4dfcdf20edcef 100644 --- a/src/libraries/System.Threading.ThreadPool/tests/RegisteredWaitTests.cs +++ b/src/libraries/System.Threading.ThreadPool/tests/RegisteredWaitTests.cs @@ -160,11 +160,8 @@ public static void QueueRegisterNegativeTest() ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); - if (!PlatformDetection.IsNetFramework) // .NET Framework silently overflows the timeout - { - AssertExtensions.Throws("millisecondsTimeOutInterval", () => - ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); - } + AssertExtensions.Throws("millisecondsTimeOutInterval", () => + ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); AssertExtensions.Throws("timeout", () => ThreadPool.RegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); AssertExtensions.Throws("timeout", () => @@ -181,11 +178,8 @@ public static void QueueRegisterNegativeTest() ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, -2, true)); AssertExtensions.Throws("millisecondsTimeOutInterval", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)-2, true)); - if (!PlatformDetection.IsNetFramework) // .NET Framework silently overflows the timeout - { - AssertExtensions.Throws("millisecondsTimeOutInterval", () => - ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); - } + AssertExtensions.Throws("millisecondsTimeOutInterval", () => + ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, (long)int.MaxValue + 1, true)); AssertExtensions.Throws("timeout", () => ThreadPool.UnsafeRegisterWaitForSingleObject(waitHandle, callback, null, TimeSpan.FromMilliseconds(-2), true)); AssertExtensions.Throws("timeout", () => diff --git a/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index a9b09f53895db..0b51d5e07a6ec 100644 --- a/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/libraries/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -136,7 +136,7 @@ public static void SetMinMaxThreadsTest() VerifyMaxThreads(MaxPossibleThreadCount, MaxPossibleThreadCount); Assert.True(ThreadPool.SetMaxThreads(MaxPossibleThreadCount + 1, MaxPossibleThreadCount + 1)); VerifyMaxThreads(MaxPossibleThreadCount, MaxPossibleThreadCount); - Assert.Equal(PlatformDetection.IsNetFramework, ThreadPool.SetMaxThreads(-1, -1)); + Assert.False(ThreadPool.SetMaxThreads(-1, -1)); VerifyMaxThreads(MaxPossibleThreadCount, MaxPossibleThreadCount); Assert.True(ThreadPool.SetMinThreads(MaxPossibleThreadCount, MaxPossibleThreadCount));