Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 6c120e2

Browse files
committed
Address PR feedback
1 parent fc2d772 commit 6c120e2

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Reflection;
5+
6+
namespace System.IO.Compression.Tests
7+
{
8+
internal static class Common
9+
{
10+
internal static void SetDeflaterMode(string mode)
11+
{
12+
const string fieldName = "s_forcedTestingDeflaterType";
13+
FieldInfo forceType = typeof(DeflateStream).GetTypeInfo().GetDeclaredField(fieldName);
14+
if (forceType != null)
15+
{
16+
forceType.SetValue(null, mode == "zlib" ? (byte)2 : mode == "managed" ? (byte)1 : (byte)0);
17+
}
18+
else if (mode == "zlib" || mode == "managed")
19+
{
20+
Console.Error.WriteLine("Could not change deflater type to " + mode + ": missing " + fieldName);
21+
}
22+
}
23+
}
24+
}

src/System.IO.Compression/tests/DeflateStreamTests.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,20 @@ namespace System.IO.Compression.Tests
1010
{
1111
public class ZLibDeflateStreamTests : DeflateStreamTests, IDisposable
1212
{
13-
public ZLibDeflateStreamTests() { SetWorkerMode("zlib"); }
14-
public void Dispose() { SetWorkerMode("unknown"); }
13+
public ZLibDeflateStreamTests() { Common.SetDeflaterMode("zlib"); }
14+
public void Dispose() { Common.SetDeflaterMode("unknown"); }
1515
}
1616

1717
public class ManagedDeflateStreamTests : DeflateStreamTests, IDisposable
1818
{
19-
public ManagedDeflateStreamTests() { SetWorkerMode("managed"); }
20-
public void Dispose() { SetWorkerMode("unknown"); }
19+
public ManagedDeflateStreamTests() { Common.SetDeflaterMode("managed"); }
20+
public void Dispose() { Common.SetDeflaterMode("unknown"); }
2121
}
2222

2323
public abstract class DeflateStreamTests
2424
{
2525
static string gzTestFile(String fileName) { return Path.Combine("GZTestData", fileName); }
2626

27-
internal static void SetWorkerMode(string mode)
28-
{
29-
FieldInfo forceType = typeof(DeflateStream).GetTypeInfo().GetDeclaredField("s_forcedTestingDeflaterType");
30-
if (forceType != null)
31-
{
32-
forceType.SetValue(null, mode == "zlib" ? (byte)2 : mode == "managed" ? (byte)1 : (byte)0);
33-
}
34-
}
35-
3627
[Fact]
3728
public void BaseStream1()
3829
{

src/System.IO.Compression/tests/GZipStreamTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace System.IO.Compression.Tests
99
{
1010
public class ZLibGZipStreamTests : GZipStreamTests, IDisposable
1111
{
12-
public ZLibGZipStreamTests() { DeflateStreamTests.SetWorkerMode("zlib"); }
13-
public void Dispose() { DeflateStreamTests.SetWorkerMode("unknown"); }
12+
public ZLibGZipStreamTests() { Common.SetDeflaterMode("zlib"); }
13+
public void Dispose() { Common.SetDeflaterMode("unknown"); }
1414
}
1515

1616
public class ManagedGZipStreamTests : GZipStreamTests, IDisposable
1717
{
18-
public ManagedGZipStreamTests() { DeflateStreamTests.SetWorkerMode("managed"); }
19-
public void Dispose() { DeflateStreamTests.SetWorkerMode("unknown"); }
18+
public ManagedGZipStreamTests() { Common.SetDeflaterMode("managed"); }
19+
public void Dispose() { Common.SetDeflaterMode("unknown"); }
2020
}
2121

2222
public abstract class GZipStreamTests

src/System.IO.Compression/tests/System.IO.Compression.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</ProjectReference>
2323
</ItemGroup>
2424
<ItemGroup>
25+
<Compile Include="Common.cs" />
2526
<Compile Include="DeflateStreamTests.cs" />
2627
<Compile Include="GZipStreamTests.cs" />
2728
<Compile Include="XunitAssemblyAttributes.cs" />

0 commit comments

Comments
 (0)