Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TpsParser/TpsBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private static bool IsCompletePage(TpsRandomAccess rx)

if (offset < pageSize)
{
int address = BinaryPrimitives.ReadInt32LittleEndian(span[offset..]);
int address = BinaryPrimitives.ReadInt32BigEndian(span[offset..]);

if (address == position)
{
Expand Down
51 changes: 51 additions & 0 deletions tests/TpsParser.Tests/ResourceTests/TestCompletePageIssue-11.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace TpsParser.Tests.ResourceTests;

internal sealed class TestCompletePageIssue_11
{
[Test]
[Description("Issue #11 - IsCompletePage address check should read an Int32BE, not Int32LE.")]
public void ShouldReadCompletePages()
{
using var fs = new FileStream("Resources/CompletePageIssue-11.tps", FileMode.Open, FileAccess.Read);

var tpsFile = new TpsFile(fs);

IEnumerable<TpsBlock>? blocks = null;

Assert.DoesNotThrow(() =>
{
blocks = tpsFile.GetBlocks();
});

if (blocks is null)
{
Assert.Fail();
return;
}

var singleBlock = blocks.Single();

var pages = singleBlock.GetPages();

var singlePage = pages.Single();

using (Assert.EnterMultipleScope())
{
Assert.That(singlePage.AbsoluteAddress, Is.EqualTo(512));
Assert.That(singlePage.Flags, Is.Zero);
Assert.That(singlePage.RecordCount, Is.EqualTo(9));
Assert.That(singlePage.Size, Is.EqualTo(1526));
Assert.That(singlePage.SizeUncompressed, Is.EqualTo(2119));
Assert.That(singlePage.SizeUncompressedExpanded, Is.EqualTo(2161));

var records = singlePage.GetRecords(tpsFile.ErrorHandlingOptions);

Assert.That(records, Has.Count.EqualTo(9));
}
}
}
Binary file not shown.