Skip to content

Commit

Permalink
Added some tests for larger files.
Browse files Browse the repository at this point in the history
Examined needs to be the entire buffer.
  • Loading branch information
wasabii committed Oct 28, 2024
1 parent 7978416 commit 5cc069f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/IKVM.ByteCode.Tests/Decoding/ClassFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ void TestElementValue(ClassFile clazz, ArrayElementValue value)
TestElementValue(clazz, elementValue);
}

[TestMethod]
public void CanReadFromLargeModuleInfo()
{
using var clazz = ClassFile.Read(Path.Combine(Path.GetDirectoryName(typeof(ClassFileTests).Assembly.Location), "Decoding", "large-module-info.class"));
clazz.Should().NotBeNull();
}

[TestMethod]
public void CanReadFromLargeModuleInfoFromStream()
{
var buf = File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(typeof(ClassFileTests).Assembly.Location), "Decoding", "large-module-info.class"));
var stm = new MemoryStream(buf);
using var clazz = ClassFile.Read(stm);
clazz.Should().NotBeNull();
}

}

}
Binary file not shown.
6 changes: 0 additions & 6 deletions src/IKVM.ByteCode.Tests/IKVM.ByteCode.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Parsing\**" />
<EmbeddedResource Remove="Parsing\**" />
<None Remove="Parsing\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down
11 changes: 5 additions & 6 deletions src/IKVM.ByteCode/Decoding/ClassFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,19 @@ public static bool TryMeasure(in ReadOnlySequence<byte> buffer, ref int size, ou
/// <exception cref="ByteCodeException"></exception>
public static bool TryRead(in ReadOnlySequence<byte> buffer, out ClassFile? clazz, out SequencePosition consumed, out SequencePosition examined, IMemoryOwner<byte>? owner = null)
{
consumed = buffer.Start;

var reader = new ClassFormatReader(buffer);
if (TryRead(ref reader, out clazz, owner) == false)
{
// examined up to the position of the reader, but consumed nothing
examined = reader.Position;
// examined up to the end of the buffer, but consumed nothing
examined = buffer.End;
consumed = buffer.Start;
return false;
}
else
{
// examined up to the point of the reader, consumed the same
// examined up to the end of thebuffer, but consumed up until the position of the reader
examined = buffer.End;
consumed = reader.Position;
examined = reader.Position;
return true;
}
}
Expand Down

0 comments on commit 5cc069f

Please sign in to comment.