more async tests

This commit is contained in:
Adam Hathcock
2026-04-28 09:14:31 +01:00
parent fc096e1996
commit 0352740ea1
6 changed files with 27 additions and 72 deletions

View File

@@ -41,7 +41,7 @@ internal partial class Unpack
if (((WrPtr - UnpPtr) & MaxWinMask) < 270 && WrPtr != UnpPtr)
{
UnpWriteBuf20();
await UnpWriteBuf20Async(cancellationToken).ConfigureAwait(false);
}
if (StMode != 0)
@@ -95,6 +95,6 @@ internal partial class Unpack
}
}
}
UnpWriteBuf20();
await UnpWriteBuf20Async(cancellationToken).ConfigureAwait(false);
}
}

View File

@@ -49,7 +49,7 @@ internal partial class Unpack
if (((WrPtr - UnpPtr) & MaxWinMask) < 270 && WrPtr != UnpPtr)
{
UnpWriteBuf20();
await UnpWriteBuf20Async(cancellationToken).ConfigureAwait(false);
if (Suspended)
{
return;
@@ -165,8 +165,8 @@ internal partial class Unpack
continue;
}
}
ReadLastTables();
UnpWriteBuf20();
await ReadLastTables20Async(cancellationToken).ConfigureAwait(false);
await UnpWriteBuf20Async(cancellationToken).ConfigureAwait(false);
}
private async Task UnpWriteBuf20Async(CancellationToken cancellationToken = default)
@@ -316,4 +316,22 @@ internal partial class Unpack
Array.Copy(Table, 0, this.UnpOldTable20, 0, UnpOldTable20.Length);
return true;
}
private async Task ReadLastTables20Async(CancellationToken cancellationToken = default)
{
if (ReadTop >= Inp.InAddr + 5)
{
if (UnpAudioBlock)
{
if (DecodeNumber(Inp, MD[UnpCurChannel]) == 256)
{
await ReadTables20Async(cancellationToken).ConfigureAwait(false);
}
}
else if (DecodeNumber(Inp, BlockTables.LD) == 269)
{
await ReadTables20Async(cancellationToken).ConfigureAwait(false);
}
}
}
}

View File

@@ -5,14 +5,9 @@ using System.Threading.Tasks;
namespace SharpCompress.Test.Mocks;
public class AsyncOnlyStream : Stream
public class AsyncOnlyStream(Stream stream) : Stream
{
private readonly Stream _stream;
public AsyncOnlyStream(Stream stream)
{
_stream = stream ?? throw new ArgumentNullException(nameof(stream));
}
private readonly Stream _stream = stream ?? throw new ArgumentNullException(nameof(stream));
public override bool CanRead => _stream.CanRead;
public override bool CanSeek => _stream.CanSeek;

View File

@@ -1,58 +0,0 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace SharpCompress.Test.Mocks;
public sealed class SyncWriteNotSupportedStream(Stream stream) : Stream
{
public override bool CanRead => stream.CanRead;
public override bool CanSeek => stream.CanSeek;
public override bool CanWrite => stream.CanWrite;
public override long Length => stream.Length;
public override long Position
{
get => stream.Position;
set => stream.Position = value;
}
public override void Flush() => stream.Flush();
public override int Read(byte[] buffer, int offset, int count) =>
stream.Read(buffer, offset, count);
public override long Seek(long offset, SeekOrigin origin) => stream.Seek(offset, origin);
public override void SetLength(long value) => stream.SetLength(value);
public override void Write(byte[] buffer, int offset, int count) =>
throw new NotSupportedException("Synchronous Write is not supported");
public override Task WriteAsync(
byte[] buffer,
int offset,
int count,
CancellationToken cancellationToken
) => stream.WriteAsync(buffer, offset, count, cancellationToken);
#if NET8_0_OR_GREATER
public override ValueTask WriteAsync(
ReadOnlyMemory<byte> buffer,
CancellationToken cancellationToken = default
) => stream.WriteAsync(buffer, cancellationToken);
#endif
protected override void Dispose(bool disposing)
{
if (disposing)
{
stream.Dispose();
}
base.Dispose(disposing);
}
}

View File

@@ -30,7 +30,7 @@ public class RarArchiveAsyncTests : ArchiveTests
await foreach (var entry in archive.EntriesAsync.Where(entry => !entry.IsDirectory))
{
using var output = new SyncWriteNotSupportedStream(new MemoryStream());
using var output = new AsyncOnlyStream(new MemoryStream());
await entry.WriteToAsync(output);
extractedEntries++;
}

View File

@@ -32,7 +32,7 @@ public class RarReaderAsyncTests : ReaderTests
{
if (!reader.Entry.IsDirectory)
{
using var output = new SyncWriteNotSupportedStream(new MemoryStream());
using var output = new AsyncOnlyStream(new MemoryStream());
await reader.WriteEntryToAsync(output);
}
}