mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-24 07:54:39 +00:00
more clean up on tests
This commit is contained in:
@@ -31,7 +31,7 @@ using Xunit;
|
||||
|
||||
namespace SharpCompress.Test;
|
||||
|
||||
public class ADCTest : TestBase
|
||||
public class AdcTest : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void TestBuffer()
|
||||
@@ -64,7 +64,7 @@ public class ADCTest : TestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestADCStreamWholeChunk()
|
||||
public void TestAdcStreamWholeChunk()
|
||||
{
|
||||
using var decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin"));
|
||||
var decompressed = new byte[decFs.Length];
|
||||
@@ -80,7 +80,7 @@ public class ADCTest : TestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestADCStream()
|
||||
public void TestAdcStream()
|
||||
{
|
||||
using var decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin"));
|
||||
var decompressed = new byte[decFs.Length];
|
||||
@@ -114,11 +114,11 @@ public class ADCTest : TestBase
|
||||
|
||||
decFs.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var crc32a = crcStream.Crc;
|
||||
var crc32A = crcStream.Crc;
|
||||
|
||||
var crc32b = Crc32Stream.Compute(memory.ToArray());
|
||||
var crc32B = Crc32Stream.Compute(memory.ToArray());
|
||||
|
||||
Assert.Equal(crc32, crc32a);
|
||||
Assert.Equal(crc32, crc32b);
|
||||
Assert.Equal(crc32, crc32A);
|
||||
Assert.Equal(crc32, crc32B);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,10 +199,7 @@ public class ArchiveTests : ReaderTests
|
||||
)
|
||||
{
|
||||
var src = testArchives.ToArray();
|
||||
using var archive = ArchiveFactory.Open(
|
||||
testArchives.Select(f => new FileInfo(f)),
|
||||
readerOptions
|
||||
);
|
||||
using var archive = ArchiveFactory.Open(src.Select(f => new FileInfo(f)), readerOptions);
|
||||
var idx = 0;
|
||||
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace SharpCompress.Test.Filters;
|
||||
|
||||
public class BranchExecTests
|
||||
{
|
||||
private static byte[] x86resultData { get; } =
|
||||
private static byte[] X86ResultData { get; } =
|
||||
{
|
||||
0x12,
|
||||
0x00,
|
||||
@@ -94,7 +94,7 @@ public class BranchExecTests
|
||||
0x00,
|
||||
};
|
||||
|
||||
private static byte[] x86Data { get; } =
|
||||
private static byte[] X86Data { get; } =
|
||||
{
|
||||
0x12,
|
||||
0x00,
|
||||
@@ -176,7 +176,7 @@ public class BranchExecTests
|
||||
0x00,
|
||||
};
|
||||
|
||||
private static byte[] ppcResultData { get; } =
|
||||
private static byte[] PpcResultData { get; } =
|
||||
{
|
||||
0xF8,
|
||||
0x6B,
|
||||
@@ -276,7 +276,7 @@ public class BranchExecTests
|
||||
0xED
|
||||
};
|
||||
|
||||
private static byte[] ppcData { get; } =
|
||||
private static byte[] PpcData { get; } =
|
||||
{
|
||||
0xF8,
|
||||
0x6B,
|
||||
@@ -376,7 +376,7 @@ public class BranchExecTests
|
||||
0xED
|
||||
};
|
||||
|
||||
private static byte[] armResultData { get; } =
|
||||
private static byte[] ArmResultData { get; } =
|
||||
{
|
||||
0x7C,
|
||||
0xFC,
|
||||
@@ -476,7 +476,7 @@ public class BranchExecTests
|
||||
0xE2
|
||||
};
|
||||
|
||||
private static byte[] armData { get; } =
|
||||
private static byte[] ArmData { get; } =
|
||||
{
|
||||
0x7C,
|
||||
0xFC,
|
||||
@@ -576,7 +576,7 @@ public class BranchExecTests
|
||||
0xE2
|
||||
};
|
||||
|
||||
private static byte[] armtResultData { get; } =
|
||||
private static byte[] ArmtResultData { get; } =
|
||||
{
|
||||
0x95,
|
||||
0x23,
|
||||
@@ -692,7 +692,7 @@ public class BranchExecTests
|
||||
0x0F
|
||||
};
|
||||
|
||||
private static byte[] armtData { get; } =
|
||||
private static byte[] ArmtData { get; } =
|
||||
{
|
||||
0x95,
|
||||
0x23,
|
||||
@@ -808,7 +808,7 @@ public class BranchExecTests
|
||||
0x0F
|
||||
};
|
||||
|
||||
private static byte[] ia64ResultData { get; } =
|
||||
private static byte[] Ia64ResultData { get; } =
|
||||
{
|
||||
0x4D,
|
||||
0xF8,
|
||||
@@ -908,7 +908,7 @@ public class BranchExecTests
|
||||
0x0D
|
||||
};
|
||||
|
||||
private static byte[] ia64Data { get; } =
|
||||
private static byte[] Ia64Data { get; } =
|
||||
{
|
||||
0x4D,
|
||||
0xF8,
|
||||
@@ -1008,7 +1008,7 @@ public class BranchExecTests
|
||||
0x0D
|
||||
};
|
||||
|
||||
private static byte[] sparcResultData { get; } =
|
||||
private static byte[] SparcResultData { get; } =
|
||||
{
|
||||
0x78,
|
||||
0x2E,
|
||||
@@ -1090,7 +1090,7 @@ public class BranchExecTests
|
||||
0x00,
|
||||
};
|
||||
|
||||
private static byte[] sparcData { get; } =
|
||||
private static byte[] SparcData { get; } =
|
||||
{
|
||||
0x78,
|
||||
0x2E,
|
||||
@@ -1180,53 +1180,53 @@ public class BranchExecTests
|
||||
{
|
||||
uint state = 0;
|
||||
uint ip = 0x2000;
|
||||
var testData = x86Data;
|
||||
var testData = X86Data;
|
||||
BranchExecFilter.X86Converter(testData, ip, ref state);
|
||||
CompareBuffer(testData, x86resultData);
|
||||
CompareBuffer(testData, X86ResultData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PowerPCConverterDecodeTest()
|
||||
public void PowerPcConverterDecodeTest()
|
||||
{
|
||||
uint ip = 0x6A0;
|
||||
var testData = ppcData;
|
||||
var testData = PpcData;
|
||||
BranchExecFilter.PowerPCConverter(testData, ip);
|
||||
CompareBuffer(testData, ppcResultData);
|
||||
CompareBuffer(testData, PpcResultData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARMConverteDecoderTest()
|
||||
public void ArmConverteDecoderTest()
|
||||
{
|
||||
uint ip = 0x3C00;
|
||||
var testData = armData;
|
||||
var testData = ArmData;
|
||||
BranchExecFilter.ARMConverter(testData, ip);
|
||||
CompareBuffer(testData, armResultData);
|
||||
CompareBuffer(testData, ArmResultData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARMTConverterDecodeTest()
|
||||
public void ArmtConverterDecodeTest()
|
||||
{
|
||||
uint ip = 0xA00;
|
||||
var testData = armtData;
|
||||
var testData = ArmtData;
|
||||
BranchExecFilter.ARMTConverter(testData, ip);
|
||||
CompareBuffer(testData, armtResultData);
|
||||
CompareBuffer(testData, ArmtResultData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IA64ConverterDecodeTest()
|
||||
public void Ia64ConverterDecodeTest()
|
||||
{
|
||||
uint ip = 0xAA0;
|
||||
var testData = ia64Data;
|
||||
var testData = Ia64Data;
|
||||
BranchExecFilter.IA64Converter(testData, ip);
|
||||
CompareBuffer(testData, ia64ResultData);
|
||||
CompareBuffer(testData, Ia64ResultData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SPARCConverterDecodeTest()
|
||||
public void SparcConverterDecodeTest()
|
||||
{
|
||||
uint ip = 0x100;
|
||||
var testData = sparcData;
|
||||
var testData = SparcData;
|
||||
BranchExecFilter.SPARCConverter(testData, ip);
|
||||
CompareBuffer(testData, sparcResultData);
|
||||
CompareBuffer(testData, SparcResultData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,28 +9,28 @@ namespace SharpCompress.Test.Mocks;
|
||||
|
||||
public class FlushOnDisposeStream : Stream, IDisposable
|
||||
{
|
||||
private Stream inner;
|
||||
private Stream _inner;
|
||||
|
||||
public FlushOnDisposeStream(Stream innerStream) => inner = innerStream;
|
||||
public FlushOnDisposeStream(Stream innerStream) => _inner = innerStream;
|
||||
|
||||
public override bool CanRead => inner.CanRead;
|
||||
public override bool CanRead => _inner.CanRead;
|
||||
|
||||
public override bool CanSeek => false;
|
||||
|
||||
public override bool CanWrite => false;
|
||||
|
||||
public override long Length => inner.Length;
|
||||
public override long Length => _inner.Length;
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get => inner.Position;
|
||||
set => inner.Position = value;
|
||||
get => _inner.Position;
|
||||
set => _inner.Position = value;
|
||||
}
|
||||
|
||||
public override void Flush() { }
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
inner.Read(buffer, offset, count);
|
||||
_inner.Read(buffer, offset, count);
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) =>
|
||||
throw new NotImplementedException();
|
||||
@@ -44,8 +44,8 @@ public class FlushOnDisposeStream : Stream, IDisposable
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
inner.Flush();
|
||||
inner.Close();
|
||||
_inner.Flush();
|
||||
_inner.Close();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace SharpCompress.Test.Mocks;
|
||||
|
||||
public class ForwardOnlyStream : Stream
|
||||
{
|
||||
private readonly Stream stream;
|
||||
private readonly Stream _stream;
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public ForwardOnlyStream(Stream stream) => this.stream = stream;
|
||||
public ForwardOnlyStream(Stream stream) => _stream = stream;
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
@@ -17,7 +17,7 @@ public class ForwardOnlyStream : Stream
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
stream.Dispose();
|
||||
_stream.Dispose();
|
||||
IsDisposed = true;
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class ForwardOnlyStream : Stream
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
stream.Read(buffer, offset, count);
|
||||
_stream.Read(buffer, offset, count);
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace SharpCompress.Test.Mocks;
|
||||
|
||||
public class TestStream : Stream
|
||||
{
|
||||
private readonly Stream stream;
|
||||
private readonly Stream _stream;
|
||||
|
||||
public TestStream(Stream stream)
|
||||
: this(stream, stream.CanRead, stream.CanWrite, stream.CanSeek) { }
|
||||
@@ -13,7 +13,7 @@ public class TestStream : Stream
|
||||
|
||||
public TestStream(Stream stream, bool read, bool write, bool seek)
|
||||
{
|
||||
this.stream = stream;
|
||||
_stream = stream;
|
||||
CanRead = read;
|
||||
CanWrite = write;
|
||||
CanSeek = seek;
|
||||
@@ -22,7 +22,7 @@ public class TestStream : Stream
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
stream.Dispose();
|
||||
_stream.Dispose();
|
||||
IsDisposed = true;
|
||||
}
|
||||
|
||||
@@ -32,23 +32,23 @@ public class TestStream : Stream
|
||||
|
||||
public override bool CanWrite { get; }
|
||||
|
||||
public override void Flush() => stream.Flush();
|
||||
public override void Flush() => _stream.Flush();
|
||||
|
||||
public override long Length => stream.Length;
|
||||
public override long Length => _stream.Length;
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get => stream.Position;
|
||||
set => stream.Position = value;
|
||||
get => _stream.Position;
|
||||
set => _stream.Position = value;
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
stream.Read(buffer, offset, count);
|
||||
_stream.Read(buffer, offset, count);
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => stream.Seek(offset, origin);
|
||||
public override long Seek(long offset, SeekOrigin origin) => _stream.Seek(offset, origin);
|
||||
|
||||
public override void SetLength(long value) => stream.SetLength(value);
|
||||
public override void SetLength(long value) => _stream.SetLength(value);
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) =>
|
||||
stream.Write(buffer, offset, count);
|
||||
_stream.Write(buffer, offset, count);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace SharpCompress.Test.Rar;
|
||||
/// </summary>
|
||||
public class RarHeaderFactoryTest : TestBase
|
||||
{
|
||||
private readonly RarHeaderFactory rarHeaderFactory;
|
||||
private readonly RarHeaderFactory _rarHeaderFactory;
|
||||
|
||||
public RarHeaderFactoryTest() =>
|
||||
rarHeaderFactory = new RarHeaderFactory(
|
||||
_rarHeaderFactory = new RarHeaderFactory(
|
||||
StreamingMode.Seekable,
|
||||
new ReaderOptions { LeaveStreamOpen = true }
|
||||
);
|
||||
@@ -40,11 +40,11 @@ public class RarHeaderFactoryTest : TestBase
|
||||
FileMode.Open,
|
||||
FileAccess.Read
|
||||
);
|
||||
foreach (var header in rarHeaderFactory.ReadHeaders(stream))
|
||||
foreach (var header in _rarHeaderFactory.ReadHeaders(stream))
|
||||
{
|
||||
if (header.HeaderType == HeaderType.Archive || header.HeaderType == HeaderType.Crypt)
|
||||
{
|
||||
Assert.Equal(isEncrypted, rarHeaderFactory.IsEncrypted);
|
||||
Assert.Equal(isEncrypted, _rarHeaderFactory.IsEncrypted);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class LzmaStreamTests
|
||||
Assert.Equal('X', decompressor.ReadByte());
|
||||
}
|
||||
|
||||
private static byte[] lzmaData { get; } =
|
||||
private static byte[] LzmaData { get; } =
|
||||
{
|
||||
0x5D,
|
||||
0x00,
|
||||
@@ -178,9 +178,9 @@ public class LzmaStreamTests
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The decoded data for <see cref="lzmaData"/>.
|
||||
/// The decoded data for <see cref="LzmaData"/>.
|
||||
/// </summary>
|
||||
private static byte[] lzmaResultData { get; } =
|
||||
private static byte[] LzmaResultData { get; } =
|
||||
{
|
||||
0x01,
|
||||
0x00,
|
||||
@@ -515,7 +515,7 @@ public class LzmaStreamTests
|
||||
[Fact]
|
||||
public void TestLzmaBuffer()
|
||||
{
|
||||
var input = new MemoryStream(lzmaData);
|
||||
var input = new MemoryStream(LzmaData);
|
||||
using var output = new MemoryStream();
|
||||
var properties = new byte[5];
|
||||
input.Read(properties, 0, 5);
|
||||
@@ -528,13 +528,13 @@ public class LzmaStreamTests
|
||||
coder.SetDecoderProperties(properties);
|
||||
coder.Code(input, output, input.Length, fileLength, null);
|
||||
|
||||
Assert.Equal(output.ToArray(), lzmaResultData);
|
||||
Assert.Equal(output.ToArray(), LzmaResultData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestLzmaStreamEncodingWritesData()
|
||||
{
|
||||
using var inputStream = new MemoryStream(lzmaResultData);
|
||||
using var inputStream = new MemoryStream(LzmaResultData);
|
||||
using MemoryStream outputStream = new();
|
||||
using var lzmaStream = new LzmaStream(LzmaEncoderProperties.Default, false, outputStream);
|
||||
inputStream.CopyTo(lzmaStream);
|
||||
@@ -545,7 +545,7 @@ public class LzmaStreamTests
|
||||
[Fact]
|
||||
public void TestLzmaEncodingAccuracy()
|
||||
{
|
||||
var input = new MemoryStream(lzmaResultData);
|
||||
var input = new MemoryStream(LzmaResultData);
|
||||
var compressed = new MemoryStream();
|
||||
var lzmaEncodingStream = new LzmaStream(LzmaEncoderProperties.Default, false, compressed);
|
||||
input.CopyTo(lzmaEncodingStream);
|
||||
@@ -558,10 +558,10 @@ public class LzmaStreamTests
|
||||
compressed,
|
||||
compressed.Length,
|
||||
output,
|
||||
lzmaResultData.LongLength
|
||||
LzmaResultData.LongLength
|
||||
);
|
||||
|
||||
Assert.Equal(output.ToArray(), lzmaResultData);
|
||||
Assert.Equal(output.ToArray(), LzmaResultData);
|
||||
}
|
||||
|
||||
private static void DecompressLzmaStream(
|
||||
|
||||
@@ -6,6 +6,11 @@ using SharpCompress.Readers;
|
||||
using SharpCompress.Readers.Tar;
|
||||
using SharpCompress.Test.Mocks;
|
||||
using Xunit;
|
||||
#if !NETFRAMEWORK
|
||||
using System.Runtime.InteropServices;
|
||||
using Mono.Unix;
|
||||
#endif
|
||||
|
||||
|
||||
namespace SharpCompress.Test.Tar;
|
||||
|
||||
@@ -124,7 +129,7 @@ public class TarReaderTests : ReaderTests
|
||||
{
|
||||
using Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.bz2"));
|
||||
using var reader = TarReader.Open(stream);
|
||||
List<string> names = new List<string>();
|
||||
var names = new List<string>();
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
if (!reader.Entry.IsDirectory)
|
||||
@@ -173,13 +178,11 @@ public class TarReaderTests : ReaderTests
|
||||
using var reader = ReaderFactory.Open(stream);
|
||||
var memoryStream = new MemoryStream();
|
||||
|
||||
Action action = () => reader.MoveToNextEntry();
|
||||
var exception = Record.Exception(action);
|
||||
Assert.Null(exception);
|
||||
reader.MoveToNextEntry();
|
||||
Assert.True(reader.MoveToNextEntry());
|
||||
Assert.True(reader.MoveToNextEntry());
|
||||
reader.WriteEntryTo(memoryStream);
|
||||
stream.Close();
|
||||
Assert.Throws<IncompleteArchiveException>(action);
|
||||
Assert.Throws<IncompleteArchiveException>(() => reader.MoveToNextEntry());
|
||||
}
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
@@ -191,7 +194,6 @@ public class TarReaderTests : ReaderTests
|
||||
Path.Combine(TEST_ARCHIVES_PATH, "TarWithSymlink.tar.gz")
|
||||
);
|
||||
using var reader = TarReader.Open(stream);
|
||||
List<string> names = new List<string>();
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
if (reader.Entry.IsDirectory)
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace SharpCompress.Test;
|
||||
|
||||
public class WriterTests : TestBase
|
||||
{
|
||||
private readonly ArchiveType type;
|
||||
private readonly ArchiveType _type;
|
||||
|
||||
protected WriterTests(ArchiveType type) => this.type = type;
|
||||
protected WriterTests(ArchiveType type) => _type = type;
|
||||
|
||||
protected void Write(
|
||||
CompressionType compressionType,
|
||||
@@ -26,7 +26,7 @@ public class WriterTests : TestBase
|
||||
|
||||
writerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default;
|
||||
|
||||
using var writer = WriterFactory.Open(stream, type, writerOptions);
|
||||
using var writer = WriterFactory.Open(stream, _type, writerOptions);
|
||||
writer.WriteAll(ORIGINAL_FILES_PATH, "*", SearchOption.AllDirectories);
|
||||
}
|
||||
CompareArchivesByPath(
|
||||
|
||||
@@ -6,16 +6,16 @@ namespace SharpCompress.Test.Xz;
|
||||
|
||||
public class Crc32Tests
|
||||
{
|
||||
private const string SimpleString = @"The quick brown fox jumps over the lazy dog.";
|
||||
private readonly byte[] SimpleBytes = Encoding.ASCII.GetBytes(SimpleString);
|
||||
private const string SimpleString2 =
|
||||
private const string SIMPLE_STRING = @"The quick brown fox jumps over the lazy dog.";
|
||||
private readonly byte[] _simpleBytes = Encoding.ASCII.GetBytes(SIMPLE_STRING);
|
||||
private const string SIMPLE_STRING2 =
|
||||
@"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it.";
|
||||
private readonly byte[] SimpleBytes2 = Encoding.ASCII.GetBytes(SimpleString2);
|
||||
private readonly byte[] _simpleBytes2 = Encoding.ASCII.GetBytes(SIMPLE_STRING2);
|
||||
|
||||
[Fact]
|
||||
public void ShortAsciiString()
|
||||
{
|
||||
var actual = Crc32.Compute(SimpleBytes);
|
||||
var actual = Crc32.Compute(_simpleBytes);
|
||||
|
||||
Assert.Equal((uint)0x519025e9, actual);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class Crc32Tests
|
||||
[Fact]
|
||||
public void ShortAsciiString2()
|
||||
{
|
||||
var actual = Crc32.Compute(SimpleBytes2);
|
||||
var actual = Crc32.Compute(_simpleBytes2);
|
||||
|
||||
Assert.Equal((uint)0x6ee3ad88, actual);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ namespace SharpCompress.Test.Xz;
|
||||
|
||||
public class Crc64Tests
|
||||
{
|
||||
private const string SimpleString = @"The quick brown fox jumps over the lazy dog.";
|
||||
private readonly byte[] SimpleBytes = Encoding.ASCII.GetBytes(SimpleString);
|
||||
private const string SimpleString2 =
|
||||
private const string SIMPLE_STRING = @"The quick brown fox jumps over the lazy dog.";
|
||||
private readonly byte[] _simpleBytes = Encoding.ASCII.GetBytes(SIMPLE_STRING);
|
||||
private const string SIMPLE_STRING2 =
|
||||
@"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it.";
|
||||
private readonly byte[] SimpleBytes2 = Encoding.ASCII.GetBytes(SimpleString2);
|
||||
private readonly byte[] _simpleBytes2 = Encoding.ASCII.GetBytes(SIMPLE_STRING2);
|
||||
|
||||
[Fact]
|
||||
public void ShortAsciiString()
|
||||
{
|
||||
var actual = Crc64.Compute(SimpleBytes);
|
||||
var actual = Crc64.Compute(_simpleBytes);
|
||||
|
||||
Assert.Equal((ulong)0x7E210EB1B03E5A1D, actual);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class Crc64Tests
|
||||
[Fact]
|
||||
public void ShortAsciiString2()
|
||||
{
|
||||
var actual = Crc64.Compute(SimpleBytes2);
|
||||
var actual = Crc64.Compute(_simpleBytes2);
|
||||
|
||||
Assert.Equal((ulong)0x416B4150508661EE, actual);
|
||||
}
|
||||
|
||||
@@ -9,56 +9,56 @@ using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Xz.Filters;
|
||||
|
||||
public class BCJTests : XZTestsBase
|
||||
public class BcjTests : XzTestsBase
|
||||
{
|
||||
private readonly ArmFilter armFilter;
|
||||
private readonly ArmThumbFilter armtFilter;
|
||||
private readonly IA64Filter ia64Filter;
|
||||
private readonly PowerPCFilter ppcFilter;
|
||||
private readonly SparcFilter sparcFilter;
|
||||
private readonly X86Filter x86Filter;
|
||||
private readonly ArmFilter _armFilter;
|
||||
private readonly ArmThumbFilter _armtFilter;
|
||||
private readonly IA64Filter _ia64Filter;
|
||||
private readonly PowerPCFilter _ppcFilter;
|
||||
private readonly SparcFilter _sparcFilter;
|
||||
private readonly X86Filter _x86Filter;
|
||||
|
||||
public BCJTests()
|
||||
public BcjTests()
|
||||
{
|
||||
armFilter = new ArmFilter();
|
||||
armtFilter = new ArmThumbFilter();
|
||||
ia64Filter = new IA64Filter();
|
||||
ppcFilter = new PowerPCFilter();
|
||||
sparcFilter = new SparcFilter();
|
||||
x86Filter = new X86Filter();
|
||||
_armFilter = new ArmFilter();
|
||||
_armtFilter = new ArmThumbFilter();
|
||||
_ia64Filter = new IA64Filter();
|
||||
_ppcFilter = new PowerPCFilter();
|
||||
_sparcFilter = new SparcFilter();
|
||||
_x86Filter = new X86Filter();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsOnlyAllowedLast()
|
||||
{
|
||||
Assert.False(armFilter.AllowAsLast);
|
||||
Assert.True(armFilter.AllowAsNonLast);
|
||||
Assert.False(_armFilter.AllowAsLast);
|
||||
Assert.True(_armFilter.AllowAsNonLast);
|
||||
|
||||
Assert.False(armtFilter.AllowAsLast);
|
||||
Assert.True(armtFilter.AllowAsNonLast);
|
||||
Assert.False(_armtFilter.AllowAsLast);
|
||||
Assert.True(_armtFilter.AllowAsNonLast);
|
||||
|
||||
Assert.False(ia64Filter.AllowAsLast);
|
||||
Assert.True(ia64Filter.AllowAsNonLast);
|
||||
Assert.False(_ia64Filter.AllowAsLast);
|
||||
Assert.True(_ia64Filter.AllowAsNonLast);
|
||||
|
||||
Assert.False(ppcFilter.AllowAsLast);
|
||||
Assert.True(ppcFilter.AllowAsNonLast);
|
||||
Assert.False(_ppcFilter.AllowAsLast);
|
||||
Assert.True(_ppcFilter.AllowAsNonLast);
|
||||
|
||||
Assert.False(sparcFilter.AllowAsLast);
|
||||
Assert.True(sparcFilter.AllowAsNonLast);
|
||||
Assert.False(_sparcFilter.AllowAsLast);
|
||||
Assert.True(_sparcFilter.AllowAsNonLast);
|
||||
|
||||
Assert.False(x86Filter.AllowAsLast);
|
||||
Assert.True(x86Filter.AllowAsNonLast);
|
||||
Assert.False(_x86Filter.AllowAsLast);
|
||||
Assert.True(_x86Filter.AllowAsNonLast);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChangesStreamSize()
|
||||
{
|
||||
Assert.False(armFilter.ChangesDataSize);
|
||||
Assert.False(armtFilter.ChangesDataSize);
|
||||
Assert.False(ia64Filter.ChangesDataSize);
|
||||
Assert.False(ppcFilter.ChangesDataSize);
|
||||
Assert.False(sparcFilter.ChangesDataSize);
|
||||
Assert.False(x86Filter.ChangesDataSize);
|
||||
Assert.False(_armFilter.ChangesDataSize);
|
||||
Assert.False(_armtFilter.ChangesDataSize);
|
||||
Assert.False(_ia64Filter.ChangesDataSize);
|
||||
Assert.False(_ppcFilter.ChangesDataSize);
|
||||
Assert.False(_sparcFilter.ChangesDataSize);
|
||||
Assert.False(_x86Filter.ChangesDataSize);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -67,22 +67,22 @@ public class BCJTests : XZTestsBase
|
||||
public void OnlyAcceptsOneByte(byte[] bytes)
|
||||
{
|
||||
InvalidDataException ex;
|
||||
ex = Assert.Throws<InvalidDataException>(() => armFilter.Init(bytes));
|
||||
ex = Assert.Throws<InvalidDataException>(() => _armFilter.Init(bytes));
|
||||
Assert.Equal("ARM properties unexpected length", ex.Message);
|
||||
|
||||
ex = Assert.Throws<InvalidDataException>(() => armtFilter.Init(bytes));
|
||||
ex = Assert.Throws<InvalidDataException>(() => _armtFilter.Init(bytes));
|
||||
Assert.Equal("ARM Thumb properties unexpected length", ex.Message);
|
||||
|
||||
ex = Assert.Throws<InvalidDataException>(() => ia64Filter.Init(bytes));
|
||||
ex = Assert.Throws<InvalidDataException>(() => _ia64Filter.Init(bytes));
|
||||
Assert.Equal("IA64 properties unexpected length", ex.Message);
|
||||
|
||||
ex = Assert.Throws<InvalidDataException>(() => ppcFilter.Init(bytes));
|
||||
ex = Assert.Throws<InvalidDataException>(() => _ppcFilter.Init(bytes));
|
||||
Assert.Equal("PPC properties unexpected length", ex.Message);
|
||||
|
||||
ex = Assert.Throws<InvalidDataException>(() => sparcFilter.Init(bytes));
|
||||
ex = Assert.Throws<InvalidDataException>(() => _sparcFilter.Init(bytes));
|
||||
Assert.Equal("SPARC properties unexpected length", ex.Message);
|
||||
|
||||
ex = Assert.Throws<InvalidDataException>(() => x86Filter.Init(bytes));
|
||||
ex = Assert.Throws<InvalidDataException>(() => _x86Filter.Init(bytes));
|
||||
Assert.Equal("X86 properties unexpected length", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,21 +5,21 @@ using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Xz.Filters;
|
||||
|
||||
public class Lzma2Tests : XZTestsBase
|
||||
public class Lzma2Tests : XzTestsBase
|
||||
{
|
||||
private readonly Lzma2Filter filter;
|
||||
private readonly Lzma2Filter _filter;
|
||||
|
||||
public Lzma2Tests() => filter = new Lzma2Filter();
|
||||
public Lzma2Tests() => _filter = new Lzma2Filter();
|
||||
|
||||
[Fact]
|
||||
public void IsOnlyAllowedLast()
|
||||
{
|
||||
Assert.True(filter.AllowAsLast);
|
||||
Assert.False(filter.AllowAsNonLast);
|
||||
Assert.True(_filter.AllowAsLast);
|
||||
Assert.False(_filter.AllowAsNonLast);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChangesStreamSize() => Assert.True(filter.ChangesDataSize);
|
||||
public void ChangesStreamSize() => Assert.True(_filter.ChangesDataSize);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, (uint)4 * 1024)]
|
||||
@@ -31,18 +31,18 @@ public class Lzma2Tests : XZTestsBase
|
||||
[InlineData(40, (uint)(1024 * 1024 * 1024 - 1) * 4 + 3)]
|
||||
public void CalculatesDictionarySize(byte inByte, uint dicSize)
|
||||
{
|
||||
filter.Init(new[] { inByte });
|
||||
Assert.Equal(filter.DictionarySize, dicSize);
|
||||
_filter.Init(new[] { inByte });
|
||||
Assert.Equal(_filter.DictionarySize, dicSize);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CalculatesDictionarySizeError()
|
||||
{
|
||||
uint temp;
|
||||
filter.Init(new byte[] { 41 });
|
||||
_filter.Init(new byte[] { 41 });
|
||||
var ex = Assert.Throws<OverflowException>(() =>
|
||||
{
|
||||
temp = filter.DictionarySize;
|
||||
temp = _filter.DictionarySize;
|
||||
});
|
||||
Assert.Equal("Dictionary size greater than UInt32.Max", ex.Message);
|
||||
}
|
||||
@@ -52,14 +52,14 @@ public class Lzma2Tests : XZTestsBase
|
||||
[InlineData(new byte[] { 0, 0 })]
|
||||
public void OnlyAcceptsOneByte(byte[] bytes)
|
||||
{
|
||||
var ex = Assert.Throws<InvalidDataException>(() => filter.Init(bytes));
|
||||
var ex = Assert.Throws<InvalidDataException>(() => _filter.Init(bytes));
|
||||
Assert.Equal("LZMA properties unexpected length", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReservedBytesThrow()
|
||||
{
|
||||
var ex = Assert.Throws<InvalidDataException>(() => filter.Init(new byte[] { 0xC0 }));
|
||||
var ex = Assert.Throws<InvalidDataException>(() => _filter.Init(new byte[] { 0xC0 }));
|
||||
Assert.Equal("Reserved bits used in LZMA properties", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Xz;
|
||||
|
||||
public class XZBlockTests : XZTestsBase
|
||||
public class XzBlockTests : XzTestsBase
|
||||
{
|
||||
protected override void Rewind(Stream stream) => stream.Position = 12;
|
||||
|
||||
@@ -28,10 +28,10 @@ public class XZBlockTests : XZTestsBase
|
||||
{
|
||||
var bytes = new byte[] { 0 };
|
||||
using Stream indexBlockStream = new MemoryStream(bytes);
|
||||
var XZBlock = new XZBlock(indexBlockStream, CheckType.CRC64, 8);
|
||||
var xzBlock = new XZBlock(indexBlockStream, CheckType.CRC64, 8);
|
||||
Assert.Throws<XZIndexMarkerReachedException>(() =>
|
||||
{
|
||||
ReadBytes(XZBlock, 1);
|
||||
ReadBytes(xzBlock, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ public class XZBlockTests : XZTestsBase
|
||||
bytes[20]++;
|
||||
using Stream badCrcStream = new MemoryStream(bytes);
|
||||
Rewind(badCrcStream);
|
||||
var XZBlock = new XZBlock(badCrcStream, CheckType.CRC64, 8);
|
||||
var xzBlock = new XZBlock(badCrcStream, CheckType.CRC64, 8);
|
||||
var ex = Assert.Throws<InvalidDataException>(() =>
|
||||
{
|
||||
ReadBytes(XZBlock, 1);
|
||||
ReadBytes(xzBlock, 1);
|
||||
});
|
||||
Assert.Equal("Block header corrupt", ex.Message);
|
||||
}
|
||||
@@ -53,24 +53,24 @@ public class XZBlockTests : XZTestsBase
|
||||
[Fact]
|
||||
public void CanReadM()
|
||||
{
|
||||
var XZBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("M"), ReadBytes(XZBlock, 1));
|
||||
var xzBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("M"), ReadBytes(xzBlock, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanReadMary()
|
||||
{
|
||||
var XZBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("M"), ReadBytes(XZBlock, 1));
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("a"), ReadBytes(XZBlock, 1));
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("ry"), ReadBytes(XZBlock, 2));
|
||||
var xzBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("M"), ReadBytes(xzBlock, 1));
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("a"), ReadBytes(xzBlock, 1));
|
||||
Assert.Equal(Encoding.ASCII.GetBytes("ry"), ReadBytes(xzBlock, 2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanReadPoemWithStreamReader()
|
||||
{
|
||||
var XZBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
var sr = new StreamReader(XZBlock);
|
||||
var xzBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
var sr = new StreamReader(xzBlock);
|
||||
Assert.Equal(sr.ReadToEnd(), Original);
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public class XZBlockTests : XZTestsBase
|
||||
public void NoopWhenNoPadding()
|
||||
{
|
||||
// CompressedStream's only block has no padding.
|
||||
var XZBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
var sr = new StreamReader(XZBlock);
|
||||
var xzBlock = new XZBlock(CompressedStream, CheckType.CRC64, 8);
|
||||
var sr = new StreamReader(xzBlock);
|
||||
sr.ReadToEnd();
|
||||
Assert.Equal(0L, CompressedStream.Position % 4L);
|
||||
}
|
||||
@@ -88,8 +88,8 @@ public class XZBlockTests : XZTestsBase
|
||||
public void SkipsPaddingWhenPresent()
|
||||
{
|
||||
// CompressedIndexedStream's first block has 1-byte padding.
|
||||
var XZBlock = new XZBlock(CompressedIndexedStream, CheckType.CRC64, 8);
|
||||
var sr = new StreamReader(XZBlock);
|
||||
var xzBlock = new XZBlock(CompressedIndexedStream, CheckType.CRC64, 8);
|
||||
var sr = new StreamReader(xzBlock);
|
||||
sr.ReadToEnd();
|
||||
Assert.Equal(0L, CompressedIndexedStream.Position % 4L);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Xz;
|
||||
|
||||
public class XZHeaderTests : XZTestsBase
|
||||
public class XzHeaderTests : XzTestsBase
|
||||
{
|
||||
[Fact]
|
||||
public void ChecksMagicNumber()
|
||||
|
||||
@@ -4,7 +4,7 @@ using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Xz;
|
||||
|
||||
public class XZIndexTests : XZTestsBase
|
||||
public class XzIndexTests : XzTestsBase
|
||||
{
|
||||
protected override void RewindEmpty(Stream stream) => stream.Position = 12;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using Xunit;
|
||||
|
||||
namespace SharpCompress.Test.Xz;
|
||||
|
||||
public class XZStreamTests : XZTestsBase
|
||||
public class XzStreamTests : XzTestsBase
|
||||
{
|
||||
[Fact]
|
||||
public void CanReadEmptyStream()
|
||||
|
||||
@@ -4,9 +4,9 @@ using System.Text;
|
||||
|
||||
namespace SharpCompress.Test.Xz;
|
||||
|
||||
public abstract class XZTestsBase : IDisposable
|
||||
public abstract class XzTestsBase : IDisposable
|
||||
{
|
||||
public XZTestsBase()
|
||||
public XzTestsBase()
|
||||
{
|
||||
RewindEmpty(CompressedEmptyStream);
|
||||
Rewind(CompressedStream);
|
||||
|
||||
@@ -25,27 +25,27 @@ public class Zip64Tests : WriterTests
|
||||
[Trait("format", "zip64")]
|
||||
public void Zip64_Single_Large_File() =>
|
||||
// One single file, requires zip64
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: true, forward_only: false);
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, setZip64: true, forwardOnly: false);
|
||||
|
||||
[Trait("format", "zip64")]
|
||||
public void Zip64_Two_Large_Files() =>
|
||||
// One single file, requires zip64
|
||||
RunSingleTest(2, FOUR_GB_LIMIT, set_zip64: true, forward_only: false);
|
||||
RunSingleTest(2, FOUR_GB_LIMIT, setZip64: true, forwardOnly: false);
|
||||
|
||||
[Trait("format", "zip64")]
|
||||
public void Zip64_Two_Small_files() =>
|
||||
// Multiple files, does not require zip64
|
||||
RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: false, forward_only: false);
|
||||
RunSingleTest(2, FOUR_GB_LIMIT / 2, setZip64: false, forwardOnly: false);
|
||||
|
||||
[Trait("format", "zip64")]
|
||||
public void Zip64_Two_Small_files_stream() =>
|
||||
// Multiple files, does not require zip64, and works with streams
|
||||
RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: false, forward_only: true);
|
||||
RunSingleTest(2, FOUR_GB_LIMIT / 2, setZip64: false, forwardOnly: true);
|
||||
|
||||
[Trait("format", "zip64")]
|
||||
public void Zip64_Two_Small_Files_Zip64() =>
|
||||
// Multiple files, use zip64 even though it is not required
|
||||
RunSingleTest(2, FOUR_GB_LIMIT / 2, set_zip64: true, forward_only: false);
|
||||
RunSingleTest(2, FOUR_GB_LIMIT / 2, setZip64: true, forwardOnly: false);
|
||||
|
||||
[Trait("format", "zip64")]
|
||||
public void Zip64_Single_Large_File_Fail()
|
||||
@@ -53,7 +53,7 @@ public class Zip64Tests : WriterTests
|
||||
try
|
||||
{
|
||||
// One single file, should fail
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: false, forward_only: false);
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, setZip64: false, forwardOnly: false);
|
||||
throw new InvalidOperationException("Test did not fail?");
|
||||
}
|
||||
catch (NotSupportedException) { }
|
||||
@@ -65,7 +65,7 @@ public class Zip64Tests : WriterTests
|
||||
try
|
||||
{
|
||||
// One single file, should fail (fast) with zip64
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: true, forward_only: true);
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, setZip64: true, forwardOnly: true);
|
||||
throw new InvalidOperationException("Test did not fail?");
|
||||
}
|
||||
catch (NotSupportedException) { }
|
||||
@@ -77,7 +77,7 @@ public class Zip64Tests : WriterTests
|
||||
try
|
||||
{
|
||||
// One single file, should fail once the write discovers the problem
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: false, forward_only: true);
|
||||
RunSingleTest(1, FOUR_GB_LIMIT, setZip64: false, forwardOnly: true);
|
||||
throw new InvalidOperationException("Test did not fail?");
|
||||
}
|
||||
catch (NotSupportedException) { }
|
||||
@@ -86,9 +86,9 @@ public class Zip64Tests : WriterTests
|
||||
public void RunSingleTest(
|
||||
long files,
|
||||
long filesize,
|
||||
bool set_zip64,
|
||||
bool forward_only,
|
||||
long write_chunk_size = 1024 * 1024,
|
||||
bool setZip64,
|
||||
bool forwardOnly,
|
||||
long writeChunkSize = 1024 * 1024,
|
||||
string filename = "zip64-test.zip"
|
||||
)
|
||||
{
|
||||
@@ -101,7 +101,7 @@ public class Zip64Tests : WriterTests
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
CreateZipArchive(filename, files, filesize, write_chunk_size, set_zip64, forward_only);
|
||||
CreateZipArchive(filename, files, filesize, writeChunkSize, setZip64, forwardOnly);
|
||||
}
|
||||
|
||||
var resForward = ReadForwardOnly(filename);
|
||||
@@ -140,20 +140,20 @@ public class Zip64Tests : WriterTests
|
||||
long files,
|
||||
long filesize,
|
||||
long chunksize,
|
||||
bool set_zip64,
|
||||
bool forward_only
|
||||
bool setZip64,
|
||||
bool forwardOnly
|
||||
)
|
||||
{
|
||||
var data = new byte[chunksize];
|
||||
|
||||
// Use deflate for speed
|
||||
var opts = new ZipWriterOptions(CompressionType.Deflate) { UseZip64 = set_zip64 };
|
||||
var opts = new ZipWriterOptions(CompressionType.Deflate) { UseZip64 = setZip64 };
|
||||
|
||||
// Use no compression to ensure we hit the limits (actually inflates a bit, but seems better than using method==Store)
|
||||
var eo = new ZipWriterEntryOptions { DeflateCompressionLevel = CompressionLevel.None };
|
||||
|
||||
using var zip = File.OpenWrite(filename);
|
||||
using var st = forward_only ? (Stream)new ForwardOnlyStream(zip) : zip;
|
||||
using var st = forwardOnly ? (Stream)new ForwardOnlyStream(zip) : zip;
|
||||
using var zipWriter = (ZipWriter)WriterFactory.Open(st, ArchiveType.Zip, opts);
|
||||
for (var i = 0; i < files; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user