Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions src/System.Text.Encoding.Extensions/Encoding.Extensions.Tests.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encoding.Extensions.Tests", "tests\4.0.10.0\Encoding\Encoding.Extensions.Tests.csproj", "{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|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}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
159 changes: 159 additions & 0 deletions src/System.Text.Encoding.Extensions/tests/4.0.10.0/Encoding/ASCII.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Xunit;
using System;
using System.Text;

namespace EncodingTests
{
public static class ASCII
{
private static readonly EncodingTestHelper s_encodingUtil_ASCII = new EncodingTestHelper("ASCII");

[Fact]
public static void GetByteCount_BoundaryValues()
{
s_encodingUtil_ASCII.GetByteCountTest(String.Empty, 0, 0, 0);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest(String.Empty, 0, 1, 0));
Assert.Throws<ArgumentNullException>(() => s_encodingUtil_ASCII.GetByteCountTest((String)null, 0, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest("abc", -1, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest("abc", 0, -1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest("abc", -1, -1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest("abc", 1, -1, 0));
s_encodingUtil_ASCII.GetByteCountTest("abc", 3, 0, 0);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest("abc", 3, 1, 0));
s_encodingUtil_ASCII.GetByteCountTest("abc", 2, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest("abc", 4, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetByteCountTest("abc", 2, 2, 0));
}

[Fact]
public static void GetCharCount_BoundaryValues()
{
Assert.Throws<ArgumentNullException>(() => s_encodingUtil_ASCII.GetCharCountTest((Byte[])null, 0, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, -1, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, -1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, -1, -1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, 1, -1, 0));
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, 3, 0, 0);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, 3, 1, 0));
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, 2, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, 4, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x61, 0x62, 0x63 }, 2, 2, 0));
}

[Fact]
public static void GetBytes_BoundaryValues()
{
Assert.Throws<ArgumentNullException>(() => s_encodingUtil_ASCII.GetBytesTest((String)null, 0, 0, 0, 0, new Byte[] { }, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", -1, 0, 0, 0, new Byte[] { }, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, -1, 0, 0, new Byte[] { }, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", -1, -1, 0, 0, new Byte[] { }, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 1, -1, 0, 0, new Byte[] { }, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 4, 0, 0, new Byte[] { }, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 1, 3, 0, 0, new Byte[] { }, 0));
}

[Fact]
public static void GetChars_BoundaryValues()
{
Assert.Throws<ArgumentNullException>(() => s_encodingUtil_ASCII.GetCharsTest((Byte[])null, 0, 0, 0, 0, String.Empty, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, -1, 0, 0, 0, String.Empty, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, -1, 0, 0, String.Empty, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, -1, -1, 0, 0, String.Empty, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 1, -1, 0, 0, String.Empty, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 4, 0, 0, String.Empty, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 1, 3, 0, 0, String.Empty, 0));
}

[Fact]
public static void GetChars_BufferBoundary()
{
Assert.Throws<ArgumentNullException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 3, -2, 0, String.Empty, 0));
Assert.Throws<ArgumentException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 3, 0, 0, String.Empty, 0));
Assert.Throws<ArgumentException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 3, -1, 1, String.Empty, 0));
Assert.Throws<ArgumentException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 3, 1, 0, String.Empty, 0));
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 0, 1, 1, "\u0000", 0);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 0, 1, 2, String.Empty, 0));
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 3, 5, 1, "\u0000\u0061\u0062\u0063\u0000", 3);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 0, -1, -1, String.Empty, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x61, 0x62, 0x63 }, 0, 1, -1, -1, String.Empty, 0));
}

[Fact]
public static void GetBytes_BufferBoundary()
{
Assert.Throws<ArgumentNullException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 3, -2, 0, (Byte[])null, 0));
Assert.Throws<ArgumentException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 3, 0, 0, (Byte[])null, 0));
Assert.Throws<ArgumentException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 3, -1, 1, (Byte[])null, 0));
Assert.Throws<ArgumentException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 3, 1, 0, (Byte[])null, 0));
s_encodingUtil_ASCII.GetBytesTest("abc", 0, 0, 1, 1, new Byte[] { 0x00 }, 0);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 0, 1, 2, (Byte[])null, 0));
s_encodingUtil_ASCII.GetBytesTest("abc", 0, 3, 5, 1, new Byte[] { 0x00, 0x61, 0x62, 0x63, 0x00 }, 3);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 0, -1, -1, (Byte[])null, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetBytesTest("abc", 0, 1, -1, -1, (Byte[])null, 0));
}

[Fact]
public static void CorrectByteCodes()
{
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x41 }, 0, 1, -1, 0, "A", 1);
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x41 }, 0, 1, 1);
}

[Fact]
public static void InvalidSequences()
{
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x7F }, 0, 1, -1, 0, "", 1);
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x7F }, 0, 1, 1);
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0x80 }, 0, 1, -1, 0, "?", 1);
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0x80 }, 0, 1, 1);
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0xFF }, 0, 1, -1, 0, "?", 1);
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0xFF }, 0, 1, 1);
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0xC1 }, 0, 1, -1, 0, "?", 1);
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0xC1 }, 0, 1, 1);
s_encodingUtil_ASCII.GetCharsTest(new Byte[] { 0xC1, 0x41, 0xF0, 0x42 }, 0, 4, -1, 0, "?A?B", 4);
s_encodingUtil_ASCII.GetCharCountTest(new Byte[] { 0xC1, 0x41, 0xF0, 0x42 }, 0, 4, 4);
s_encodingUtil_ASCII.GetBytesTest("A", 0, 1, -1, 0, new Byte[] { 0x41 }, 1);
s_encodingUtil_ASCII.GetByteCountTest("A", 0, 1, 1);
s_encodingUtil_ASCII.GetBytesTest("\u0080", 0, 1, -1, 0, new Byte[] { 0x3F }, 1);
s_encodingUtil_ASCII.GetByteCountTest("\u0080", 0, 1, 1);
s_encodingUtil_ASCII.GetBytesTest("\uD800\uDC00\u0061\u0CFF", 0, 4, -1, 0, new Byte[] { 0x3F, 0x3F, 0x61, 0x3F }, 4);
s_encodingUtil_ASCII.GetByteCountTest("\uD800\uDC00\u0061\u0CFF", 0, 4, 4);
s_encodingUtil_ASCII.GetBytesTest("\u00FF", 0, 1, -1, 0, new Byte[] { 0x3F }, 1);
}

[Fact]
public static void MaxCharCount()
{
s_encodingUtil_ASCII.GetMaxCharCountTest(0, 0);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetMaxCharCountTest(-1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetMaxCharCountTest(-2147483648, 0));
s_encodingUtil_ASCII.GetMaxCharCountTest(2147483647, 2147483647);
s_encodingUtil_ASCII.GetMaxCharCountTest(10, 10);
}

[Fact]
public static void MaxByteCount()
{
s_encodingUtil_ASCII.GetMaxByteCountTest(0, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetMaxByteCountTest(-1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => s_encodingUtil_ASCII.GetMaxByteCountTest(-2147483648, 0));
s_encodingUtil_ASCII.GetMaxByteCountTest(2147483646, 2147483647);
s_encodingUtil_ASCII.GetMaxByteCountTest(10, 11);
}

[Fact]
public static void Preamble()
{
s_encodingUtil_ASCII.GetPreambleTest(new Byte[] { });
}

[Fact]
public static void DefaultFallback()
{
s_encodingUtil_ASCII.GetBytesTest("\u0080\u00FF\u0B71\uFFFF\uD800\uDFFF", 0, 6, -1, 0, new Byte[] { 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F }, 6);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>System.Text.Encoding.Extensions.Tests</AssemblyName>
<RootNamespace>System.Text.Encoding.Extensions.Tests</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<Compile Include="ASCII.cs" />
<Compile Include="EncodingTestHelper.cs" />
<Compile Include="ISO-8859-1.cs" />
<Compile Include="UTF16BE.cs" />
<Compile Include="UTF16LE.cs" />
<Compile Include="UTF32BE.cs" />
<Compile Include="UTF32LE.cs" />
<Compile Include="UTF7.cs" />
<Compile Include="UTF8.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
Loading