Skip to content

Commit 5003e43

Browse files
committed
Add DisposedCompressorThrows test
1 parent e44b07e commit 5003e43

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test/LibDeflate.Tests/CompressorTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ private static byte[] GetRandomBuffer(int length)
4040
return input;
4141
}
4242

43+
[Theory]
44+
[MemberData(nameof(Compressors), 1)]
45+
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
46+
public void DisposedCompressorThrows(Compressor compressor, ReadOnlyMemory<byte> input, BclInflater _)
47+
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters
48+
{
49+
using (compressor)
50+
{
51+
//make sure we don't throw when not disposed
52+
Compress();
53+
}
54+
55+
Assert.Throws<ObjectDisposedException>(Compress);
56+
57+
void Compress()
58+
{
59+
ReadOnlySpan<byte> inSpan = input.Span;
60+
using var outputOwner = compressor.Compress(inSpan);
61+
62+
Span<byte> output = new byte[input.Length];
63+
compressor.Compress(inSpan, output);
64+
}
65+
}
66+
4367
[Theory]
4468
[MemberData(nameof(AllCompressors))]
4569
public void CompressOwnedBufferTest(Compressor compressor, ReadOnlyMemory<byte> input, BclInflater bclInflater)

0 commit comments

Comments
 (0)