Skip to content

Commit

Permalink
Added unit test that can be used to reproduce the issue reported in #…
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed May 15, 2023
1 parent 7d84716 commit 8613068
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Magick.NET/Helpers/ByteArrayWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ImageMagick;

internal sealed unsafe class ByteArrayWrapper : IDisposable
{
private const int BufferSize = 81920;
internal const int BufferSize = 81920;

private readonly byte[] _buffer;
private readonly byte* _bufferStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using System.Linq;
using ImageMagick;
using Xunit;

Expand Down Expand Up @@ -53,5 +54,23 @@ public unsafe void ShouldReturnTheNumberOfBytesThatCouldBeWritten()
Assert.Equal(19, wrapper.GetBytes().Length);
}
}

[Fact]
public unsafe void ShouldCalculateRemainingBytesInBytesCorrectly()
{
using var wrapper = new ByteArrayWrapper();
wrapper.Seek(ByteArrayWrapper.BufferSize + 2, (IntPtr)SeekOrigin.Begin, IntPtr.Zero);
wrapper.Seek(ByteArrayWrapper.BufferSize + 1, (IntPtr)SeekOrigin.Begin, IntPtr.Zero);

var buffer = new byte[5] { 1, 2, 3, 4, 5 };
fixed (byte* p = buffer)
{
var count = wrapper.Write((IntPtr)p, (UIntPtr)buffer.Length, IntPtr.Zero);
Assert.Equal(5, count);

var bytes = wrapper.GetBytes().Reverse().Take(5).Reverse();
Assert.Equal(buffer, bytes);
}
}
}
}

0 comments on commit 8613068

Please sign in to comment.