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,123 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO.Tests", "tests\System.IO.Tests.csproj", "{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}"
ProjectSection(ProjectDependencies) = postProject
{07390899-C8F6-4E83-A3A9-6867B8CB46A0} = {07390899-C8F6-4E83-A3A9-6867B8CB46A0}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO", "src\System.IO.csproj", "{07390899-C8F6-4E83-A3A9-6867B8CB46A0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A14C0271-4180-44DD-9241-908C97229CDC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{FEFA9BDE-0B1C-45E1-B46C-4997A473CC63}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{029F788F-D7DC-472C-9DC5-169EDFFA5DEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.IO", "ref\System.IO.csproj", "{F82A69C2-3687-4A50-9C80-BC7005F40ADC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = uap101aot-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = uap101aot-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = uap101aot-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = uap101aot-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = uap101aot-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = uap101aot-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = uap101aot-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = uap101aot-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = uap101aot-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = uap101aot-Windows_NT-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = uap101aot-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppuap101aot-Windows_NTnetcoreapp|AnyCPU.Build.0 = uap101aot-Windows_NT-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{07390899-C8F6-4E83-A3A9-6867B8CB46A0}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02} = {492EC54D-D2C4-4B3F-AC1F-646B3F7EBB02}
{07390899-C8F6-4E83-A3A9-6867B8CB46A0} = {07390899-C8F6-4E83-A3A9-6867B8CB46A0}
EndGlobalSection
EndGlobal

View 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.2.0.0</AssemblyVersion>
<IsNETCoreApp>true</IsNETCoreApp>
</PropertyGroup>
</Project>

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>
netcoreapp;
uap;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,26 @@
// 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.
// ------------------------------------------------------------------------------
// Types moved down into System.Runtime
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.FileNotFoundException))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.IOException))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.SeekOrigin))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.Stream))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.BinaryReader))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.BinaryWriter))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.BufferedStream))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.EndOfStreamException))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.InvalidDataException))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.MemoryStream))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.StreamReader))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.StreamWriter))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.StringReader))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.StringWriter))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.TextReader))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.IO.TextWriter))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.CodeDom.Compiler.IndentedTextWriter))]

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 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.IO.Manual.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Runtime.Extensions\ref\System.Runtime.Extensions.csproj" />
<ProjectReference Include="..\..\System.Text.Encoding\ref\System.Text.Encoding.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,3 @@
MembersMustExist : Member 'System.IO.BufferedStream.BufferSize.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.BufferedStream.UnderlyingStream.get()' does not exist in the implementation but it does exist in the contract.
CannotMakeMemberNonVirtual : Member 'System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)' is non-virtual in the implementation but is virtual in the contract.

View File

@@ -0,0 +1,19 @@
Compat issues with assembly System.IO:
CannotRemoveBaseTypeOrInterface : Type 'System.IO.BufferedStream' does not inherit from base type 'System.MarshalByRefObject' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.IO.EndOfStreamException' does not inherit from base type 'System.SystemException' in the implementation but it does in the contract.
MembersMustExist : Member 'System.IO.EndOfStreamException..ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.IO.FileNotFoundException' does not inherit from base type 'System.SystemException' in the implementation but it does in the contract.
MembersMustExist : Member 'System.IO.FileNotFoundException..ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.FileNotFoundException.FusionLog.get()' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.IO.IOException' does not inherit from base type 'System.SystemException' in the implementation but it does in the contract.
MembersMustExist : Member 'System.IO.IOException..ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.IO.MemoryStream' does not inherit from base type 'System.MarshalByRefObject' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.IO.Stream' does not inherit from base type 'System.MarshalByRefObject' in the implementation but it does in the contract.
MembersMustExist : Member 'System.IO.Stream.CreateWaitHandle()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.Stream.ObjectInvariant()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.Stream.Synchronized(System.IO.Stream)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.TextReader.Synchronized(System.IO.TextReader)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.TextWriter.Synchronized(System.IO.TextWriter)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.BufferedStream.BufferSize.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.IO.BufferedStream.UnderlyingStream.get()' does not exist in the implementation but it does exist in the contract.
CannotMakeMemberNonVirtual : Member 'System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)' is non-virtual in the implementation but is virtual in the contract.

View 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>
net461-Windows_NT;
uap101aot-Windows_NT;
netcoreapp;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<AssemblyName>System.IO</AssemblyName>
<ProjectGuid>{07390899-C8F6-4e83-A3A9-6867B8CB46A0}</ProjectGuid>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<DefineConstants Condition="'$(TargetGroup)'=='netcoreapp'">$(DefineConstants);netcoreapp17</DefineConstants>
<NoWarn Condition="'$(TargetGroup)' == 'netcoreapp' or '$(TargetGroup)' == 'uap101aot'">CS0436</NoWarn>
</PropertyGroup>
<!-- Default configurations to help VS understand the options -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net461-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net461-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap101aot-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='uap101aot-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(TargetGroup)' == 'net461'">
<ResourcesSourceOutputDirectory>None</ResourcesSourceOutputDirectory>
</PropertyGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'net461'">
<TargetingPackReference Include="mscorlib" />
<TargetingPackReference Include="System" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,133 @@
// 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;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xunit;
namespace System.IO.Tests
{
public class BinaryReaderTests
{
protected virtual Stream CreateStream()
{
return new MemoryStream();
}
[Fact]
public void BinaryReader_DisposeTests()
{
// Disposing multiple times should not throw an exception
using (Stream memStream = CreateStream())
using (BinaryReader binaryReader = new BinaryReader(memStream))
{
binaryReader.Dispose();
binaryReader.Dispose();
binaryReader.Dispose();
}
}
[Fact]
public void BinaryReader_CloseTests()
{
// Closing multiple times should not throw an exception
using (Stream memStream = CreateStream())
using (BinaryReader binaryReader = new BinaryReader(memStream))
{
binaryReader.Close();
binaryReader.Close();
binaryReader.Close();
}
}
[Fact]
public void BinaryReader_DisposeTests_Negative()
{
using (Stream memStream = CreateStream())
{
BinaryReader binaryReader = new BinaryReader(memStream);
binaryReader.Dispose();
ValidateDisposedExceptions(binaryReader);
}
}
[Fact]
public void BinaryReader_CloseTests_Negative()
{
using (Stream memStream = CreateStream())
{
BinaryReader binaryReader = new BinaryReader(memStream);
binaryReader.Close();
ValidateDisposedExceptions(binaryReader);
}
}
private void ValidateDisposedExceptions(BinaryReader binaryReader)
{
byte[] byteBuffer = new byte[10];
char[] charBuffer = new char[10];
Assert.Throws<ObjectDisposedException>(() => binaryReader.PeekChar());
Assert.Throws<ObjectDisposedException>(() => binaryReader.Read());
Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(byteBuffer, 0, 1));
Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(charBuffer, 0, 1));
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBoolean());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadByte());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBytes(1));
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChar());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChars(1));
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDecimal());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDouble());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt16());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt32());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt64());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSByte());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSingle());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadString());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt16());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt32());
Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt64());
}
public class NegEncoding : UTF8Encoding
{
public override Decoder GetDecoder()
{
return new NegDecoder();
}
public class NegDecoder : Decoder
{
public override int GetCharCount(byte[] bytes, int index, int count)
{
return 1;
}
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{
return -10000000;
}
}
}
[Fact]
public void Read_InvalidEncoding()
{
using (var str = CreateStream())
{
byte[] memb = new byte[100];
new Random(345).NextBytes(memb);
str.Write(memb, 0, 100);
str.Position = 0;
using (var reader = new BinaryReader(str, new NegEncoding()))
{
Assert.Throws<ArgumentOutOfRangeException>("charsRemaining", () => reader.Read(new char[10], 0, 10));
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,181 @@
// 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.IO;
using System.Text;
namespace System.IO.Tests
{
public class BinaryWriter_WriteTests
{
[Fact]
public void BinaryWriter_WriteBoolTest()
{
// [] Write a series of booleans to a stream
using(Stream mstr = CreateStream())
using(BinaryWriter dw2 = new BinaryWriter(mstr))
using(BinaryReader dr2 = new BinaryReader(mstr))
{
dw2.Write(false);
dw2.Write(false);
dw2.Write(true);
dw2.Write(false);
dw2.Write(true);
dw2.Write(5);
dw2.Write(0);
dw2.Flush();
mstr.Position = 0;
Assert.False(dr2.ReadBoolean()); //false
Assert.False(dr2.ReadBoolean()); //false
Assert.True(dr2.ReadBoolean()); //true
Assert.False(dr2.ReadBoolean()); //false
Assert.True(dr2.ReadBoolean()); //true
Assert.Equal(5, dr2.ReadInt32()); //5
Assert.Equal(0, dr2.ReadInt32()); //0
}
}
[Fact]
public void BinaryWriter_WriteSingleTest()
{
float[] sglArr = new float[] {
float.MinValue, float.MaxValue, float.Epsilon, float.PositiveInfinity, float.NegativeInfinity, new float(),
0, (float)(-1E20), (float)(-3.5E-20), (float)(1.4E-10), (float)10000.2, (float)2.3E30
};
WriteTest(sglArr, (bw, s) => bw.Write(s), (br) => br.ReadSingle());
}
[Fact]
public void BinaryWriter_WriteDecimalTest()
{
decimal[] decArr = new decimal[] {
decimal.One, decimal.Zero, decimal.MinusOne, decimal.MinValue, decimal.MaxValue,
new decimal(-1000.5), new decimal(-10.0E-40), new decimal(3.4E-40898), new decimal(3.4E-28),
new decimal(3.4E+28), new decimal(0.45), new decimal(5.55), new decimal(3.4899E23)
};
WriteTest(decArr, (bw, s) => bw.Write(s), (br) => br.ReadDecimal());
}
[Fact]
public void BinaryWriter_WriteDoubleTest()
{
double[] dblArr = new double[] {
double.NegativeInfinity, double.PositiveInfinity, double.Epsilon, double.MinValue, double.MaxValue,
-3E59, -1000.5, -1E-40, 3.4E-37, 0.45, 5.55, 3.4899E233
};
WriteTest(dblArr, (bw, s) => bw.Write(s), (br) => br.ReadDouble());
}
[Fact]
public void BinaryWriter_WriteInt16Test()
{
short[] i16Arr = new short[] { short.MinValue, short.MaxValue, 0, -10000, 10000, -50, 50 };
WriteTest(i16Arr, (bw, s) => bw.Write(s), (br) => br.ReadInt16());
}
[Fact]
public void BinaryWriter_WriteInt32Test()
{
int[] i32arr = new int[] { int.MinValue, int.MaxValue, 0, -10000, 10000, -50, 50 };
WriteTest(i32arr, (bw, s) => bw.Write(s), (br) => br.ReadInt32());
}
[Fact]
public void BinaryWriter_WriteInt64Test()
{
long[] i64arr = new long[] { long.MinValue, long.MaxValue, 0, -10000, 10000, -50, 50 };
WriteTest(i64arr, (bw, s) => bw.Write(s), (br) => br.ReadInt64());
}
[Fact]
public void BinaryWriter_WriteUInt16Test()
{
ushort[] ui16Arr = new ushort[] { ushort.MinValue, ushort.MaxValue, 0, 100, 1000, 10000, ushort.MaxValue - 100 };
WriteTest(ui16Arr, (bw, s) => bw.Write(s), (br) => br.ReadUInt16());
}
[Fact]
public void BinaryWriter_WriteUInt32Test()
{
uint[] ui32Arr = new uint[] { uint.MinValue, uint.MaxValue, 0, 100, 1000, 10000, uint.MaxValue - 100 };
WriteTest(ui32Arr, (bw, s) => bw.Write(s), (br) => br.ReadUInt32());
}
[Fact]
public void BinaryWriter_WriteUInt64Test()
{
ulong[] ui64Arr = new ulong[] { ulong.MinValue, ulong.MaxValue, 0, 100, 1000, 10000, ulong.MaxValue - 100 };
WriteTest(ui64Arr, (bw, s) => bw.Write(s), (br) => br.ReadUInt64());
}
[Fact]
public void BinaryWriter_WriteStringTest()
{
StringBuilder sb = new StringBuilder();
string str1;
for (int ii = 0; ii < 5; ii++)
sb.Append("abc");
str1 = sb.ToString();
string[] strArr = new string[] {
"ABC", "\t\t\n\n\n\0\r\r\v\v\t\0\rHello", "This is a normal string", "12345667789!@#$%^&&())_+_)@#",
"ABSDAFJPIRUETROPEWTGRUOGHJDOLJHLDHWEROTYIETYWsdifhsiudyoweurscnkjhdfusiyugjlskdjfoiwueriye", " ",
"\0\0\0\t\t\tHey\"\"", "\u0022\u0011", str1, string.Empty };
WriteTest(strArr, (bw, s) => bw.Write(s), (br) => br.ReadString());
}
[Fact]
public void BinaryWriter_WriteStringTest_Null()
{
using (Stream memStream = CreateStream())
using (BinaryWriter dw2 = new BinaryWriter(memStream))
{
Assert.Throws<ArgumentNullException>(() => dw2.Write((string)null));
}
}
protected virtual Stream CreateStream()
{
return new MemoryStream();
}
private void WriteTest<T>(T[] testElements, Action<BinaryWriter, T> write, Func<BinaryReader, T> read)
{
using (Stream memStream = CreateStream())
using (BinaryWriter writer = new BinaryWriter(memStream))
using (BinaryReader reader = new BinaryReader(memStream))
{
for (int i = 0; i < testElements.Length; i++)
{
write(writer, testElements[i]);
}
writer.Flush();
memStream.Position = 0;
for (int i = 0; i < testElements.Length; i++)
{
Assert.Equal(testElements[i], read(reader));
}
// We've reached the end of the stream. Check for expected EndOfStreamException
Assert.Throws<EndOfStreamException>(() => read(reader));
}
}
}
}

View File

@@ -0,0 +1,381 @@
// 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;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xunit;
namespace System.IO.Tests
{
public class BinaryWriterTests
{
protected virtual Stream CreateStream()
{
return new MemoryStream();
}
[Fact]
public void BinaryWriter_CtorAndWriteTests1()
{
// [] Smoke test to ensure that we can write with the constructed writer
using (Stream mstr = CreateStream())
using (BinaryWriter dw2 = new BinaryWriter(mstr))
using (BinaryReader dr2 = new BinaryReader(mstr))
{
dw2.Write(true);
dw2.Flush();
mstr.Position = 0;
Assert.True(dr2.ReadBoolean());
}
}
[Fact]
public void BinaryWriter_CtorAndWriteTests1_Negative()
{
// [] Should throw ArgumentNullException for null argument
Assert.Throws<ArgumentNullException>(() => new BinaryWriter(null));
// [] Can't construct a BinaryWriter on a readonly stream
using (Stream memStream = new MemoryStream(new byte[10], false))
{
Assert.Throws<ArgumentException>(() => new BinaryWriter(memStream));
}
// [] Can't construct a BinaryWriter with a closed stream
{
Stream memStream = CreateStream();
memStream.Dispose();
Assert.Throws<ArgumentException>(() => new BinaryWriter(memStream));
}
}
[Theory]
[MemberData(nameof(EncodingAndEncodingStrings))]
public void BinaryWriter_EncodingCtorAndWriteTests(Encoding encoding, string testString)
{
using (Stream memStream = CreateStream())
using (BinaryWriter writer = new BinaryWriter(memStream, encoding))
using (BinaryReader reader = new BinaryReader(memStream, encoding))
{
writer.Write(testString);
writer.Flush();
memStream.Position = 0;
Assert.Equal(testString, reader.ReadString());
}
}
public static IEnumerable<object[]> EncodingAndEncodingStrings
{
get
{
yield return new object[] { Encoding.UTF8, "This is UTF8\u00FF" };
yield return new object[] { Encoding.BigEndianUnicode, "This is BigEndianUnicode\u00FF" };
yield return new object[] { Encoding.Unicode, "This is Unicode\u00FF" };
}
}
[Fact]
public void BinaryWriter_EncodingCtorAndWriteTests_Negative()
{
// [] Check for ArgumentNullException on null stream
Assert.Throws<ArgumentNullException>(() => new BinaryReader((Stream)null, Encoding.UTF8));
// [] Check for ArgumentNullException on null encoding
Assert.Throws<ArgumentNullException>(() => new BinaryReader(CreateStream(), null));
}
[Fact]
public void BinaryWriter_SeekTests()
{
int[] iArrLargeValues = new int[] { 10000, 100000, int.MaxValue / 200, int.MaxValue / 1000, short.MaxValue, int.MaxValue, int.MaxValue - 1, int.MaxValue / 2, int.MaxValue / 10, int.MaxValue / 100 };
BinaryWriter dw2 = null;
MemoryStream mstr = null;
byte[] bArr = null;
StringBuilder sb = new StringBuilder();
Int64 lReturn = 0;
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("Hello, this is my string".ToCharArray());
for (int iLoop = 0; iLoop < iArrLargeValues.Length; iLoop++)
{
lReturn = dw2.Seek(iArrLargeValues[iLoop], SeekOrigin.Begin);
Assert.Equal(iArrLargeValues[iLoop], lReturn);
}
dw2.Dispose();
mstr.Dispose();
// [] Seek from start of stream
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("0123456789".ToCharArray());
lReturn = dw2.Seek(0, SeekOrigin.Begin);
Assert.Equal(0, lReturn);
dw2.Write("lki".ToCharArray());
dw2.Flush();
bArr = mstr.ToArray();
sb = new StringBuilder();
for (int i = 0; i < bArr.Length; i++)
sb.Append((char)bArr[i]);
Assert.Equal("lki3456789", sb.ToString());
dw2.Dispose();
mstr.Dispose();
// [] Seek into stream from start
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("0123456789".ToCharArray());
lReturn = dw2.Seek(3, SeekOrigin.Begin);
Assert.Equal(3, lReturn);
dw2.Write("lk".ToCharArray());
dw2.Flush();
bArr = mstr.ToArray();
sb = new StringBuilder();
for (int i = 0; i < bArr.Length; i++)
sb.Append((char)bArr[i]);
Assert.Equal("012lk56789", sb.ToString());
dw2.Dispose();
mstr.Dispose();
// [] Seek from end of stream
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("0123456789".ToCharArray());
lReturn = dw2.Seek(-3, SeekOrigin.End);
Assert.Equal(7, lReturn);
dw2.Write("ll".ToCharArray());
dw2.Flush();
bArr = mstr.ToArray();
sb = new StringBuilder();
for (int i = 0; i < bArr.Length; i++)
sb.Append((char)bArr[i]);
Assert.Equal("0123456ll9", sb.ToString());
dw2.Dispose();
mstr.Dispose();
// [] Seeking from current position
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("0123456789".ToCharArray());
mstr.Position = 2;
lReturn = dw2.Seek(2, SeekOrigin.Current);
Assert.Equal(4, lReturn);
dw2.Write("ll".ToCharArray());
dw2.Flush();
bArr = mstr.ToArray();
sb = new StringBuilder();
for (int i = 0; i < bArr.Length; i++)
sb.Append((char)bArr[i]);
Assert.Equal("0123ll6789", sb.ToString());
dw2.Dispose();
mstr.Dispose();
// [] Seeking past the end from middle
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("0123456789".ToCharArray());
lReturn = dw2.Seek(4, SeekOrigin.End); //This wont throw any exception now.
Assert.Equal(14, mstr.Position);
dw2.Dispose();
mstr.Dispose();
// [] Seek past the end from beginning
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("0123456789".ToCharArray());
lReturn = dw2.Seek(11, SeekOrigin.Begin); //This wont throw any exception now.
Assert.Equal(11, mstr.Position);
dw2.Dispose();
mstr.Dispose();
// [] Seek to the end
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
dw2.Write("0123456789".ToCharArray());
lReturn = dw2.Seek(10, SeekOrigin.Begin);
Assert.Equal(10, lReturn);
dw2.Write("ll".ToCharArray());
bArr = mstr.ToArray();
sb = new StringBuilder();
for (int i = 0; i < bArr.Length; i++)
sb.Append((char)bArr[i]);
Assert.Equal("0123456789ll", sb.ToString());
dw2.Dispose();
mstr.Dispose();
}
[Theory]
[InlineData(-1)]
[InlineData(-2)]
[InlineData(-10000)]
[InlineData(int.MinValue)]
public void BinaryWriter_SeekTests_NegativeOffset(int invalidValue)
{
// [] IOException if offset is negative
using (Stream memStream = CreateStream())
using (BinaryWriter writer = new BinaryWriter(memStream))
{
writer.Write("Hello, this is my string".ToCharArray());
Assert.Throws<IOException>(() => writer.Seek(invalidValue, SeekOrigin.Begin));
}
}
[Fact]
public void BinaryWriter_SeekTests_InvalidSeekOrigin()
{
// [] ArgumentException for invalid seekOrigin
using (Stream memStream = CreateStream())
using (BinaryWriter writer = new BinaryWriter(memStream))
{
writer.Write("012345789".ToCharArray());
Assert.Throws<ArgumentException>(() =>
{
writer.Seek(3, ~SeekOrigin.Begin);
});
}
}
[Fact]
public void BinaryWriter_BaseStreamTests()
{
// [] Get the base stream for MemoryStream
using (Stream ms2 = CreateStream())
using (BinaryWriter sr2 = new BinaryWriter(ms2))
{
Assert.Same(ms2, sr2.BaseStream);
}
}
[Fact]
public virtual void BinaryWriter_FlushTests()
{
// [] Check that flush updates the underlying stream
using (Stream memstr2 = CreateStream())
using (BinaryWriter bw2 = new BinaryWriter(memstr2))
{
string str = "HelloWorld";
int expectedLength = str.Length + 1; // 1 for 7-bit encoded length
bw2.Write(str);
Assert.Equal(expectedLength, memstr2.Length);
bw2.Flush();
Assert.Equal(expectedLength, memstr2.Length);
}
// [] Flushing a closed writer may throw an exception depending on the underlying stream
using (Stream memstr2 = CreateStream())
{
BinaryWriter bw2 = new BinaryWriter(memstr2);
bw2.Dispose();
bw2.Flush();
}
}
[Fact]
public void BinaryWriter_DisposeTests()
{
// Disposing multiple times should not throw an exception
using (Stream memStream = CreateStream())
using (BinaryWriter binaryWriter = new BinaryWriter(memStream))
{
binaryWriter.Dispose();
binaryWriter.Dispose();
binaryWriter.Dispose();
}
}
#if netstandard17
[Fact]
public void BinaryWriter_CloseTests()
{
// Closing multiple times should not throw an exception
using (Stream memStream = CreateStream())
using (BinaryWriter binaryWriter = new BinaryWriter(memStream))
{
binaryWriter.Close();
binaryWriter.Close();
binaryWriter.Close();
}
}
#endif //netstandard17
[Fact]
public void BinaryWriter_DisposeTests_Negative()
{
using (Stream memStream = CreateStream())
{
BinaryWriter binaryWriter = new BinaryWriter(memStream);
binaryWriter.Dispose();
ValidateDisposedExceptions(binaryWriter);
}
}
#if netstandard17
[Fact]
public void BinaryWriter_CloseTests_Negative()
{
using (Stream memStream = CreateStream())
{
BinaryWriter binaryWriter = new BinaryWriter(memStream);
binaryWriter.Close();
ValidateDisposedExceptions(binaryWriter);
}
}
#endif //netstandard17
private void ValidateDisposedExceptions(BinaryWriter binaryWriter)
{
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Seek(1, SeekOrigin.Begin));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write(new byte[2], 0, 2));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write(new char[2], 0, 2));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write(true));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((byte)4));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write(new byte[] { 1, 2 }));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write('a'));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write(new char[] { 'a', 'b' }));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write(5.3));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((short)3));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write(33));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((Int64)42));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((sbyte)4));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write("Hello There"));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((float)4.3));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((UInt16)3));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((uint)4));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write((ulong)5));
Assert.Throws<ObjectDisposedException>(() => binaryWriter.Write("Bah"));
}
}
}

View File

@@ -0,0 +1,77 @@
// 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.Diagnostics;
using System.Threading.Tasks;
using Xunit;
namespace System.IO.Tests
{
public class BufferedStreamFlushTests
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task ShouldNotFlushUnderlyingStreamIfReadOnly(bool underlyingCanSeek)
{
var underlying = new DelegateStream(
canReadFunc: () => true,
canWriteFunc: () => false,
canSeekFunc: () => underlyingCanSeek,
readFunc: (_, __, ___) => 123,
writeFunc: (_, __, ___) =>
{
throw new NotSupportedException();
},
seekFunc: (_, __) => 123L
);
var wrapper = new CallTrackingStream(underlying);
var buffered = new BufferedStream(wrapper);
buffered.ReadByte();
buffered.Flush();
Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
}
[Theory]
[InlineData(true, true)]
[InlineData(true, false)]
[InlineData(false, true)]
[InlineData(false, false)]
public async Task ShouldAlwaysFlushUnderlyingStreamIfWritable(bool underlyingCanRead, bool underlyingCanSeek)
{
var underlying = new DelegateStream(
canReadFunc: () => underlyingCanRead,
canWriteFunc: () => true,
canSeekFunc: () => underlyingCanSeek,
readFunc: (_, __, ___) => 123,
writeFunc: (_, __, ___) => { },
seekFunc: (_, __) => 123L
);
var wrapper = new CallTrackingStream(underlying);
var buffered = new BufferedStream(wrapper);
buffered.Flush();
Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
buffered.WriteByte(0);
buffered.Flush();
Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
}
}
}

View File

@@ -0,0 +1,154 @@
// 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.Threading;
using Xunit;
namespace System.IO.Tests
{
public class BufferedStream_InvalidParameters
{
[Fact]
public static void NullConstructor_Throws_ArgumentNullException()
{
Assert.Throws<ArgumentNullException>(() => new BufferedStream(null));
}
[Fact]
public static void NegativeBufferSize_Throws_ArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new BufferedStream(new MemoryStream(), -1));
}
[Fact]
public static void ZeroBufferSize_Throws_ArgumentNullException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new BufferedStream(new MemoryStream(), 0));
}
[Fact]
public static void UnderlyingStreamDisposed_Throws_ObjectDisposedException()
{
MemoryStream disposedStream = new MemoryStream();
disposedStream.Dispose();
Assert.Throws<ObjectDisposedException>(() => new BufferedStream(disposedStream));
}
[Fact]
public static void SetPositionToNegativeValue_Throws_ArgumentOutOfRangeException()
{
using (BufferedStream stream = new BufferedStream(new MemoryStream()))
{
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Position = -1);
}
}
[Fact]
public static void Read_Arguments()
{
using (BufferedStream stream = new BufferedStream(new MemoryStream()))
{
byte[] array = new byte[10];
Assert.Throws<ArgumentNullException>("array", () => stream.Read(null, 1, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Read(array, -1, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Read(array, 1, -1));
Assert.Throws<ArgumentException>(() => stream.Read(array, 9, 2));
}
}
[Fact]
public static void Write_Arguments()
{
using (BufferedStream stream = new BufferedStream(new MemoryStream()))
{
byte[] array = new byte[10];
Assert.Throws<ArgumentNullException>("array", () => stream.Write(null, 1, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(array, -1, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(array, 1, -1));
Assert.Throws<ArgumentException>(() => stream.Write(array, 9, 2));
}
}
[Fact]
public static void SetLength_NegativeValue()
{
using (MemoryStream underlying = new MemoryStream())
using (BufferedStream stream = new BufferedStream(underlying))
{
Assert.Throws<ArgumentOutOfRangeException>(() => stream.SetLength(-1));
stream.SetLength(1);
Assert.Equal(1, underlying.Length);
Assert.Equal(1, stream.Length);
}
}
[Fact]
public static void ReadOnUnreadableStream_Throws_NotSupportedException()
{
using (WrappedMemoryStream underlying = new WrappedMemoryStream(false, true, true))
using (BufferedStream stream = new BufferedStream(underlying))
{
Assert.Throws<NotSupportedException>(() => stream.Read(new byte[] { 1 }, 0, 1));
}
}
[Fact]
public static void WriteOnUnwritableStream_Throws_NotSupportedException()
{
using (WrappedMemoryStream underlying = new WrappedMemoryStream(true, false, true))
using (BufferedStream stream = new BufferedStream(underlying))
{
Assert.Throws<NotSupportedException>(() => stream.Write(new byte[] { 1 }, 0, 1));
}
}
[Fact]
public static void SeekOnUnseekableStream_Throws_NotSupportedException()
{
using (WrappedMemoryStream underlying = new WrappedMemoryStream(true, true, false))
using (BufferedStream stream = new BufferedStream(underlying))
{
Assert.Throws<NotSupportedException>(() => stream.Seek(0, new SeekOrigin()));
}
}
[Fact]
public void CopyToAsync_InvalidArguments_Throws()
{
using (var s = new BufferedStream(new MemoryStream()))
{
// Null destination
Assert.Throws<ArgumentNullException>("destination", () => { s.CopyToAsync(null); });
// Buffer size out-of-range
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { s.CopyToAsync(new MemoryStream(), 0); });
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { s.CopyToAsync(new MemoryStream(), -1, CancellationToken.None); });
// Copying to non-writable stream
Assert.Throws<NotSupportedException>(() => { s.CopyToAsync(new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: true)); });
// Copying to a non-writable and non-readable stream
Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new WrappedMemoryStream(canRead: false, canWrite: false, canSeek: false)); });
// Copying after disposing the buffer stream
s.Dispose();
Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new MemoryStream()); });
}
// Copying after disposing the underlying stream
using (var ms = new MemoryStream())
using (var s = new BufferedStream(ms))
{
ms.Dispose();
Assert.Throws<ObjectDisposedException>(() => { s.CopyToAsync(new MemoryStream()); });
}
// Copying from a non-readable source
using (var s = new BufferedStream(new WrappedMemoryStream(canRead: false, canWrite: true, canSeek: true)))
{
Assert.Throws<NotSupportedException>(() => { s.CopyToAsync(new MemoryStream()); });
}
}
}
}

View File

@@ -0,0 +1,281 @@
// 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.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace System.IO.Tests
{
public class BufferedStream_StreamAsync : StreamAsync
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
[Fact]
public async Task ConcurrentOperationsAreSerialized()
{
byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)i).ToArray();
var mcaos = new ManuallyReleaseAsyncOperationsStream();
var stream = new BufferedStream(mcaos, 1);
var tasks = new Task[4];
for (int i = 0; i < 4; i++)
{
tasks[i] = stream.WriteAsync(data, 250 * i, 250);
}
Assert.False(tasks.All(t => t.IsCompleted));
mcaos.Release();
await Task.WhenAll(tasks);
stream.Position = 0;
for (int i = 0; i < tasks.Length; i++)
{
Assert.Equal(i, stream.ReadByte());
}
}
[Fact]
public void UnderlyingStreamThrowsExceptions()
{
var stream = new BufferedStream(new ThrowsExceptionFromAsyncOperationsStream());
Assert.Equal(TaskStatus.Faulted, stream.ReadAsync(new byte[1], 0, 1).Status);
Assert.Equal(TaskStatus.Faulted, stream.WriteAsync(new byte[10000], 0, 10000).Status);
stream.WriteByte(1);
Assert.Equal(TaskStatus.Faulted, stream.FlushAsync().Status);
}
[Fact]
public async Task CopyToAsyncTest_RequiresAsyncFlushingOfWrites()
{
byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();
var manualReleaseStream = new ManuallyReleaseAsyncOperationsStream();
var src = new BufferedStream(manualReleaseStream);
src.Write(data, 0, data.Length);
src.Position = 0;
var dst = new MemoryStream();
data[0] = 42;
src.WriteByte(42);
dst.WriteByte(42);
Task copyTask = src.CopyToAsync(dst);
manualReleaseStream.Release();
await copyTask;
Assert.Equal(data, dst.ToArray());
}
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task CopyToAsyncTest_ReadBeforeCopy_CopiesAllData(bool wrappedStreamCanSeek)
{
byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();
var wrapped = new ManuallyReleaseAsyncOperationsStream();
wrapped.Release();
wrapped.Write(data, 0, data.Length);
wrapped.Position = 0;
wrapped.SetCanSeek(wrappedStreamCanSeek);
var src = new BufferedStream(wrapped, 100);
src.ReadByte();
var dst = new MemoryStream();
await src.CopyToAsync(dst);
var expected = new byte[data.Length - 1];
Array.Copy(data, 1, expected, 0, expected.Length);
Assert.Equal(expected, dst.ToArray());
}
}
public class BufferedStream_StreamMethods : StreamMethods
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
protected override Stream CreateStream(int bufferSize)
{
return new BufferedStream(new MemoryStream(), bufferSize);
}
}
public class BufferedStream_TestLeaveOpen : TestLeaveOpen
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
}
public class StreamWriterWithBufferedStream_CloseTests : CloseTests
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
}
public class StreamWriterWithBufferedStream_FlushTests : FlushTests
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
[Fact]
public void WriteAfterRead_NonSeekableStream_Throws()
{
var wrapped = new WrappedMemoryStream(canRead: true, canWrite: true, canSeek: false, data: new byte[] { 1, 2, 3, 4, 5 });
var s = new BufferedStream(wrapped);
s.Read(new byte[3], 0, 3);
Assert.Throws<NotSupportedException>(() => s.Write(new byte[10], 0, 10));
}
}
public class StreamWriterWithBufferedStream_WriteTests : WriteTests
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
}
public class StreamReaderWithBufferedStream_Tests : StreamReaderTests
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
protected override Stream GetSmallStream()
{
byte[] testData = new byte[] { 72, 69, 76, 76, 79 };
return new BufferedStream(new MemoryStream(testData));
}
protected override Stream GetLargeStream()
{
byte[] testData = new byte[] { 72, 69, 76, 76, 79 };
List<byte> data = new List<byte>();
for (int i = 0; i < 1000; i++)
{
data.AddRange(testData);
}
return new BufferedStream(new MemoryStream(data.ToArray()));
}
}
public class BinaryWriterWithBufferedStream_Tests : BinaryWriterTests
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
[Fact]
public override void BinaryWriter_FlushTests()
{
// [] Check that flush updates the underlying stream
using (Stream memstr2 = CreateStream())
using (BinaryWriter bw2 = new BinaryWriter(memstr2))
{
string str = "HelloWorld";
int expectedLength = str.Length + 1; // 1 for 7-bit encoded length
bw2.Write(str);
Assert.Equal(expectedLength, memstr2.Length);
bw2.Flush();
Assert.Equal(expectedLength, memstr2.Length);
}
// [] Flushing a closed writer may throw an exception depending on the underlying stream
using (Stream memstr2 = CreateStream())
{
BinaryWriter bw2 = new BinaryWriter(memstr2);
bw2.Dispose();
Assert.Throws<ObjectDisposedException>(() => bw2.Flush());
}
}
}
public class BinaryWriterWithBufferedStream_WriteByteCharTests : BinaryWriter_WriteByteCharTests
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
}
public class BinaryWriterWithBufferedStream_WriteTests : BinaryWriter_WriteTests
{
protected override Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
}
internal sealed class ManuallyReleaseAsyncOperationsStream : MemoryStream
{
private readonly TaskCompletionSource<bool> _tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
private bool _canSeek = true;
public override bool CanSeek => _canSeek;
public void SetCanSeek(bool canSeek) => _canSeek = canSeek;
public void Release() { _tcs.SetResult(true); }
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
await _tcs.Task;
return await base.ReadAsync(buffer, offset, count, cancellationToken);
}
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
await _tcs.Task;
await base.WriteAsync(buffer, offset, count, cancellationToken);
}
public override async Task FlushAsync(CancellationToken cancellationToken)
{
await _tcs.Task;
await base.FlushAsync(cancellationToken);
}
}
internal sealed class ThrowsExceptionFromAsyncOperationsStream : MemoryStream
{
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
throw new InvalidOperationException("Exception from ReadAsync");
}
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
throw new InvalidOperationException("Exception from WriteAsync");
}
public override Task FlushAsync(CancellationToken cancellationToken)
{
throw new InvalidOperationException("Exception from FlushAsync");
}
}
}

View File

@@ -0,0 +1,27 @@
// 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.IO;
using Xunit;
namespace System.IO.Tests
{
public partial class BufferedStreamTests
{
[Fact]
public void UnderlyingStream()
{
var underlyingStream = new MemoryStream();
var bufferedStream = new BufferedStream(underlyingStream);
Assert.Same(underlyingStream, bufferedStream.UnderlyingStream);
}
[Fact]
public void BufferSize()
{
var bufferedStream = new BufferedStream(new MemoryStream(), 1234);
Assert.Equal(1234, bufferedStream.BufferSize);
}
}
}

View File

@@ -0,0 +1,40 @@
// 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.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace System.IO.Tests
{
public class BufferedStream_NS17
{
protected Stream CreateStream()
{
return new BufferedStream(new MemoryStream());
}
public void EndCallback(IAsyncResult ar)
{ }
[Fact]
public void BeginEndReadTest()
{
Stream stream = CreateStream();
IAsyncResult result = stream.BeginRead(new byte[1], 0, 1, new AsyncCallback(EndCallback), new object());
stream.EndRead(result);
}
[Fact]
public void BeginEndWriteTest()
{
Stream stream = CreateStream();
IAsyncResult result = stream.BeginWrite(new byte[1], 0, 1, new AsyncCallback(EndCallback), new object());
stream.EndWrite(result);
}
}
}

View 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>
netstandard1.5;
netcoreapp;
netstandard;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,176 @@
// 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.Text;
using System.CodeDom.Compiler;
using Xunit;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Globalization;
namespace System.CodeDom.Tests
{
public class IndentedTextWriterTests
{
[Fact]
public static void Ctor_ExpectedDefaults()
{
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var itw = new IndentedTextWriter(sw);
Assert.IsType<UnicodeEncoding>(itw.Encoding);
Assert.Equal(0, itw.Indent);
Assert.Same(sw, itw.InnerWriter);
Assert.Equal(sw.NewLine, itw.NewLine);
Assert.Equal(new string(' ', 4), IndentedTextWriter.DefaultTabString);
}
[Theory]
[InlineData(42)]
[InlineData(4)]
[InlineData(-1)]
[InlineData(-4)]
[InlineData(0)]
[InlineData(8)]
public static void Indent_RoundtripsAndAffectsOutput(int indent)
{
const string TabString = "\t\t";
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var itw = new IndentedTextWriter(sw, TabString);
itw.Indent = indent;
Assert.Equal(indent >= 0 ? indent : 0, itw.Indent);
itw.WriteLine("first");
itw.WriteLine("second");
itw.WriteLine("third");
string expectedTab = string.Concat(Enumerable.Repeat(TabString, itw.Indent));
Assert.Equal(
"first" + Environment.NewLine +
expectedTab + "second" + Environment.NewLine +
expectedTab + "third" + Environment.NewLine,
sb.ToString());
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("space")]
[InlineData(" ")]
public static void TabString_UsesProvidedString(string tabString)
{
var sb = new StringBuilder();
var sw = new StringWriter(sb);
using (var itw = tabString == null ? new IndentedTextWriter(sw) : new IndentedTextWriter(sw, tabString))
{
itw.Indent = 1;
if (tabString == null)
{
tabString = IndentedTextWriter.DefaultTabString;
}
itw.WriteLine();
itw.WriteLine("Should be indented");
itw.Flush();
Assert.Equal(itw.NewLine + tabString + "Should be indented" + itw.NewLine, sb.ToString());
itw.Close();
}
}
[Theory]
[InlineData("\r\n")]
[InlineData("\n")]
[InlineData("newline")]
public static async Task Writes_ProducesExpectedOutput(string newline)
{
var sb = new StringBuilder();
var sw = new StringWriter(sb, CultureInfo.InvariantCulture);
var itw = new IndentedTextWriter(sw, "t");
itw.Indent = 1;
itw.NewLine = newline;
itw.WriteLine();
itw.Write(true);
itw.Write('a');
itw.Write(new char[] { 'b', 'c' });
itw.Write(new char[] { 'd', 'e' }, 0, 2);
itw.Write(4m);
itw.Write(5.6);
itw.Write(6.7f);
itw.Write(8);
itw.Write(9L);
itw.Write((object)10);
itw.Write("11");
itw.Write(12u);
itw.Write(13uL);
itw.Write("{0}", 14);
itw.Write("{0} {1}", 15, 16);
itw.Write("{0} {1} {2}", 15, 16, 17);
itw.Write("{0} {1} {2} {3}", 15, 16, 17, 18);
itw.WriteLine(true);
itw.WriteLine('a');
itw.WriteLine(new char[] { 'b', 'c' });
itw.WriteLine(new char[] { 'd', 'e' }, 0, 2);
itw.WriteLine(4m);
itw.WriteLine(5.6);
itw.WriteLine(6.7f);
itw.WriteLine(8);
itw.WriteLine(9L);
itw.WriteLine((object)10);
itw.WriteLine("11");
itw.WriteLine(12u);
itw.WriteLine(13uL);
itw.WriteLine("{0}", 14);
itw.WriteLine("{0} {1}", 15, 16);
itw.WriteLine("{0} {1} {2}", 15, 16, 17);
itw.WriteLine("{0} {1} {2} {3}", 15, 16, 17, 18);
await itw.WriteAsync('a');
await itw.WriteAsync(new char[] { 'b', 'c' });
await itw.WriteAsync(new char[] { 'd', 'e' }, 0, 2);
await itw.WriteAsync("1");
await itw.WriteLineAsync('a');
await itw.WriteLineAsync(new char[] { 'b', 'c' });
await itw.WriteLineAsync(new char[] { 'd', 'e' }, 0, 2);
await itw.WriteLineAsync("1");
itw.WriteLineNoTabs("notabs");
Assert.Equal(
"" + newline +
"tTrueabcde45.66.789101112131415 1615 16 1715 16 17 18True" + newline +
"ta" + newline +
"tbc" + newline +
"tde" + newline +
"t4" + newline +
"t5.6" + newline +
"t6.7" + newline +
"t8" + newline +
"t9" + newline +
"t10" + newline +
"t11" + newline +
"t12" + newline +
"t13" + newline +
"t14" + newline +
"t15 16" + newline +
"t15 16 17" + newline +
"t15 16 17 18" + newline +
"tabcde1a" + newline +
"tbc" + newline +
"tde" + newline +
"t1" + newline +
"notabs" + newline,
sb.ToString());
}
}
}

Some files were not shown because too many files have changed in this diff Show More