Adds more unit tests (#133)
This commit is contained in:
parent
e138706536
commit
8278694105
37 changed files with 1406 additions and 996 deletions
|
|
@ -11,7 +11,8 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
Span<byte> data = new CancelArrow().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[] {
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBA, // Packet
|
||||
0x00, // Command
|
||||
0xFF, 0xFF, // X
|
||||
|
|
@ -29,7 +30,8 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
Span<byte> data = new SetArrow(x, y).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[] {
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBA, // Packet
|
||||
0x01, // Command
|
||||
0x00, 0x00, // X
|
||||
|
|
@ -50,7 +52,8 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
Span<byte> data = new CancelArrowHS(x, y, 0x1).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[] {
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBA, // Packet
|
||||
0x00, // Command
|
||||
0x00, 0x00, // X
|
||||
|
|
@ -72,7 +75,8 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
Span<byte> data = new SetArrowHS(x, y, 0x1).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[] {
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBA, // Packet
|
||||
0x01, // Command
|
||||
0x00, 0x00, // X
|
||||
|
|
@ -6,19 +6,19 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
public class DamagePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
private readonly Mobile mobile;
|
||||
|
||||
public DamagePacketTests(ServerFixture fixture) => mobile = fixture.fromMobile;
|
||||
|
||||
[Theory]
|
||||
[InlineData(10, 10)]
|
||||
[InlineData(-5, 0)]
|
||||
[InlineData(1024, 0xFF)]
|
||||
public void TestDamagePacketOld(int inputAmount, byte expectedAmount)
|
||||
{
|
||||
Span<byte> data = new DamagePacketOld(mobile, inputAmount).Compile();
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[] {
|
||||
Span<byte> data = new DamagePacketOld(m, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBF, // Packet
|
||||
0x00, 0x0B, // Length
|
||||
0x00, 0x22, // Sub-packet
|
||||
|
|
@ -27,7 +27,7 @@ namespace Server.Tests.Network.Packets
|
|||
expectedAmount // Amount
|
||||
};
|
||||
|
||||
mobile.Serial.CopyTo(expectedData.Slice(6, 4));
|
||||
m.Serial.CopyTo(expectedData.Slice(6, 4));
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
|
|
@ -38,15 +38,19 @@ namespace Server.Tests.Network.Packets
|
|||
[InlineData(100000, 0xFFFF)]
|
||||
public void TestDamagePacket(int inputAmount, ushort expectedAmount)
|
||||
{
|
||||
Span<byte> data = new DamagePacket(mobile, inputAmount).Compile();
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[] {
|
||||
Span<byte> data = new DamagePacket(m, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x0B, // Packet
|
||||
0x00, 0x00, 0x00, 0x00, // Mobile Serial
|
||||
0x00, 0x00 // Amount
|
||||
};
|
||||
|
||||
mobile.Serial.CopyTo(expectedData.Slice(1, 4));
|
||||
m.Serial.CopyTo(expectedData.Slice(1, 4));
|
||||
expectedAmount.CopyTo(expectedData.Slice(5, 2));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using Server.HuePickers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class DisplayHuePickerTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayHuePicker()
|
||||
{
|
||||
ushort itemID = 0xFF01;
|
||||
var huePicker = new HuePicker(itemID);
|
||||
|
||||
Span<byte> data = new DisplayHuePicker(huePicker).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x95, // Packet ID
|
||||
0x00, 0x00, 0x00, 0x00, // Hue Picker Serial
|
||||
0x00, 0x00, // Nothing
|
||||
0x00, 0x00 // Item ID
|
||||
};
|
||||
|
||||
huePicker.Serial.CopyTo(expectedData.Slice(1, 4));
|
||||
itemID.CopyTo(expectedData.Slice(7, 2));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,8 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
Span<byte> data = new MapPatches().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[] {
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBF, // Packet
|
||||
0x00, 0x29, // Length
|
||||
0x00, 0x18, // Sub-packet
|
||||
|
|
@ -28,5 +29,18 @@ namespace Server.Tests.Network.Packets
|
|||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInvalidMapEnable()
|
||||
{
|
||||
Span<byte> data = new InvalidMapEnable().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xC6 // Packet ID
|
||||
};
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.ContextMenus;
|
||||
using Server.Menus.ItemLists;
|
||||
using Server.Menus.Questions;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
internal class ContextMenuItem : Item
|
||||
{
|
||||
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
|
||||
{
|
||||
base.GetContextMenuEntries(from, list);
|
||||
|
||||
list.Add(new ContextMenuEntry(500000));
|
||||
list.Add(new ContextMenuEntry(500001));
|
||||
list.Add(new ContextMenuEntry(500002));
|
||||
}
|
||||
|
||||
public ContextMenuItem(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class MenuPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayItemListMenu()
|
||||
{
|
||||
var menu = new ItemListMenu(
|
||||
"Which item would you choose?",
|
||||
new[]
|
||||
{
|
||||
new ItemListEntry("Item 1", 0x01),
|
||||
new ItemListEntry("Item 2", 0x100),
|
||||
new ItemListEntry("Item 3", 0x1000, 250)
|
||||
}
|
||||
);
|
||||
|
||||
string question = menu.Question?.Trim() ?? "";
|
||||
int questionLength = Math.Min(255, question.Length);
|
||||
|
||||
int length = 11 + questionLength + menu.Entries.Sum(entry => 5 + entry.Name?.Trim().Length ?? 0);
|
||||
|
||||
Span<byte> data = new DisplayItemListMenu(menu).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData[pos++] = 0x7C; // Packet ID
|
||||
((ushort)length).CopyTo(ref pos, expectedData);
|
||||
menu.Serial.CopyTo(ref pos, expectedData);
|
||||
pos += 2; // ((ushort)0x00).CopyTo(ref pos, expectedData);
|
||||
expectedData[pos++] = (byte)questionLength;
|
||||
question.CopyASCIITo(ref pos, expectedData);
|
||||
expectedData[pos++] = (byte)menu.Entries.Length;
|
||||
for (int i = 0; i < menu.Entries.Length; i++)
|
||||
{
|
||||
var entry = menu.Entries[i];
|
||||
((ushort)entry.ItemID).CopyTo(ref pos, expectedData);
|
||||
((ushort)entry.Hue).CopyTo(ref pos, expectedData);
|
||||
string name = entry.Name?.Trim() ?? "";
|
||||
|
||||
expectedData[pos++] = (byte)name.Length;
|
||||
name.CopyASCIITo(ref pos, expectedData);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayQuestionMenu()
|
||||
{
|
||||
var menu = new QuestionMenu(
|
||||
"Which option would you choose?",
|
||||
new[]
|
||||
{
|
||||
"Option 1",
|
||||
"Option 2",
|
||||
"Option 3"
|
||||
}
|
||||
);
|
||||
|
||||
string question = menu.Question?.Trim() ?? "";
|
||||
int questionLength = Math.Min(255, question.Length);
|
||||
|
||||
int length = 11 + questionLength + menu.Answers.Sum(answer => 5 + answer?.Trim().Length ?? 0);
|
||||
|
||||
Span<byte> data = new DisplayQuestionMenu(menu).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData[pos++] = 0x7C; // Packet ID
|
||||
((ushort)length).CopyTo(ref pos, expectedData);
|
||||
menu.Serial.CopyTo(ref pos, expectedData);
|
||||
pos += 2; // ((ushort)0x00).CopyTo(ref pos, expectedData);
|
||||
expectedData[pos++] = (byte)questionLength;
|
||||
question?.CopyASCIITo(ref pos, expectedData);
|
||||
expectedData[pos++] = (byte)menu.Answers.Length;
|
||||
for (int i = 0; i < menu.Answers.Length; i++)
|
||||
{
|
||||
pos += 4; // 0x0.CopyTo(ref pos, expectedData);
|
||||
var answer = menu.Answers[i]?.Trim() ?? "";
|
||||
expectedData[pos++] = (byte)answer.Length;
|
||||
answer.CopyASCIITo(ref pos, expectedData);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayContextMenu()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new ContextMenuItem(Serial.LastItem + 1);
|
||||
var menu = new ContextMenu(m, item);
|
||||
|
||||
Span<byte> data = new DisplayContextMenu(menu).Compile();
|
||||
|
||||
int length = 12 + menu.Entries.Length * 8;
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
expectedData[pos++] = 0xBF; // Packet ID
|
||||
((ushort)length).CopyTo(ref pos, expectedData); // Length
|
||||
((ushort)0x14).CopyTo(ref pos, expectedData); // Command
|
||||
((ushort)0x02).CopyTo(ref pos, expectedData); // Subcommand
|
||||
menu.Target.Serial.CopyTo(ref pos, expectedData);
|
||||
var entries = menu.Entries;
|
||||
|
||||
expectedData[pos++] = (byte)entries.Length;
|
||||
|
||||
for (int i = 0; i < entries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
entry.Number.CopyTo(ref pos, expectedData);
|
||||
((ushort)i).CopyTo(ref pos, expectedData);
|
||||
|
||||
var flags = entry.Flags;
|
||||
|
||||
var range = entry.Range;
|
||||
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
|
||||
flags |= CMEFlags.Disabled;
|
||||
|
||||
((ushort)flags).CopyTo(ref pos, expectedData);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayContextMenuOld()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new ContextMenuItem(Serial.LastItem + 1);
|
||||
var menu = new ContextMenu(m, item);
|
||||
|
||||
Span<byte> data = new DisplayContextMenuOld(menu).Compile();
|
||||
|
||||
int length = 12 + menu.Entries.Sum(entry => 6 + ((entry.Color & 0xFFFF) != 0xFFFF ? 2 : 0));
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
expectedData[pos++] = 0xBF; // Packet ID
|
||||
((ushort)length).CopyTo(ref pos, expectedData); // Length
|
||||
((ushort)0x14).CopyTo(ref pos, expectedData); // Command
|
||||
((ushort)0x01).CopyTo(ref pos, expectedData); // Subcommand
|
||||
menu.Target.Serial.CopyTo(ref pos, expectedData);
|
||||
var entries = menu.Entries;
|
||||
|
||||
expectedData[pos++] = (byte)entries.Length;
|
||||
|
||||
for (int i = 0; i < entries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
((ushort)i).CopyTo(ref pos, expectedData);
|
||||
((ushort)(entry.Number - 3000000)).CopyTo(ref pos, expectedData);
|
||||
|
||||
var flags = entry.Flags;
|
||||
|
||||
var color = entry.Color & 0xFFFF;
|
||||
|
||||
if (color != 0xFFFF)
|
||||
flags |= CMEFlags.Colored;
|
||||
|
||||
var range = entry.Range;
|
||||
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
|
||||
flags |= CMEFlags.Disabled;
|
||||
|
||||
((ushort)flags).CopyTo(ref pos, expectedData);
|
||||
|
||||
if ((flags & CMEFlags.Colored) != 0)
|
||||
((ushort)color).CopyTo(ref pos, expectedData);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,25 +7,18 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
public class SecureTradePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
private readonly Mobile to;
|
||||
private readonly Container firstCont;
|
||||
private readonly Container secondCont;
|
||||
private readonly Item itemInFirstCont;
|
||||
|
||||
public SecureTradePacketTests(ServerFixture fixture)
|
||||
{
|
||||
to = fixture.toMobile;
|
||||
firstCont = fixture.fromCont;
|
||||
secondCont = fixture.toCont;
|
||||
itemInFirstCont = fixture.itemInFromCont;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("short-name")]
|
||||
[InlineData("this is a really long name that is more than 30 characters, probably")]
|
||||
public void TestDisplaySecureTrade(string name)
|
||||
{
|
||||
Span<byte> data = new DisplaySecureTrade(to, firstCont, secondCont, name).Compile();
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var firstCont = new Container(Serial.LastItem + 1);
|
||||
var secondCont = new Container(Serial.LastItem + 2);
|
||||
|
||||
Span<byte> data = new DisplaySecureTrade(m, firstCont, secondCont, name).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
|
|
@ -42,7 +35,7 @@ namespace Server.Tests.Network.Packets
|
|||
};
|
||||
|
||||
int pos = 4;
|
||||
to.Serial.CopyTo(ref pos, expectedData);
|
||||
m.Serial.CopyTo(ref pos, expectedData);
|
||||
firstCont.Serial.CopyTo(ref pos, expectedData);
|
||||
secondCont.Serial.CopyTo(ref pos, expectedData);
|
||||
pos++;
|
||||
|
|
@ -54,7 +47,9 @@ namespace Server.Tests.Network.Packets
|
|||
[Fact]
|
||||
public void TestCloseSecureTrade()
|
||||
{
|
||||
Span<byte> data = new CloseSecureTrade(firstCont).Compile();
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
Span<byte> data = new CloseSecureTrade(cont).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
|
|
@ -64,7 +59,7 @@ namespace Server.Tests.Network.Packets
|
|||
0x00, 0x00, 0x00, 0x00 // Container Serial
|
||||
};
|
||||
|
||||
firstCont.Serial.CopyTo(expectedData.Slice(4, 4));
|
||||
cont.Serial.CopyTo(expectedData.Slice(4, 4));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -74,6 +69,9 @@ namespace Server.Tests.Network.Packets
|
|||
[InlineData(false, true)] // Update second
|
||||
public void TestUpdateSecureTrade(bool first, bool second)
|
||||
{
|
||||
var firstCont = new Container(Serial.LastItem + 1);
|
||||
var secondCont = new Container(Serial.LastItem + 2);
|
||||
|
||||
Container cont = first ? firstCont : secondCont;
|
||||
Span<byte> data = new UpdateSecureTrade(cont, first, second).Compile();
|
||||
|
||||
|
|
@ -97,7 +95,8 @@ namespace Server.Tests.Network.Packets
|
|||
[InlineData(250000, 50000, TradeFlag.UpdateLedger)]
|
||||
public void TestUpdateGoldSecureTrade(int gold, int plat, TradeFlag flag)
|
||||
{
|
||||
Span<byte> data = new UpdateSecureTrade(firstCont, flag, gold, plat).Compile();
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
Span<byte> data = new UpdateSecureTrade(cont, flag, gold, plat).Compile();
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x6F, // Packet ID
|
||||
|
|
@ -109,7 +108,7 @@ namespace Server.Tests.Network.Packets
|
|||
};
|
||||
|
||||
int pos = 4;
|
||||
firstCont.Serial.CopyTo(ref pos, expectedData);
|
||||
cont.Serial.CopyTo(ref pos, expectedData);
|
||||
gold.CopyTo(ref pos, expectedData);
|
||||
plat.CopyTo(ref pos, expectedData);
|
||||
|
||||
|
|
@ -119,7 +118,13 @@ namespace Server.Tests.Network.Packets
|
|||
[Fact]
|
||||
public void TestSecureTradeEquip()
|
||||
{
|
||||
Span<byte> data = new SecureTradeEquip(itemInFirstCont, to).Compile();
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
var itemInCont = new Item(Serial.LastItem + 2) { Parent = cont };
|
||||
|
||||
Span<byte> data = new SecureTradeEquip(itemInCont, m).Compile();
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x25, // Packet ID
|
||||
|
|
@ -134,14 +139,14 @@ namespace Server.Tests.Network.Packets
|
|||
};
|
||||
|
||||
int pos = 1;
|
||||
itemInFirstCont.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.ItemID).CopyTo(ref pos, expectedData);
|
||||
pos++;
|
||||
((short)itemInFirstCont.Amount).CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.X).CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.Y).CopyTo(ref pos, expectedData);
|
||||
to.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.Hue).CopyTo(ref pos, expectedData);
|
||||
itemInCont.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.ItemID).CopyTo(ref pos, expectedData);
|
||||
pos++; // expectedData[pos++] = 0x0;
|
||||
((short)itemInCont.Amount).CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.X).CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.Y).CopyTo(ref pos, expectedData);
|
||||
m.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.Hue).CopyTo(ref pos, expectedData);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -149,7 +154,13 @@ namespace Server.Tests.Network.Packets
|
|||
[Fact]
|
||||
public void TestSecureTradeEquip6017()
|
||||
{
|
||||
Span<byte> data = new SecureTradeEquip6017(itemInFirstCont, to).Compile();
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
var itemInCont = new Item(Serial.LastItem + 2) { Parent = cont };
|
||||
|
||||
Span<byte> data = new SecureTradeEquip6017(itemInCont, m).Compile();
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x25, // Packet ID
|
||||
|
|
@ -165,15 +176,15 @@ namespace Server.Tests.Network.Packets
|
|||
};
|
||||
|
||||
int pos = 1;
|
||||
itemInFirstCont.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.ItemID).CopyTo(ref pos, expectedData);
|
||||
itemInCont.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.ItemID).CopyTo(ref pos, expectedData);
|
||||
pos++;
|
||||
((short)itemInFirstCont.Amount).CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.X).CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.Y).CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.Amount).CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.X).CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.Y).CopyTo(ref pos, expectedData);
|
||||
pos++;
|
||||
to.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInFirstCont.Hue).CopyTo(ref pos, expectedData);
|
||||
m.Serial.CopyTo(ref pos, expectedData);
|
||||
((short)itemInCont.Hue).CopyTo(ref pos, expectedData);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class TestEquipmentPackets : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayEquipmentInfo()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new Item(Serial.LastItem + 1);
|
||||
|
||||
var info = new EquipmentInfo(
|
||||
500000,
|
||||
m,
|
||||
false,
|
||||
new []
|
||||
{
|
||||
new EquipInfoAttribute(500001, 1),
|
||||
new EquipInfoAttribute(500002, 2),
|
||||
new EquipInfoAttribute(500002, 3)
|
||||
}
|
||||
);
|
||||
|
||||
Span<byte> data = new DisplayEquipmentInfo(item, info).Compile();
|
||||
|
||||
var attrs = info.Attributes;
|
||||
|
||||
int length = 17 + (info.Unidentified ? 4 : 0) + attrs.Length * 6;
|
||||
if (info.Crafter != null) length += 6 + (info.Crafter.Name?.Length ?? 0);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData[pos++] = 0xBF; // Packet ID
|
||||
((ushort)length).CopyTo(ref pos, expectedData); // Length
|
||||
((ushort)0x10).CopyTo(ref pos, expectedData); // Subcommand
|
||||
item.Serial.CopyTo(ref pos, expectedData);
|
||||
info.Number.CopyTo(ref pos, expectedData);
|
||||
if (info.Crafter != null)
|
||||
{
|
||||
var name = info.Crafter.Name ?? "";
|
||||
(-3).CopyTo(ref pos, expectedData);
|
||||
((ushort)name.Length).CopyTo(ref pos, expectedData);
|
||||
name.CopyASCIITo(ref pos, expectedData);
|
||||
}
|
||||
|
||||
if (info.Unidentified) (-4).CopyTo(ref pos, expectedData);
|
||||
|
||||
for (var i = 0; i < attrs.Length; i++)
|
||||
{
|
||||
var attr = attrs[i];
|
||||
attr.Number.CopyTo(ref pos, expectedData);
|
||||
((ushort)attr.Charges).CopyTo(ref pos, expectedData);
|
||||
}
|
||||
|
||||
(-1).CopyTo(ref pos, expectedData);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEquipUpdate()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new Item(Serial.LastItem + 1) { Parent = m };
|
||||
|
||||
Span<byte> data = new EquipUpdate(item).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x2E, // Packet ID
|
||||
0x00, 0x00, 0x00, 0x00, // Serial
|
||||
0x00, 0x00, // Item ID
|
||||
0x00, (byte)item.Layer,
|
||||
0x00, 0x00, 0x00, 0x00, // Parent Serial
|
||||
0x00, 0x00, // Hue
|
||||
};
|
||||
|
||||
item.Serial.CopyTo(expectedData.Slice(1, 4));
|
||||
((ushort)item.ItemID).CopyTo(expectedData.Slice(5, 2));
|
||||
item.Parent.Serial.CopyTo(expectedData.Slice(9, 4));
|
||||
((ushort)item.Hue).CopyTo(expectedData.Slice(13, 2));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using Server.Network;
|
||||
using Server.Prompts;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
internal class TestPrompt : Prompt
|
||||
{
|
||||
}
|
||||
|
||||
public class UnicodePromptTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestUnicodePrompt()
|
||||
{
|
||||
var prompt = new TestPrompt();
|
||||
Span<byte> data = new UnicodePrompt(prompt).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xC2, // Packet ID
|
||||
0x00, 0x15, // Length
|
||||
0x00, 0x00, 0x00, 0x00, // Serial
|
||||
0x00, 0x00, 0x00, 0x00, // Prompt Serial
|
||||
0x00, 0x00, 0x00, 0x00, // Unused
|
||||
0x00, 0x00, 0x00, 0x00, // Unused
|
||||
0x00, 0x00 // Unused
|
||||
};
|
||||
|
||||
prompt.Serial.CopyTo(expectedData.Slice(3, 4));
|
||||
prompt.Serial.CopyTo(expectedData.Slice(7, 4));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,33 +4,23 @@ using System.Linq;
|
|||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class VendorBuyPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
private readonly Mobile vendor;
|
||||
private readonly Container cont;
|
||||
|
||||
private readonly List<BuyItemState> buyStates;
|
||||
|
||||
public VendorBuyPacketTests(ServerFixture fixture)
|
||||
[Fact]
|
||||
public void TestVendorBuyContent()
|
||||
{
|
||||
vendor = fixture.fromMobile;
|
||||
cont = fixture.fromCont;
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
buyStates = new List<BuyItemState>
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVendorBuyContent()
|
||||
{
|
||||
Span<byte> data = new VendorBuyContent(buyStates).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + buyStates.Count * 19];
|
||||
|
|
@ -62,6 +52,15 @@ namespace Server.Tests.Network.Packets
|
|||
[Fact]
|
||||
public void TestVendorBuyContent6017()
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
Span<byte> data = new VendorBuyContent6017(buyStates).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + buyStates.Count * 20];
|
||||
|
|
@ -94,6 +93,9 @@ namespace Server.Tests.Network.Packets
|
|||
[Fact]
|
||||
public void TestDisplayBuyList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new DisplayBuyList(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
|
|
@ -111,6 +113,9 @@ namespace Server.Tests.Network.Packets
|
|||
[Fact]
|
||||
public void TestDisplayBuyListHS()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new DisplayBuyListHS(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
|
|
@ -129,6 +134,18 @@ namespace Server.Tests.Network.Packets
|
|||
[Fact]
|
||||
public void TestVendorBuyList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
Span<byte> data = new VendorBuyList(vendor, buyStates).Compile();
|
||||
|
||||
int length = 8 + 5 * 3 + buyStates.Sum(state => state.Description.Length + 1);
|
||||
|
|
@ -154,5 +171,26 @@ namespace Server.Tests.Network.Packets
|
|||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEndVendorBuy()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new EndVendorBuy(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x3B, // Packet ID
|
||||
0x00, 0x08, // Length
|
||||
0x00, 0x00, 0x00, 0x00, // Vendor Serial
|
||||
0x00
|
||||
};
|
||||
|
||||
vendor.Serial.CopyTo(expectedData.Slice(3, 4));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class VendorSellPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestVendorSellList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var item1 = new Item(Serial.LastItem + 1);
|
||||
var item2 = new Item(Serial.LastItem + 2) { Name = "Second Item" };
|
||||
var item3 = new Item(Serial.LastItem + 3);
|
||||
|
||||
var sellStates = new List<SellItemState>
|
||||
{
|
||||
new SellItemState(item1, 100, "Item 1"),
|
||||
new SellItemState(item2, 100000, "Item 2"),
|
||||
new SellItemState(item3, 1, "Item 3")
|
||||
};
|
||||
|
||||
Span<byte> data = new VendorSellList(vendor, sellStates).Compile();
|
||||
|
||||
int length = 9 + 14 * 3 + sellStates.Sum(state =>
|
||||
(string.IsNullOrWhiteSpace(state.Item.Name) ? state.Name ?? "" : state.Item.Name.Trim()).Length
|
||||
);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
expectedData[pos++] = 0x9E; // Packet ID
|
||||
((ushort)length).CopyTo(ref pos, expectedData);
|
||||
vendor.Serial.CopyTo(ref pos, expectedData);
|
||||
((ushort)sellStates.Count).CopyTo(ref pos, expectedData);
|
||||
|
||||
for (int i = 0; i < sellStates.Count; i++)
|
||||
{
|
||||
SellItemState state = sellStates[i];
|
||||
state.Item.Serial.CopyTo(ref pos, expectedData);
|
||||
((ushort)state.Item.ItemID).CopyTo(ref pos, expectedData);
|
||||
((ushort)state.Item.Hue).CopyTo(ref pos, expectedData);
|
||||
((ushort)state.Item.Amount).CopyTo(ref pos, expectedData);
|
||||
((ushort)state.Price).CopyTo(ref pos, expectedData);
|
||||
string name = string.IsNullOrWhiteSpace(state.Item.Name) ? state.Name ?? "" : state.Item.Name.Trim();
|
||||
((ushort)name.Length).CopyTo(ref pos, expectedData);
|
||||
name.CopyASCIITo(ref pos, expectedData);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEndVendorSell()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new EndVendorBuy(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x3B, // Packet ID
|
||||
0x00, 0x08, // Length
|
||||
0x00, 0x00, 0x00, 0x00, // Vendor Serial
|
||||
0x00
|
||||
};
|
||||
|
||||
vendor.Serial.CopyTo(expectedData.Slice(3, 4));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue