private void TestWadEntryDataHandleOperations(Wad wad) { foreach (WadEntry entry in wad.Entries.Values) { // Ignore file redirections if (entry.Type == WadEntryType.FileRedirection) { return; } WadEntryDataHandle dataHandle = entry.GetDataHandle(); Stream compressedDataStream = null; Stream decompressedDataStream = null; Assert.DoesNotThrow(delegate { compressedDataStream = dataHandle.GetCompressedStream(); }, "Failed to get compressed stream"); Assert.DoesNotThrow(delegate { decompressedDataStream = dataHandle.GetDecompressedStream(); }, "Failed to get decompressed data stream"); Assert.AreEqual((int)compressedDataStream.Length, entry.CompressedSize); Assert.AreEqual((int)decompressedDataStream.Length, entry.UncompressedSize); // Verify checksum if (entry.ChecksumType == WadEntryChecksumType.SHA256) { using (SHA256 sha = SHA256.Create()) { byte[] computedHash = sha.ComputeHash(compressedDataStream).Take(8).ToArray(); Assert.IsTrue(computedHash.SequenceEqual(entry.Checksum), $"Entry ({entry.XXHash}) SHA256 checksum does not match computed one"); } } else if (entry.ChecksumType == WadEntryChecksumType.XXHash3) { byte[] compressedData = new byte[compressedDataStream.Length]; compressedDataStream.Seek(0, SeekOrigin.Begin); compressedDataStream.Read(compressedData); ulong computedHash = XXHash3.Hash64(compressedData); byte[] computedHashBytes = BitConverter.GetBytes(computedHash); Assert.IsTrue(computedHashBytes.SequenceEqual(entry.Checksum), $"Entry ({entry.XXHash}) XXHash3 checksum does not match computed one"); } } }
private void TestWadEntryDataHandleOperations(Wad wad) { foreach (WadEntry entry in wad.Entries.Values) { // Ignore file redirections if (entry.Type == WadEntryType.FileRedirection) { return; } WadEntryDataHandle dataHandle = entry.GetDataHandle(); Stream comressedDataStream = null; Stream decompressedDataStream = null; Assert.DoesNotThrow(delegate { comressedDataStream = dataHandle.GetCompressedStream(); }, "Failed to get compressed stream"); Assert.DoesNotThrow(delegate { decompressedDataStream = dataHandle.GetDecompressedStream(); }, "Failed to get decompressed data stream"); Assert.AreEqual((int)comressedDataStream.Length, entry.CompressedSize); Assert.AreEqual((int)decompressedDataStream.Length, entry.UncompressedSize); // Verify SHA checksum using (SHA256 sha = SHA256.Create()) { byte[] computedHash = sha.ComputeHash(comressedDataStream).Take(8).ToArray(); Assert.IsTrue(computedHash.SequenceEqual(entry.SHA), $"Entry ({entry.XXHash}) checksum does not match computed one"); } } }