151 lines
5.3 KiB
C#
151 lines
5.3 KiB
C#
// <copyright file="ChatServerPacketTests.cs" company="MUnique">
|
|
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
|
// </copyright>
|
|
|
|
//------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This source code was auto-generated by an XSL transformation.
|
|
// Do not change this file. Instead, change the XML data which contains
|
|
// the packet definitions and re-run the transformation (rebuild this project).
|
|
// </auto-generated>
|
|
//------------------------------------------------------------------------------
|
|
|
|
namespace MUnique.OpenMU.Network.Packets.Tests.ChatServer;
|
|
|
|
using System;
|
|
using System.Text;
|
|
using NUnit.Framework;
|
|
using MUnique.OpenMU.Network.Packets.ChatServer;
|
|
|
|
/// <summary>
|
|
/// Auto-generated tests for packet structures to validate packet definitions.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class PacketStructureTests
|
|
{
|
|
|
|
/// <summary>
|
|
/// Tests the packet size calculation for Authenticate.
|
|
/// </summary>
|
|
[Test]
|
|
public void Authenticate_PacketSizeValidation()
|
|
{
|
|
// Fixed-length packet validation
|
|
const int expectedLength = 16;
|
|
var actualLength = AuthenticateRef.Length;
|
|
|
|
Assert.That(actualLength, Is.EqualTo(expectedLength),
|
|
"Packet length mismatch: declared length does not match calculated size");
|
|
|
|
// Validate field 'RoomId' boundary
|
|
Assert.That(4 + 2, Is.LessThanOrEqualTo(expectedLength),
|
|
"Field 'RoomId' exceeds packet boundary");
|
|
|
|
// Validate field 'Token' boundary
|
|
Assert.That(6 + 10, Is.LessThanOrEqualTo(expectedLength),
|
|
"Field 'Token' exceeds packet boundary");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the packet size calculation for ChatRoomClientJoined.
|
|
/// </summary>
|
|
[Test]
|
|
public void ChatRoomClientJoined_PacketSizeValidation()
|
|
{
|
|
// Fixed-length packet validation
|
|
const int expectedLength = 15;
|
|
var actualLength = ChatRoomClientJoinedRef.Length;
|
|
|
|
Assert.That(actualLength, Is.EqualTo(expectedLength),
|
|
"Packet length mismatch: declared length does not match calculated size");
|
|
|
|
// Validate field 'ClientIndex' boundary
|
|
Assert.That(4 + 1, Is.LessThanOrEqualTo(expectedLength),
|
|
"Field 'ClientIndex' exceeds packet boundary");
|
|
|
|
// Validate field 'Name' boundary
|
|
Assert.That(5 + 10, Is.LessThanOrEqualTo(expectedLength),
|
|
"Field 'Name' exceeds packet boundary");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the packet size calculation for LeaveChatRoom.
|
|
/// </summary>
|
|
[Test]
|
|
public void LeaveChatRoom_PacketSizeValidation()
|
|
{
|
|
// Fixed-length packet validation
|
|
const int expectedLength = 3;
|
|
var actualLength = LeaveChatRoomRef.Length;
|
|
|
|
Assert.That(actualLength, Is.EqualTo(expectedLength),
|
|
"Packet length mismatch: declared length does not match calculated size");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the packet size calculation for ChatRoomClientLeft.
|
|
/// </summary>
|
|
[Test]
|
|
public void ChatRoomClientLeft_PacketSizeValidation()
|
|
{
|
|
// Fixed-length packet validation
|
|
const int expectedLength = 15;
|
|
var actualLength = ChatRoomClientLeftRef.Length;
|
|
|
|
Assert.That(actualLength, Is.EqualTo(expectedLength),
|
|
"Packet length mismatch: declared length does not match calculated size");
|
|
|
|
// Validate field 'ClientIndex' boundary
|
|
Assert.That(4 + 1, Is.LessThanOrEqualTo(expectedLength),
|
|
"Field 'ClientIndex' exceeds packet boundary");
|
|
|
|
// Validate field 'Name' boundary
|
|
Assert.That(5 + 10, Is.LessThanOrEqualTo(expectedLength),
|
|
"Field 'Name' exceeds packet boundary");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the packet size calculation for ChatRoomClients.
|
|
/// </summary>
|
|
[Test]
|
|
public void ChatRoomClients_PacketSizeValidation()
|
|
{
|
|
// Basic packet validation
|
|
// Validate header type and field boundaries
|
|
|
|
// Field 'ClientCount' starts at index 6 with size 1
|
|
Assert.That(6, Is.GreaterThanOrEqualTo(0),
|
|
"Field 'ClientCount' has invalid negative index");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the packet size calculation for ChatMessage.
|
|
/// </summary>
|
|
[Test]
|
|
public void ChatMessage_PacketSizeValidation()
|
|
{
|
|
// Variable-length packet validation
|
|
// Test GetRequiredSize method with sample data
|
|
const int testBinaryLength = 10;
|
|
var calculatedSize = ChatMessageRef.GetRequiredSize(testBinaryLength);
|
|
var expectedMinSize = testBinaryLength + 5;
|
|
|
|
Assert.That(calculatedSize, Is.GreaterThanOrEqualTo(expectedMinSize),
|
|
"GetRequiredSize calculation incorrect for binary field");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the packet size calculation for KeepAlive.
|
|
/// </summary>
|
|
[Test]
|
|
public void KeepAlive_PacketSizeValidation()
|
|
{
|
|
// Fixed-length packet validation
|
|
const int expectedLength = 3;
|
|
var actualLength = KeepAliveRef.Length;
|
|
|
|
Assert.That(actualLength, Is.EqualTo(expectedLength),
|
|
"Packet length mismatch: declared length does not match calculated size");
|
|
}
|
|
}
|