ModernUO/Projects/Server.Tests/Network/Packets/Old/Outgoing/ArrowPacketTests.cs
2020-10-24 19:10:53 -07:00

90 lines
2.6 KiB
C#

using System;
using System.Buffers;
using Server.Network;
using Xunit;
namespace Server.Tests.Network
{
public class ArrowPacketTests
{
[Fact]
public void TestCancelArrow()
{
var data = new CancelArrow().Compile();
Span<byte> expectedData = stackalloc byte[6];
var pos = 0;
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
expectedData.Write(ref pos, (byte)0); // Command
expectedData.Write(ref pos, 0xFFFFFFFF); // X, Y
AssertThat.Equal(data, expectedData);
}
[Theory]
[InlineData(0, 0)]
[InlineData(100, 10)]
[InlineData(100000, 100000)]
public void TestSetArrow(int x, int y)
{
var data = new SetArrow(x, y).Compile();
Span<byte> expectedData = stackalloc byte[6];
var pos = 0;
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
expectedData.Write(ref pos, (byte)0x01); // Command
expectedData.Write(ref pos, (ushort)x);
expectedData.Write(ref pos, (ushort)y);
AssertThat.Equal(data, expectedData);
}
[Theory]
[InlineData(0, 0)]
[InlineData(100, 10)]
[InlineData(100000, 100000)]
public void TestCancelArrowHS(int x, int y)
{
Serial serial = 0x01;
var data = new CancelArrowHS(x, y, serial).Compile();
Span<byte> expectedData = stackalloc byte[10];
var pos = 0;
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
#if NO_LOCAL_INIT
expectedData.Write(ref pos, (byte)0); // Command
#else
pos++;
#endif
expectedData.Write(ref pos, (ushort)x);
expectedData.Write(ref pos, (ushort)y);
expectedData.Write(ref pos, serial);
AssertThat.Equal(data, expectedData);
}
[Theory]
[InlineData(0, 0)]
[InlineData(100, 10)]
[InlineData(100000, 100000)]
public void TestSetArrowHS(int x, int y)
{
Serial serial = 0x01;
var data = new SetArrowHS(x, y, serial).Compile();
Span<byte> expectedData = stackalloc byte[10];
var pos = 0;
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
expectedData.Write(ref pos, (byte)0x01); // Command
expectedData.Write(ref pos, (ushort)x);
expectedData.Write(ref pos, (ushort)y);
expectedData.Write(ref pos, serial);
AssertThat.Equal(data, expectedData);
}
}
}