✅ 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:
@@ -0,0 +1,143 @@
|
||||
unit UTestConfig;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testregistry, UConfig;
|
||||
|
||||
function BuildTestConfigXML: string;
|
||||
function WriteTestConfigFile: string;
|
||||
|
||||
type
|
||||
TTestConfig = class(TTestCase)
|
||||
protected
|
||||
procedure SetUp; override;
|
||||
procedure TearDown; override;
|
||||
private
|
||||
FConfigPath: string;
|
||||
procedure ExpectLoadFailure(const AXML, ATag: string);
|
||||
published
|
||||
procedure ValidConfigLoads;
|
||||
procedure InvalidVersionRaises;
|
||||
procedure MissingAccountsRaise;
|
||||
procedure MissingMapRaises;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
function BuildTestConfigXML: string;
|
||||
begin
|
||||
Result :=
|
||||
'<CEDConfig Version="3">' +
|
||||
'<Port>2597</Port>' +
|
||||
'<Map>' +
|
||||
'<Map>map0.mul</Map>' +
|
||||
'<StaIdx>staidx0.mul</StaIdx>' +
|
||||
'<Statics>statics0.mul</Statics>' +
|
||||
'<Width>10</Width>' +
|
||||
'<Height>20</Height>' +
|
||||
'</Map>' +
|
||||
'<Tiledata>tiledata.mul</Tiledata>' +
|
||||
'<Radarcol>radarcol.mul</Radarcol>' +
|
||||
'<Regions>' +
|
||||
'<Region><Name>britain</Name><Area><Rect x1="0" y1="0" x2="10" y2="10"/></Area></Region>' +
|
||||
'<Region><Name>yew</Name><Area><Rect x1="5" y1="5" x2="15" y2="15"/></Area></Region>' +
|
||||
'</Regions>' +
|
||||
'<Accounts/>' +
|
||||
'</CEDConfig>';
|
||||
end;
|
||||
|
||||
function WriteTestConfigFile: string;
|
||||
var
|
||||
path: string;
|
||||
stream: TStringStream;
|
||||
begin
|
||||
path := GetTempDir + 'centred-test-config.xml';
|
||||
stream := TStringStream.Create(BuildTestConfigXML);
|
||||
try
|
||||
stream.SaveToFile(path);
|
||||
finally
|
||||
stream.Free;
|
||||
end;
|
||||
Result := path;
|
||||
end;
|
||||
|
||||
procedure TTestConfig.SetUp;
|
||||
begin
|
||||
FConfigPath := '';
|
||||
end;
|
||||
|
||||
procedure TTestConfig.TearDown;
|
||||
begin
|
||||
if FConfigPath <> '' then
|
||||
DeleteFile(FConfigPath);
|
||||
end;
|
||||
|
||||
procedure TTestConfig.ExpectLoadFailure(const AXML, ATag: string);
|
||||
var
|
||||
raised: Boolean;
|
||||
begin
|
||||
FConfigPath := GetTempDir + 'centred-test-config-' + ATag + '.xml';
|
||||
with TStringStream.Create(AXML) do
|
||||
try
|
||||
SaveToFile(FConfigPath);
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
raised := False;
|
||||
try
|
||||
TConfig.Create(FConfigPath).Free;
|
||||
except
|
||||
on E: Exception do
|
||||
raised := True;
|
||||
end;
|
||||
AssertTrue('loading must fail (' + ATag + ')', raised);
|
||||
end;
|
||||
|
||||
procedure TTestConfig.ValidConfigLoads;
|
||||
var
|
||||
config: TConfig;
|
||||
begin
|
||||
FConfigPath := WriteTestConfigFile;
|
||||
config := TConfig.Create(FConfigPath);
|
||||
try
|
||||
AssertEquals('port', 2597, config.Port);
|
||||
AssertEquals('map file', 'map0.mul', config.Map.MapFile);
|
||||
AssertEquals('width', 10, config.Map.Width);
|
||||
AssertEquals('height', 20, config.Map.Height);
|
||||
AssertEquals('tiledata', 'tiledata.mul', config.Tiledata);
|
||||
AssertEquals('radarcol', 'radarcol.mul', config.Radarcol);
|
||||
AssertEquals('regions', 2, config.Regions.Count);
|
||||
AssertTrue('region by name', config.Regions.Find('britain') <> nil);
|
||||
finally
|
||||
config.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestConfig.InvalidVersionRaises;
|
||||
var
|
||||
xml: string;
|
||||
begin
|
||||
xml := StringReplace(BuildTestConfigXML, 'Version="3"', 'Version="2"', []);
|
||||
ExpectLoadFailure(xml, 'badversion');
|
||||
end;
|
||||
|
||||
procedure TTestConfig.MissingAccountsRaise;
|
||||
begin
|
||||
ExpectLoadFailure(StringReplace(BuildTestConfigXML, '<Accounts/>', '', []),
|
||||
'noaccounts');
|
||||
end;
|
||||
|
||||
procedure TTestConfig.MissingMapRaises;
|
||||
begin
|
||||
ExpectLoadFailure(StringReplace(BuildTestConfigXML,
|
||||
'<Map><Map>map0.mul</Map><StaIdx>staidx0.mul</StaIdx><Statics>statics0.mul</Statics><Width>10</Width><Height>20</Height></Map>',
|
||||
'', []), 'nomap');
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterTests([TTestConfig]);
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user