Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -115,7 +115,6 @@ namespace System.IO.Tests
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Difference in behavior that added extra checks to BinaryReader/Writer buffers on .Net Core")]
[ActiveIssue(20753, TargetFrameworkMonikers.UapAot)]
public void Read_InvalidEncoding()
{
using (var str = CreateStream())

View File

@@ -86,14 +86,14 @@ namespace System.IO.Tests
for (int i = 0; i < randomNumbers.Length; i++)
{
ch = (char)randomNumbers[i];
Assert.Throws<ArgumentException>(() => writer.Write(ch));
AssertExtensions.Throws<ArgumentException>(null, () => writer.Write(ch));
}
// between 56320 <= x < 57343
randomNumbers = new int[] { 56320, 57342, 56431, 57001, 56453, 57245, 57111 };
for (int i = 0; i < randomNumbers.Length; i++)
{
ch = (char)randomNumbers[i];
Assert.Throws<ArgumentException>(() => writer.Write(ch));
AssertExtensions.Throws<ArgumentException>(null, () => writer.Write(ch));
}
writer.Dispose();
@@ -305,9 +305,9 @@ namespace System.IO.Tests
for (int iLoop = 0; iLoop < iArrLargeValues.Length; iLoop++)
{
// [] Offset out of range
Assert.Throws<ArgumentException>(() => dw2.Write(bArr, iArrLargeValues[iLoop], 0));
AssertExtensions.Throws<ArgumentException>(null, () => dw2.Write(bArr, iArrLargeValues[iLoop], 0));
// [] Invalid count value
Assert.Throws<ArgumentException>(() => dw2.Write(bArr, 0, iArrLargeValues[iLoop]));
AssertExtensions.Throws<ArgumentException>(null, () => dw2.Write(bArr, 0, iArrLargeValues[iLoop]));
}
dw2.Dispose();
mstr.Dispose();

View File

@@ -42,14 +42,14 @@ namespace System.IO.Tests
// [] Can't construct a BinaryWriter on a readonly stream
using (Stream memStream = new MemoryStream(new byte[10], false))
{
Assert.Throws<ArgumentException>(() => new BinaryWriter(memStream));
AssertExtensions.Throws<ArgumentException>(null, () => new BinaryWriter(memStream));
}
// [] Can't construct a BinaryWriter with a closed stream
{
Stream memStream = CreateStream();
memStream.Dispose();
Assert.Throws<ArgumentException>(() => new BinaryWriter(memStream));
AssertExtensions.Throws<ArgumentException>(null, () => new BinaryWriter(memStream));
}
}
@@ -261,7 +261,7 @@ namespace System.IO.Tests
{
writer.Write("012345789".ToCharArray());
Assert.Throws<ArgumentException>(() =>
AssertExtensions.Throws<ArgumentException>(null, () =>
{
writer.Seek(3, ~SeekOrigin.Begin);
});

View File

@@ -53,7 +53,7 @@ namespace System.IO.Tests
AssertExtensions.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));
AssertExtensions.Throws<ArgumentException>(null, () => stream.Read(array, 9, 2));
}
}
@@ -66,7 +66,7 @@ namespace System.IO.Tests
AssertExtensions.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));
AssertExtensions.Throws<ArgumentException>(null, () => stream.Write(array, 9, 2));
}
}

View File

@@ -113,6 +113,20 @@ namespace System.IO.Tests
{
return new BufferedStream(new MemoryStream(), bufferSize);
}
[Fact]
public void ReadByte_ThenRead_EndOfStreamCorrectlyFound()
{
using (var s = new BufferedStream(new MemoryStream(new byte[] { 1, 2 }), 2))
{
Assert.Equal(1, s.ReadByte());
Assert.Equal(2, s.ReadByte());
Assert.Equal(-1, s.ReadByte());
Assert.Equal(0, s.Read(new byte[1], 0, 1));
Assert.Equal(0, s.Read(new byte[1], 0, 1));
}
}
}
public class BufferedStream_TestLeaveOpen : TestLeaveOpen

View File

@@ -21,7 +21,7 @@ namespace System.IO.Tests
[InlineData(7, 8, 2)]
public static void MemoryStream_Ctor_OutOfRangeIndeces(int arraySize, int index, int count)
{
Assert.Throws<ArgumentException>(() => new MemoryStream(new byte[arraySize], index, count));
AssertExtensions.Throws<ArgumentException>(null, () => new MemoryStream(new byte[arraySize], index, count));
}
[Fact]

View File

@@ -127,8 +127,8 @@ namespace System.IO.Tests
Assert.Throws<ArgumentNullException>(() => ms2.Read(null, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => ms2.Read(new byte[] { 1 }, -1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => ms2.Read(new byte[] { 1 }, 0, -1));
Assert.Throws<ArgumentException>(() => ms2.Read(new byte[] { 1 }, 2, 0));
Assert.Throws<ArgumentException>(() => ms2.Read(new byte[] { 1 }, 0, 2));
AssertExtensions.Throws<ArgumentException>(null, () => ms2.Read(new byte[] { 1 }, 2, 0));
AssertExtensions.Throws<ArgumentException>(null, () => ms2.Read(new byte[] { 1 }, 0, 2));
ms2.Dispose();

View File

@@ -0,0 +1,6 @@
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Library>
<!-- Needed because of theory data which causes xunit to reflect on its ToString() -->
<Type Name="System.Text.UTF32Encoding" Dynamic="Required Public" />
</Library>
</Directives>

View File

@@ -284,8 +284,8 @@ namespace System.IO.Tests
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => { stream.ReadAsync(new byte[1], 0, -1); });
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => { stream.WriteAsync(new byte[1], 0, -1); });
Assert.Throws<ArgumentException>(() => { stream.ReadAsync(new byte[1], 0, 2); });
Assert.Throws<ArgumentException>(() => { stream.WriteAsync(new byte[1], 0, 2); });
AssertExtensions.Throws<ArgumentException>(null, () => { stream.ReadAsync(new byte[1], 0, 2); });
AssertExtensions.Throws<ArgumentException>(null, () => { stream.WriteAsync(new byte[1], 0, 2); });
}
}
}

View File

@@ -57,7 +57,6 @@ namespace System.IO.Tests
}
[Fact]
[ActiveIssue(20753, TargetFrameworkMonikers.UapAot)]
public async static Task TestNullStream_CopyToAsyncValidation()
{
// Since Stream.Null previously inherited its CopyToAsync
@@ -70,10 +69,10 @@ namespace System.IO.Tests
var readOnlyStream = new MemoryStream(new byte[1], writable: false);
await Assert.ThrowsAsync<ArgumentNullException>("destination", () => Stream.Null.CopyToAsync(null));
await Assert.ThrowsAsync<ArgumentNullException>("destination", () => Stream.Null.CopyToAsync(null, -123)); // Should check if destination == null first
await Assert.ThrowsAsync<ArgumentOutOfRangeException>("bufferSize", () => Stream.Null.CopyToAsync(Stream.Null, 0)); // 0 shouldn't be a valid buffer size
await Assert.ThrowsAsync<ArgumentOutOfRangeException>("bufferSize", () => Stream.Null.CopyToAsync(Stream.Null, -123));
await AssertExtensions.ThrowsAsync<ArgumentNullException>("destination", () => Stream.Null.CopyToAsync(null));
await AssertExtensions.ThrowsAsync<ArgumentNullException>("destination", () => Stream.Null.CopyToAsync(null, -123)); // Should check if destination == null first
await AssertExtensions.ThrowsAsync<ArgumentOutOfRangeException>("bufferSize", () => Stream.Null.CopyToAsync(Stream.Null, 0)); // 0 shouldn't be a valid buffer size
await AssertExtensions.ThrowsAsync<ArgumentOutOfRangeException>("bufferSize", () => Stream.Null.CopyToAsync(Stream.Null, -123));
await Assert.ThrowsAsync<ObjectDisposedException>(() => Stream.Null.CopyToAsync(disposedStream));
await Assert.ThrowsAsync<NotSupportedException>(() => Stream.Null.CopyToAsync(readOnlyStream));
}

View File

@@ -21,7 +21,7 @@ namespace System.IO.Tests
var ms2 = new MemoryStream();
ms2.Dispose();
Assert.Throws<ArgumentException>(() => new StreamReader(ms2, false));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamReader(ms2, false));
}
[Fact]

View File

@@ -27,10 +27,10 @@ namespace System.IO.Tests
public static void EmptyPath_ThrowsArgumentException()
{
// No argument name for the empty path exception
Assert.Throws<ArgumentException>(() => new StreamReader(""));
Assert.Throws<ArgumentException>(() => new StreamReader("", Encoding.UTF8));
Assert.Throws<ArgumentException>(() => new StreamReader("", Encoding.UTF8, true));
Assert.Throws<ArgumentException>(() => new StreamReader("", Encoding.UTF8, true, -1));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamReader(""));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamReader("", Encoding.UTF8));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamReader("", Encoding.UTF8, true));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamReader("", Encoding.UTF8, true, -1));
}
[Fact]

View File

@@ -2,11 +2,13 @@
// 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.IO.Tests
{
public partial class StreamReaderTests
public partial class StreamReaderTests : FileCleanupTestBase
{
[Fact]
public void ObjectClosedReadLine()
@@ -41,5 +43,35 @@ namespace System.IO.Tests
Assert.NotEqual(res1, res2);
}
}
public static IEnumerable<object[]> DetectEncoding_EncodingRoundtrips_MemberData()
{
yield return new object[] { new UTF8Encoding(encoderShouldEmitUTF8Identifier:true) };
yield return new object[] { new UTF32Encoding(bigEndian:false, byteOrderMark:true) };
yield return new object[] { new UTF32Encoding(bigEndian:true, byteOrderMark:true) };
yield return new object[] { new UnicodeEncoding(bigEndian:false, byteOrderMark:true) };
yield return new object[] { new UnicodeEncoding(bigEndian:true, byteOrderMark:true) };
}
[Theory]
[MemberData(nameof(DetectEncoding_EncodingRoundtrips_MemberData))]
public void DetectEncoding_EncodingRoundtrips(Encoding encoding)
{
const string Text = "This is some text for testing.";
string path = GetTestFilePath();
using (var stream = File.OpenWrite(path))
using (var writer = new StreamWriter(stream, encoding))
{
writer.Write(Text);
}
using (var stream = File.OpenRead(path))
using (var reader = new StreamReader(stream, detectEncodingFromByteOrderMarks:true))
{
Assert.Equal(Text, reader.ReadToEnd());
Assert.Equal(encoding.EncodingName, reader.CurrentEncoding.EncodingName);
}
}
}
}

View File

@@ -195,14 +195,14 @@ namespace System.IO.Tests
public void ArgumentOutOfRangeOnNegativCount()
{
var sr = GetCharArrayStream().Item2;
Assert.Throws<ArgumentException>(() => sr.Read(new char[0], 0, 1));
AssertExtensions.Throws<ArgumentException>(null, () => sr.Read(new char[0], 0, 1));
}
[Fact]
public void ArgumentExceptionOffsetAndCount()
{
var sr = GetCharArrayStream().Item2;
Assert.Throws<ArgumentException>(() => sr.Read(new char[0], 2, 0));
AssertExtensions.Throws<ArgumentException>(null, () => sr.Read(new char[0], 2, 0));
}
[Fact]

View File

@@ -29,10 +29,10 @@ namespace System.IO.Tests
public static void EmptyPath_ThrowsArgumentException()
{
// No argument name for the empty path exception
Assert.Throws<ArgumentException>(() => new StreamWriter(""));
Assert.Throws<ArgumentException>(() => new StreamWriter("", true));
Assert.Throws<ArgumentException>(() => new StreamWriter("", true, Encoding.UTF8));
Assert.Throws<ArgumentException>(() => new StreamWriter("", true, Encoding.UTF8, -1));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamWriter(""));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamWriter("", true));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamWriter("", true, Encoding.UTF8));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamWriter("", true, Encoding.UTF8, -1));
}
[Fact]

View File

@@ -153,7 +153,7 @@ namespace System.IO.Tests
Stream ms = CreateStream();
StreamWriter sw = new StreamWriter(ms);
Assert.Throws<ArgumentException>(() => sw.Write(chArr, 1, chArr.Length));
AssertExtensions.Throws<ArgumentException>(null, () => sw.Write(chArr, 1, chArr.Length));
sw.Dispose();
}

View File

@@ -129,7 +129,7 @@ namespace System.IO.Tests
for (int i = 0; i < iArrLargeValues.Length; i++)
{
StringWriter sw = new StringWriter();
Assert.Throws<ArgumentException>(() => sw.Write(chArr, iArrLargeValues[i], chArr.Length));
AssertExtensions.Throws<ArgumentException>(null, () => sw.Write(chArr, iArrLargeValues[i], chArr.Length));
}
}
@@ -140,7 +140,7 @@ namespace System.IO.Tests
for (int i = 0; i < iArrLargeValues.Length; i++)
{
StringWriter sw = new StringWriter();
Assert.Throws<ArgumentException>(() => sw.Write(chArr, 0, iArrLargeValues[i]));
AssertExtensions.Throws<ArgumentException>(null, () => sw.Write(chArr, 0, iArrLargeValues[i]));
}
}

View File

@@ -47,9 +47,6 @@
<Compile Include="Stream\Stream.TimeoutTests.cs" />
<Compile Include="StringReader\StringReader.CtorTests.cs" />
<Compile Include="StringWriter\StringWriterTests.cs" />
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
<Link>Common\System\AssertExtensions.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\IO\CallTrackingStream.cs">
<Link>Common\System\IO\CallTrackingStream.cs</Link>
</Compile>
@@ -60,5 +57,8 @@
<Link>Common\System\IO\WrappedMemoryStream.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>