Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jul 15, 2024
1 parent a8b1f2b commit 65778c3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,24 @@ public void TestTryGetDataUnsafe()
GC.KeepAlive(buf);
}

[Fact]
public void TestTryGetDataUnsafe_MemoryBufferReference()
{
var buffer = new Windows.Foundation.MemoryBuffer(256);
var reference = buffer.CreateReference();

Assert.True(WindowsRuntimeMarshal.TryGetDataUnsafe(reference, out IntPtr dataPtr1));
Assert.True(dataPtr1 != IntPtr.Zero);

Assert.True(WindowsRuntimeMarshal.TryGetDataUnsafe(reference, out IntPtr dataPtr2));
Assert.True(dataPtr2 != IntPtr.Zero);

Assert.True(dataPtr1 == dataPtr2);

// Ensure the reference doesn't get collected while we use the data pointer
GC.KeepAlive(reference);
}

[Fact]
public void TestBufferTryGetArray()
{
Expand Down

0 comments on commit 65778c3

Please sign in to comment.