diff --git a/src/TpsParser/TpsBlock.cs b/src/TpsParser/TpsBlock.cs index d43c3f3..67c2c0f 100644 --- a/src/TpsParser/TpsBlock.cs +++ b/src/TpsParser/TpsBlock.cs @@ -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) { diff --git a/tests/TpsParser.Tests/ResourceTests/TestCompletePageIssue-11.cs b/tests/TpsParser.Tests/ResourceTests/TestCompletePageIssue-11.cs new file mode 100644 index 0000000..ed345b3 --- /dev/null +++ b/tests/TpsParser.Tests/ResourceTests/TestCompletePageIssue-11.cs @@ -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? 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)); + } + } +} diff --git a/tests/TpsParser.Tests/Resources/CompletePageIssue-11.tps b/tests/TpsParser.Tests/Resources/CompletePageIssue-11.tps new file mode 100644 index 0000000..8a2b718 Binary files /dev/null and b/tests/TpsParser.Tests/Resources/CompletePageIssue-11.tps differ