aboutsummaryrefslogtreecommitdiff
path: root/lib/Utils/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Utils/tests')
-rw-r--r--lib/Utils/tests/.runsettings3
-rw-r--r--lib/Utils/tests/IO/VnMemoryStreamTests.cs15
-rw-r--r--lib/Utils/tests/Memory/NativeHeapTests.cs10
3 files changed, 15 insertions, 13 deletions
diff --git a/lib/Utils/tests/.runsettings b/lib/Utils/tests/.runsettings
index 0e7a703..b13ddb7 100644
--- a/lib/Utils/tests/.runsettings
+++ b/lib/Utils/tests/.runsettings
@@ -3,6 +3,9 @@
<RunConfiguration>
<EnvironmentVariables>
<VNLIB_SHARED_HEAP_DIAGNOSTICS>1</VNLIB_SHARED_HEAP_DIAGNOSTICS>
+ <TEST_RPMALLOC_LIB_PATH>../../../../../Utils.Memory/vnlib_rpmalloc/build/Debug/vnlib_rpmalloc.dll</TEST_RPMALLOC_LIB_PATH>
+ <TEST_MIMALLOC_LIB_PATH>../../../../../Utils.Memory/vnlib_mimalloc/build/Debug/vnlib_mimalloc.dll</TEST_MIMALLOC_LIB_PATH>
+
</EnvironmentVariables>
</RunConfiguration>
</RunSettings> \ No newline at end of file
diff --git a/lib/Utils/tests/IO/VnMemoryStreamTests.cs b/lib/Utils/tests/IO/VnMemoryStreamTests.cs
index 9bcb823..6bbf328 100644
--- a/lib/Utils/tests/IO/VnMemoryStreamTests.cs
+++ b/lib/Utils/tests/IO/VnMemoryStreamTests.cs
@@ -47,8 +47,11 @@ namespace VNLib.Utils.IO.Tests
Assert.IsTrue(vms.CanWrite == true);
}
+ //Handle should throw since the stream owns the handle and it gets dispoed
+ Assert.ThrowsException<ObjectDisposedException>(handle.ThrowIfClosed);
+
//From existing data
- ReadOnlySpan<byte> testSpan = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
+ ReadOnlySpan<byte> testSpan = [1, 2, 3, 4, 5, 6, 7, 8];
using (VnMemoryStream vms = new (privateHeap, testSpan))
{
Assert.IsTrue(vms.Length == testSpan.Length);
@@ -125,19 +128,13 @@ namespace VNLib.Utils.IO.Tests
ReadOnlyMemory<byte> memory = vms.AsMemory();
Assert.AreEqual(memory.Length, testData.Length);
- for (int i = 0; i < memory.Length; i++)
- {
- Assert.AreEqual(memory.Span[i], testData[i]);
- }
+ Assert.IsTrue(memory.Span.SequenceEqual(testData));
//Get the data as a byte array
byte[] array = vms.ToArray();
Assert.AreEqual(array.Length, testData.Length);
- for (int i = 0; i < array.Length; i++)
- {
- Assert.AreEqual(array[i], testData[i]);
- }
+ Assert.IsTrue(array.AsSpan().SequenceEqual(testData));
}
}
} \ No newline at end of file
diff --git a/lib/Utils/tests/Memory/NativeHeapTests.cs b/lib/Utils/tests/Memory/NativeHeapTests.cs
index 8653bd0..a7072ed 100644
--- a/lib/Utils/tests/Memory/NativeHeapTests.cs
+++ b/lib/Utils/tests/Memory/NativeHeapTests.cs
@@ -1,20 +1,22 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
+using System.Runtime.InteropServices;
namespace VNLib.Utils.Memory.Tests
{
[TestClass()]
public class NativeHeapTests
{
- const string RpMallocLibPath = "../../../../../Utils.Memory/vnlib_rpmalloc/build/Debug/vnlib_rpmalloc.dll";
- const string MimallocLibPath = "../../../../../Utils.Memory/vnlib_mimalloc/build/Debug/vnlib_mimalloc.dll";
+ private static string? RpMallocLibPath => Environment.GetEnvironmentVariable("TEST_RPMALLOC_LIB_PATH");
+
+ private static string? MimallocLibPath => Environment.GetEnvironmentVariable("TEST_MIMALLOC_LIB_PATH");
[TestMethod()]
public void LoadInTreeRpmallocTest()
{
//Try to load the shared heap
- using NativeHeap heap = NativeHeap.LoadHeap(RpMallocLibPath, System.Runtime.InteropServices.DllImportSearchPath.SafeDirectories, HeapCreation.Shared, 0);
+ using NativeHeap heap = NativeHeap.LoadHeap(RpMallocLibPath, DllImportSearchPath.SafeDirectories, HeapCreation.Shared, flags: 0);
Assert.IsFalse(heap.IsInvalid);
@@ -36,7 +38,7 @@ namespace VNLib.Utils.Memory.Tests
public void LoadInTreeMimallocTest()
{
//Try to load the shared heap
- using NativeHeap heap = NativeHeap.LoadHeap(MimallocLibPath, System.Runtime.InteropServices.DllImportSearchPath.SafeDirectories, HeapCreation.Shared, 0);
+ using NativeHeap heap = NativeHeap.LoadHeap(MimallocLibPath, DllImportSearchPath.SafeDirectories, HeapCreation.Shared, flags: 0);
Assert.IsFalse(heap.IsInvalid);