Skip to content

Commit

Permalink
Add stream conformance tests for standalone streams (#44069)
Browse files Browse the repository at this point in the history
* Nullable-enable stream conformance tests

* Add standalone stream conformance tests

* Address PR feedback
  • Loading branch information
stephentoub authored Nov 3, 2020
1 parent 7a6ee5f commit 7de7895
Show file tree
Hide file tree
Showing 48 changed files with 1,639 additions and 3,818 deletions.
1,620 changes: 1,272 additions & 348 deletions src/libraries/Common/tests/Tests/System/IO/StreamConformanceTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="CompressionStreamUnitTests.ZLib.cs" />
Expand Down

This file was deleted.

47 changes: 0 additions & 47 deletions src/libraries/System.IO.FileSystem/tests/FileStream/CanRead.cs

This file was deleted.

60 changes: 0 additions & 60 deletions src/libraries/System.IO.FileSystem/tests/FileStream/CanSeek.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/libraries/System.IO.FileSystem/tests/FileStream/CanTimeout.cs

This file was deleted.

51 changes: 0 additions & 51 deletions src/libraries/System.IO.FileSystem/tests/FileStream/CanWrite.cs

This file was deleted.

20 changes: 0 additions & 20 deletions src/libraries/System.IO.FileSystem/tests/FileStream/CopyToAsync.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Win32.SafeHandles;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -174,22 +171,5 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
return base.ReadAsync(buffer, offset, count, cancellationToken);
}
}

#region Windows P/Invokes
// We need to P/Invoke to test the named pipe async behavior with FileStream
// because NamedPipeClientStream internally binds the created handle,
// and that then prevents FileStream's constructor from working with the handle
// when trying to set isAsync to true.

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool WaitNamedPipeW(string name, int timeout);

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern SafeFileHandle CreateFileW(
string lpFileName, int dwDesiredAccess, FileShare dwShareMode,
IntPtr securityAttrs, FileMode dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);

#endregion
}
}
16 changes: 0 additions & 16 deletions src/libraries/System.IO.FileSystem/tests/FileStream/Dispose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ namespace System.IO.Tests
{
public class FileStream_Dispose : FileSystemTest
{
[Fact]
public void CanDispose()
{
new FileStream(GetTestFilePath(), FileMode.Create).Dispose();
}

[Fact]
public void DisposeClosesHandle()
{
Expand All @@ -30,16 +24,6 @@ public void DisposeClosesHandle()
Assert.True(handle.IsClosed);
}

[Fact]
public void HandlesMultipleDispose()
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
fs.Dispose();
fs.Dispose();
} // disposed as we leave using
}

private class MyFileStream : FileStream
{
public MyFileStream(string path, FileMode mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace System.IO.Tests
{
public class FileStream_DisposeAsync : FileSystemTest
{
[Fact]
public void CanDisposeAsync()
{
Assert.True(new FileStream(GetTestFilePath(), FileMode.Create).DisposeAsync().IsCompletedSuccessfully);
}

[Fact]
public async Task DisposeAsyncClosesHandle()
{
Expand All @@ -25,15 +19,6 @@ public async Task DisposeAsyncClosesHandle()
Assert.True(handle.IsClosed);
}

[Fact]
public async Task HandlesMultipleDisposeAsync()
{
var fs = new FileStream(GetTestFilePath(), FileMode.Create);
await fs.DisposeAsync();
fs.Dispose();
await fs.DisposeAsync();
}

[Fact]
public async Task DisposeAsyncFlushes()
{
Expand Down
Loading

0 comments on commit 7de7895

Please sign in to comment.