Browse Source

Improve code coverage.

af/merge-core
James Jackson-South 6 years ago
parent
commit
9e232fe57a
  1. 14
      src/ImageSharp/Formats/Png/Zlib/Deflater.cs
  2. 47
      src/ImageSharp/Formats/Png/Zlib/DeflaterHuffman.cs
  3. 24
      src/ImageSharp/Formats/Png/Zlib/DeflaterOutputStream.cs
  4. 34
      src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs
  5. 2
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

14
src/ImageSharp/Formats/Png/Zlib/Deflater.cs

@ -281,23 +281,15 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this.isDisposed)
{
if (disposing)
{
this.engine.Dispose();
}
this.engine.Dispose();
this.engine = null;
this.isDisposed = true;
}
GC.SuppressFinalize(this);
}
}
}

47
src/ImageSharp/Formats/Png/Zlib/DeflaterHuffman.cs

@ -372,7 +372,25 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);
if (!this.isDisposed)
{
this.Pending.Dispose();
this.distanceBufferHandle.Dispose();
this.distanceManagedBuffer.Dispose();
this.literalBufferHandle.Dispose();
this.literalManagedBuffer.Dispose();
this.literalTree.Dispose();
this.blTree.Dispose();
this.distTree.Dispose();
this.Pending = null;
this.literalTree = null;
this.blTree = null;
this.distTree = null;
this.isDisposed = true;
}
GC.SuppressFinalize(this);
}
@ -407,33 +425,6 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
return code + distance;
}
private void Dispose(bool disposing)
{
if (!this.isDisposed)
{
if (disposing)
{
this.Pending.Dispose();
this.distanceBufferHandle.Dispose();
this.distanceManagedBuffer.Dispose();
this.literalBufferHandle.Dispose();
this.literalManagedBuffer.Dispose();
this.literalTree.Dispose();
this.blTree.Dispose();
this.distTree.Dispose();
}
this.Pending = null;
this.literalTree = null;
this.blTree = null;
this.distTree = null;
this.isDisposed = true;
}
}
private sealed class Tree : IDisposable
{
private readonly int minNumCodes;

24
src/ImageSharp/Formats/Png/Zlib/DeflaterOutputStream.cs

@ -134,22 +134,20 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (this.isDisposed)
if (!this.isDisposed)
{
return;
}
if (disposing)
{
this.Finish();
this.deflater.Dispose();
this.memoryOwner.Dispose();
}
if (disposing)
{
this.Finish();
this.deflater.Dispose();
this.memoryOwner.Dispose();
this.deflater = null;
this.memoryOwner = null;
this.isDisposed = true;
base.Dispose(disposing);
}
this.deflater = null;
this.memoryOwner = null;
this.isDisposed = true;
base.Dispose(disposing);
}
}
}

34
src/ImageSharp/Formats/Png/Zlib/ZlibDeflateStream.cs

@ -120,28 +120,16 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
}
/// <inheritdoc/>
public override void Flush()
{
this.deflateStream?.Flush();
}
public override void Flush() => this.deflateStream.Flush();
/// <inheritdoc/>
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
/// <inheritdoc/>
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
/// <inheritdoc/>
public override void SetLength(long value)
{
throw new NotSupportedException();
}
public override void SetLength(long value) => throw new NotSupportedException();
/// <inheritdoc/>
public override void Write(byte[] buffer, int offset, int count)
@ -161,17 +149,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
if (disposing)
{
// dispose managed resources
if (this.deflateStream != null)
{
this.deflateStream.Dispose();
this.deflateStream = null;
}
else
{
// Hack: empty input?
this.rawStream.WriteByte(3);
this.rawStream.WriteByte(0);
}
this.deflateStream.Dispose();
// Add the crc
uint crc = (uint)this.adler32.Value;
@ -181,6 +159,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib
this.rawStream.WriteByte((byte)(crc & 0xFF));
}
this.deflateStream = null;
base.Dispose(disposing);
this.isDisposed = true;
}

2
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
/// </summary>
public static readonly TheoryData<int> CompressionLevels = new TheoryData<int>
{
1, 2, 3, 4, 5, 6, 7, 8, 9
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
};
public static readonly TheoryData<int> PaletteSizes = new TheoryData<int>

Loading…
Cancel
Save