|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using Microsoft.DotNet.RemoteExecutor; |
| 5 | +using System.Diagnostics; |
| 6 | +using System.Reflection; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace System.Globalization.Tests |
| 10 | +{ |
| 11 | + public class IcuAppLocalTests |
| 12 | + { |
| 13 | + private static bool SupportsIcuPackageDownload => RemoteExecutor.IsSupported && |
| 14 | + ((PlatformDetection.IsWindows && !PlatformDetection.IsArmProcess) || |
| 15 | + (PlatformDetection.IsLinux && (PlatformDetection.IsX64Process || PlatformDetection.IsArm64Process) && |
| 16 | + !PlatformDetection.IsAlpine && !PlatformDetection.IsLinuxBionic)); |
| 17 | + |
| 18 | + |
| 19 | + [ConditionalFact(nameof(SupportsIcuPackageDownload))] |
| 20 | + public void TestIcuAppLocal() |
| 21 | + { |
| 22 | + // We define this switch dynamically during the runtime using RemoteExecutor. |
| 23 | + // The reason is, if we enable ICU app-local here, this test will compile and run |
| 24 | + // on all supported OSs even the ICU NuGet package not have native bits support such OSs. |
| 25 | + // Note, it doesn't matter if we have test case conditioned to not run on such OSs, because |
| 26 | + // the test has to start running first before filtering the test cases and the globalization |
| 27 | + // code will run and fail fast at that time. |
| 28 | + |
| 29 | + ProcessStartInfo psi = new ProcessStartInfo(); |
| 30 | + psi.Environment.Add("DOTNET_SYSTEM_GLOBALIZATION_APPLOCALICU", "68.2.0.9"); |
| 31 | + |
| 32 | + RemoteExecutor.Invoke(() => |
| 33 | + { |
| 34 | + // Ensure initializing globalization code before checking the ICU version. |
| 35 | + CultureInfo ci = CultureInfo.GetCultureInfo("en-US"); |
| 36 | + |
| 37 | + Type? interopGlobalization = Type.GetType("Interop+Globalization, System.Private.CoreLib"); |
| 38 | + Assert.NotNull(interopGlobalization); |
| 39 | + |
| 40 | + MethodInfo? methodInfo = interopGlobalization.GetMethod("GetICUVersion", BindingFlags.NonPublic | BindingFlags.Static); |
| 41 | + Assert.NotNull(methodInfo); |
| 42 | + |
| 43 | + // Assert the ICU version 0x44020009 is 68.2.0.9 |
| 44 | + Assert.Equal(0x44020009, (int)methodInfo.Invoke(null, null)); |
| 45 | + |
| 46 | + // Now call globalization API to ensure the binding working without any problem. |
| 47 | + Assert.Equal(-1, ci.CompareInfo.Compare("sample\u0000", "Sample\u0000", CompareOptions.IgnoreSymbols)); |
| 48 | + }, new RemoteInvokeOptions { StartInfo = psi }).Dispose(); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments