Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the globalization test. #42212

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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