Files
CentrED/tests/UTestLocalization.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

127 lines
2.9 KiB
ObjectPascal

unit UTestLocalization;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, fpcunit, testregistry,
UEnhancedMemoryStream, ULocalization;
type
TTestLocalizationEntry = class(TTestCase)
published
procedure SerializeDeserializeRoundtrip;
procedure SizeMatchesSerializedBytes;
procedure SizeCountsEncodedBytesForNonASCII;
procedure NonASCIISurvivesRoundtrip;
end;
implementation
procedure TTestLocalizationEntry.SerializeDeserializeRoundtrip;
var
entry, loaded: TLocalizationEntry;
stream: TEnhancedMemoryStream;
begin
entry := TLocalizationEntry.Create;
try
entry.Number := 4711;
entry.Unknown := 7;
entry.Text := 'hello world';
stream := TEnhancedMemoryStream.Create;
try
entry.Serialize(stream);
stream.Position := 0;
loaded := TLocalizationEntry.Deserialize(stream);
try
AssertEquals('number survives', 4711, loaded.Number);
AssertEquals('unknown survives', 7, loaded.Unknown);
AssertEquals('text survives', 'hello world', loaded.Text);
finally
loaded.Free;
end;
finally
stream.Free;
end;
finally
entry.Free;
end;
end;
procedure TTestLocalizationEntry.SizeMatchesSerializedBytes;
var
entry: TLocalizationEntry;
stream: TEnhancedMemoryStream;
begin
entry := TLocalizationEntry.Create;
try
entry.Text := 'sample text';
stream := TEnhancedMemoryStream.Create;
try
entry.Serialize(stream);
AssertEquals('GetSize must match the serialized byte count',
Int64(entry.GetSize), stream.Size);
finally
stream.Free;
end;
finally
entry.Free;
end;
end;
procedure TTestLocalizationEntry.SizeCountsEncodedBytesForNonASCII;
var
entry: TLocalizationEntry;
stream: TEnhancedMemoryStream;
begin
entry := TLocalizationEntry.Create;
try
//'Grüße' is 5 characters but 7 bytes in UTF-8
entry.Text := 'Grüße';
stream := TEnhancedMemoryStream.Create;
try
entry.Serialize(stream);
AssertEquals('size must count encoded bytes, not characters',
Int64(entry.GetSize), stream.Size);
AssertTrue('utf-8 encoding of Grüße exceeds the character count',
entry.GetSize > 7 + 5);
finally
stream.Free;
end;
finally
entry.Free;
end;
end;
procedure TTestLocalizationEntry.NonASCIISurvivesRoundtrip;
var
entry, loaded: TLocalizationEntry;
stream: TEnhancedMemoryStream;
begin
entry := TLocalizationEntry.Create;
try
entry.Text := 'Grüße aus München';
stream := TEnhancedMemoryStream.Create;
try
entry.Serialize(stream);
stream.Position := 0;
loaded := TLocalizationEntry.Deserialize(stream);
try
AssertEquals('utf-8 text survives', 'Grüße aus München', loaded.Text);
finally
loaded.Free;
end;
finally
stream.Free;
end;
finally
entry.Free;
end;
end;
initialization
RegisterTests([TTestLocalizationEntry]);
end.