Match native asset fallback behavior
This commit is contained in:
@@ -307,6 +307,10 @@ public class Sys4AssetStoreTests
|
||||
File.Delete(Path.Combine(loose, "TEST.BIN"));
|
||||
Assert.Equal(new byte[] { 1, 2, 3 }, store.ReadAll(entry));
|
||||
|
||||
Directory.CreateDirectory(Path.Combine(loose, "TEST.BIN"));
|
||||
Assert.Equal(new byte[] { 1, 2, 3 }, store.ReadAll(entry));
|
||||
Directory.Delete(Path.Combine(loose, "TEST.BIN"));
|
||||
|
||||
var reads = await Task.WhenAll(Enumerable.Range(0, 8).Select(_ => Task.Run(() => store.ReadAll(entry))));
|
||||
Assert.All(reads, bytes => Assert.Equal(new byte[] { 1, 2, 3 }, bytes));
|
||||
Assert.Throws<InvalidDataException>(() => store.Open(entry with { Name = "../TEST.BIN" }));
|
||||
@@ -319,6 +323,28 @@ public class Sys4AssetStoreTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TypedResolutionReportsInvalidAndMismatchedPackedIdsOnce()
|
||||
{
|
||||
var catalog = Sys4AssetCatalog.Parse(Sys4StartupSettingsTests.BuildCatalog(
|
||||
includeTrailer: true, fileName: "TEST.BIN"));
|
||||
var diagnostics = new List<string>();
|
||||
var resources = new ResourceMap(catalog, diagnostic: diagnostics.Add);
|
||||
|
||||
Assert.Null(resources.ResolveTexture(0x02000000));
|
||||
Assert.Null(resources.ResolveTexture(0x02000000));
|
||||
Assert.Null(resources.ResolveTexture(0));
|
||||
Assert.Null(resources.ResolveTexture(0));
|
||||
|
||||
Assert.Collection(diagnostics,
|
||||
message => Assert.Equal(
|
||||
"[asset-resolution] texture resource 0x2000000 does not select a mounted SYS4INI/AAI record",
|
||||
message),
|
||||
message => Assert.Equal(
|
||||
"[asset-resolution] texture resource 0x0 selects TEST.BIN, expected an AGF record",
|
||||
message));
|
||||
}
|
||||
|
||||
private static byte[] ReadToEnd(Stream stream)
|
||||
{
|
||||
using var copy = new MemoryStream();
|
||||
|
||||
@@ -101,11 +101,11 @@ public class Sys4StartupSettingsTests
|
||||
params (string Key, string Value)[] pairs)
|
||||
=> WrapCatalog(BuildExpanded(pairs));
|
||||
|
||||
internal static byte[] BuildCatalog(bool includeTrailer)
|
||||
=> WrapCatalog(BuildExpanded(Array.Empty<(string, string)>(), includeTrailer));
|
||||
internal static byte[] BuildCatalog(bool includeTrailer, string fileName = "@")
|
||||
=> WrapCatalog(BuildExpanded(Array.Empty<(string, string)>(), includeTrailer, fileName));
|
||||
|
||||
private static byte[] BuildExpanded(
|
||||
(string Key, string Value)[] pairs, bool includeTrailer = true)
|
||||
(string Key, string Value)[] pairs, bool includeTrailer = true, string fileName = "@")
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
Encoding cp932 = Encoding.GetEncoding(932);
|
||||
@@ -113,7 +113,7 @@ public class Sys4StartupSettingsTests
|
||||
AddU32(blob, 1);
|
||||
AddFixedString(blob, "DATA.ALF", 256, cp932);
|
||||
AddU32(blob, 1);
|
||||
AddFixedString(blob, "@", 64, cp932);
|
||||
AddFixedString(blob, fileName, 64, cp932);
|
||||
AddU32(blob, 0);
|
||||
AddU32(blob, 0);
|
||||
AddU32(blob, 0);
|
||||
|
||||
Reference in New Issue
Block a user