ModernUO/Projects/UOContent.Tests/Tests/Engines/ML Quests/MLQuestPacketTests.cs
Kamron Batman 10a69bf754
feat: Adds a memory mirrored ring buffer for networking. (#1533)
## Breaking Changes

Incoming packet registration signature has changed to:
```cs
delegate* void OnReceiveCallback(NetState state, SpanReader reader, int packetLength);

IncomingPackets.Register(int packetID, int length, bool ingame, OnReceiveCallback onReceive);
```

For example, an incoming packet handler signature would now look like this:
```cs
public static void SomeIncomingPacket(NetState state, SpanReader reader, int packetLength)
{
    // Parse the data
}
```

## Summary

Updates the network Pipe class to use a mirrored memory technique. This technique involves mapping the same physical memory to two contiguous virtual memory spaces so the byte buffer appears duplicated. This allows writing to a double-sized array to wrap around without the need for the `CircularBuffer` classes.

In practice this allows us to use `Span<byte>` as if the buffer was a regular array.


### Bug Fixes

- [X] Fixes bad fixed length string parsing
2023-10-09 00:57:53 -07:00

90 lines
2.4 KiB
C#

using System;
using Server.Tests;
using Server.Tests.Network;
using Xunit;
namespace Server.Engines.MLQuests;
public class MLQuestPacketTests
{
private class MockedRace : Race
{
public MockedRace(
int raceID,
int raceIndex,
string name,
string pluralName,
int maleBody,
int femaleBody,
int maleGhostBody,
int femaleGhostBody,
Expansion requiredExpansion
) : base(
raceID,
raceIndex,
name,
pluralName,
maleBody,
femaleBody,
maleGhostBody,
femaleGhostBody,
requiredExpansion
)
{
}
public override bool ValidateHair(bool female, int itemID) => throw new NotImplementedException();
public override int RandomHair(bool female) => throw new NotImplementedException();
public override bool ValidateFacialHair(bool female, int itemID) => throw new NotImplementedException();
public override int RandomFacialHair(bool female) => throw new NotImplementedException();
public override int ClipSkinHue(int hue) => throw new NotImplementedException();
public override int RandomSkinHue() => throw new NotImplementedException();
public override int ClipHairHue(int hue) => throw new NotImplementedException();
public override int RandomHairHue() => throw new NotImplementedException();
}
[Theory]
[InlineData(true, 1)]
[InlineData(false, 2)]
public void TestRaceChanger(bool female, int raceId)
{
var race = new MockedRace(
raceId,
0,
"Test Race",
"Test Races",
0x1,
0x2,
0x3,
0x4,
Expansion.None
);
var expected = new RaceChanger(female, race).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendRaceChanger(female, race);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
[Fact]
public void TestCloseRaceChanger()
{
var expected = new CloseRaceChanger().Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendCloseRaceChanger();
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
}