Browse Source
* Fix SlicedStream.Seek(offset, SeekOrigin.End) This fixes https://github.com/AvaloniaUI/Avalonia/issues/13604 The offset _from is applied in set_Position, so applying it also in Seek mispositions the stream. ZipArchive exposes the problem by seeking to the end to read the table of contents. * Add tests for SlicedStream --------- Co-authored-by: Julien Lebosquain <julien@lebosquain.net>pull/18331/head
committed by
GitHub
2 changed files with 30 additions and 1 deletions
@ -0,0 +1,29 @@ |
|||||
|
using System.IO; |
||||
|
using Avalonia.Platform.Internal; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Base.UnitTests; |
||||
|
|
||||
|
public class SlicedStreamTests |
||||
|
{ |
||||
|
[Theory] |
||||
|
[InlineData(2, SeekOrigin.Begin, 22, 2, 9)] |
||||
|
[InlineData(2, SeekOrigin.Current, 22, 17, 24)] |
||||
|
[InlineData(-2, SeekOrigin.End, 22, 40, 47)] |
||||
|
public void Seek_Works( |
||||
|
long offset, |
||||
|
SeekOrigin origin, |
||||
|
long startingUnderlyingPosition, |
||||
|
long expectedPosition, |
||||
|
long expectedUnderlyingPosition) |
||||
|
{ |
||||
|
var memoryStream = new MemoryStream(new byte[1024]); |
||||
|
var slicedStream = new SlicedStream(memoryStream, 7, 42); |
||||
|
memoryStream.Position = startingUnderlyingPosition; |
||||
|
|
||||
|
slicedStream.Seek(offset, origin); |
||||
|
|
||||
|
Assert.Equal(expectedPosition, slicedStream.Position); |
||||
|
Assert.Equal(expectedUnderlyingPosition, memoryStream.Position); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue