✅ 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
+168
View File
@@ -0,0 +1,168 @@
unit UTestEnhancedMemoryStream;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, fpcunit, testregistry,
UStreamHelper, UEnhancedMemoryStream;
type
TTestEnhancedMemoryStream = class(TTestCase)
protected
procedure SetUp; override;
procedure TearDown; override;
published
procedure ReadWriteIntegers;
procedure ReadStringNullBasic;
procedure ReadStringNullStopsAtEndWithoutTerminator;
procedure ReadStringNullEmptyWindow;
procedure ReadStringNullNormalizesLineEnds;
procedure ReadStringNullDoesNotReadPastWindow;
procedure ReadStringBigUniNullBasic;
procedure ReadStringBigUniNullStopsAtEnd;
procedure ReadStringFixedConsumesExactlyLength;
procedure WriteStringFixedPadsWithZeros;
procedure WriteStringFixedKeepsLongValues;
end;
implementation
var
stream: TEnhancedMemoryStream;
procedure TTestEnhancedMemoryStream.SetUp;
begin
stream := TEnhancedMemoryStream.Create;
end;
procedure TTestEnhancedMemoryStream.TearDown;
begin
stream.Free;
end;
procedure TTestEnhancedMemoryStream.ReadWriteIntegers;
begin
stream.WriteCardinal($AABBCCDD);
stream.WriteWord($BEEF);
stream.WriteByte($42);
stream.WriteShortInt(-5);
stream.Position := 0;
AssertEquals('cardinal', Cardinal($AABBCCDD), stream.ReadCardinal);
AssertEquals('word', Word($BEEF), stream.ReadWord);
AssertEquals('byte', Byte($42), stream.ReadByte);
AssertEquals('shortint', ShortInt(-5), stream.ReadShortInt);
end;
procedure TTestEnhancedMemoryStream.ReadStringNullBasic;
begin
stream.WriteStringNull('alice');
stream.Position := 0;
AssertEquals('alice', stream.ReadStringNull);
AssertEquals('position after terminator', Int64(6), stream.Position);
end;
procedure TTestEnhancedMemoryStream.ReadStringNullStopsAtEndWithoutTerminator;
begin
stream.WriteByte(Ord('a'));
stream.WriteByte(Ord('b'));
stream.Position := 0;
AssertEquals('ab', stream.ReadStringNull);
AssertEquals('no overshoot on missing terminator', Int64(2), stream.Position);
end;
procedure TTestEnhancedMemoryStream.ReadStringNullEmptyWindow;
begin
stream.Lock(0, 0);
try
AssertEquals('', stream.ReadStringNull);
finally
stream.Unlock;
end;
end;
procedure TTestEnhancedMemoryStream.ReadStringNullNormalizesLineEnds;
begin
stream.WriteStringNull('a' + #10 + 'b' + #13 + 'c' + #13#10 + 'd');
stream.Position := 0;
AssertEquals('a' + #13#10 + 'b' + #13#10 + 'c' + #13#10 + 'd',
stream.ReadStringNull);
end;
procedure TTestEnhancedMemoryStream.ReadStringNullDoesNotReadPastWindow;
var
nextByte: Byte;
begin
stream.WriteStringNull('ab');
stream.WriteByte($99); //must not be consumed by the locked read
stream.Position := 0;
stream.Lock(0, 3); //only the null-terminated string
try
AssertEquals('ab', stream.ReadStringNull);
finally
stream.Unlock;
end;
nextByte := stream.ReadByte;
AssertEquals('window boundary must be respected', Byte($99), nextByte);
end;
procedure TTestEnhancedMemoryStream.ReadStringBigUniNullBasic;
begin
//big endian UTF-16
stream.WriteWord(Word(Ord('A')) shl 8);
stream.WriteWord(Word(Ord('B')) shl 8);
stream.WriteWord(0);
stream.Position := 0;
AssertEquals('AB', string(stream.ReadStringBigUniNull));
AssertEquals('position after terminator', Int64(6), stream.Position);
end;
procedure TTestEnhancedMemoryStream.ReadStringBigUniNullStopsAtEnd;
begin
stream.WriteWord(Word(Ord('A')) shl 8);
stream.Position := 0;
AssertEquals('A', string(stream.ReadStringBigUniNull));
AssertEquals('no overshoot', Int64(2), stream.Position);
end;
procedure TTestEnhancedMemoryStream.ReadStringFixedConsumesExactlyLength;
begin
stream.WriteStringNull('abcde');
stream.Position := 0;
AssertEquals('abc', stream.ReadStringFixed(3));
AssertEquals('consumed exactly the requested bytes', Int64(3), stream.Position);
end;
procedure TTestEnhancedMemoryStream.WriteStringFixedPadsWithZeros;
var
i: Integer;
buffer: array[0..4] of Byte;
begin
stream.WriteStringFixed('ab', 5);
AssertEquals('padded size', Int64(5), stream.Size);
stream.Position := 0;
stream.Read(buffer, 5);
AssertEquals('a', Char(buffer[0]));
AssertEquals('b', Char(buffer[1]));
for i := 2 to 4 do
AssertEquals('padding byte', 0, buffer[i]);
end;
procedure TTestEnhancedMemoryStream.WriteStringFixedKeepsLongValues;
var
buffer: array[0..2] of Byte;
begin
stream.WriteStringFixed('abcd', 3);
AssertEquals('truncated to target length', Int64(3), stream.Size);
stream.Position := 0;
stream.Read(buffer, 3);
AssertEquals('a', Char(buffer[0]));
AssertEquals('b', Char(buffer[1]));
AssertEquals('c', Char(buffer[2]));
end;
initialization
RegisterTests([TTestEnhancedMemoryStream]);
end.