2024-07-16 00:02:49 -04:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Hashing.Test
|
|
|
|
|
{
|
|
|
|
|
public class CompressedStreamTests
|
|
|
|
|
{
|
2024-07-19 10:50:46 -04:00
|
|
|
/// <summary>
|
2024-07-19 10:54:54 -04:00
|
|
|
/// Path to PKZIP archive containing a single compressed file to hash
|
2024-07-19 10:50:46 -04:00
|
|
|
/// </summary>
|
2024-07-19 10:54:54 -04:00
|
|
|
private static readonly string _singleGzipFilePath
|
|
|
|
|
= Path.Combine(Environment.CurrentDirectory, "TestData", "file-to-hash.bin.gz");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Path to PKZIP archive containing a single compressed file to hash
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static readonly string _singleZipFilePath
|
2024-07-19 10:50:46 -04:00
|
|
|
= Path.Combine(Environment.CurrentDirectory, "TestData", "file-to-hash.zip");
|
2024-07-16 00:02:49 -04:00
|
|
|
|
2024-07-19 10:50:46 -04:00
|
|
|
/// <summary>
|
2024-07-19 10:54:54 -04:00
|
|
|
/// Path to PKZIP archive containing a multiple compressed files to hash
|
2024-07-19 10:50:46 -04:00
|
|
|
/// </summary>
|
2024-07-19 10:54:54 -04:00
|
|
|
private static readonly string _multiZipFilePath
|
2024-07-19 10:50:46 -04:00
|
|
|
= Path.Combine(Environment.CurrentDirectory, "TestData", "file-to-hash-multi.zip");
|
2024-07-16 00:02:49 -04:00
|
|
|
|
|
|
|
|
[Fact]
|
2024-07-19 10:54:54 -04:00
|
|
|
public void GetSingleGzipStreamHashesTest()
|
|
|
|
|
{
|
|
|
|
|
var gzipStream = new GZipStream(File.OpenRead(_singleGzipFilePath), CompressionMode.Decompress);
|
2025-01-05 23:10:50 -05:00
|
|
|
var hashDict = HashTool.GetStreamHashesAndSize(gzipStream, out long actualSize);
|
|
|
|
|
TestHelper.ValidateSize(actualSize);
|
2024-07-19 10:54:54 -04:00
|
|
|
TestHelper.ValidateHashes(hashDict);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetSingleDeflateStreamHashesTest()
|
2024-07-16 00:02:49 -04:00
|
|
|
{
|
2024-07-19 10:54:54 -04:00
|
|
|
var zipFile = ZipFile.OpenRead(_singleZipFilePath);
|
2024-07-16 00:02:49 -04:00
|
|
|
var fileStream = zipFile.Entries[0].Open();
|
2025-01-05 23:10:50 -05:00
|
|
|
var hashDict = HashTool.GetStreamHashesAndSize(fileStream, out long actualSize);
|
|
|
|
|
TestHelper.ValidateSize(actualSize);
|
2024-07-19 10:47:42 -04:00
|
|
|
TestHelper.ValidateHashes(hashDict);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2024-07-19 10:54:54 -04:00
|
|
|
public void GetMultiDeflateStreamHashesTest()
|
2024-07-19 10:47:42 -04:00
|
|
|
{
|
2024-07-19 10:54:54 -04:00
|
|
|
var zipFile = ZipFile.OpenRead(_multiZipFilePath);
|
2024-07-16 00:02:49 -04:00
|
|
|
|
2024-07-19 10:47:42 -04:00
|
|
|
for (int i = 0; i < zipFile.Entries.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var fileStream = zipFile.Entries[i].Open();
|
2025-01-05 23:10:50 -05:00
|
|
|
var hashDict = HashTool.GetStreamHashesAndSize(fileStream, out long actualSize);
|
|
|
|
|
TestHelper.ValidateSize(actualSize);
|
2024-07-19 10:47:42 -04:00
|
|
|
TestHelper.ValidateHashes(hashDict);
|
|
|
|
|
}
|
2024-07-16 00:02:49 -04:00
|
|
|
}
|
|
|
|
|
}
|
2025-11-12 20:00:11 -05:00
|
|
|
}
|