Skip to content

Commit

Permalink
Fix the globalization test. (#42212)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh committed Sep 14, 2020
1 parent 8473b0a commit b7aa8b5
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Buffers;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Text;
using Xunit;
Expand Down Expand Up @@ -359,6 +360,14 @@ public void SortKeyKanaTest(CompareInfo compareInfo, string string1, string stri
SortKeyTest(compareInfo, string1, string2, options, expected);
}


[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int CompareStringEx(string lpLocaleName, uint dwCmpFlags, string lpString1, int cchCount1, string lpString2, int cchCount2, IntPtr lpVersionInformation, IntPtr lpReserved, int lParam);
private const int NORM_LINGUISTIC_CASING = 0x08000000; // use linguistic rules for casing

private static bool WindowsVersionHasTheCompareStringRegression =>
PlatformDetection.IsNlsGlobalization && CompareStringEx("", NORM_LINGUISTIC_CASING, "", 0, "\u200C", 1, IntPtr.Zero, IntPtr.Zero, 0) != 2;

[Theory]
[MemberData(nameof(SortKey_TestData))]
public void SortKeyTest(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expectedSign)
Expand All @@ -368,7 +377,11 @@ public void SortKeyTest(CompareInfo compareInfo, string string1, string string2,

Assert.Equal(expectedSign, Math.Sign(SortKey.Compare(sk1, sk2)));
Assert.Equal(expectedSign == 0, sk1.Equals(sk2));
Assert.Equal(Math.Sign(compareInfo.Compare(string1, string2, options)), Math.Sign(SortKey.Compare(sk1, sk2)));

if (!WindowsVersionHasTheCompareStringRegression)
{
Assert.Equal(Math.Sign(compareInfo.Compare(string1, string2, options)), Math.Sign(SortKey.Compare(sk1, sk2)));
}

Assert.Equal(compareInfo.GetHashCode(string1, options), sk1.GetHashCode());
Assert.Equal(compareInfo.GetHashCode(string2, options), sk2.GetHashCode());
Expand Down

0 comments on commit b7aa8b5

Please sign in to comment.