Introduces two headless FPCUnit runners under tests/ with 119 tests covering the shared stream, cache, and packet layers, the MUL file library, and the server config, region, account, and landscape bounds logic. Each runner uses its own object output directory so client and server PPUs with colliding unit names cannot pollute each other's builds. Drone now builds and runs both suites before packaging. Found on the way: two product defects fixed in the previous commits.
104 lines
2.5 KiB
ObjectPascal
104 lines
2.5 KiB
ObjectPascal
unit UTestPacket;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, fpcunit, testregistry, UEnhancedMemoryStream, UPacket;
|
|
|
|
type
|
|
TTestPacket = class(TTestCase)
|
|
published
|
|
procedure FixedLengthPacketLayout;
|
|
procedure DynamicLengthIsPatchedUp;
|
|
procedure DynamicLengthPatchIsIdempotent;
|
|
procedure EmptyDynamicPacket;
|
|
end;
|
|
|
|
implementation
|
|
|
|
procedure TTestPacket.FixedLengthPacketLayout;
|
|
var
|
|
packet: TPacket;
|
|
stream: TEnhancedMemoryStream;
|
|
begin
|
|
packet := TPacket.Create($05, 5);
|
|
try
|
|
AssertEquals('declared length', Cardinal(5), packet.PacketLength);
|
|
stream := packet.Stream;
|
|
//fixed length packets carry only the id byte; the length lives in the
|
|
//handler table on the receiving side
|
|
AssertEquals('stream holds only the id byte', Int64(1), stream.Size);
|
|
stream.Position := 0;
|
|
AssertEquals('id byte', Byte($05), stream.ReadByte);
|
|
finally
|
|
packet.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TTestPacket.DynamicLengthIsPatchedUp;
|
|
var
|
|
packet: TPacket;
|
|
stream: TEnhancedMemoryStream;
|
|
begin
|
|
packet := TPacket.Create($04, 0);
|
|
try
|
|
stream := packet.Stream; //one getter call: patches length, resets position
|
|
stream.Position := stream.Size;
|
|
stream.WriteWord($1234);
|
|
stream.WriteWord($5678);
|
|
AssertEquals('id + length + payload', Int64(9), stream.Size);
|
|
stream := packet.Stream; //property access patches the length field
|
|
stream.Position := 1;
|
|
AssertEquals('length covers the whole packet', Cardinal(9),
|
|
stream.ReadCardinal);
|
|
finally
|
|
packet.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TTestPacket.DynamicLengthPatchIsIdempotent;
|
|
var
|
|
packet: TPacket;
|
|
stream: TEnhancedMemoryStream;
|
|
begin
|
|
packet := TPacket.Create($04, 0);
|
|
try
|
|
stream := packet.Stream;
|
|
stream.Position := stream.Size;
|
|
stream.WriteByte($42);
|
|
stream := packet.Stream; //property access patches the length field
|
|
stream.Position := 1;
|
|
AssertEquals('first access patches', Cardinal(6), stream.ReadCardinal);
|
|
stream.Position := 1;
|
|
AssertEquals('second access keeps the length', Cardinal(6),
|
|
stream.ReadCardinal);
|
|
finally
|
|
packet.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TTestPacket.EmptyDynamicPacket;
|
|
var
|
|
packet: TPacket;
|
|
stream: TEnhancedMemoryStream;
|
|
begin
|
|
packet := TPacket.Create($04, 0);
|
|
try
|
|
stream := packet.Stream;
|
|
AssertEquals('header only', Int64(5), stream.Size);
|
|
stream.Position := 0;
|
|
stream.ReadByte;
|
|
AssertEquals('length is the header size', Cardinal(5),
|
|
stream.ReadCardinal);
|
|
finally
|
|
packet.Free;
|
|
end;
|
|
end;
|
|
|
|
initialization
|
|
RegisterTests([TTestPacket]);
|
|
|
|
end.
|