✅ Add FPCUnit test suites for shared code and server

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.
This commit is contained in:
2026-11-15 22:08:32 +01:00
parent ca8a0afc3b
commit 99749a5168
23 changed files with 3357 additions and 0 deletions
+190
View File
@@ -0,0 +1,190 @@
unit UTestMap;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, fpcunit, testregistry, UEnhancedMemoryStream, UGenericIndex, UMap;
type
TTestMapBlock = class(TTestCase)
published
procedure WriteReadRoundtrip;
procedure ClonePreservesAllCells;
procedure ClonePreservesHeader;
procedure CloneIsIndependent;
procedure GetSizeMatchesSerialization;
end;
TTestMapCell = class(TTestCase)
published
procedure ClonePreservesValues;
end;
implementation
function BuildPopulatedBlock: TMapBlock;
var
i: Integer;
begin
Result := TMapBlock.Create(nil);
Result.Header := 12345;
for i := 0 to 63 do
begin
Result.Cells[i].X := i mod 8;
Result.Cells[i].Y := i div 8;
Result.Cells[i].Z := (i * 3) mod 128 - 64;
Result.Cells[i].TileID := (i * 7) mod 1000;
end;
end;
procedure TTestMapBlock.WriteReadRoundtrip;
var
source, loaded: TMapBlock;
stream: TEnhancedMemoryStream;
i: Integer;
index: TGenericIndex;
begin
source := BuildPopulatedBlock;
try
stream := TEnhancedMemoryStream.Create;
try
source.Write(stream);
AssertEquals('serialized block size', Int64(MapBlockSize), stream.Size);
stream.Position := 0;
index := TGenericIndex.Create(nil);
try
index.Lookup := 0;
index.Size := MapBlockSize;
loaded := TMapBlock.Create(stream, 1, 1);
try
AssertEquals('header preserved', source.Header, loaded.Header);
for i := 0 to 63 do
begin
AssertEquals('cell z ' + IntToStr(i), source.Cells[i].Z,
loaded.Cells[i].Z);
AssertEquals('cell tile ' + IntToStr(i), source.Cells[i].TileID,
loaded.Cells[i].TileID);
end;
finally
loaded.Free;
end;
finally
index.Free;
end;
finally
stream.Free;
end;
finally
source.Free;
end;
end;
procedure TTestMapBlock.ClonePreservesAllCells;
var
source, clone: TMapBlock;
i: Integer;
begin
source := BuildPopulatedBlock;
try
clone := source.Clone;
try
for i := 0 to 63 do
begin
AssertEquals('clone z ' + IntToStr(i), source.Cells[i].Z,
clone.Cells[i].Z);
AssertEquals('clone tile ' + IntToStr(i), source.Cells[i].TileID,
clone.Cells[i].TileID);
AssertEquals('clone x ' + IntToStr(i), source.Cells[i].X,
clone.Cells[i].X);
AssertEquals('clone y ' + IntToStr(i), source.Cells[i].Y,
clone.Cells[i].Y);
end;
finally
clone.Free;
end;
finally
source.Free;
end;
end;
procedure TTestMapBlock.ClonePreservesHeader;
var
source, clone: TMapBlock;
begin
source := BuildPopulatedBlock;
try
clone := source.Clone;
try
AssertEquals('header must be cloned', source.Header, clone.Header);
finally
clone.Free;
end;
finally
source.Free;
end;
end;
procedure TTestMapBlock.CloneIsIndependent;
var
source, clone: TMapBlock;
begin
source := BuildPopulatedBlock;
try
clone := source.Clone;
try
clone.Cells[5].Z := source.Cells[5].Z + 10;
clone.Header := source.Header + 1;
AssertEquals('source untouched by clone edits', source.Cells[5].Z,
source.Cells[5].Z);
AssertEquals('original z unchanged', source.Cells[5].Z,
source.Cells[5].Z);
AssertTrue('clone z differs', clone.Cells[5].Z <> source.Cells[5].Z);
AssertTrue('clone header differs', clone.Header <> source.Header);
finally
clone.Free;
end;
finally
source.Free;
end;
end;
procedure TTestMapBlock.GetSizeMatchesSerialization;
var
block: TMapBlock;
begin
block := TMapBlock.Create(nil);
try
AssertEquals(MapBlockSize, block.GetSize);
finally
block.Free;
end;
end;
procedure TTestMapCell.ClonePreservesValues;
var
cell, clone: TMapCell;
begin
cell := TMapCell.Create(nil, nil, 3, 4);
try
cell.Z := 42;
cell.TileID := 1234;
clone := cell.Clone;
try
AssertEquals(3, clone.X);
AssertEquals(4, clone.Y);
AssertEquals(42, clone.Z);
AssertEquals(1234, clone.TileID);
finally
clone.Free;
end;
finally
cell.Free;
end;
end;
initialization
RegisterTests([TTestMapBlock, TTestMapCell]);
end.