Files
CentrED/tests/UTestStatics.pas
T
aksdb 99749a5168 ✅ 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.
2026-11-15 22:08:32 +01:00

192 lines
4.5 KiB
ObjectPascal

unit UTestStatics;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, fpcunit, testregistry,
UEnhancedMemoryStream, UGenericIndex, UStatics;
type
TTestStaticBlock = class(TTestCase)
published
procedure WriteReadRoundtrip;
procedure LoadsBlockAtOffsetZero;
procedure EmptyLookupLoadsNothing;
procedure ClonePreservesItems;
procedure SortOrdersByPriority;
end;
implementation
procedure PopulateBlock(ABlock: TStaticBlock);
var
item: TStaticItem;
begin
item := TStaticItem.Create(nil, nil, 0, 0);
item.X := 2;
item.Y := 3;
item.Z := 10;
item.TileID := 100;
item.Hue := 5;
ABlock.Items.Add(item);
item := TStaticItem.Create(nil, nil, 0, 0);
item.X := 2;
item.Y := 3;
item.Z := -20;
item.TileID := 200;
item.Hue := 0;
ABlock.Items.Add(item);
end;
procedure TTestStaticBlock.WriteReadRoundtrip;
var
source, loaded: TStaticBlock;
stream: TEnhancedMemoryStream;
index: TGenericIndex;
begin
source := TStaticBlock.Create(nil, nil, 1, 2);
try
PopulateBlock(source);
stream := TEnhancedMemoryStream.Create;
try
source.Write(stream);
AssertEquals('two items serialized', Int64(2 * 7), stream.Size);
stream.Position := 0;
index := TGenericIndex.Create(nil);
try
index.Lookup := 0;
index.Size := stream.Size;
loaded := TStaticBlock.Create(stream, index, 1, 2);
try
AssertEquals('item count', 2, loaded.Items.Count);
AssertEquals('item 0 tile', 100, loaded.Items[0].TileID);
AssertEquals('item 0 z', 10, loaded.Items[0].Z);
AssertEquals('item 0 hue', 5, loaded.Items[0].Hue);
AssertEquals('item 1 tile', 200, loaded.Items[1].TileID);
AssertEquals('item 1 z', -20, loaded.Items[1].Z);
finally
loaded.Free;
end;
finally
index.Free;
end;
finally
stream.Free;
end;
finally
source.Free;
end;
end;
procedure TTestStaticBlock.LoadsBlockAtOffsetZero;
var
source, loaded: TStaticBlock;
stream: TEnhancedMemoryStream;
index: TGenericIndex;
begin
source := TStaticBlock.Create(nil, nil, 0, 0);
try
PopulateBlock(source);
stream := TEnhancedMemoryStream.Create;
try
source.Write(stream);
stream.Position := 0;
index := TGenericIndex.Create(nil);
try
index.Lookup := 0; //offset zero is valid, especially in fresh files
index.Size := stream.Size;
loaded := TStaticBlock.Create(stream, index, 0, 0);
try
AssertEquals('block at offset zero must load', 2, loaded.Items.Count);
finally
loaded.Free;
end;
finally
index.Free;
end;
finally
stream.Free;
end;
finally
source.Free;
end;
end;
procedure TTestStaticBlock.EmptyLookupLoadsNothing;
var
stream: TEnhancedMemoryStream;
index: TGenericIndex;
loaded: TStaticBlock;
begin
stream := TEnhancedMemoryStream.Create;
try
index := TGenericIndex.Create(nil);
try
index.Lookup := -1;
index.Size := 0;
loaded := TStaticBlock.Create(stream, index, 0, 0);
try
AssertEquals('no items for empty lookup', 0, loaded.Items.Count);
finally
loaded.Free;
end;
finally
index.Free;
end;
finally
stream.Free;
end;
end;
procedure TTestStaticBlock.ClonePreservesItems;
var
source, clone: TStaticBlock;
i: Integer;
begin
source := TStaticBlock.Create(nil, nil, 0, 0);
try
PopulateBlock(source);
clone := source.Clone;
try
AssertEquals('item count cloned', source.Items.Count, clone.Items.Count);
for i := 0 to source.Items.Count - 1 do
begin
AssertEquals('tile ' + IntToStr(i), source.Items[i].TileID,
clone.Items[i].TileID);
AssertEquals('z ' + IntToStr(i), source.Items[i].Z, clone.Items[i].Z);
AssertEquals('hue ' + IntToStr(i), source.Items[i].Hue,
clone.Items[i].Hue);
end;
finally
clone.Free;
end;
finally
source.Free;
end;
end;
procedure TTestStaticBlock.SortOrdersByPriority;
var
block: TStaticBlock;
begin
block := TStaticBlock.Create(nil, nil, 0, 0);
try
PopulateBlock(block);
block.Items[0].Priority := 2;
block.Items[1].Priority := 1;
block.Sort;
AssertEquals('lower priority first', 1, block.Items[0].Priority);
AssertEquals('higher priority second', 2, block.Items[1].Priority);
finally
block.Free;
end;
end;
initialization
RegisterTests([TTestStaticBlock]);
end.