Skip to content

Commit

Permalink
Add test to verify Idx.Write
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeeynamo committed Jun 2, 2020
1 parent 90bbe46 commit 96c60ad
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions OpenKh.Tests/kh2/IdxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public void ReadIdxEntry()
Assert.Equal(5, entry.Length);
}

[Fact]
public void WriteIdxEntry() => Helpers.AssertStream(CreateMockIdxStream(1, 2, 3, 4, 5), stream =>
{
var outStream = new MemoryStream();
Idx.Write(outStream, Idx.Read(stream));
return outStream;
});

[Theory]
[InlineData(0x3fff, false, false)]
[InlineData(0x4000, true, false)]
Expand Down Expand Up @@ -74,21 +83,24 @@ public void GiveRealNames(uint hash32, ushort hash16, string name)
Assert.Equal(name, IdxName.Lookup(hash32, hash16));
}

private static List<Idx.Entry> MockIdx(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length)
private static Stream CreateMockIdxStream(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length)
{
const int IdxFileCount = 1;

using var stream = new MemoryStream(0x14);
var stream = new MemoryStream(0x14);
stream.Write(IdxFileCount);
stream.Write(hash32);
stream.Write(hash16);
stream.Write(blockDescriptor);
stream.Write(offset);
stream.Write(length);

return Idx.Read(stream.SetPosition(0));
return stream.SetPosition(0);
}

private static List<Idx.Entry> MockIdx(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) =>
CreateMockIdxStream(hash32, hash16, blockDescriptor, offset, length).Using(Idx.Read);

private static Idx.Entry MockIdxEntry(uint hash32, ushort hash16, ushort blockDescriptor, int offset, int length) =>
MockIdx(hash32, hash16, blockDescriptor, offset, length).First();
}
Expand Down

0 comments on commit 96c60ad

Please sign in to comment.