From 0ef2e06719d99d3eaa43c4ed375dbea6d772d0da Mon Sep 17 00:00:00 2001 From: Todd Jeffreys Date: Tue, 4 Jan 2022 08:47:01 -0700 Subject: [PATCH] Add test to ProtectedModeMemoryCore for tracking malloc exhaustion and switching to different segments. --- .../Memory/ProtectedModeMemoryCore_Tests.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/MBBSEmu.Tests/Memory/ProtectedModeMemoryCore_Tests.cs b/MBBSEmu.Tests/Memory/ProtectedModeMemoryCore_Tests.cs index 4de03b5d..7e60e4fd 100644 --- a/MBBSEmu.Tests/Memory/ProtectedModeMemoryCore_Tests.cs +++ b/MBBSEmu.Tests/Memory/ProtectedModeMemoryCore_Tests.cs @@ -1,4 +1,5 @@ -using MBBSEmu.DependencyInjection; +using FluentAssertions; +using MBBSEmu.DependencyInjection; using MBBSEmu.Memory; using NLog; using System.Text; @@ -24,8 +25,24 @@ public void EndOfSegmentString() var stringFromMemory = Encoding.ASCII.GetString((memoryCore as IMemoryCore).GetString(1, testStringOffset, stripNull: false)); - Assert.Equal(testString, stringFromMemory); + stringFromMemory.Should().Be(testString); + } + + [Fact] + public void MultiSegmentAllocation() + { + var memoryCore = new ProtectedModeMemoryCore(_logger); + var data1 = memoryCore.Malloc(0xFF00); + data1.Should().NotBeNull(); + + var data2 = memoryCore.Malloc(0xFF00); + data2.Should().NotBeNull(); + data2.Segment.Should().NotBe(data1.Segment); + var data3 = memoryCore.Malloc(0xFF00); + data3.Should().NotBeNull(); + data3.Segment.Should().NotBe(data2.Segment); + data3.Segment.Should().NotBe(data1.Segment); } } }