You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
76
external/corefx/src/System.Text.Encoding/System.Text.Encoding.Tests.sln
vendored
Normal file
76
external/corefx/src/System.Text.Encoding/System.Text.Encoding.Tests.sln
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Text.Encoding.Tests", "tests\System.Text.Encoding.Tests.csproj", "{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Text.Encoding", "src\System.Text.Encoding.csproj", "{ECD16D77-404B-4992-A476-C0C8A34BBB15}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Text.Encoding.Performance.Tests", "tests\Performance\System.Text.Encoding.Performance.Tests.csproj", "{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
net46_Debug|Any CPU = net46_Debug|Any CPU
|
||||
net46_Release|Any CPU = net46_Release|Any CPU
|
||||
netcore50_Debug|Any CPU = netcore50_Debug|Any CPU
|
||||
netcore50_Release|Any CPU = netcore50_Release|Any CPU
|
||||
netcore50aot_Debug|Any CPU = netcore50aot_Debug|Any CPU
|
||||
netcore50aot_Release|Any CPU = netcore50aot_Release|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.net46_Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.net46_Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.net46_Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.net46_Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50_Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50_Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50_Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50_Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50aot_Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50aot_Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50aot_Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.netcore50aot_Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.net46_Debug|Any CPU.ActiveCfg = net46_Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.net46_Debug|Any CPU.Build.0 = net46_Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.net46_Release|Any CPU.ActiveCfg = net46_Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.net46_Release|Any CPU.Build.0 = net46_Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50_Debug|Any CPU.ActiveCfg = netcore50_Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50_Debug|Any CPU.Build.0 = netcore50_Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50_Release|Any CPU.ActiveCfg = netcore50_Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50_Release|Any CPU.Build.0 = netcore50_Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50aot_Debug|Any CPU.ActiveCfg = netcore50aot_Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50aot_Debug|Any CPU.Build.0 = netcore50aot_Debug|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50aot_Release|Any CPU.ActiveCfg = netcore50aot_Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.netcore50aot_Release|Any CPU.Build.0 = netcore50aot_Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ECD16D77-404B-4992-A476-C0C8A34BBB15}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.net46_Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.net46_Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.net46_Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.net46_Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50_Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50_Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50_Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50_Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50aot_Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50aot_Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50aot_Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.netcore50aot_Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F6AD626-B78D-4231-BD0F-A0C462FDBF2E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
8
external/corefx/src/System.Text.Encoding/dir.props
vendored
Normal file
8
external/corefx/src/System.Text.Encoding/dir.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-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>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
9
external/corefx/src/System.Text.Encoding/ref/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Text.Encoding/ref/Configurations.props
vendored
Normal 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>
|
||||
netcoreapp;
|
||||
uap;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
21
external/corefx/src/System.Text.Encoding/ref/System.Text.Encoding.Forwards.cs
vendored
Normal file
21
external/corefx/src/System.Text.Encoding/ref/System.Text.Encoding.Forwards.cs
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
// ------------------------------------------------------------------------------
|
||||
// Changes to this file must follow the http://aka.ms/api-review process.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.Decoder))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.DecoderExceptionFallback))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.DecoderFallback))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.DecoderFallbackBuffer))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.DecoderFallbackException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.DecoderReplacementFallback))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.Encoder))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.EncoderExceptionFallback))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.EncoderFallback))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.EncoderFallbackBuffer))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.EncoderFallbackException))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.EncoderReplacementFallback))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.Encoding))]
|
||||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Text.EncodingProvider))]
|
||||
18
external/corefx/src/System.Text.Encoding/ref/System.Text.Encoding.csproj
vendored
Normal file
18
external/corefx/src/System.Text.Encoding/ref/System.Text.Encoding.csproj
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?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>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="System.Text.Encoding.Forwards.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
19
external/corefx/src/System.Text.Encoding/src/ApiCompatBaseline.uap101aot.txt
vendored
Normal file
19
external/corefx/src/System.Text.Encoding/src/ApiCompatBaseline.uap101aot.txt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
MembersMustExist : Member 'System.Text.Decoder.Convert(System.Byte*, System.Int32, System.Char*, System.Int32, System.Boolean, System.Int32, System.Int32, System.Boolean)' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Decoder.GetCharCount(System.Byte*, System.Int32, System.Boolean)' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Decoder.GetChars(System.Byte*, System.Int32, System.Char*, System.Int32, System.Boolean)' does not exist in the implementation but it does exist in the contract.
|
||||
CannotRemoveBaseTypeOrInterface : Type 'System.Text.DecoderFallbackException' does not inherit from base type 'System.SystemException' in the implementation but it does in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoder.Convert(System.Char*, System.Int32, System.Byte*, System.Int32, System.Boolean, System.Int32, System.Int32, System.Boolean)' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoder.GetBytes(System.Char*, System.Int32, System.Byte*, System.Int32, System.Boolean)' does not exist in the implementation but it does exist in the contract.
|
||||
CannotRemoveBaseTypeOrInterface : Type 'System.Text.EncoderFallbackException' does not inherit from base type 'System.SystemException' in the implementation but it does in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.BodyName.get()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.Default.get()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.GetEncodings()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.HeaderName.get()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.IsAlwaysNormalized()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.IsAlwaysNormalized(System.Text.NormalizationForm)' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.IsBrowserDisplay.get()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.IsBrowserSave.get()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.IsMailNewsDisplay.get()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.IsMailNewsSave.get()' does not exist in the implementation but it does exist in the contract.
|
||||
MembersMustExist : Member 'System.Text.Encoding.WindowsCodePage.get()' does not exist in the implementation but it does exist in the contract.
|
||||
|
||||
10
external/corefx/src/System.Text.Encoding/src/Configurations.props
vendored
Normal file
10
external/corefx/src/System.Text.Encoding/src/Configurations.props
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
uap101aot-Windows_NT;
|
||||
net463-Windows_NT;
|
||||
netcoreapp;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
24
external/corefx/src/System.Text.Encoding/src/System.Text.Encoding.csproj
vendored
Normal file
24
external/corefx/src/System.Text.Encoding/src/System.Text.Encoding.csproj
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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>
|
||||
<AssemblyName>System.Text.Encoding</AssemblyName>
|
||||
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
|
||||
<!-- copy to uap10.1 until nuget makes the change to map that to ns1.7 -->
|
||||
</PropertyGroup>
|
||||
<!-- Help VS understand available configurations -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap101aot-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap101aot-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<TargetingPackReference Include="mscorlib" Condition="'$(TargetGroup)' == 'net463'" />
|
||||
<TargetingPackReference Include="System.Private.CoreLib" Condition="'$(TargetGroup)' != 'net463'" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ReferenceFromRuntime Include="System.Private.CoreLib" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
79
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingDecode.cs
vendored
Normal file
79
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingDecode.cs
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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 Xunit;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class ASCIIEncodingDecode
|
||||
{
|
||||
public static IEnumerable<object[]> Decode_TestData()
|
||||
{
|
||||
// All ASCII chars
|
||||
for (int i = 0; i <= 0x7F; i++)
|
||||
{
|
||||
byte b = (byte)i;
|
||||
yield return new object[] { new byte[] { b }, 0, 1 };
|
||||
yield return new object[] { new byte[] { 96, b, 97 }, 1, 1 };
|
||||
yield return new object[] { new byte[] { 96, b, 98 }, 2, 1 };
|
||||
yield return new object[] { new byte[] { 97, b, 97 }, 0, 3 };
|
||||
}
|
||||
|
||||
// Empty strings
|
||||
yield return new object[] { new byte[0], 0, 0 };
|
||||
yield return new object[] { new byte[10], 5, 0 };
|
||||
yield return new object[] { new byte[10], 5, 5 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Decode_TestData))]
|
||||
public void Decode(byte[] bytes, int index, int count)
|
||||
{
|
||||
string expected = GetString(bytes, index, count);
|
||||
EncodingHelpers.Decode(new ASCIIEncoding(), bytes, index, count, expected);
|
||||
|
||||
// Decoding valid bytes should not throw with a DecoderExceptionFallback
|
||||
Encoding exceptionEncoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("?"), new DecoderExceptionFallback());
|
||||
EncodingHelpers.Decode(exceptionEncoding, bytes, index, count, expected);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Decode_InvalidBytes_TestData()
|
||||
{
|
||||
// All Latin-1 Supplement bytes
|
||||
for (int i = 0x80; i <= byte.MaxValue; i++)
|
||||
{
|
||||
byte b = (byte)i;
|
||||
yield return new object[] { new byte[] { b }, 0, 1 };
|
||||
yield return new object[] { new byte[] { 96, b, 97 }, 1, 1 };
|
||||
yield return new object[] { new byte[] { 97, b, 97 }, 0, 3 };
|
||||
}
|
||||
|
||||
yield return new object[] { new byte[] { 0xC1, 0x41, 0xF0, 0x42 }, 0, 4 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Decode_InvalidBytes_TestData))]
|
||||
public void Decode_InvalidBytes(byte[] bytes, int index, int count)
|
||||
{
|
||||
string expected = GetString(bytes, index, count);
|
||||
EncodingHelpers.Decode(new ASCIIEncoding(), bytes, index, count, expected);
|
||||
|
||||
// Decoding invalid bytes should throw with a DecoderExceptionFallback
|
||||
Encoding exceptionEncoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("?"), new DecoderExceptionFallback());
|
||||
NegativeEncodingTests.Decode_Invalid(exceptionEncoding, bytes, index, count);
|
||||
}
|
||||
|
||||
public static string GetString(byte[] bytes, int index, int count)
|
||||
{
|
||||
char[] chars = new char[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
byte b = bytes[i + index];
|
||||
chars[i] = b <= 0x7F ? (char)b : '?';
|
||||
}
|
||||
return new string(chars);
|
||||
}
|
||||
}
|
||||
}
|
||||
114
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingEncode.cs
vendored
Normal file
114
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingEncode.cs
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
// 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 Xunit;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class ASCIIEncodingEncode
|
||||
{
|
||||
public static IEnumerable<object[]> Encode_TestData()
|
||||
{
|
||||
// All ASCII chars
|
||||
for (int i = 0; i <= 0x7F; i++)
|
||||
{
|
||||
char b = (char)i;
|
||||
yield return new object[] { b, 0, 1 };
|
||||
yield return new object[] { "a" + b + "c", 1, 1 };
|
||||
yield return new object[] { "a" + b + "c", 2, 1 };
|
||||
yield return new object[] { "a" + b + "c", 0, 3 };
|
||||
}
|
||||
|
||||
string testString = "Hello World123#?!";
|
||||
yield return new object[] { testString, 0, testString.Length };
|
||||
yield return new object[] { testString, 4, 5 };
|
||||
|
||||
yield return new object[] { "ABCDEFGH", 0, 8 };
|
||||
|
||||
// Empty strings
|
||||
yield return new object[] { string.Empty, 0, 0 };
|
||||
yield return new object[] { "abc", 3, 0 };
|
||||
yield return new object[] { "abc", 0, 0 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Encode_TestData))]
|
||||
public void Encode(string source, int index, int count)
|
||||
{
|
||||
byte[] expected = GetBytes(source, index, count);
|
||||
EncodingHelpers.Encode(new ASCIIEncoding(), source, index, count, expected);
|
||||
|
||||
// Encoding valid chars should not throw with an EncoderExceptionFallback
|
||||
Encoding exceptionEncoding = Encoding.GetEncoding("ascii", new EncoderExceptionFallback(), new DecoderReplacementFallback("?"));
|
||||
EncodingHelpers.Encode(exceptionEncoding, source, index, count, expected);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Encode_InvalidChars_TestData()
|
||||
{
|
||||
// All non-ASCII Latin1 chars
|
||||
for (int i = 0x80; i <= 0xFF; i++)
|
||||
{
|
||||
char b = (char)i;
|
||||
yield return new object[] { b, 0, 1 };
|
||||
}
|
||||
|
||||
// Unicode chars
|
||||
yield return new object[] { "\u1234\u2345", 0, 2 };
|
||||
yield return new object[] { "a\u1234\u2345b", 0, 4 };
|
||||
|
||||
yield return new object[] { "\uD800\uDC00", 0, 2 };
|
||||
yield return new object[] { "a\uD800\uDC00b", 0, 2 };
|
||||
|
||||
yield return new object[] { "\uD800\uDC00\u0061\u0CFF", 0, 4 };
|
||||
|
||||
// Invalid Unicode
|
||||
yield return new object[] { "\uD800", 0, 1 }; // Lone high surrogate
|
||||
yield return new object[] { "\uDC00", 0, 1 }; // Lone low surrogate
|
||||
yield return new object[] { "\uD800\uDC00", 0, 1 }; // Surrogate pair out of range
|
||||
yield return new object[] { "\uD800\uDC00", 1, 1 }; // Surrogate pair out of range
|
||||
|
||||
yield return new object[] { "\uD800\uD800", 0, 2 }; // High, high
|
||||
yield return new object[] { "\uDC00\uD800", 0, 2 }; // Low, high
|
||||
yield return new object[] { "\uDC00\uDC00", 0, 2 }; // Low, low
|
||||
|
||||
yield return new object[] { "\u0080\u00FF\u0B71\uFFFF\uD800\uDFFF", 0, 6 };
|
||||
|
||||
// High BMP non-chars
|
||||
yield return new object[] { "\uFFFD", 0, 1 };
|
||||
yield return new object[] { "\uFFFE", 0, 1 };
|
||||
yield return new object[] { "\uFFFF", 0, 1 };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Encode_InvalidChars_TestData))]
|
||||
public void Encode_InvalidChars(string source, int index, int count)
|
||||
{
|
||||
byte[] expected = GetBytes(source, index, count);
|
||||
EncodingHelpers.Encode(new ASCIIEncoding(), source, index, count, expected);
|
||||
|
||||
// Encoding invalid chars should throw with an EncoderExceptionFallback
|
||||
Encoding exceptionEncoding = Encoding.GetEncoding("ascii", new EncoderExceptionFallback(), new DecoderReplacementFallback("?"));
|
||||
NegativeEncodingTests.Encode_Invalid(exceptionEncoding, source, index, count);
|
||||
}
|
||||
|
||||
private static byte[] GetBytes(string source, int index, int count)
|
||||
{
|
||||
byte[] bytes = new byte[count];
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
if (source[i] <= 0x7f)
|
||||
{
|
||||
bytes[i] = (byte)source[i + index];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Verify the fallback character for non-ASCII chars
|
||||
bytes[i] = (byte)'?';
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetDecoder.cs
vendored
Normal file
18
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetDecoder.cs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class ASCIIEncodingGetDecoder
|
||||
{
|
||||
[Fact]
|
||||
public void GetDecoder()
|
||||
{
|
||||
Decoder decoder = new ASCIIEncoding().GetDecoder();
|
||||
Assert.NotNull(decoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetEncoder.cs
vendored
Normal file
18
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetEncoder.cs
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class ASCIIEncodingGetEncoder
|
||||
{
|
||||
[Fact]
|
||||
public void GetEncoder()
|
||||
{
|
||||
Encoder decoder = new ASCIIEncoding().GetEncoder();
|
||||
Assert.NotNull(decoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetMaxByteCount.cs
vendored
Normal file
20
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetMaxByteCount.cs
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class ASCIIEncodingGetMaxByteCount
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(int.MaxValue - 1)]
|
||||
public void GetMaxByteCount(int charCount)
|
||||
{
|
||||
Assert.Equal(charCount + 1, new ASCIIEncoding().GetMaxByteCount(charCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
20
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetMaxCharCount.cs
vendored
Normal file
20
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingGetMaxCharCount.cs
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class ASCIIEncodingGetMaxCharCount
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(int.MaxValue)]
|
||||
public void GetMaxCharCount(int byteCount)
|
||||
{
|
||||
Assert.Equal(byteCount, new ASCIIEncoding().GetMaxCharCount(byteCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
91
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingTests.cs
vendored
Normal file
91
external/corefx/src/System.Text.Encoding/tests/ASCIIEncoding/ASCIIEncodingTests.cs
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
// 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 Xunit;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class ASCIIEncodingTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor()
|
||||
{
|
||||
ASCIIEncoding encoding = new ASCIIEncoding();
|
||||
Assert.Equal(new EncoderReplacementFallback("?"), encoding.EncoderFallback);
|
||||
Assert.Equal(new DecoderReplacementFallback("?"), encoding.DecoderFallback);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Encodings_TestData()
|
||||
{
|
||||
yield return new object[] { new ASCIIEncoding() };
|
||||
yield return new object[] { Encoding.ASCII };
|
||||
yield return new object[] { Encoding.GetEncoding("ascii") };
|
||||
yield return new object[] { Encoding.GetEncoding("us-ascii") };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Encodings_TestData))]
|
||||
public void WebName(ASCIIEncoding encoding)
|
||||
{
|
||||
Assert.Equal("us-ascii", encoding.WebName);
|
||||
}
|
||||
[Theory]
|
||||
[MemberData(nameof(Encodings_TestData))]
|
||||
public void CodePage(ASCIIEncoding encoding)
|
||||
{
|
||||
Assert.Equal(20127, encoding.CodePage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Encodings_TestData))]
|
||||
public void EncodingName(ASCIIEncoding encoding)
|
||||
{
|
||||
Assert.NotEmpty(encoding.EncodingName); // US-ASCII in en-US
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Encodings_TestData))]
|
||||
public void IsSingleByte(ASCIIEncoding encoding)
|
||||
{
|
||||
Assert.True(encoding.IsSingleByte);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Encodings_TestData))]
|
||||
public void Clone(ASCIIEncoding encoding)
|
||||
{
|
||||
ASCIIEncoding clone = (ASCIIEncoding)encoding.Clone();
|
||||
Assert.NotSame(encoding, clone);
|
||||
Assert.Equal(encoding, clone);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { new ASCIIEncoding(), new ASCIIEncoding(), true };
|
||||
yield return new object[] { Encoding.ASCII, Encoding.ASCII, true };
|
||||
yield return new object[] { Encoding.ASCII, new ASCIIEncoding(), true };
|
||||
yield return new object[] { Encoding.ASCII, Encoding.GetEncoding("ascii"), true };
|
||||
yield return new object[] { Encoding.ASCII, Encoding.GetEncoding("us-ascii"), true };
|
||||
|
||||
yield return new object[] { new ASCIIEncoding(), new object(), false };
|
||||
yield return new object[] { new ASCIIEncoding(), null, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals(ASCIIEncoding encoding, object value, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, encoding.Equals(value));
|
||||
Assert.Equal(expected, encoding.GetHashCode().Equals(value?.GetHashCode()));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Encodings_TestData))]
|
||||
public void GetPreamble(ASCIIEncoding encoding)
|
||||
{
|
||||
Assert.Empty(encoding.GetPreamble());
|
||||
}
|
||||
}
|
||||
}
|
||||
9
external/corefx/src/System.Text.Encoding/tests/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Text.Encoding/tests/Configurations.props
vendored
Normal 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>
|
||||
249
external/corefx/src/System.Text.Encoding/tests/Decoder/Decoder.netstandard.cs
vendored
Normal file
249
external/corefx/src/System.Text.Encoding/tests/Decoder/Decoder.netstandard.cs
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
// 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.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Text.Encodings.Tests
|
||||
{
|
||||
public class DecoderMiscTests
|
||||
{
|
||||
[Fact]
|
||||
public static unsafe void ConvertTest()
|
||||
{
|
||||
string s1 = "This is simple ascii string";
|
||||
string s2 = "\uD800\uDC00\u0200"; // non ascii letters
|
||||
string s3 = s1 + s2;
|
||||
|
||||
Encoding utf8 = Encoding.UTF8;
|
||||
Decoder decoder = utf8.GetDecoder();
|
||||
char [] chars = new char[200];
|
||||
|
||||
byte [] bytes1 = utf8.GetBytes(s1);
|
||||
byte [] bytes2 = utf8.GetBytes(s2);
|
||||
byte [] bytes3 = utf8.GetBytes(s3);
|
||||
|
||||
int bytesUsed;
|
||||
int charsUsed;
|
||||
bool completed;
|
||||
|
||||
fixed (byte *pBytes1 = bytes1)
|
||||
fixed (byte *pBytes2 = bytes2)
|
||||
fixed (byte *pBytes3 = bytes3)
|
||||
fixed (char *pChars = chars)
|
||||
{
|
||||
decoder.Convert(pBytes1, bytes1.Length, pChars, chars.Length, true, out bytesUsed, out charsUsed, out completed);
|
||||
string s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(bytes1.Length, bytesUsed);
|
||||
Assert.Equal(s1.Length, charsUsed);
|
||||
Assert.True(completed, "Expected to have the full operation compeleted with bytes1");
|
||||
Assert.Equal(s1, s);
|
||||
|
||||
decoder.Convert(pBytes2, bytes2.Length, pChars, chars.Length, true, out bytesUsed, out charsUsed, out completed);
|
||||
s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(bytes2.Length, bytesUsed);
|
||||
Assert.Equal(s2.Length, charsUsed);
|
||||
Assert.True(completed, "Expected to have the full operation compeleted with bytes2");
|
||||
Assert.Equal(s2, s);
|
||||
|
||||
decoder.Convert(pBytes3, bytes3.Length, pChars, chars.Length, true, out bytesUsed, out charsUsed, out completed);
|
||||
s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(bytes3.Length, bytesUsed);
|
||||
Assert.Equal(s3.Length, charsUsed);
|
||||
Assert.True(completed, "Expected to have the full operation compeleted with bytes3");
|
||||
Assert.Equal(s3, s);
|
||||
|
||||
decoder.Convert(pBytes3 + bytes1.Length, bytes3.Length - bytes1.Length, pChars, chars.Length, true, out bytesUsed, out charsUsed, out completed);
|
||||
s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(bytes2.Length, bytesUsed);
|
||||
Assert.Equal(s2.Length, charsUsed);
|
||||
Assert.True(completed, "Expected to have the full operation compeleted with bytes3+bytes1.Length");
|
||||
Assert.Equal(s2, s);
|
||||
|
||||
decoder.Convert(pBytes3 + bytes1.Length, bytes3.Length - bytes1.Length, pChars, 2, true, out bytesUsed, out charsUsed, out completed);
|
||||
s = new string(chars, 0, charsUsed);
|
||||
Assert.True(bytes2.Length > bytesUsed, "Expected to use less bytes when there is not enough char buffer");
|
||||
Assert.Equal(2, charsUsed);
|
||||
Assert.False(completed, "Expected to have the operation not fully completed");
|
||||
Assert.Equal(s2.Substring(0, 2), s);
|
||||
|
||||
int encodedBytes = bytesUsed;
|
||||
decoder.Convert(pBytes3 + bytes1.Length + bytesUsed, bytes3.Length - bytes1.Length - encodedBytes, pChars, 1, true, out bytesUsed, out charsUsed, out completed);
|
||||
Assert.Equal(bytes3.Length - bytes1.Length - encodedBytes, bytesUsed);
|
||||
Assert.Equal(1, charsUsed);
|
||||
Assert.True(completed, "expected to flush the remaining character");
|
||||
Assert.Equal(s2[s2.Length - 1], pChars[0]);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static unsafe void ConvertNegativeTest()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
int bytesUsed;
|
||||
int charsUsed;
|
||||
bool completed;
|
||||
|
||||
byte [] bytes = Encoding.UTF8.GetBytes("\u0D800\uDC00");
|
||||
|
||||
fixed (byte *bytesPtr = bytes)
|
||||
fixed (char *charsPtr = new char[1])
|
||||
{
|
||||
byte *pBytes = bytesPtr;
|
||||
char *pChars = charsPtr;
|
||||
|
||||
Assert.Throws<ArgumentNullException>("chars", () => decoder.Convert(pBytes, bytes.Length, null, 1, true, out bytesUsed, out charsUsed, out completed));
|
||||
Assert.Throws<ArgumentNullException>("bytes", () => decoder.Convert(null, bytes.Length, pChars, 1, true, out bytesUsed, out charsUsed, out completed));
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("byteCount", () => decoder.Convert(pBytes, -1, pChars, 1, true, out bytesUsed, out charsUsed, out completed));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("charCount", () => decoder.Convert(pBytes, bytes.Length, pChars, -1, true, out bytesUsed, out charsUsed, out completed));
|
||||
|
||||
Assert.Throws<ArgumentException>("chars", () => decoder.Convert(pBytes, bytes.Length, pChars, 0, true, out bytesUsed, out charsUsed, out completed));
|
||||
}
|
||||
|
||||
decoder = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetDecoder();
|
||||
|
||||
fixed (byte *bytesPtr = new byte [] { 0xFF, 0xFF })
|
||||
fixed (char *charsPtr = new char[2])
|
||||
{
|
||||
byte *pBytes = bytesPtr;
|
||||
char *pChars = charsPtr;
|
||||
|
||||
Assert.Throws<DecoderFallbackException>(() => decoder.Convert(pBytes, 2, pChars, 2, true, out bytesUsed, out charsUsed, out completed));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static unsafe void GetCharsTest()
|
||||
{
|
||||
string s1 = "This is simple ascii string";
|
||||
string s2 = "\uD800\uDC00\u0200"; // non ascii letters
|
||||
string s3 = s1 + s2;
|
||||
|
||||
Encoding utf8 = Encoding.UTF8;
|
||||
Decoder decoder = utf8.GetDecoder();
|
||||
char [] chars = new char[200];
|
||||
|
||||
byte [] bytes1 = utf8.GetBytes(s1);
|
||||
byte [] bytes2 = utf8.GetBytes(s2);
|
||||
byte [] bytes3 = utf8.GetBytes(s3);
|
||||
|
||||
fixed (byte *pBytes1 = bytes1)
|
||||
fixed (byte *pBytes2 = bytes2)
|
||||
fixed (byte *pBytes3 = bytes3)
|
||||
fixed (char *pChars = chars)
|
||||
{
|
||||
int charsUsed = decoder.GetChars(pBytes1, bytes1.Length, pChars, chars.Length, true);
|
||||
string s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(s1.Length, charsUsed);
|
||||
Assert.Equal(s1.Length, decoder.GetCharCount(pBytes1, bytes1.Length, true));
|
||||
Assert.Equal(s1, s);
|
||||
|
||||
charsUsed = decoder.GetChars(pBytes2, bytes2.Length, pChars, chars.Length, true);
|
||||
s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(s2.Length, charsUsed);
|
||||
Assert.Equal(s2.Length, decoder.GetCharCount(pBytes2, bytes2.Length, true));
|
||||
Assert.Equal(s2, s);
|
||||
|
||||
charsUsed = decoder.GetChars(pBytes3, bytes3.Length, pChars, chars.Length, true);
|
||||
s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(s3.Length, charsUsed);
|
||||
Assert.Equal(s3.Length, decoder.GetCharCount(pBytes3, bytes3.Length, true));
|
||||
Assert.Equal(s3, s);
|
||||
|
||||
charsUsed = decoder.GetChars(pBytes3 + bytes1.Length, bytes3.Length - bytes1.Length, pChars, chars.Length, true);
|
||||
s = new string(chars, 0, charsUsed);
|
||||
Assert.Equal(s2.Length, charsUsed);
|
||||
Assert.Equal(s2.Length, decoder.GetCharCount(pBytes3 + bytes1.Length, bytes3.Length - bytes1.Length, true));
|
||||
Assert.Equal(s2, s);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static unsafe void GetCharsNegativeTest()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
byte [] bytes = Encoding.UTF8.GetBytes("\u0D800\uDC00");
|
||||
|
||||
fixed (byte *bytesPtr = bytes)
|
||||
fixed (char *charsPtr = new char[1])
|
||||
{
|
||||
byte *pBytes = bytesPtr;
|
||||
char *pChars = charsPtr;
|
||||
|
||||
Assert.Throws<ArgumentNullException>("chars", () => decoder.GetChars(pBytes, bytes.Length, null, 1, true));
|
||||
Assert.Throws<ArgumentNullException>("bytes", () => decoder.GetChars(null, bytes.Length, pChars, 1, true));
|
||||
Assert.Throws<ArgumentNullException>("bytes", () => decoder.GetCharCount(null, bytes.Length, true));
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("byteCount", () => decoder.GetChars(pBytes, -1, pChars, 1, true));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("charCount", () => decoder.GetChars(pBytes, bytes.Length, pChars, -1, true));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => decoder.GetCharCount(pBytes, -1, true));
|
||||
|
||||
Assert.Throws<ArgumentException>("chars", () => decoder.GetChars(pBytes, bytes.Length, pChars, 1, true));
|
||||
}
|
||||
|
||||
decoder = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetDecoder();
|
||||
|
||||
fixed (byte *bytesPtr = new byte [] { 0xFF, 0xFF })
|
||||
fixed (char *charsPtr = new char[2])
|
||||
{
|
||||
byte *pBytes = bytesPtr;
|
||||
char *pChars = charsPtr;
|
||||
|
||||
Assert.Throws<DecoderFallbackException>(() => decoder.GetChars(pBytes, 2, pChars, 2, true));
|
||||
Assert.Throws<DecoderFallbackException>(() => decoder.GetCharCount(pBytes, 2, true));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void DecoderExceptionFallbackBufferTest()
|
||||
{
|
||||
Decoder decoder = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetDecoder();
|
||||
|
||||
byte [] bytes = new byte [] { 0xFF, 0xFF };
|
||||
char [] chars = new char [bytes.Length];
|
||||
|
||||
Assert.Throws<DecoderFallbackException>(() => decoder.GetChars(bytes, 0, 2, chars, 2));
|
||||
|
||||
DecoderFallbackBuffer fallbackBuffer = decoder.FallbackBuffer;
|
||||
Assert.True(fallbackBuffer is DecoderExceptionFallbackBuffer, "Expected to get DecoderExceptionFallbackBuffer type");
|
||||
Assert.Throws<DecoderFallbackException>(() => fallbackBuffer.Fallback(bytes, 0));
|
||||
Assert.Throws<DecoderFallbackException>(() => fallbackBuffer.Fallback(new byte [] { 0x40, 0x60 }, 0));
|
||||
|
||||
Assert.Equal(0, fallbackBuffer.Remaining);
|
||||
Assert.Equal('\u0000', fallbackBuffer.GetNextChar());
|
||||
|
||||
Assert.False(fallbackBuffer.MovePrevious(), "MovePrevious expected to always return false");
|
||||
|
||||
fallbackBuffer.Reset();
|
||||
|
||||
Assert.Equal(0, fallbackBuffer.Remaining);
|
||||
Assert.Equal('\u0000', fallbackBuffer.GetNextChar());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void DecoderReplacementFallbackBufferTest()
|
||||
{
|
||||
Decoder decoder = Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback(), new DecoderReplacementFallback()).GetDecoder();
|
||||
|
||||
byte [] bytes = new byte [] { 0xFF, 0xFF };
|
||||
char [] chars = new char [bytes.Length];
|
||||
|
||||
DecoderFallbackBuffer fallbackBuffer = decoder.FallbackBuffer;
|
||||
Assert.True(fallbackBuffer is DecoderReplacementFallbackBuffer, "Expected to get DecoderReplacementFallbackBuffer type");
|
||||
Assert.True(fallbackBuffer.Fallback(bytes, 0), "Expected we fallback on the given buffer");
|
||||
Assert.Equal(1, fallbackBuffer.Remaining);
|
||||
Assert.False(fallbackBuffer.MovePrevious(), "Expected we cannot move back on the replacement buffer as we are at the Beginning of the buffer");
|
||||
Assert.Equal('?', fallbackBuffer.GetNextChar());
|
||||
Assert.True(fallbackBuffer.MovePrevious(), "Expected we can move back on the replacement buffer");
|
||||
Assert.Equal('?', fallbackBuffer.GetNextChar());
|
||||
|
||||
fallbackBuffer.Reset();
|
||||
Assert.Equal(0, fallbackBuffer.Remaining);
|
||||
Assert.Equal('\u0000', fallbackBuffer.GetNextChar());
|
||||
Assert.False(fallbackBuffer.MovePrevious(), "Expected we cannot move back on the replacement buffer as we are rest the buffer");
|
||||
}
|
||||
}
|
||||
}
|
||||
325
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderConvert2.cs
vendored
Normal file
325
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderConvert2.cs
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class DecoderConvert2Decoder : Decoder
|
||||
{
|
||||
private Decoder _decoder = null;
|
||||
|
||||
public DecoderConvert2Decoder()
|
||||
{
|
||||
_decoder = Encoding.UTF8.GetDecoder();
|
||||
}
|
||||
|
||||
public override int GetCharCount(byte[] bytes, int index, int count)
|
||||
{
|
||||
return _decoder.GetCharCount(bytes, index, count);
|
||||
}
|
||||
|
||||
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
|
||||
{
|
||||
return _decoder.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
_decoder.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
// Convert(System.Byte[],System.Int32,System.Int32,System.Char[],System.Int32,System.Int32,System.Boolean,System.Int32@,System.Int32@,System.Boolean@)
|
||||
public class DecoderConvert2
|
||||
{
|
||||
private const int c_SIZE_OF_ARRAY = 127;
|
||||
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
|
||||
|
||||
// PosTest1: Call Convert to convert a arbitrary byte array to character array by using ASCII decoder
|
||||
[Fact]
|
||||
public void PosTest1()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
char[] chars = new char[c_SIZE_OF_ARRAY];
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = _generator.GetByte(-55);
|
||||
}
|
||||
|
||||
int bytesUsed;
|
||||
int charsUsed;
|
||||
bool completed;
|
||||
decoder.Convert(bytes, 0, bytes.Length, chars, 0, chars.Length, true, out bytesUsed, out charsUsed, out completed);
|
||||
decoder.Reset();
|
||||
|
||||
decoder.Convert(bytes, 0, bytes.Length, chars, 0, chars.Length, false, out bytesUsed, out charsUsed, out completed);
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest2: Call Convert to convert a arbitrary byte array to character array by using Unicode decoder"
|
||||
[Fact]
|
||||
public void PosTest2()
|
||||
{
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
char[] chars = new char[c_SIZE_OF_ARRAY];
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY * 2];
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = _generator.GetByte(-55);
|
||||
}
|
||||
|
||||
int bytesUsed;
|
||||
int charsUsed;
|
||||
bool completed;
|
||||
decoder.Convert(bytes, 0, bytes.Length, chars, 0, chars.Length, true, out bytesUsed, out charsUsed, out completed);
|
||||
decoder.Reset();
|
||||
|
||||
decoder.Convert(bytes, 0, bytes.Length, chars, 0, chars.Length, false, out bytesUsed, out charsUsed, out completed);
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest3: Call Convert to convert a ASCII byte array to character array by using ASCII decoder
|
||||
[Fact]
|
||||
public void PosTest3()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
char[] chars = new char[c_SIZE_OF_ARRAY];
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
char[] expected = new char[c_SIZE_OF_ARRAY];
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
for (int i = 0; i < expected.Length; ++i)
|
||||
{
|
||||
expected[i] = (char)('\0' + i);
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, true, bytes.Length, chars.Length, true, expected, "003.1");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, false, bytes.Length, chars.Length, true, expected, "003.2");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest4: Call Convert to convert a ASCII byte array with user implemented decoder
|
||||
[Fact]
|
||||
public void PosTest4()
|
||||
{
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
char[] chars = new char[bytes.Length];
|
||||
char[] expected = new char[bytes.Length];
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
for (int i = 0; i < expected.Length; ++i)
|
||||
{
|
||||
expected[i] = (char)('\0' + i);
|
||||
}
|
||||
|
||||
Decoder decoder = new DecoderConvert2Decoder();
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, true, bytes.Length, chars.Length, true, expected, "004.1");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, false, bytes.Length, chars.Length, true, expected, "004.2");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest5: Call Convert to convert partial of a ASCII byte array with ASCII decoder
|
||||
[Fact]
|
||||
public void PosTest5()
|
||||
{
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
char[] chars = new char[bytes.Length];
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, 1, chars, 0, 1, false, 1, 1, true, "005.1");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, 1, chars, 0, 1, true, 1, 1, true, "005.2");
|
||||
decoder.Reset();
|
||||
|
||||
// Verify maxBytes is large than character count
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length - 1, false, bytes.Length - 1, chars.Length - 1, false, "005.3");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length - 1, true, bytes.Length - 1, chars.Length - 1, false, "005.4");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest6: Call Convert to convert a ASCII character array with Unicode encoder
|
||||
[Fact]
|
||||
public void PosTest6()
|
||||
{
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
char[] chars = new char[bytes.Length];
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, false, bytes.Length, chars.Length / 2, true, "006.1");
|
||||
decoder.Reset();
|
||||
// There will be 1 byte left unconverted after previous statement, and set flush = false should left this 1 byte in the buffer.
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, true, bytes.Length, chars.Length / 2 + 1, true, "006.2");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest7: Call Convert to convert partial of a ASCII character array with Unicode encoder
|
||||
[Fact]
|
||||
public void PosTest7()
|
||||
{
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
char[] chars = new char[bytes.Length];
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, 2, chars, 0, 1, false, 2, 1, true, "007.1");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, 2, chars, 0, 1, true, 2, 1, true, "007.2");
|
||||
decoder.Reset();
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, 1, false, 2, 1, false, "007.3");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, 1, true, 2, 1, false, "007.4");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest8: Call Convert to convert a Unicode character array with Unicode encoder
|
||||
[Fact]
|
||||
public void PosTest8()
|
||||
{
|
||||
char[] expected = "\u8FD9\u4E2A\u4E00\u4E2A\u6D4B\u8BD5".ToCharArray();
|
||||
byte[] bytes = new byte[] {
|
||||
217,
|
||||
143,
|
||||
42,
|
||||
78,
|
||||
0,
|
||||
78,
|
||||
42,
|
||||
78,
|
||||
75,
|
||||
109,
|
||||
213,
|
||||
139
|
||||
};
|
||||
char[] chars = new char[expected.Length];
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, false, bytes.Length, chars.Length, true, expected, "008.1");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, chars.Length, true, bytes.Length, chars.Length, true, expected, "008.2");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest9: Call Convert to convert partial of a Unicode character array with Unicode encoder
|
||||
[Fact]
|
||||
public void PosTest9()
|
||||
{
|
||||
char[] expected = "\u8FD9".ToCharArray();
|
||||
char[] chars = new char[expected.Length];
|
||||
byte[] bytes = new byte[] {
|
||||
217,
|
||||
143,
|
||||
42,
|
||||
78,
|
||||
0,
|
||||
78,
|
||||
42,
|
||||
78,
|
||||
75,
|
||||
109,
|
||||
213,
|
||||
139
|
||||
};
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, 2, chars, 0, 1, false, 2, 1, true, expected, "009.1");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, 2, chars, 0, 1, true, 2, 1, true, expected, "009.2");
|
||||
decoder.Reset();
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, 1, false, 2, 1, false, expected, "009.3");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, chars, 0, 1, true, 2, 1, false, expected, "009.4");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest10: Call Convert with ASCII decoder and convert nothing
|
||||
[Fact]
|
||||
public void PosTest10()
|
||||
{
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
char[] chars = new char[bytes.Length];
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, 0, chars, 0, 0, false, 0, 0, true, "010.1");
|
||||
decoder.Reset();
|
||||
VerificationHelper(decoder, bytes, 0, 0, chars, 0, chars.Length, true, 0, 0, true, "010.2");
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
private void VerificationHelper(Decoder decoder, byte[] bytes,
|
||||
int byteIndex,
|
||||
int byteCount,
|
||||
char[] chars,
|
||||
int charIndex,
|
||||
int charCount,
|
||||
bool flush,
|
||||
int desiredBytesUsed,
|
||||
int desiredCharsUsed,
|
||||
bool desiredCompleted,
|
||||
string errorno)
|
||||
{
|
||||
int bytesUsed;
|
||||
int charsUsed;
|
||||
bool completed;
|
||||
|
||||
decoder.Convert(bytes, byteIndex, byteCount, chars, charIndex, charCount, flush, out bytesUsed,
|
||||
out charsUsed, out completed);
|
||||
|
||||
Assert.Equal(desiredBytesUsed, bytesUsed);
|
||||
Assert.Equal(desiredCharsUsed, charsUsed);
|
||||
Assert.Equal(desiredCompleted, completed);
|
||||
}
|
||||
|
||||
private void VerificationHelper(Decoder decoder, byte[] bytes,
|
||||
int byteIndex,
|
||||
int byteCount,
|
||||
char[] chars,
|
||||
int charIndex,
|
||||
int charCount,
|
||||
bool flush,
|
||||
int desiredBytesUsed,
|
||||
int desiredCharsUsed,
|
||||
bool desiredCompleted,
|
||||
char[] desiredChars,
|
||||
string errorno)
|
||||
{
|
||||
VerificationHelper(decoder, bytes, byteIndex, byteCount, chars, charIndex, charCount, flush, desiredBytesUsed,
|
||||
desiredCharsUsed, desiredCompleted, errorno + ".1");
|
||||
|
||||
Assert.Equal(desiredChars.Length, chars.Length);
|
||||
|
||||
for (int i = 0; i < chars.Length; ++i)
|
||||
{
|
||||
Assert.Equal(desiredChars[i], chars[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderCtor.cs
vendored
Normal file
33
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderCtor.cs
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
public class DecoderCtorDecoder : Decoder
|
||||
{
|
||||
public override int GetCharCount(byte[] bytes, int index, int count)
|
||||
{
|
||||
throw new Exception("The method or operation is not implemented.");
|
||||
}
|
||||
|
||||
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
|
||||
{
|
||||
throw new Exception("The method or operation is not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class DecoderCtor
|
||||
{
|
||||
// PosTest1: Call ctor to create a decoder instance
|
||||
[Fact]
|
||||
public void PosTest1()
|
||||
{
|
||||
DecoderCtorDecoder decoder = new DecoderCtorDecoder();
|
||||
Assert.NotNull(decoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
171
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderGetCharCount2.cs
vendored
Normal file
171
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderGetCharCount2.cs
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Text.Tests
|
||||
{
|
||||
// GetCharCount(System.Byte[],System.Int32,System.Int32,System.Boolean)
|
||||
public class DecoderGetCharCount2
|
||||
{
|
||||
#region Private Fields
|
||||
private const int c_SIZE_OF_ARRAY = 127;
|
||||
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
|
||||
#endregion
|
||||
|
||||
#region Positive Test Cases
|
||||
// PosTest1: Call GetCharCount with ASCII decoder and ASCII byte array
|
||||
[Fact]
|
||||
public void PosTest1()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
int expected = bytes.Length;
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, true, expected, "001.1");
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, false, expected, "001.2");
|
||||
}
|
||||
|
||||
// PosTest2: Call GetCharCount with Unicode decoder and ASCII byte array
|
||||
[Fact]
|
||||
public void PosTest2()
|
||||
{
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, true, bytes.Length / 2 + 1, "002.1");
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, false, bytes.Length / 2, "002.2");
|
||||
}
|
||||
|
||||
// PosTest3: Call GetCharCount with Unicode decoder and Unicode byte array
|
||||
[Fact]
|
||||
public void PosTest3()
|
||||
{
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
int expected = 6;
|
||||
// Unicode string: 这个一个测试
|
||||
byte[] bytes = new byte[] {
|
||||
217,
|
||||
143,
|
||||
42,
|
||||
78,
|
||||
0,
|
||||
78,
|
||||
42,
|
||||
78,
|
||||
75,
|
||||
109,
|
||||
213,
|
||||
139
|
||||
};
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, true, expected, "003.1");
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length, false, expected, "003.2");
|
||||
}
|
||||
|
||||
// PosTest4: Call GetCharCount with Unicode decoder and Arbitrary byte array
|
||||
[Fact]
|
||||
public void PosTest4()
|
||||
{
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
_generator.GetBytes(-55, bytes);
|
||||
|
||||
decoder.GetCharCount(bytes, 0, bytes.Length, true);
|
||||
decoder.GetCharCount(bytes, 0, bytes.Length, false);
|
||||
}
|
||||
|
||||
// PosTest5: Call GetCharCount with ASCII decoder and Arbitrary byte array
|
||||
[Fact]
|
||||
public void PosTest5()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
_generator.GetBytes(-55, bytes);
|
||||
|
||||
decoder.GetCharCount(bytes, 0, bytes.Length, true);
|
||||
decoder.GetCharCount(bytes, 0, bytes.Length, false);
|
||||
}
|
||||
|
||||
// PosTest6: Call GetCharCount with ASCII decoder and convert partial of ASCII array
|
||||
[Fact]
|
||||
public void PosTest6()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
int expected = bytes.Length / 2;
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, expected, true, expected, "006.1");
|
||||
VerificationHelper(decoder, bytes, 0, expected, false, expected, "006.2");
|
||||
VerificationHelper(decoder, bytes, expected, expected, true, expected, "006.3");
|
||||
VerificationHelper(decoder, bytes, 1, expected, false, expected, "006.4");
|
||||
}
|
||||
|
||||
// PosTest7: Call GetCharCount with Unicode decoder and convert partial of Unicode byte array
|
||||
[Fact]
|
||||
public void PosTest7()
|
||||
{
|
||||
Decoder decoder = Encoding.Unicode.GetDecoder();
|
||||
// Unicode string: 这个一个测试
|
||||
byte[] bytes = new byte[] {
|
||||
217,
|
||||
143,
|
||||
42,
|
||||
78,
|
||||
0,
|
||||
78,
|
||||
42,
|
||||
78,
|
||||
75,
|
||||
109,
|
||||
213,
|
||||
139
|
||||
};
|
||||
int expected = 3;
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length / 2, true, expected, "007.1");
|
||||
VerificationHelper(decoder, bytes, 0, bytes.Length / 2, false, expected, "007.2");
|
||||
VerificationHelper(decoder, bytes, bytes.Length / 2, 0, true, 0, "007.3");
|
||||
// Set index to 1, so some characters may be not converted
|
||||
VerificationHelper(decoder, bytes, 1, bytes.Length / 2, false, expected, "007.4");
|
||||
}
|
||||
|
||||
// PosTest8: Call GetCharCount with ASCII decoder and count = 0
|
||||
[Fact]
|
||||
public void PosTest8()
|
||||
{
|
||||
Decoder decoder = Encoding.UTF8.GetDecoder();
|
||||
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
|
||||
int expected = 0;
|
||||
for (int i = 0; i < bytes.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
VerificationHelper(decoder, bytes, 0, expected, true, expected, "008.1");
|
||||
VerificationHelper(decoder, bytes, 0, expected, false, expected, "008.2");
|
||||
VerificationHelper(decoder, bytes, 1, expected, true, expected, "008.3");
|
||||
VerificationHelper(decoder, bytes, bytes.Length, expected, false, expected, "008.4");
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void VerificationHelper(Decoder decoder, byte[] bytes, int index, int count, bool flush, int expected, string errorno)
|
||||
{
|
||||
int ret = decoder.GetCharCount(bytes, index, count, flush);
|
||||
Assert.Equal(expected, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user