Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard1.3;
netstandard;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,160 @@
// 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 Xunit;
using System;
using System.Text;
namespace EncodingTests
{
public static class Fallback
{
private static readonly string s_asciiInputStringWithFallback = "\u00abX\u00bb"; // DOUBLE ANGLE QUOTATION MARK (U+00AB), 'X' (U+0058), and RIGHT POINTING DOUBLE ANGLE QUOTATION MARK (U+00BB).
private static readonly string s_asciiInputStringWinNoFallback = "abc";
[Fact]
public static void TestEncoderReplacementFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback("(unknown)"), new DecoderReplacementFallback(""));
byte[] encodedBytes = new byte[asciiEncoding.GetByteCount(s_asciiInputStringWithFallback)];
int numberOfEncodedBytes = asciiEncoding.GetBytes(s_asciiInputStringWithFallback, 0, s_asciiInputStringWithFallback.Length, encodedBytes, 0);
Assert.Equal(
encodedBytes,
new byte[] {0x28, 0x75, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x29, 0x58, 0x28, 0x75, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x29 });
string decodedString = asciiEncoding.GetString(encodedBytes);
Assert.Equal(decodedString, "(unknown)X(unknown)");
// Test when the fallback will not occur
encodedBytes = new byte[asciiEncoding.GetByteCount(s_asciiInputStringWinNoFallback)];
numberOfEncodedBytes = asciiEncoding.GetBytes(s_asciiInputStringWinNoFallback, 0, s_asciiInputStringWinNoFallback.Length, encodedBytes, 0);
Assert.Equal(encodedBytes, new byte[] { (byte)'a', (byte)'b', (byte)'c' });
decodedString = asciiEncoding.GetString(encodedBytes);
Assert.Equal(decodedString, s_asciiInputStringWinNoFallback);
}
[Fact]
public static void TestDecoderReplacementFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback("(unknown)"), new DecoderReplacementFallback("Error"));
Assert.Equal(asciiEncoding.GetString(new byte [] { 0xAA, (byte)'x', 0xAB }), "ErrorxError");
}
[Fact]
public static void TestEncoderExceptionFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback());
Assert.Throws<EncoderFallbackException>(() => asciiEncoding.GetByteCount(s_asciiInputStringWithFallback));
}
[Fact]
public static void TestDecoderExceptionFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback());
Assert.Throws<DecoderFallbackException>(() => asciiEncoding.GetString(new byte [] { 0xAA, (byte)'x', 0xAB }));
}
[Fact]
public static void TestCustomFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderCustomFallback(), new DecoderReplacementFallback(""));
byte[] encodedBytes = new byte[asciiEncoding.GetByteCount(s_asciiInputStringWithFallback)];
int numberOfEncodedBytes = asciiEncoding.GetBytes(s_asciiInputStringWithFallback, 0, s_asciiInputStringWithFallback.Length, encodedBytes, 0);
Assert.Equal(
encodedBytes,
new byte[] {(byte) 'a', 0x58, (byte) 'b'});
string decodedString = asciiEncoding.GetString(encodedBytes);
Assert.Equal(decodedString, "aXb");
}
}
// a simple fallback class which fallback using the character sequence 'a', 'b', 'c',...etc.
internal sealed class EncoderCustomFallback : EncoderFallback
{
public EncoderCustomFallback()
{
}
public string DefaultString
{
get { return " "; }
}
public override EncoderFallbackBuffer CreateFallbackBuffer()
{
return new EncoderCustomFallbackBuffer();
}
public override int MaxCharCount
{
get { return 1; }
}
public override bool Equals(Object value)
{
return value is EncoderCustomFallback;
}
public override int GetHashCode()
{
return "EncoderCustomFallback".GetHashCode();
}
}
internal sealed class EncoderCustomFallbackBuffer : EncoderFallbackBuffer
{
private int _nextChar;
private bool _fallback;
public EncoderCustomFallbackBuffer()
{
_fallback = false;
_nextChar = (int)'a' - 1;
}
public override bool Fallback(char charUnknown, int index)
{
_fallback = true;
return true;
}
public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
{
_fallback = true;
return true;
}
public override char GetNextChar()
{
if (!_fallback)
return (char)0;
_fallback = false;
return (char)++_nextChar;
}
public override bool MovePrevious()
{
return --_nextChar >= (int)'a' - 1;
}
public override int Remaining
{
get { return 0; }
}
public override void Reset()
{
_fallback = false;
_nextChar = (int)'a' - 1;
}
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Text.Encoding.Extensions.Tests.csproj" />
<Project Include="System.Text.Encoding.Extensions.Tests.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.Text.Encoding.Extensions.Tests.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
<OSGroup>Windows_NT</OSGroup>
<TestTFMs>netcore50;net46</TestTFMs>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}</ProjectGuid>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="Fallback.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>