This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System.IO.Compression;
|
||||
using Ludarium.Infrastructure;
|
||||
|
||||
namespace Ludarium.IntegrationTests;
|
||||
|
||||
public sealed class N64ZipRomTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("game.z64", "80371240")]
|
||||
[InlineData("game.v64", "37804012")]
|
||||
[InlineData("game.n64", "40123780")]
|
||||
public async Task SingleBoundedRomWithVerifiedMagicStreamsWithoutExtraction(string name, string magic)
|
||||
{
|
||||
await using var archive = Zip((name, Convert.FromHexString(magic + "01020304")));
|
||||
|
||||
Assert.True(await N64ZipRom.ValidateAsync(archive, CancellationToken.None));
|
||||
archive.Position = 0;
|
||||
var opened = await N64ZipRom.OpenAsync(archive, CancellationToken.None);
|
||||
await using var content = opened.Content;
|
||||
var bytes = new byte[8];
|
||||
await content.ReadExactlyAsync(bytes);
|
||||
|
||||
Assert.Equal(name, opened.FileName);
|
||||
Assert.Equal(8, opened.Length);
|
||||
Assert.Equal(Convert.FromHexString(magic), bytes[..4]);
|
||||
Assert.False(content.CanSeek);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MultipleRomEntriesAndInvalidMagicFailClosed()
|
||||
{
|
||||
await using var multiple = Zip(("one.z64", Convert.FromHexString("8037124001")),
|
||||
("two.v64", Convert.FromHexString("3780401202")));
|
||||
await using var invalid = Zip(("game.z64", Convert.FromHexString("0000000001")));
|
||||
|
||||
Assert.False(await N64ZipRom.ValidateAsync(multiple, CancellationToken.None));
|
||||
Assert.False(await N64ZipRom.ValidateAsync(invalid, CancellationToken.None));
|
||||
}
|
||||
|
||||
private static MemoryStream Zip(params (string Name, byte[] Content)[] entries)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true))
|
||||
foreach (var item in entries)
|
||||
{
|
||||
var entry = archive.CreateEntry(item.Name, CompressionLevel.SmallestSize);
|
||||
using var content = entry.Open();
|
||||
content.Write(item.Content);
|
||||
}
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user