Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@ -2,6 +2,8 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<AssemblyKey>MSFT</AssemblyKey>
<IsUAP>true</IsUAP>
</PropertyGroup>
</Project>

View File

@ -6,8 +6,17 @@
<SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Text.Encoding.CodePages.csproj" />
<HarvestIncludePaths Include="lib/net46" />
<HarvestIncludePaths Include="ref/netstandard1.3;runtimes/win/lib/netstandard1.3" />
<HarvestIncludePaths Include="runtimes/unix/lib/netstandard1.3">
<!-- package unix impl (which is actually platform agnostic) as RID agnostic -->
<TargetPath>lib/netstandard1.3</TargetPath>
</HarvestIncludePaths>
</ItemGroup>
<ItemGroup>
<InboxOnTargetFramework Include="uap10.1">
<PackageTargetRuntime>win</PackageTargetRuntime>
</InboxOnTargetFramework>
<InboxOnTargetFramework Include="MonoAndroid10" />
<InboxOnTargetFramework Include="MonoTouch10" />
<InboxOnTargetFramework Include="xamarinios10" />

View File

@ -3,13 +3,10 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{73FAB2B8-589D-4BEA-ADCA-E5CC02296F25}</ProjectGuid>
<!-- UAP10.1 is not yet mapped to netstandard2.0, manually duplicate this ref -->
<PackageTargetFramework>netstandard2.0;uap10.1</PackageTargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
<SuppressPackageTargetFrameworkCompatibility Include="uap10.1" />
<Compile Include="System.Text.Encoding.CodePages.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />

View File

@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp-Unix;
<PackageConfigurations>
netstandard;
netcoreapp-Windows_NT;
uap-Windows_NT;
netstandard-Windows_NT;
</PackageConfigurations>
<BuildConfigurations>
$(PackageConfigurations);
uap-Windows_NT;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@ -7,12 +7,13 @@
<RootNamespace>System.Text.Encoding.CodePages</RootNamespace>
<AssemblyName>System.Text.Encoding.CodePages</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- copy the Windows-specific implementation to net461 folder so that restore without a RID works -->
<PackageTargetFramework Condition="'$(TargetGroup)' == 'netstandard' AND '$(TargetsWindows)' == 'true'">netstandard2.0;net461</PackageTargetFramework>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Debug|AnyCPU'" />
@ -51,8 +52,8 @@
<Link>Common\Interop\Windows\Interop.GetCPInfoEx.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition=" '$(TargetsUnix)' == 'true' ">
<Compile Include="System\Text\CodePagesEncodingProvider.Unix.cs" />
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard' AND '$(TargetsWindows)' != 'true' ">
<Compile Include="System\Text\CodePagesEncodingProvider.Default.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Data\codepages.nlp">

View File

@ -81,8 +81,7 @@ namespace System.Text
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
CodePageEncodingSurrogate.SerializeEncoding(this, info, context);
info.SetType(typeof(CodePageEncodingSurrogate));
throw new PlatformNotSupportedException();
}
// Just a helper as we cannot use 'this' when calling 'base(...)'

View File

@ -48,45 +48,7 @@ namespace System.Text
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(DecoderNLSSurrogate.EncodingKey, m_encoding);
info.AddValue(DecoderNLSSurrogate.DecoderFallbackKey, m_fallback);
info.SetType(typeof(DecoderNLSSurrogate));
}
[Serializable]
internal sealed class DecoderNLSSurrogate : IObjectReference, ISerializable
{
internal const string EncodingKey = "Encoding";
internal const string DecoderFallbackKey = "DecoderFallback";
private readonly Encoding _encoding;
private readonly DecoderFallback _fallback;
internal DecoderNLSSurrogate(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
_encoding = (Encoding)info.GetValue(EncodingKey, typeof(Encoding));
_fallback = (DecoderFallback)info.GetValue(DecoderFallbackKey, typeof(DecoderFallback));
}
public object GetRealObject(StreamingContext context)
{
Decoder decoder = _encoding.GetDecoder();
if (_fallback != null)
{
decoder.Fallback = _fallback;
}
return decoder;
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
// This should never be called. If it is, there's a bug in the formatter being used.
throw new NotSupportedException();
}
throw new PlatformNotSupportedException();
}
internal new DecoderFallback Fallback

View File

@ -43,57 +43,7 @@ namespace System.Text
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(EncoderNLSSurrogate.EncodingKey, m_encoding);
info.AddValue(EncoderNLSSurrogate.DecoderFallbackKey, m_fallback);
info.AddValue(EncoderNLSSurrogate.CharLeftOverKey, charLeftOver);
info.SetType(typeof(EncoderNLSSurrogate));
}
[Serializable]
internal sealed class EncoderNLSSurrogate : ISerializable, IObjectReference
{
internal const string EncodingKey = "Encoding";
internal const string DecoderFallbackKey = "EncoderFallback";
internal const string CharLeftOverKey = "CharLeftOver";
private readonly Encoding _encoding;
private readonly EncoderFallback _fallback;
private char _charLeftOver;
internal EncoderNLSSurrogate(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
_encoding = (Encoding)info.GetValue(EncodingKey, typeof(Encoding));
_fallback = (EncoderFallback)info.GetValue(DecoderFallbackKey, typeof(EncoderFallback));
_charLeftOver = (char)info.GetValue(CharLeftOverKey, typeof(char));
}
public object GetRealObject(StreamingContext context)
{
Encoder encoder = _encoding.GetEncoder();
if (_fallback != null)
{
encoder.Fallback = _fallback;
if (_charLeftOver != default(char))
{
EncoderNLS encoderNls = encoder as EncoderNLS;
if (encoderNls != null)
{
encoderNls.charLeftOver = _charLeftOver;
}
}
}
return encoder;
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
// This should never be called. If it is, there's a bug in the formatter being used.
throw new NotSupportedException();
}
throw new PlatformNotSupportedException();
}
internal new EncoderFallback Fallback

View File

@ -579,63 +579,5 @@ namespace System.Text
return _webName;
}
}
[Serializable]
protected sealed class CodePageEncodingSurrogate : ISerializable, IObjectReference
{
internal const string CodePageKey = "CodePage";
internal const string IsReadOnlyKey = "IsReadOnly";
internal const string EncoderFallbackKey = "EncoderFallback";
internal const string DecoderFallbackKey = "DecoderFallback";
private readonly int _codePage;
private readonly bool _isReadOnly;
private readonly EncoderFallback _encoderFallback;
private readonly DecoderFallback _decoderFallback;
internal CodePageEncodingSurrogate(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
_codePage = (int)info.GetValue(CodePageKey, typeof(int));
_isReadOnly = (bool)info.GetValue(IsReadOnlyKey, typeof(bool));
_encoderFallback = (EncoderFallback)info.GetValue(EncoderFallbackKey, typeof(EncoderFallback));
_decoderFallback = (DecoderFallback)info.GetValue(DecoderFallbackKey, typeof(DecoderFallback));
}
internal static void SerializeEncoding(Encoding e, SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
info.AddValue(CodePageKey, e.CodePage);
info.AddValue(IsReadOnlyKey, e.IsReadOnly);
info.AddValue(EncoderFallbackKey, e.EncoderFallback);
info.AddValue(DecoderFallbackKey, e.DecoderFallback);
}
public object GetRealObject(StreamingContext context)
{
Encoding realEncoding = GetEncoding(_codePage);
if (!_isReadOnly)
{
realEncoding = (Encoding)realEncoding.Clone();
realEncoding.EncoderFallback = _encoderFallback;
realEncoding.DecoderFallback = _decoderFallback;
}
return realEncoding;
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
// This should never be called. If it is, there's a bug in the formatter being used.
throw new NotSupportedException();
}
}
}
}

View File

@ -1 +1 @@
6a7c5cb3925dfb14b5e8af6ac93581adf25fd5d6
779fa4d26cd1990b1117f33b3e7ca94bbdd820dc

View File

@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization.Formatters.Tests;
using Xunit;
namespace System.Text.Tests
@ -447,7 +448,7 @@ namespace System.Text.Tests
yield return Map(65000, "utf-7");
yield return Map(65001, "utf-8");
}
private static KeyValuePair<int, string> Map(int codePage, string webName)
{
return new KeyValuePair<int, string>(codePage, webName);
@ -512,9 +513,50 @@ namespace System.Text.Tests
Assert.NotNull(defaultEncoding);
mappedEncoding = Map(defaultEncoding.CodePage, defaultEncoding.WebName);
Assert.Contains(mappedEncoding, CrossplatformDefaultEncodings().Union(CodePageInfo().Select(i => Map((int)i[0], (string)i[1]))));
TestRegister1252();
}
static partial void ValidateSerializeDeserialize(Encoding e);
static void ValidateSerializeDeserialize(Encoding e)
{
// Make sure the Encoding roundtrips
Assert.Equal(e, BinaryFormatterHelpers.Clone(e));
// Get an encoder and decoder from the encoding, and clone them
Encoder origEncoder = e.GetEncoder();
Decoder origDecoder = e.GetDecoder();
Encoder clonedEncoder = BinaryFormatterHelpers.Clone(origEncoder);
Decoder clonedDecoder = BinaryFormatterHelpers.Clone(origDecoder);
// Encode and decode some text with each pairing
const string InputText = "abcdefghijklmnopqrstuvwxyz";
char[] inputTextChars = InputText.ToCharArray();
var pairs = new[]
{
Tuple.Create(origEncoder, origDecoder),
Tuple.Create(origEncoder, clonedDecoder),
Tuple.Create(clonedEncoder, origDecoder),
Tuple.Create(clonedEncoder, clonedDecoder),
};
var results = new List<char[]>();
foreach (Tuple<Encoder, Decoder> pair in pairs)
{
byte[] encodedBytes = new byte[pair.Item1.GetByteCount(inputTextChars, 0, inputTextChars.Length, true)];
Assert.Equal(encodedBytes.Length, pair.Item1.GetBytes(inputTextChars, 0, inputTextChars.Length, encodedBytes, 0, true));
char[] decodedChars = new char[pair.Item2.GetCharCount(encodedBytes, 0, encodedBytes.Length)];
Assert.Equal(decodedChars.Length, pair.Item2.GetChars(encodedBytes, 0, encodedBytes.Length, decodedChars, 0));
results.Add(decodedChars);
}
// Validate that all of the pairings produced the same results
foreach (char[] a in results)
{
foreach (char[] b in results)
{
Assert.Equal(a, b);
}
}
}
private static void ValidateDefaultEncodings()
{
@ -597,6 +639,41 @@ namespace System.Text.Tests
Assert.False(string.IsNullOrWhiteSpace(name));
Assert.All(name, c => Assert.True(c >= ' ' && c < '~' + 1, "Name: " + name + " contains character: " + c));
}
// This test is run as part of the default mappings test, since it modifies global state which that test
// depends on.
public static void TestRegister1252()
{
// This test case ensure we can map all 1252 codepage codepoints without any exception.
string s1252Result =
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f" +
"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f" +
"\u0020\u0021\u0022\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002a\u002b\u002c\u002d\u002e\u002f" +
"\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f" +
"\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047\u0048\u0049\u004a\u004b\u004c\u004d\u004e\u004f" +
"\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057\u0058\u0059\u005a\u005b\u005c\u005d\u005e\u005f" +
"\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067\u0068\u0069\u006a\u006b\u006c\u006d\u006e\u006f" +
"\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077\u0078\u0079\u007a\u007b\u007c\u007d\u007e\u007f" +
"\u20ac\u0081\u201a\u0192\u201e\u2026\u2020\u2021\u02c6\u2030\u0160\u2039\u0152\u008d\u017d\u008f" +
"\u0090\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u02dc\u2122\u0161\u203a\u0153\u009d\u017e\u0178" +
"\u00a0\u00a1\u00a2\u00a3\u00a4\u00a5\u00a6\u00a7\u00a8\u00a9\u00aa\u00ab\u00ac\u00ad\u00ae\u00af" +
"\u00b0\u00b1\u00b2\u00b3\u00b4\u00b5\u00b6\u00b7\u00b8\u00b9\u00ba\u00bb\u00bc\u00bd\u00be\u00bf" +
"\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf" +
"\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d7\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u00df" +
"\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef" +
"\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f7\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff";
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding win1252 = Encoding.GetEncoding("windows-1252", EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
byte[] enc = new byte[256];
for (int j = 0; j < 256; j++)
{
enc[j] = (byte)j;
}
Assert.Equal(s1252Result, win1252.GetString(enc));
}
}
public class CultureSetup : IDisposable

View File

@ -1,54 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Tests;
using Xunit;
namespace System.Text.Tests
{
public partial class EncodingTest
{
static partial void ValidateSerializeDeserialize(Encoding e)
{
// Make sure the Encoding roundtrips
Assert.Equal(e, BinaryFormatterHelpers.Clone(e));
// Get an encoder and decoder from the encoding, and clone them
Encoder origEncoder = e.GetEncoder();
Decoder origDecoder = e.GetDecoder();
Encoder clonedEncoder = BinaryFormatterHelpers.Clone(origEncoder);
Decoder clonedDecoder = BinaryFormatterHelpers.Clone(origDecoder);
// Encode and decode some text with each pairing
const string InputText = "abcdefghijklmnopqrstuvwxyz";
char[] inputTextChars = InputText.ToCharArray();
var pairs = new[]
{
Tuple.Create(origEncoder, origDecoder),
Tuple.Create(origEncoder, clonedDecoder),
Tuple.Create(clonedEncoder, origDecoder),
Tuple.Create(clonedEncoder, clonedDecoder),
};
var results = new List<char[]>();
foreach (Tuple<Encoder, Decoder> pair in pairs)
{
byte[] encodedBytes = new byte[pair.Item1.GetByteCount(inputTextChars, 0, inputTextChars.Length, true)];
Assert.Equal(encodedBytes.Length, pair.Item1.GetBytes(inputTextChars, 0, inputTextChars.Length, encodedBytes, 0, true));
char[] decodedChars = new char[pair.Item2.GetCharCount(encodedBytes, 0, encodedBytes.Length)];
Assert.Equal(decodedChars.Length, pair.Item2.GetChars(encodedBytes, 0, encodedBytes.Length, decodedChars, 0));
results.Add(decodedChars);
}
// Validate that all of the pairings produced the same results
foreach (char[] a in results)
{
foreach (char[] b in results)
{
Assert.Equal(a, b);
}
}
}
}
}

View File

@ -9,10 +9,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="EncodingCodePages.cs" />
<Compile Include="EncodingCodePages.netstandard.cs" />
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>CommonTest\System\PlatformDetection.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
<Link>Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>