✅ 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:
@@ -12,6 +12,13 @@ steps:
|
|||||||
- ~/lazarus/lazbuild --lazarusdir=~/lazarus --build-mode="Release.win32" -B Server/cedserver.lpi
|
- ~/lazarus/lazbuild --lazarusdir=~/lazarus --build-mode="Release.win32" -B Server/cedserver.lpi
|
||||||
- ~/lazarus/lazbuild --lazarusdir=~/lazarus --build-mode="Release.Linux.x64" -B Server/cedserver.lpi
|
- ~/lazarus/lazbuild --lazarusdir=~/lazarus --build-mode="Release.Linux.x64" -B Server/cedserver.lpi
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
image: git.aksdb.de/aksdb/centred:builder-221016
|
||||||
|
commands:
|
||||||
|
- ~/lazarus/lazbuild --lazarusdir=~/lazarus -B tests/unittests.lpi
|
||||||
|
- tests/bin/unittests --all --format=plain
|
||||||
|
- ~/lazarus/lazbuild --lazarusdir=~/lazarus -B tests/unittests-server.lpi
|
||||||
|
- tests/bin/unittests-server --all --format=plain
|
||||||
- name: Package
|
- name: Package
|
||||||
image: git.aksdb.de/aksdb/centred:builder-221016
|
image: git.aksdb.de/aksdb/centred:builder-221016
|
||||||
commands:
|
commands:
|
||||||
|
|||||||
@@ -23,3 +23,5 @@ Setup/*
|
|||||||
*.sh
|
*.sh
|
||||||
*.exe
|
*.exe
|
||||||
*.res
|
*.res
|
||||||
|
tests/bin/*
|
||||||
|
tests/obj-tests/*
|
||||||
|
|||||||
@@ -0,0 +1,192 @@
|
|||||||
|
unit UTestAccount;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, DOM, XMLRead, XMLWrite, fpcunit, testregistry,
|
||||||
|
UEnums, UInterfaces, UAccount, UConfig, UTestConfig;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestAccounts = class(TTestCase)
|
||||||
|
private
|
||||||
|
function BuildAccount: TAccount;
|
||||||
|
function AccountToXML(AAccount: TAccount): string;
|
||||||
|
protected
|
||||||
|
procedure SetUp; override;
|
||||||
|
procedure TearDown; override;
|
||||||
|
published
|
||||||
|
procedure CreateAndCheckPassword;
|
||||||
|
procedure UpdatePasswordInvalidatesOldPassword;
|
||||||
|
procedure HashDoesNotContainPassword;
|
||||||
|
procedure FindInList;
|
||||||
|
procedure SerializeDeserializeRoundtrip;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
MD5;
|
||||||
|
|
||||||
|
type
|
||||||
|
TDummyOwner = class(TObject, IInvalidate)
|
||||||
|
procedure Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDummyOwner.Invalidate;
|
||||||
|
begin
|
||||||
|
//notify chain ends here in tests
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
configPath: string;
|
||||||
|
dummyOwner: TDummyOwner;
|
||||||
|
|
||||||
|
procedure TTestAccounts.SetUp;
|
||||||
|
begin
|
||||||
|
//account serialization validates regions against the global config
|
||||||
|
configPath := WriteTestConfigFile;
|
||||||
|
Config := TConfig.Create(configPath);
|
||||||
|
dummyOwner := TDummyOwner.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestAccounts.TearDown;
|
||||||
|
begin
|
||||||
|
FreeAndNil(Config);
|
||||||
|
dummyOwner.Free;
|
||||||
|
DeleteFile(configPath);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTestAccounts.BuildAccount: TAccount;
|
||||||
|
var
|
||||||
|
regions: TStringList;
|
||||||
|
begin
|
||||||
|
regions := TStringList.Create;
|
||||||
|
regions.Add('britain');
|
||||||
|
regions.Add('yew');
|
||||||
|
Result := TAccount.Create(dummyOwner, 'alice', 'secret', alNormal, regions);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTestAccounts.AccountToXML(AAccount: TAccount): string;
|
||||||
|
var
|
||||||
|
doc: TXMLDocument;
|
||||||
|
root: TDOMElement;
|
||||||
|
stream: TStringStream;
|
||||||
|
begin
|
||||||
|
doc := TXMLDocument.Create;
|
||||||
|
try
|
||||||
|
root := doc.CreateElement('accounts');
|
||||||
|
doc.AppendChild(root);
|
||||||
|
AAccount.Serialize(root);
|
||||||
|
stream := TStringStream.Create('');
|
||||||
|
try
|
||||||
|
WriteXMLFile(doc, stream);
|
||||||
|
Result := stream.DataString;
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
doc.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestAccounts.CreateAndCheckPassword;
|
||||||
|
var
|
||||||
|
account: TAccount;
|
||||||
|
begin
|
||||||
|
account := BuildAccount;
|
||||||
|
try
|
||||||
|
AssertEquals('name', 'alice', account.Name);
|
||||||
|
AssertTrue('correct password accepted', account.CheckPassword('secret'));
|
||||||
|
AssertFalse('wrong password rejected', account.CheckPassword('wrong'));
|
||||||
|
finally
|
||||||
|
account.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestAccounts.UpdatePasswordInvalidatesOldPassword;
|
||||||
|
var
|
||||||
|
account: TAccount;
|
||||||
|
begin
|
||||||
|
account := BuildAccount;
|
||||||
|
try
|
||||||
|
account.UpdatePassword('newpass');
|
||||||
|
AssertFalse('old password must stop working', account.CheckPassword('secret'));
|
||||||
|
AssertTrue('new password accepted', account.CheckPassword('newpass'));
|
||||||
|
finally
|
||||||
|
account.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestAccounts.HashDoesNotContainPassword;
|
||||||
|
var
|
||||||
|
account: TAccount;
|
||||||
|
begin
|
||||||
|
account := BuildAccount;
|
||||||
|
try
|
||||||
|
AssertTrue('stored hash must not contain the plain password',
|
||||||
|
Pos('secret', account.PasswordHash) = 0);
|
||||||
|
finally
|
||||||
|
account.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestAccounts.FindInList;
|
||||||
|
var
|
||||||
|
list: TAccountList;
|
||||||
|
account: TAccount;
|
||||||
|
begin
|
||||||
|
list := TAccountList.Create(dummyOwner);
|
||||||
|
try
|
||||||
|
account := BuildAccount;
|
||||||
|
list.Add(account);
|
||||||
|
AssertSame('find existing', account, list.Find('alice'));
|
||||||
|
AssertEquals('index', 0, list.IndexOf('alice'));
|
||||||
|
AssertTrue('missing is nil', list.Find('bob') = nil);
|
||||||
|
finally
|
||||||
|
list.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestAccounts.SerializeDeserializeRoundtrip;
|
||||||
|
var
|
||||||
|
account, loaded: TAccount;
|
||||||
|
xml: string;
|
||||||
|
stream: TStringStream;
|
||||||
|
doc: TXMLDocument;
|
||||||
|
begin
|
||||||
|
account := BuildAccount;
|
||||||
|
try
|
||||||
|
xml := AccountToXML(account);
|
||||||
|
stream := TStringStream.Create(xml);
|
||||||
|
try
|
||||||
|
ReadXMLFile(doc, stream);
|
||||||
|
try
|
||||||
|
loaded := TAccount.Deserialize(nil, doc.DocumentElement);
|
||||||
|
try
|
||||||
|
AssertEquals('name survives', 'alice', loaded.Name);
|
||||||
|
AssertTrue('password hash survives',
|
||||||
|
loaded.CheckPassword('secret'));
|
||||||
|
AssertEquals('access level survives', Ord(alNormal),
|
||||||
|
Ord(loaded.AccessLevel));
|
||||||
|
AssertEquals('regions survive', 2, loaded.Regions.Count);
|
||||||
|
AssertEquals('region name', 'britain', loaded.Regions[0]);
|
||||||
|
finally
|
||||||
|
loaded.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
doc.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
account.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestAccounts]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
unit UTestArt;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry,
|
||||||
|
UEnhancedMemoryStream, UGenericIndex, UMulBlock, UArt;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestArt = class(TTestCase)
|
||||||
|
private
|
||||||
|
function BuildLandBlock: TMemoryStream;
|
||||||
|
function BuildStaticBlock: TMemoryStream;
|
||||||
|
function LandBlockSize: Integer;
|
||||||
|
published
|
||||||
|
procedure LandRoundtripIsByteIdentical;
|
||||||
|
procedure StaticRoundtripIsByteIdentical;
|
||||||
|
procedure LandRejectsWrongDimensions;
|
||||||
|
procedure StaticRejectsEmptyDimensions;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
function TTestArt.LandBlockSize: Integer;
|
||||||
|
begin
|
||||||
|
//22 rows of 2,4,...,44 words plus 22 rows of 44,42,...,2 words
|
||||||
|
Result := (2 + 44) * 22 * 2;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTestArt.BuildLandBlock: TMemoryStream;
|
||||||
|
var
|
||||||
|
x, y: Integer;
|
||||||
|
startCol, words, i: Integer;
|
||||||
|
color: Word;
|
||||||
|
begin
|
||||||
|
Result := TMemoryStream.Create;
|
||||||
|
for y := 0 to 43 do
|
||||||
|
begin
|
||||||
|
if y < 22 then
|
||||||
|
begin
|
||||||
|
startCol := 21 - y;
|
||||||
|
words := (y + 1) * 2;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
startCol := y - 22;
|
||||||
|
words := (44 - y) * 2;
|
||||||
|
end;
|
||||||
|
for i := 0 to words - 1 do
|
||||||
|
begin
|
||||||
|
x := startCol + i;
|
||||||
|
//deterministic pattern, alpha bit set like real land tiles; channel
|
||||||
|
//values are 0 or 31 so they survive the 16 to 32 to 16 bit conversion
|
||||||
|
case (x + y) mod 4 of
|
||||||
|
0: color := $8000;
|
||||||
|
1: color := $8000 or $7C00;
|
||||||
|
2: color := $8000 or $03E0;
|
||||||
|
3: color := $8000 or $001F;
|
||||||
|
end;
|
||||||
|
Result.Write(color, SizeOf(Word));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTestArt.BuildStaticBlock: TMemoryStream;
|
||||||
|
var
|
||||||
|
row, i: Integer;
|
||||||
|
color: Word;
|
||||||
|
offset, runLen: Word;
|
||||||
|
lookup: array[0..3] of Word;
|
||||||
|
begin
|
||||||
|
Result := TMemoryStream.Create;
|
||||||
|
Result.WriteDWord(1); //header
|
||||||
|
Result.WriteWord(8); //width
|
||||||
|
Result.WriteWord(4); //height
|
||||||
|
//row offsets in words, relative to the start of the pixel data
|
||||||
|
//row length: offset + run + 3 colors + end marker = 14 bytes = 7 words
|
||||||
|
//last row: offset + run + 2 colors + end marker = 12 bytes
|
||||||
|
lookup[0] := 0;
|
||||||
|
lookup[1] := 7;
|
||||||
|
lookup[2] := 14;
|
||||||
|
lookup[3] := 21;
|
||||||
|
for i := 0 to 3 do
|
||||||
|
Result.WriteWord(lookup[i]);
|
||||||
|
for row := 0 to 3 do
|
||||||
|
begin
|
||||||
|
if row < 3 then
|
||||||
|
begin
|
||||||
|
offset := 0;
|
||||||
|
runLen := 3;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
offset := 1;
|
||||||
|
runLen := 2;
|
||||||
|
end;
|
||||||
|
Result.Write(offset, SizeOf(Word));
|
||||||
|
Result.Write(runLen, SizeOf(Word));
|
||||||
|
for i := 0 to runLen - 1 do
|
||||||
|
begin
|
||||||
|
//channels 0 or 31 survive the 16 to 32 to 16 bit conversion
|
||||||
|
case (row + i) mod 4 of
|
||||||
|
0: color := $0000;
|
||||||
|
1: color := $7C00;
|
||||||
|
2: color := $03E0;
|
||||||
|
3: color := $001F;
|
||||||
|
end;
|
||||||
|
Result.Write(color, SizeOf(Word));
|
||||||
|
end;
|
||||||
|
offset := 0;
|
||||||
|
runLen := 0;
|
||||||
|
Result.Write(offset, SizeOf(Word));
|
||||||
|
Result.Write(runLen, SizeOf(Word));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestArt.LandRoundtripIsByteIdentical;
|
||||||
|
var
|
||||||
|
block, output: TMemoryStream;
|
||||||
|
index: TGenericIndex;
|
||||||
|
art: TArt;
|
||||||
|
decoded, encoded: PByteArray;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
block := BuildLandBlock;
|
||||||
|
try
|
||||||
|
index := TGenericIndex.Create(nil);
|
||||||
|
try
|
||||||
|
index.Lookup := 0;
|
||||||
|
index.Size := block.Size;
|
||||||
|
block.Position := 0;
|
||||||
|
art := TArt.Create(block, index, atLand);
|
||||||
|
try
|
||||||
|
AssertEquals('decoded size matches block', Int64(LandBlockSize),
|
||||||
|
Int64(art.GetSize));
|
||||||
|
output := TMemoryStream.Create;
|
||||||
|
try
|
||||||
|
art.Write(output);
|
||||||
|
AssertEquals('re-encoded size', Int64(LandBlockSize),
|
||||||
|
Int64(output.Size));
|
||||||
|
decoded := block.Memory;
|
||||||
|
encoded := output.Memory;
|
||||||
|
for i := 0 to LandBlockSize - 1 do
|
||||||
|
if decoded^[i] <> encoded^[i] then
|
||||||
|
begin
|
||||||
|
AssertEquals('pixel data at byte ' + IntToStr(i),
|
||||||
|
decoded^[i], encoded^[i]);
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
AssertTrue('roundtrip must be byte identical', True);
|
||||||
|
finally
|
||||||
|
output.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
art.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
index.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
block.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestArt.StaticRoundtripIsByteIdentical;
|
||||||
|
var
|
||||||
|
block, output: TMemoryStream;
|
||||||
|
index: TGenericIndex;
|
||||||
|
art: TArt;
|
||||||
|
decoded, encoded: PByteArray;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
block := BuildStaticBlock;
|
||||||
|
try
|
||||||
|
index := TGenericIndex.Create(nil);
|
||||||
|
try
|
||||||
|
index.Lookup := 0;
|
||||||
|
index.Size := block.Size;
|
||||||
|
block.Position := 0;
|
||||||
|
art := TArt.Create(block, index, atStatic);
|
||||||
|
try
|
||||||
|
AssertEquals('decoded size matches block', Int64(block.Size),
|
||||||
|
Int64(art.GetSize));
|
||||||
|
output := TMemoryStream.Create;
|
||||||
|
try
|
||||||
|
art.Write(output);
|
||||||
|
AssertEquals('re-encoded size', Int64(block.Size),
|
||||||
|
Int64(output.Size));
|
||||||
|
decoded := block.Memory;
|
||||||
|
encoded := output.Memory;
|
||||||
|
for i := 0 to block.Size - 1 do
|
||||||
|
if decoded^[i] <> encoded^[i] then
|
||||||
|
begin
|
||||||
|
AssertEquals('pixel data at byte ' + IntToStr(i),
|
||||||
|
decoded^[i], encoded^[i]);
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
AssertTrue('roundtrip must be byte identical', True);
|
||||||
|
finally
|
||||||
|
output.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
art.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
index.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
block.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestArt.LandRejectsWrongDimensions;
|
||||||
|
var
|
||||||
|
block: TMemoryStream;
|
||||||
|
index: TGenericIndex;
|
||||||
|
art: TArt;
|
||||||
|
begin
|
||||||
|
block := TMemoryStream.Create; //not 44x44 worth of data
|
||||||
|
try
|
||||||
|
index := TGenericIndex.Create(nil);
|
||||||
|
try
|
||||||
|
index.Lookup := 0;
|
||||||
|
index.Size := 0;
|
||||||
|
art := TArt.Create(nil, index, atLand);
|
||||||
|
try
|
||||||
|
AssertEquals('empty output for invalid dimensions', Int64(0),
|
||||||
|
Int64(art.GetSize));
|
||||||
|
finally
|
||||||
|
art.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
index.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
block.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestArt.StaticRejectsEmptyDimensions;
|
||||||
|
var
|
||||||
|
index: TGenericIndex;
|
||||||
|
art: TArt;
|
||||||
|
begin
|
||||||
|
index := TGenericIndex.Create(nil);
|
||||||
|
try
|
||||||
|
index.Lookup := 0;
|
||||||
|
index.Size := 0;
|
||||||
|
art := TArt.Create(nil, index, atStatic);
|
||||||
|
try
|
||||||
|
AssertEquals('empty output for empty dimensions', Int64(0),
|
||||||
|
Int64(art.GetSize));
|
||||||
|
finally
|
||||||
|
art.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
index.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestArt]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
unit UTestBufferedStreams;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry,
|
||||||
|
UEnhancedMemoryStream, UBufferedStreams;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestBufferedStream = class(TTestCase)
|
||||||
|
protected
|
||||||
|
procedure SetUp; override;
|
||||||
|
procedure TearDown; override;
|
||||||
|
published
|
||||||
|
procedure RefreshLoadsBaseContent;
|
||||||
|
procedure FlushWritesAppendedData;
|
||||||
|
procedure FlushWritesShrunkenData;
|
||||||
|
procedure ReaderWriteGoesThroughToBase;
|
||||||
|
procedure ReaderFlushIsHarmless;
|
||||||
|
procedure ReaderReadReturnsBaseContent;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
var
|
||||||
|
base: TMemoryStream;
|
||||||
|
buffered: TBufferedStream;
|
||||||
|
reader: TBufferedReader;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.SetUp;
|
||||||
|
begin
|
||||||
|
base := TMemoryStream.Create;
|
||||||
|
buffered := nil;
|
||||||
|
reader := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.TearDown;
|
||||||
|
begin
|
||||||
|
FreeAndNil(buffered);
|
||||||
|
FreeAndNil(reader);
|
||||||
|
FreeAndNil(base);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.RefreshLoadsBaseContent;
|
||||||
|
var
|
||||||
|
buffer: array[0..4] of Byte;
|
||||||
|
begin
|
||||||
|
base.Write(PChar('hello')^, 5);
|
||||||
|
buffered := TBufferedStream.Create(base, False);
|
||||||
|
AssertEquals('size mirrors base', Int64(5), buffered.Size);
|
||||||
|
buffered.Position := 0;
|
||||||
|
buffered.Read(buffer, 5);
|
||||||
|
AssertEquals('h', Char(buffer[0]));
|
||||||
|
AssertEquals('e', Char(buffer[1]));
|
||||||
|
AssertEquals('l', Char(buffer[2]));
|
||||||
|
AssertEquals('l', Char(buffer[3]));
|
||||||
|
AssertEquals('o', Char(buffer[4]));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.FlushWritesAppendedData;
|
||||||
|
begin
|
||||||
|
base.Write(PChar('hello')^, 5);
|
||||||
|
buffered := TBufferedStream.Create(base, False);
|
||||||
|
buffered.Seek(0, soFromEnd);
|
||||||
|
buffered.Write(PChar(' world')^, 6);
|
||||||
|
buffered.Flush;
|
||||||
|
AssertEquals('base received appended data', Int64(11), base.Size);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.FlushWritesShrunkenData;
|
||||||
|
begin
|
||||||
|
base.Write(PChar('hello')^, 5);
|
||||||
|
buffered := TBufferedStream.Create(base, False);
|
||||||
|
buffered.Size := 3;
|
||||||
|
buffered.Flush;
|
||||||
|
AssertEquals('base follows shrink', Int64(3), base.Size);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.ReaderWriteGoesThroughToBase;
|
||||||
|
begin
|
||||||
|
reader := TBufferedReader.Create(base, False);
|
||||||
|
reader.Seek(0, soFromEnd);
|
||||||
|
reader.Write(PChar('data')^, 4);
|
||||||
|
AssertEquals('base has the written bytes', Int64(4), base.Size);
|
||||||
|
AssertEquals('reader agrees on size', Int64(4), reader.Size);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.ReaderFlushIsHarmless;
|
||||||
|
begin
|
||||||
|
base.Write(PChar('data')^, 4);
|
||||||
|
reader := TBufferedReader.Create(base, False);
|
||||||
|
reader.Flush; //must not truncate or raise
|
||||||
|
AssertEquals('base intact after flush', Int64(4), base.Size);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBufferedStream.ReaderReadReturnsBaseContent;
|
||||||
|
var
|
||||||
|
buffer: array[0..3] of Byte;
|
||||||
|
begin
|
||||||
|
base.Write(PChar('abcd')^, 4);
|
||||||
|
reader := TBufferedReader.Create(base, False);
|
||||||
|
AssertEquals('reader sees base size', Int64(4), reader.Size);
|
||||||
|
reader.Position := 0;
|
||||||
|
reader.Read(buffer, 4);
|
||||||
|
AssertEquals('a', Char(buffer[0]));
|
||||||
|
AssertEquals('b', Char(buffer[1]));
|
||||||
|
AssertEquals('c', Char(buffer[2]));
|
||||||
|
AssertEquals('d', Char(buffer[3]));
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestBufferedStream]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
unit UTestCacheManager;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry, UCacheManager;
|
||||||
|
|
||||||
|
type
|
||||||
|
TIntegerCache = specialize TCacheManager<TObject>;
|
||||||
|
|
||||||
|
TTestCacheManager = class(TTestCase)
|
||||||
|
published
|
||||||
|
procedure RejectsSizeBelowTwo;
|
||||||
|
procedure StoreAfterMissKeepsInvariant;
|
||||||
|
procedure StoreTwiceKeepsInvariant;
|
||||||
|
procedure HitReordersWithoutBreakingStore;
|
||||||
|
procedure RemoveIDKeepsInvariant;
|
||||||
|
procedure ClearRemovesAllObjects;
|
||||||
|
procedure DiscardIDKeepsEntryUsable;
|
||||||
|
procedure DestroyFreesAllEntries;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure TTestCacheManager.RejectsSizeBelowTwo;
|
||||||
|
var
|
||||||
|
raised: Boolean;
|
||||||
|
begin
|
||||||
|
raised := False;
|
||||||
|
try
|
||||||
|
TIntegerCache.Create(1).Free;
|
||||||
|
except
|
||||||
|
on E: Exception do
|
||||||
|
raised := True;
|
||||||
|
end;
|
||||||
|
AssertTrue('size 1 must be rejected', raised);
|
||||||
|
|
||||||
|
raised := False;
|
||||||
|
try
|
||||||
|
TIntegerCache.Create(0).Free;
|
||||||
|
except
|
||||||
|
on E: Exception do
|
||||||
|
raised := True;
|
||||||
|
end;
|
||||||
|
AssertTrue('size 0 must be rejected', raised);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCacheManager.StoreAfterMissKeepsInvariant;
|
||||||
|
var
|
||||||
|
cache: TIntegerCache;
|
||||||
|
objects: array[0..15] of TObject;
|
||||||
|
resultObj: TObject;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
objects[i] := TObject.Create;
|
||||||
|
cache := TIntegerCache.Create(8);
|
||||||
|
try
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
begin
|
||||||
|
AssertFalse('query must miss', cache.QueryID(i, resultObj));
|
||||||
|
cache.StoreID(i, objects[i]);
|
||||||
|
end;
|
||||||
|
//entries 0..7 were evicted (and freed by the cache), 8..15 must hit
|
||||||
|
AssertTrue('most recent entry must hit', cache.QueryID(15, resultObj));
|
||||||
|
AssertSame('hit must return the stored object', objects[15], resultObj);
|
||||||
|
AssertTrue('oldest surviving entry must hit', cache.QueryID(8, resultObj));
|
||||||
|
AssertFalse('evicted entry must miss', cache.QueryID(7, resultObj));
|
||||||
|
finally
|
||||||
|
cache.Free; //frees the remaining owned objects
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCacheManager.StoreTwiceKeepsInvariant;
|
||||||
|
var
|
||||||
|
cache: TIntegerCache;
|
||||||
|
objA, objB, resultObj: TObject;
|
||||||
|
begin
|
||||||
|
objA := TObject.Create;
|
||||||
|
objB := TObject.Create;
|
||||||
|
cache := TIntegerCache.Create(4);
|
||||||
|
try
|
||||||
|
AssertFalse(cache.QueryID(1, resultObj));
|
||||||
|
cache.StoreID(1, objA);
|
||||||
|
cache.StoreID(2, objB); //used to nil-deref via a stale tail pointer
|
||||||
|
AssertTrue(cache.QueryID(2, resultObj));
|
||||||
|
AssertSame(objB, resultObj);
|
||||||
|
AssertTrue(cache.QueryID(1, resultObj));
|
||||||
|
AssertSame(objA, resultObj);
|
||||||
|
finally
|
||||||
|
cache.Free; //frees objA and objB
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCacheManager.HitReordersWithoutBreakingStore;
|
||||||
|
var
|
||||||
|
cache: TIntegerCache;
|
||||||
|
objects: array[0..6] of TObject;
|
||||||
|
resultObj: TObject;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
objects[i] := TObject.Create;
|
||||||
|
cache := TIntegerCache.Create(8);
|
||||||
|
try
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
begin
|
||||||
|
AssertFalse(cache.QueryID(i, resultObj));
|
||||||
|
cache.StoreID(i, objects[i]);
|
||||||
|
end;
|
||||||
|
//hit an entry that is not at the front, then store again
|
||||||
|
AssertTrue(cache.QueryID(2, resultObj));
|
||||||
|
AssertSame(objects[2], resultObj);
|
||||||
|
AssertFalse(cache.QueryID(7, resultObj));
|
||||||
|
cache.StoreID(7, TObject.Create); //entry 7 becomes front
|
||||||
|
AssertTrue(cache.QueryID(2, resultObj));
|
||||||
|
AssertSame(objects[2], resultObj);
|
||||||
|
AssertTrue(cache.QueryID(5, resultObj));
|
||||||
|
AssertSame(objects[5], resultObj);
|
||||||
|
finally
|
||||||
|
cache.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCacheManager.RemoveIDKeepsInvariant;
|
||||||
|
var
|
||||||
|
cache: TIntegerCache;
|
||||||
|
objects: array[0..3] of TObject;
|
||||||
|
obj5, resultObj: TObject;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
objects[i] := TObject.Create;
|
||||||
|
obj5 := TObject.Create;
|
||||||
|
cache := TIntegerCache.Create(4);
|
||||||
|
try
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
begin
|
||||||
|
AssertFalse(cache.QueryID(i, resultObj));
|
||||||
|
cache.StoreID(i, objects[i]);
|
||||||
|
end;
|
||||||
|
cache.RemoveID(3); //frees objects[3]
|
||||||
|
cache.RemoveID(0); //frees objects[0]
|
||||||
|
AssertFalse('removed entry must miss', cache.QueryID(3, resultObj));
|
||||||
|
AssertFalse('removed entry must miss', cache.QueryID(0, resultObj));
|
||||||
|
cache.StoreID(5, obj5); //store right after removals
|
||||||
|
AssertTrue(cache.QueryID(5, resultObj));
|
||||||
|
AssertSame(obj5, resultObj);
|
||||||
|
AssertTrue(cache.QueryID(2, resultObj));
|
||||||
|
AssertTrue(cache.QueryID(1, resultObj));
|
||||||
|
finally
|
||||||
|
cache.Free; //frees objects[1], objects[2], obj5
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCacheManager.ClearRemovesAllObjects;
|
||||||
|
var
|
||||||
|
cache: TIntegerCache;
|
||||||
|
objects: array[0..2] of TObject;
|
||||||
|
replacement, resultObj: TObject;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
objects[i] := TObject.Create;
|
||||||
|
cache := TIntegerCache.Create(4);
|
||||||
|
try
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
begin
|
||||||
|
AssertFalse(cache.QueryID(i, resultObj));
|
||||||
|
cache.StoreID(i, objects[i]);
|
||||||
|
end;
|
||||||
|
cache.Clear; //frees the objects
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
AssertFalse('cleared entry must miss', cache.QueryID(i, resultObj));
|
||||||
|
replacement := TObject.Create;
|
||||||
|
cache.StoreID(9, replacement); //entries must be reusable afterwards
|
||||||
|
AssertTrue(cache.QueryID(9, resultObj));
|
||||||
|
AssertSame(replacement, resultObj);
|
||||||
|
finally
|
||||||
|
cache.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCacheManager.DiscardIDKeepsEntryUsable;
|
||||||
|
var
|
||||||
|
cache: TIntegerCache;
|
||||||
|
objA, objB, resultObj: TObject;
|
||||||
|
begin
|
||||||
|
objA := TObject.Create;
|
||||||
|
objB := TObject.Create;
|
||||||
|
cache := TIntegerCache.Create(4);
|
||||||
|
try
|
||||||
|
AssertFalse(cache.QueryID(1, resultObj));
|
||||||
|
cache.StoreID(1, objA);
|
||||||
|
cache.DiscardID(1); //entry detached, ownership back to the caller
|
||||||
|
AssertFalse('discarded entry must miss', cache.QueryID(1, resultObj));
|
||||||
|
cache.StoreID(2, objB);
|
||||||
|
AssertTrue(cache.QueryID(2, resultObj));
|
||||||
|
AssertSame(objB, resultObj);
|
||||||
|
finally
|
||||||
|
cache.Free; //frees objB only
|
||||||
|
objA.Free; //discarded object is ours again
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestCacheManager.DestroyFreesAllEntries;
|
||||||
|
var
|
||||||
|
cache: TIntegerCache;
|
||||||
|
objects: array[0..3] of TObject;
|
||||||
|
resultObj: TObject;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
objects[i] := TObject.Create;
|
||||||
|
cache := TIntegerCache.Create(4);
|
||||||
|
for i := 0 to High(objects) do
|
||||||
|
begin
|
||||||
|
AssertFalse(cache.QueryID(i, resultObj));
|
||||||
|
cache.StoreID(i, objects[i]);
|
||||||
|
end;
|
||||||
|
AssertTrue(cache.QueryID(3, resultObj)); //move-to-front before destroy
|
||||||
|
cache.Free; //must not crash, must free all entries
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestCacheManager]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -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.
|
||||||
@@ -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.
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
unit UTestLandscapeBounds;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry, UMap, UTiledata, ULandscape;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestLandscapeBounds = class(TTestCase)
|
||||||
|
private
|
||||||
|
FMap: TMemoryStream;
|
||||||
|
FStatics: TMemoryStream;
|
||||||
|
FStaIdx: TMemoryStream;
|
||||||
|
FTiledata: TMemoryStream;
|
||||||
|
FRadarColPath: string;
|
||||||
|
FLandscape: TLandscape;
|
||||||
|
procedure BuildStreams;
|
||||||
|
procedure BuildLandscape;
|
||||||
|
protected
|
||||||
|
procedure SetUp; override;
|
||||||
|
procedure TearDown; override;
|
||||||
|
published
|
||||||
|
procedure ValidStreamSizesValidate;
|
||||||
|
procedure BlockSubscriptionAtOrigin;
|
||||||
|
procedure BlockSubscriptionOutsideIsNil;
|
||||||
|
procedure MapCellInsideBlock;
|
||||||
|
procedure MapCellOutsideIsNil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
UEnhancedMemoryStream;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.SetUp;
|
||||||
|
begin
|
||||||
|
FMap := nil;
|
||||||
|
FStatics := nil;
|
||||||
|
FStaIdx := nil;
|
||||||
|
FTiledata := nil;
|
||||||
|
FLandscape := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.TearDown;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FLandscape);
|
||||||
|
FreeAndNil(FMap);
|
||||||
|
FreeAndNil(FStatics);
|
||||||
|
FreeAndNil(FStaIdx);
|
||||||
|
FreeAndNil(FTiledata);
|
||||||
|
if FRadarColPath <> '' then
|
||||||
|
DeleteFile(FRadarColPath);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.BuildStreams;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
//one map block: header + 64 cells (tile id word + altitude byte)
|
||||||
|
FMap := TMemoryStream.Create;
|
||||||
|
FMap.WriteDWord(0);
|
||||||
|
for i := 0 to 63 do
|
||||||
|
begin
|
||||||
|
FMap.WriteWord(0);
|
||||||
|
FMap.WriteByte(5);
|
||||||
|
end;
|
||||||
|
|
||||||
|
//one empty static index entry
|
||||||
|
FStaIdx := TMemoryStream.Create;
|
||||||
|
FStaIdx.WriteDWord(Cardinal($FFFFFFFF));
|
||||||
|
FStaIdx.WriteDWord(0);
|
||||||
|
FStaIdx.WriteDWord(0);
|
||||||
|
|
||||||
|
FStatics := TMemoryStream.Create;
|
||||||
|
|
||||||
|
//legacy tiledata: 512 land groups worth of zeroed entries
|
||||||
|
FTiledata := TMemoryStream.Create;
|
||||||
|
for i := 0 to 512 * LandTileGroupSize - 1 do
|
||||||
|
FTiledata.WriteByte(0);
|
||||||
|
|
||||||
|
//radarcol: one color, must live on disk
|
||||||
|
FRadarColPath := GetTempDir + 'centred-test-radarcol.mul';
|
||||||
|
with TFileStream.Create(FRadarColPath, fmCreate) do
|
||||||
|
try
|
||||||
|
WriteWord(Word($3173));
|
||||||
|
finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.BuildLandscape;
|
||||||
|
var
|
||||||
|
valid: Boolean;
|
||||||
|
begin
|
||||||
|
FLandscape := TLandscape.Create(FMap, FStatics, FStaIdx, FTiledata,
|
||||||
|
FRadarColPath, 1, 1, valid);
|
||||||
|
AssertTrue('fixture landscape must validate', valid);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.ValidStreamSizesValidate;
|
||||||
|
begin
|
||||||
|
BuildStreams;
|
||||||
|
BuildLandscape;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.BlockSubscriptionAtOrigin;
|
||||||
|
begin
|
||||||
|
BuildStreams;
|
||||||
|
BuildLandscape;
|
||||||
|
AssertTrue('subscription list exists for block 0,0',
|
||||||
|
FLandscape.BlockSubscriptions[0, 0] <> nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.BlockSubscriptionOutsideIsNil;
|
||||||
|
begin
|
||||||
|
BuildStreams;
|
||||||
|
BuildLandscape;
|
||||||
|
//x = width must be rejected (used to read past the array)
|
||||||
|
AssertTrue('x outside must be nil', FLandscape.BlockSubscriptions[1, 0] = nil);
|
||||||
|
//y = height must be rejected
|
||||||
|
AssertTrue('y outside must be nil', FLandscape.BlockSubscriptions[0, 1] = nil);
|
||||||
|
AssertTrue('both outside must be nil',
|
||||||
|
FLandscape.BlockSubscriptions[1, 1] = nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.MapCellInsideBlock;
|
||||||
|
var
|
||||||
|
cell: TMapCell;
|
||||||
|
begin
|
||||||
|
BuildStreams;
|
||||||
|
BuildLandscape;
|
||||||
|
cell := FLandscape.MapCell[0, 0];
|
||||||
|
AssertTrue('cell 0,0 exists', cell <> nil);
|
||||||
|
AssertEquals('altitude from the fixture', 5, cell.Altitude);
|
||||||
|
cell := FLandscape.MapCell[7, 7];
|
||||||
|
AssertTrue('cell 7,7 exists', cell <> nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLandscapeBounds.MapCellOutsideIsNil;
|
||||||
|
begin
|
||||||
|
BuildStreams;
|
||||||
|
BuildLandscape;
|
||||||
|
AssertTrue('x = cell width is outside',
|
||||||
|
FLandscape.MapCell[8, 0] = nil);
|
||||||
|
AssertTrue('y = cell height is outside',
|
||||||
|
FLandscape.MapCell[0, 8] = nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestLandscapeBounds]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
unit UTestLinkedList;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry, ULinkedList;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestLinkedList = class(TTestCase)
|
||||||
|
protected
|
||||||
|
procedure SetUp; override;
|
||||||
|
procedure TearDown; override;
|
||||||
|
published
|
||||||
|
procedure AddAndIterate;
|
||||||
|
procedure DeleteOnlyRemovesFirstMatch;
|
||||||
|
procedure DeleteHead;
|
||||||
|
procedure DeleteTail;
|
||||||
|
procedure DeleteMiddle;
|
||||||
|
procedure DeleteByID;
|
||||||
|
procedure DeleteMissingIsHarmless;
|
||||||
|
procedure ClearEmptiesList;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
var
|
||||||
|
items: array[0..2] of Pointer;
|
||||||
|
list: TLinkedList;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.SetUp;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to High(items) do
|
||||||
|
items[i] := Pointer(PtrInt(100 + i));
|
||||||
|
list := TLinkedList.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.TearDown;
|
||||||
|
begin
|
||||||
|
list.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.AddAndIterate;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
count: Integer;
|
||||||
|
begin
|
||||||
|
list.Add(0, items[0]);
|
||||||
|
list.Add(0, items[1]);
|
||||||
|
list.Add(0, items[2]);
|
||||||
|
count := 0;
|
||||||
|
item := nil;
|
||||||
|
while list.Iterate(item) do
|
||||||
|
begin
|
||||||
|
case count of
|
||||||
|
0: AssertSame('order 1', items[0], item^.Data);
|
||||||
|
1: AssertSame('order 2', items[1], item^.Data);
|
||||||
|
2: AssertSame('order 3', items[2], item^.Data);
|
||||||
|
end;
|
||||||
|
Inc(count);
|
||||||
|
end;
|
||||||
|
AssertEquals(3, count);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.DeleteOnlyRemovesFirstMatch;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
count, firstMatches: Integer;
|
||||||
|
begin
|
||||||
|
list.Add(0, items[0]);
|
||||||
|
list.Add(0, items[0]); //duplicate
|
||||||
|
list.Add(0, items[1]);
|
||||||
|
list.Delete(items[0]);
|
||||||
|
count := 0;
|
||||||
|
firstMatches := 0;
|
||||||
|
item := nil;
|
||||||
|
while list.Iterate(item) do
|
||||||
|
begin
|
||||||
|
if item^.Data = items[0] then Inc(firstMatches);
|
||||||
|
Inc(count);
|
||||||
|
end;
|
||||||
|
AssertEquals('duplicate survives', 1, firstMatches);
|
||||||
|
AssertEquals('two entries remain', 2, count);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.DeleteHead;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
begin
|
||||||
|
list.Add(0, items[0]);
|
||||||
|
list.Add(0, items[1]);
|
||||||
|
list.Delete(items[0]);
|
||||||
|
item := nil;
|
||||||
|
AssertTrue(list.Iterate(item));
|
||||||
|
AssertSame('second item becomes head', items[1], item^.Data);
|
||||||
|
AssertFalse('no third entry', list.Iterate(item));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.DeleteTail;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
begin
|
||||||
|
list.Add(0, items[0]);
|
||||||
|
list.Add(0, items[1]);
|
||||||
|
list.Delete(items[1]);
|
||||||
|
list.Add(0, items[2]); //append after tail deletion
|
||||||
|
item := nil;
|
||||||
|
AssertTrue(list.Iterate(item));
|
||||||
|
AssertSame(items[0], item^.Data);
|
||||||
|
AssertTrue(list.Iterate(item));
|
||||||
|
AssertSame('append after tail delete stays intact', items[2], item^.Data);
|
||||||
|
AssertFalse(list.Iterate(item));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.DeleteMiddle;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
begin
|
||||||
|
list.Add(0, items[0]);
|
||||||
|
list.Add(0, items[1]);
|
||||||
|
list.Add(0, items[2]);
|
||||||
|
list.Delete(items[1]);
|
||||||
|
item := nil;
|
||||||
|
AssertTrue(list.Iterate(item));
|
||||||
|
AssertSame(items[0], item^.Data);
|
||||||
|
AssertTrue(list.Iterate(item));
|
||||||
|
AssertSame('chain must stay linked', items[2], item^.Data);
|
||||||
|
AssertFalse(list.Iterate(item));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.DeleteByID;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
begin
|
||||||
|
list.Add(42, items[0]);
|
||||||
|
list.Add(43, items[1]);
|
||||||
|
list.Delete(42);
|
||||||
|
item := nil;
|
||||||
|
AssertTrue(list.Iterate(item));
|
||||||
|
AssertSame(items[1], item^.Data);
|
||||||
|
AssertFalse(list.Iterate(item));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.DeleteMissingIsHarmless;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
begin
|
||||||
|
list.Add(0, items[0]);
|
||||||
|
list.Delete(Pointer(PtrInt(999))); //no match, no crash
|
||||||
|
item := nil;
|
||||||
|
AssertTrue('entry untouched', list.Iterate(item));
|
||||||
|
AssertSame(items[0], item^.Data);
|
||||||
|
AssertFalse('no extra entries', list.Iterate(item));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestLinkedList.ClearEmptiesList;
|
||||||
|
var
|
||||||
|
item: PLinkedItem;
|
||||||
|
begin
|
||||||
|
list.Add(0, items[0]);
|
||||||
|
list.Add(0, items[1]);
|
||||||
|
list.Clear;
|
||||||
|
item := nil;
|
||||||
|
AssertFalse('empty after clear', list.Iterate(item));
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestLinkedList]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
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.
|
||||||
@@ -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.
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
unit UTestPacket;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry, UEnhancedMemoryStream, UPacket;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestPacket = class(TTestCase)
|
||||||
|
published
|
||||||
|
procedure FixedLengthPacketLayout;
|
||||||
|
procedure DynamicLengthIsPatchedUp;
|
||||||
|
procedure DynamicLengthPatchIsIdempotent;
|
||||||
|
procedure EmptyDynamicPacket;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure TTestPacket.FixedLengthPacketLayout;
|
||||||
|
var
|
||||||
|
packet: TPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TPacket.Create($05, 5);
|
||||||
|
try
|
||||||
|
AssertEquals('declared length', Cardinal(5), packet.PacketLength);
|
||||||
|
stream := packet.Stream;
|
||||||
|
//fixed length packets carry only the id byte; the length lives in the
|
||||||
|
//handler table on the receiving side
|
||||||
|
AssertEquals('stream holds only the id byte', Int64(1), stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
AssertEquals('id byte', Byte($05), stream.ReadByte);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestPacket.DynamicLengthIsPatchedUp;
|
||||||
|
var
|
||||||
|
packet: TPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TPacket.Create($04, 0);
|
||||||
|
try
|
||||||
|
stream := packet.Stream; //one getter call: patches length, resets position
|
||||||
|
stream.Position := stream.Size;
|
||||||
|
stream.WriteWord($1234);
|
||||||
|
stream.WriteWord($5678);
|
||||||
|
AssertEquals('id + length + payload', Int64(9), stream.Size);
|
||||||
|
stream := packet.Stream; //property access patches the length field
|
||||||
|
stream.Position := 1;
|
||||||
|
AssertEquals('length covers the whole packet', Cardinal(9),
|
||||||
|
stream.ReadCardinal);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestPacket.DynamicLengthPatchIsIdempotent;
|
||||||
|
var
|
||||||
|
packet: TPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TPacket.Create($04, 0);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
stream.Position := stream.Size;
|
||||||
|
stream.WriteByte($42);
|
||||||
|
stream := packet.Stream; //property access patches the length field
|
||||||
|
stream.Position := 1;
|
||||||
|
AssertEquals('first access patches', Cardinal(6), stream.ReadCardinal);
|
||||||
|
stream.Position := 1;
|
||||||
|
AssertEquals('second access keeps the length', Cardinal(6),
|
||||||
|
stream.ReadCardinal);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestPacket.EmptyDynamicPacket;
|
||||||
|
var
|
||||||
|
packet: TPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TPacket.Create($04, 0);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals('header only', Int64(5), stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
stream.ReadByte;
|
||||||
|
AssertEquals('length is the header size', Cardinal(5),
|
||||||
|
stream.ReadCardinal);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestPacket]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
unit UTestPackets;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry,
|
||||||
|
UEnhancedMemoryStream, UPacket, UStatics, UPackets;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestClientPackets = class(TTestCase)
|
||||||
|
published
|
||||||
|
procedure LoginRequestLayout;
|
||||||
|
procedure RequestBlocksWithoutCoords;
|
||||||
|
procedure RequestBlocksWithCoords;
|
||||||
|
procedure ElevateStaticPacketSize;
|
||||||
|
procedure ElevateStaticSignedZ;
|
||||||
|
procedure DrawMapPacketSize;
|
||||||
|
procedure MoveStaticPacketSize;
|
||||||
|
procedure DeleteStaticPacketSize;
|
||||||
|
procedure HueStaticPacketSize;
|
||||||
|
procedure InsertStaticPacketSize;
|
||||||
|
procedure CompressedPacketWireFormat;
|
||||||
|
procedure FreeBlockPacketSize;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure TTestClientPackets.LoginRequestLayout;
|
||||||
|
var
|
||||||
|
packet: TLoginRequestPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TLoginRequestPacket.Create('alice', 'secret');
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals('id + length + payload', Int64(19), stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
AssertEquals('admin id', Byte($02), stream.ReadByte);
|
||||||
|
AssertEquals('packet length', Cardinal(19), stream.ReadCardinal);
|
||||||
|
AssertEquals('connection sub id', Byte($03), stream.ReadByte);
|
||||||
|
AssertEquals('username', 'alice', stream.ReadStringNull);
|
||||||
|
AssertEquals('password', 'secret', stream.ReadStringNull);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.RequestBlocksWithoutCoords;
|
||||||
|
var
|
||||||
|
packet: TRequestBlocksPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
coords: TBlockCoordsArray;
|
||||||
|
begin
|
||||||
|
SetLength(coords, 0);
|
||||||
|
packet := TRequestBlocksPacket.Create(coords);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals('header only', Int64(5), stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
stream.ReadByte;
|
||||||
|
AssertEquals('declared length', Cardinal(5), stream.ReadCardinal);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.RequestBlocksWithCoords;
|
||||||
|
var
|
||||||
|
packet: TRequestBlocksPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
coords: TBlockCoordsArray;
|
||||||
|
begin
|
||||||
|
SetLength(coords, 2);
|
||||||
|
coords[0].X := 1;
|
||||||
|
coords[0].Y := 2;
|
||||||
|
coords[1].X := 3;
|
||||||
|
coords[1].Y := 4;
|
||||||
|
packet := TRequestBlocksPacket.Create(coords);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals('header + two coords', Int64(5 + 2 * 4), stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
stream.ReadByte;
|
||||||
|
AssertEquals('declared length matches', Cardinal(13),
|
||||||
|
stream.ReadCardinal);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.ElevateStaticPacketSize;
|
||||||
|
var
|
||||||
|
packet: TElevateStaticPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TElevateStaticPacket.Create(1, 2, 3, 4, 5, 6);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals('declared length equals stream size',
|
||||||
|
Int64(packet.PacketLength), stream.Size);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.ElevateStaticSignedZ;
|
||||||
|
var
|
||||||
|
packet: TElevateStaticPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
z: ShortInt;
|
||||||
|
begin
|
||||||
|
packet := TElevateStaticPacket.Create(1, 2, 3, 4, 5, -6);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
stream.Position := stream.Size - 1;
|
||||||
|
z := stream.ReadShortInt;
|
||||||
|
AssertEquals('negative z must survive the writer', ShortInt(-6), z);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.DrawMapPacketSize;
|
||||||
|
var
|
||||||
|
packet: TDrawMapPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TDrawMapPacket.Create(1, 2, 3, 4);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals(Int64(packet.PacketLength), stream.Size);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.MoveStaticPacketSize;
|
||||||
|
var
|
||||||
|
packet: TMoveStaticPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TMoveStaticPacket.Create(1, 2, 3, 4, 5, 6, 7);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals(Int64(packet.PacketLength), stream.Size);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.DeleteStaticPacketSize;
|
||||||
|
var
|
||||||
|
item: TStaticItem;
|
||||||
|
packet: TDeleteStaticPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
item := TStaticItem.Create(nil, nil, 1, 2);
|
||||||
|
try
|
||||||
|
packet := TDeleteStaticPacket.Create(item);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals(Int64(packet.PacketLength), stream.Size);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
item.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.HueStaticPacketSize;
|
||||||
|
var
|
||||||
|
packet: THueStaticPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := THueStaticPacket.Create(1, 2, 3, 4, 5, 6);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals(Int64(packet.PacketLength), stream.Size);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.InsertStaticPacketSize;
|
||||||
|
var
|
||||||
|
packet: TInsertStaticPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TInsertStaticPacket.Create(1, 2, 3, 4, 5);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals(Int64(packet.PacketLength), stream.Size);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.CompressedPacketWireFormat;
|
||||||
|
var
|
||||||
|
source: TPacket;
|
||||||
|
compressed: TCompressedPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
innerSize: Cardinal;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
source := TPacket.Create($06, 8);
|
||||||
|
try
|
||||||
|
stream := source.Stream;
|
||||||
|
stream.Position := stream.Size;
|
||||||
|
for i := 1 to 8 do
|
||||||
|
stream.WriteByte(Byte(i * 11));
|
||||||
|
compressed := TCompressedPacket.Create(source); //takes ownership
|
||||||
|
try
|
||||||
|
AssertEquals('wrapper id', Byte($01), compressed.PacketID);
|
||||||
|
stream := compressed.Stream;
|
||||||
|
stream.Position := 0;
|
||||||
|
AssertEquals('wrapper id byte', Byte($01), stream.ReadByte);
|
||||||
|
AssertEquals('wrapper length covers everything', Int64(stream.Size),
|
||||||
|
Int64(stream.ReadCardinal));
|
||||||
|
stream.Position := 5;
|
||||||
|
innerSize := stream.ReadCardinal;
|
||||||
|
AssertEquals('announced inner stream size', Cardinal(9), innerSize);
|
||||||
|
AssertTrue('deflate payload present', stream.Size > 9);
|
||||||
|
finally
|
||||||
|
compressed.Free;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
source.Free; //only reached if compression failed before taking ownership
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestClientPackets.FreeBlockPacketSize;
|
||||||
|
var
|
||||||
|
packet: TFreeBlockPacket;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
packet := TFreeBlockPacket.Create(3, 4);
|
||||||
|
try
|
||||||
|
stream := packet.Stream;
|
||||||
|
AssertEquals(Int64(packet.PacketLength), stream.Size);
|
||||||
|
finally
|
||||||
|
packet.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestClientPackets]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
unit UTestRegions;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, DOM, XMLRead, XMLWrite, fpcunit, testregistry, URegions;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestRegions = class(TTestCase)
|
||||||
|
private
|
||||||
|
function RegionsToXML(AList: TRegionList): string;
|
||||||
|
function ListFromXML(const AXML: string): TRegionList;
|
||||||
|
published
|
||||||
|
procedure CreateAndFind;
|
||||||
|
procedure SerializeDeserializeRoundtrip;
|
||||||
|
procedure FindMissingReturnsNil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
function TTestRegions.RegionsToXML(AList: TRegionList): string;
|
||||||
|
var
|
||||||
|
doc: TXMLDocument;
|
||||||
|
root: TDOMElement;
|
||||||
|
stream: TStringStream;
|
||||||
|
begin
|
||||||
|
doc := TXMLDocument.Create;
|
||||||
|
try
|
||||||
|
root := doc.CreateElement('regions');
|
||||||
|
doc.AppendChild(root);
|
||||||
|
AList.Serialize(root);
|
||||||
|
stream := TStringStream.Create('');
|
||||||
|
try
|
||||||
|
WriteXMLFile(doc, stream);
|
||||||
|
Result := stream.DataString;
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
doc.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTestRegions.ListFromXML(const AXML: string): TRegionList;
|
||||||
|
var
|
||||||
|
doc: TXMLDocument;
|
||||||
|
stream: TStringStream;
|
||||||
|
begin
|
||||||
|
stream := TStringStream.Create(AXML);
|
||||||
|
try
|
||||||
|
ReadXMLFile(doc, stream);
|
||||||
|
try
|
||||||
|
Result := TRegionList.Deserialize(nil, doc.DocumentElement);
|
||||||
|
finally
|
||||||
|
doc.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestRegions.CreateAndFind;
|
||||||
|
var
|
||||||
|
list: TRegionList;
|
||||||
|
region: TRegion;
|
||||||
|
begin
|
||||||
|
list := TRegionList.Create(nil);
|
||||||
|
try
|
||||||
|
region := TRegion.Create(list, 'britain');
|
||||||
|
list.Add(region);
|
||||||
|
region.Areas.Add(1, 2, 3, 4);
|
||||||
|
AssertEquals('count', 1, list.Count);
|
||||||
|
AssertSame('find by name', region, list.Find('britain'));
|
||||||
|
AssertEquals('index by name', 0, list.IndexOf('britain'));
|
||||||
|
finally
|
||||||
|
list.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestRegions.SerializeDeserializeRoundtrip;
|
||||||
|
var
|
||||||
|
list: TRegionList;
|
||||||
|
region: TRegion;
|
||||||
|
xml: string;
|
||||||
|
loaded: TRegionList;
|
||||||
|
found: TRegion;
|
||||||
|
begin
|
||||||
|
list := TRegionList.Create(nil);
|
||||||
|
try
|
||||||
|
region := TRegion.Create(list, 'yew');
|
||||||
|
list.Add(region);
|
||||||
|
region.Areas.Add(10, 20, 30, 40);
|
||||||
|
region.Areas.Add(50, 60, 70, 80);
|
||||||
|
xml := RegionsToXML(list);
|
||||||
|
loaded := ListFromXML(xml);
|
||||||
|
try
|
||||||
|
AssertEquals('region count survives', 1, loaded.Count);
|
||||||
|
found := loaded.Find('yew');
|
||||||
|
AssertTrue('region found', found <> nil);
|
||||||
|
AssertEquals('area count survives', 2, found.Areas.Count);
|
||||||
|
AssertEquals('area 0 left', 10, found.Areas.Rects[0].Left);
|
||||||
|
AssertEquals('area 0 top', 20, found.Areas.Rects[0].Top);
|
||||||
|
AssertEquals('area 0 right', 30, found.Areas.Rects[0].Right);
|
||||||
|
AssertEquals('area 0 bottom', 40, found.Areas.Rects[0].Bottom);
|
||||||
|
AssertEquals('area 1 left', 50, found.Areas.Rects[1].Left);
|
||||||
|
finally
|
||||||
|
loaded.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
list.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestRegions.FindMissingReturnsNil;
|
||||||
|
var
|
||||||
|
list: TRegionList;
|
||||||
|
begin
|
||||||
|
list := TRegionList.Create(nil);
|
||||||
|
try
|
||||||
|
AssertTrue('missing region is nil', list.Find('nowhere') = nil);
|
||||||
|
finally
|
||||||
|
list.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestRegions]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
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.
|
||||||
@@ -0,0 +1,262 @@
|
|||||||
|
unit UTestStreamHelper;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry, UStreamHelper;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestFifoStream = class(TTestCase)
|
||||||
|
private
|
||||||
|
procedure DoSeekBeforeStart;
|
||||||
|
procedure DoSeekPastEnd;
|
||||||
|
procedure DoNegativeRead;
|
||||||
|
procedure DoNegativeWrite;
|
||||||
|
procedure DoNegativeDequeue;
|
||||||
|
procedure DoWriteWhileLocked;
|
||||||
|
procedure DoDequeueThenSeek;
|
||||||
|
protected
|
||||||
|
procedure SetUp; override;
|
||||||
|
procedure TearDown; override;
|
||||||
|
published
|
||||||
|
procedure EnqueueDequeueOrder;
|
||||||
|
procedure DequeueRemovesFront;
|
||||||
|
procedure LockRestrictsWindow;
|
||||||
|
procedure UnlockRestoresFullSize;
|
||||||
|
procedure SeekBeforeStartRaises;
|
||||||
|
procedure SeekPastEndRaises;
|
||||||
|
procedure NegativeReadRaises;
|
||||||
|
procedure NegativeWriteRaises;
|
||||||
|
procedure NegativeDequeueRaises;
|
||||||
|
procedure WriteWhileLockedRaises;
|
||||||
|
procedure ClearEmptiesStream;
|
||||||
|
procedure DequeueThenSeekStaysInBounds;
|
||||||
|
procedure SaveLoadRoundtrip;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
var
|
||||||
|
fifo: TFifoStream;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.SetUp;
|
||||||
|
begin
|
||||||
|
fifo := TFifoStream.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.TearDown;
|
||||||
|
begin
|
||||||
|
fifo.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DoSeekBeforeStart;
|
||||||
|
begin
|
||||||
|
fifo.Seek(-1, soFromBeginning);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DoSeekPastEnd;
|
||||||
|
begin
|
||||||
|
fifo.Seek(11, soFromBeginning);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DoNegativeRead;
|
||||||
|
var
|
||||||
|
buffer: Byte;
|
||||||
|
begin
|
||||||
|
fifo.Read(buffer, -1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DoNegativeWrite;
|
||||||
|
var
|
||||||
|
buffer: Byte;
|
||||||
|
begin
|
||||||
|
fifo.Write(buffer, -1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DoNegativeDequeue;
|
||||||
|
begin
|
||||||
|
fifo.Dequeue(-1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DoWriteWhileLocked;
|
||||||
|
var
|
||||||
|
buffer: Byte;
|
||||||
|
begin
|
||||||
|
fifo.Write(buffer, 1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DoDequeueThenSeek;
|
||||||
|
begin
|
||||||
|
fifo.Dequeue(2);
|
||||||
|
fifo.Seek(2, soFromBeginning); //within the shrunken queue
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.EnqueueDequeueOrder;
|
||||||
|
var
|
||||||
|
buffer: array[0..2] of Byte;
|
||||||
|
i: Integer;
|
||||||
|
value: Byte;
|
||||||
|
begin
|
||||||
|
for i := 1 to 3 do
|
||||||
|
begin
|
||||||
|
value := i;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
end;
|
||||||
|
AssertEquals('size after enqueues', Int64(3), fifo.Size);
|
||||||
|
fifo.Position := 0;
|
||||||
|
fifo.Read(buffer, 3);
|
||||||
|
for i := 1 to 3 do
|
||||||
|
AssertEquals('byte order', i, buffer[i - 1]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DequeueRemovesFront;
|
||||||
|
var
|
||||||
|
buffer: array[0..0] of Byte;
|
||||||
|
i: Integer;
|
||||||
|
value: Byte;
|
||||||
|
begin
|
||||||
|
for i := 1 to 3 do
|
||||||
|
begin
|
||||||
|
value := i;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
end;
|
||||||
|
fifo.Dequeue(2);
|
||||||
|
AssertEquals('size after dequeue', Int64(1), fifo.Size);
|
||||||
|
fifo.Position := 0;
|
||||||
|
fifo.Read(buffer, 1);
|
||||||
|
AssertEquals('remaining byte', 3, buffer[0]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.LockRestrictsWindow;
|
||||||
|
var
|
||||||
|
buffer: array[0..4] of Byte;
|
||||||
|
i: Integer;
|
||||||
|
value: Byte;
|
||||||
|
begin
|
||||||
|
for i := 0 to 9 do
|
||||||
|
begin
|
||||||
|
value := i;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
end;
|
||||||
|
fifo.Lock(2, 5);
|
||||||
|
try
|
||||||
|
AssertEquals('locked size', Int64(5), fifo.Size);
|
||||||
|
fifo.Position := 0;
|
||||||
|
fifo.Read(buffer, 5);
|
||||||
|
for i := 0 to 4 do
|
||||||
|
AssertEquals('window content', 2 + i, buffer[i]);
|
||||||
|
finally
|
||||||
|
fifo.Unlock;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.UnlockRestoresFullSize;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
value: Byte;
|
||||||
|
begin
|
||||||
|
for i := 0 to 9 do
|
||||||
|
begin
|
||||||
|
value := i;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
end;
|
||||||
|
fifo.Lock(2, 5);
|
||||||
|
fifo.Unlock;
|
||||||
|
AssertEquals('full size after unlock', Int64(10), fifo.Size);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.SeekBeforeStartRaises;
|
||||||
|
begin
|
||||||
|
AssertException('seek before start must raise', EStreamError, @DoSeekBeforeStart);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.SeekPastEndRaises;
|
||||||
|
begin
|
||||||
|
AssertException('seek past end must raise', EStreamError, @DoSeekPastEnd);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.NegativeReadRaises;
|
||||||
|
begin
|
||||||
|
AssertException('negative read count must raise', EStreamError, @DoNegativeRead);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.NegativeWriteRaises;
|
||||||
|
begin
|
||||||
|
AssertException('negative write count must raise', EStreamError, @DoNegativeWrite);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.NegativeDequeueRaises;
|
||||||
|
begin
|
||||||
|
AssertException('negative dequeue must raise', EStreamError, @DoNegativeDequeue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.WriteWhileLockedRaises;
|
||||||
|
var
|
||||||
|
value: Byte;
|
||||||
|
begin
|
||||||
|
value := 1;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
fifo.Lock(0, 1);
|
||||||
|
try
|
||||||
|
AssertException('write to locked stream must raise', EStreamError,
|
||||||
|
@DoWriteWhileLocked);
|
||||||
|
finally
|
||||||
|
fifo.Unlock;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.ClearEmptiesStream;
|
||||||
|
var
|
||||||
|
value: Byte;
|
||||||
|
begin
|
||||||
|
value := 1;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
value := 2;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
fifo.Clear;
|
||||||
|
AssertEquals('empty after clear', Int64(0), fifo.Size);
|
||||||
|
value := 3;
|
||||||
|
fifo.Enqueue(value, 1); //must be usable afterwards
|
||||||
|
AssertEquals('usable after clear', Int64(1), fifo.Size);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.DequeueThenSeekStaysInBounds;
|
||||||
|
var
|
||||||
|
value: Byte;
|
||||||
|
begin
|
||||||
|
value := 1;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
value := 2;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
value := 3;
|
||||||
|
fifo.Enqueue(value, 1);
|
||||||
|
AssertException('seek must respect the shrunken queue', EStreamError,
|
||||||
|
@DoDequeueThenSeek);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestFifoStream.SaveLoadRoundtrip;
|
||||||
|
var
|
||||||
|
source: TMemoryStream;
|
||||||
|
buffer: array[0..2] of Byte;
|
||||||
|
begin
|
||||||
|
source := TMemoryStream.Create;
|
||||||
|
try
|
||||||
|
source.WriteAnsiString('abc');
|
||||||
|
fifo.LoadFromStream(source);
|
||||||
|
AssertEquals('loaded size', Int64(7), fifo.Size); //length prefix + 'abc'
|
||||||
|
fifo.Position := 4;
|
||||||
|
fifo.Read(buffer, 3);
|
||||||
|
AssertEquals('a', Char(buffer[0]));
|
||||||
|
AssertEquals('b', Char(buffer[1]));
|
||||||
|
AssertEquals('c', Char(buffer[2]));
|
||||||
|
finally
|
||||||
|
source.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestFifoStream]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,261 @@
|
|||||||
|
unit UTestTiledata;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, fpcunit, testregistry,
|
||||||
|
UEnhancedMemoryStream, UTiledata;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestTileDataOffset = class(TTestCase)
|
||||||
|
published
|
||||||
|
procedure LegacyLandOffsets;
|
||||||
|
procedure LegacyStaticOffsets;
|
||||||
|
procedure HighSeasLandOffsets;
|
||||||
|
procedure HighSeasStaticOffsets;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TTestTileDataSizes = class(TTestCase)
|
||||||
|
published
|
||||||
|
procedure LegacyLandTileSize;
|
||||||
|
procedure HighSeasLandTileSize;
|
||||||
|
procedure LegacyStaticTileSize;
|
||||||
|
procedure HighSeasStaticTileSize;
|
||||||
|
procedure LegacyLandFlagsSize;
|
||||||
|
procedure HighSeasFlagsSize;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TTestTileDataRoundtrip = class(TTestCase)
|
||||||
|
published
|
||||||
|
procedure LandTileLegacyRoundtrip;
|
||||||
|
procedure LandTileHighSeasRoundtrip;
|
||||||
|
procedure StaticTileHighSeasRoundtrip;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure TTestTileDataOffset.LegacyLandOffsets;
|
||||||
|
begin
|
||||||
|
AssertEquals('tile 0 (after group header)', 4,
|
||||||
|
GetTileDataOffset(0, tdvLegacy));
|
||||||
|
AssertEquals('tile 1', 4 + LandTileDataSize,
|
||||||
|
GetTileDataOffset(1, tdvLegacy));
|
||||||
|
AssertEquals('tile 32 starts after group header', 836 + 4,
|
||||||
|
GetTileDataOffset(32, tdvLegacy));
|
||||||
|
AssertEquals('last land tile',
|
||||||
|
511 * LandTileGroupSize + 4 + 31 * LandTileDataSize,
|
||||||
|
GetTileDataOffset($3FFF, tdvLegacy));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataOffset.LegacyStaticOffsets;
|
||||||
|
begin
|
||||||
|
AssertEquals('first static tile',
|
||||||
|
512 * LandTileGroupSize + 4,
|
||||||
|
GetTileDataOffset($4000, tdvLegacy));
|
||||||
|
AssertEquals('second static tile',
|
||||||
|
512 * LandTileGroupSize + 4 + StaticTileDataSize,
|
||||||
|
GetTileDataOffset($4001, tdvLegacy));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataOffset.HighSeasLandOffsets;
|
||||||
|
begin
|
||||||
|
//High Seas quirk: the first group header comes AFTER the unknown tile
|
||||||
|
AssertEquals('HS tile 0 sits at file start', 0,
|
||||||
|
GetTileDataOffset(0, tdvHighSeas));
|
||||||
|
AssertEquals('HS tile 1 after tile 0 and its header',
|
||||||
|
LandTileDataSizeHS + 4,
|
||||||
|
GetTileDataOffset(1, tdvHighSeas));
|
||||||
|
AssertEquals('HS tile 32 after second group header',
|
||||||
|
32 * LandTileDataSizeHS + 2 * 4,
|
||||||
|
GetTileDataOffset(32, tdvHighSeas));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataOffset.HighSeasStaticOffsets;
|
||||||
|
begin
|
||||||
|
AssertEquals('HS first static tile',
|
||||||
|
512 * LandTileGroupSizeHS + 4,
|
||||||
|
GetTileDataOffset($4000, tdvHighSeas));
|
||||||
|
AssertEquals('HS second static tile',
|
||||||
|
512 * LandTileGroupSizeHS + 4 + StaticTileDataSizeHS,
|
||||||
|
GetTileDataOffset($4001, tdvHighSeas));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataSizes.LegacyLandTileSize;
|
||||||
|
var
|
||||||
|
tile: TLandTiledata;
|
||||||
|
begin
|
||||||
|
tile := TLandTiledata.Create(nil);
|
||||||
|
try
|
||||||
|
AssertEquals(LandTileDataSize, tile.GetSize);
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataSizes.HighSeasLandTileSize;
|
||||||
|
var
|
||||||
|
tile: TLandTiledata;
|
||||||
|
begin
|
||||||
|
tile := TLandTiledata.Create(nil, tdvHighSeas);
|
||||||
|
try
|
||||||
|
AssertEquals(LandTileDataSizeHS, tile.GetSize);
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataSizes.LegacyStaticTileSize;
|
||||||
|
var
|
||||||
|
tile: TStaticTiledata;
|
||||||
|
begin
|
||||||
|
tile := TStaticTiledata.Create(nil);
|
||||||
|
try
|
||||||
|
AssertEquals(StaticTileDataSize, tile.GetSize);
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataSizes.HighSeasStaticTileSize;
|
||||||
|
var
|
||||||
|
tile: TStaticTiledata;
|
||||||
|
begin
|
||||||
|
tile := TStaticTiledata.Create(nil, tdvHighSeas);
|
||||||
|
try
|
||||||
|
AssertEquals(StaticTileDataSizeHS, tile.GetSize);
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataSizes.LegacyLandFlagsSize;
|
||||||
|
var
|
||||||
|
tile: TLandTiledata;
|
||||||
|
begin
|
||||||
|
tile := TLandTiledata.Create(nil);
|
||||||
|
try
|
||||||
|
tile.Flags := [tdfSurface, tdfBridge];
|
||||||
|
AssertEquals('legacy writes one flag dword', LandTileDataSize,
|
||||||
|
tile.GetSize);
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataSizes.HighSeasFlagsSize;
|
||||||
|
var
|
||||||
|
tile: TLandTiledata;
|
||||||
|
begin
|
||||||
|
tile := TLandTiledata.Create(nil, tdvHighSeas);
|
||||||
|
try
|
||||||
|
tile.Flags := [tdfSurface];
|
||||||
|
AssertEquals('HighSeas writes two flag dwords', LandTileDataSizeHS,
|
||||||
|
tile.GetSize);
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataRoundtrip.LandTileLegacyRoundtrip;
|
||||||
|
var
|
||||||
|
tile, loaded: TLandTiledata;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
tile := TLandTiledata.Create(nil);
|
||||||
|
try
|
||||||
|
tile.Flags := [tdfWall, tdfImpassable];
|
||||||
|
tile.TextureID := 1234;
|
||||||
|
tile.TileName := 'stone';
|
||||||
|
stream := TEnhancedMemoryStream.Create;
|
||||||
|
try
|
||||||
|
tile.Write(stream);
|
||||||
|
AssertEquals('serialized size', Int64(LandTileDataSize), stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
loaded := TLandTiledata.Create(stream);
|
||||||
|
try
|
||||||
|
AssertTrue('flags survive', [tdfWall, tdfImpassable] = loaded.Flags);
|
||||||
|
AssertEquals('texture survives', 1234, loaded.TextureID);
|
||||||
|
AssertEquals('name survives', 'stone', Trim(loaded.TileName));
|
||||||
|
finally
|
||||||
|
loaded.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataRoundtrip.LandTileHighSeasRoundtrip;
|
||||||
|
var
|
||||||
|
tile, loaded: TLandTiledata;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
tile := TLandTiledata.Create(nil, tdvHighSeas);
|
||||||
|
try
|
||||||
|
tile.Flags := [tdfSurface];
|
||||||
|
tile.TextureID := 42;
|
||||||
|
tile.TileName := 'grass';
|
||||||
|
stream := TEnhancedMemoryStream.Create;
|
||||||
|
try
|
||||||
|
tile.Write(stream);
|
||||||
|
AssertEquals('HighSeas serialized size', Int64(LandTileDataSizeHS),
|
||||||
|
stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
loaded := TLandTiledata.Create(stream, tdvHighSeas);
|
||||||
|
try
|
||||||
|
AssertTrue('flags survive', [tdfSurface] = loaded.Flags);
|
||||||
|
AssertEquals('texture survives', 42, loaded.TextureID);
|
||||||
|
AssertEquals('name survives', 'grass', Trim(loaded.TileName));
|
||||||
|
finally
|
||||||
|
loaded.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestTileDataRoundtrip.StaticTileHighSeasRoundtrip;
|
||||||
|
var
|
||||||
|
tile, loaded: TStaticTiledata;
|
||||||
|
stream: TEnhancedMemoryStream;
|
||||||
|
begin
|
||||||
|
tile := TStaticTiledata.Create(nil, tdvHighSeas);
|
||||||
|
try
|
||||||
|
tile.Flags := [tdfContainer];
|
||||||
|
tile.Weight := 10;
|
||||||
|
tile.Height := 7;
|
||||||
|
tile.TileName := 'chest';
|
||||||
|
stream := TEnhancedMemoryStream.Create;
|
||||||
|
try
|
||||||
|
tile.Write(stream);
|
||||||
|
AssertEquals('HighSeas serialized size', Int64(StaticTileDataSizeHS),
|
||||||
|
stream.Size);
|
||||||
|
stream.Position := 0;
|
||||||
|
loaded := TStaticTiledata.Create(stream, tdvHighSeas);
|
||||||
|
try
|
||||||
|
AssertTrue('flags survive', [tdfContainer] = loaded.Flags);
|
||||||
|
AssertEquals('weight survives', 10, loaded.Weight);
|
||||||
|
AssertEquals('height survives', 7, loaded.Height);
|
||||||
|
AssertEquals('name survives', 'chest', Trim(loaded.TileName));
|
||||||
|
finally
|
||||||
|
loaded.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
tile.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestTileDataOffset, TTestTileDataSizes, TTestTileDataRoundtrip]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
unit UTestXmlHelper;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, DOM, XMLRead, XMLWrite, fpcunit, testregistry, UXmlHelper;
|
||||||
|
|
||||||
|
type
|
||||||
|
TTestXmlHelper = class(TTestCase)
|
||||||
|
private
|
||||||
|
FDoc: TXMLDocument;
|
||||||
|
function Root: TDOMElement;
|
||||||
|
procedure LoadXML(const AXML: string);
|
||||||
|
protected
|
||||||
|
procedure SetUp; override;
|
||||||
|
procedure TearDown; override;
|
||||||
|
published
|
||||||
|
procedure WriteReadStringRoundtrip;
|
||||||
|
procedure ReadStringReturnsDefaultWhenMissing;
|
||||||
|
procedure WriteReadIntegerRoundtrip;
|
||||||
|
procedure ReadIntegerReturnsDefaultWhenMissing;
|
||||||
|
procedure ReadBooleanParsesValidValues;
|
||||||
|
procedure ReadBooleanFallsBackToDefaultOnGarbage;
|
||||||
|
procedure ReadBooleanFallsBackToDefaultWhenMissing;
|
||||||
|
procedure ReadStringToleratesCommentChild;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.SetUp;
|
||||||
|
begin
|
||||||
|
FDoc := TXMLDocument.Create;
|
||||||
|
FDoc.AppendChild(FDoc.CreateElement('root'));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.TearDown;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FDoc);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTestXmlHelper.Root: TDOMElement;
|
||||||
|
begin
|
||||||
|
Result := FDoc.DocumentElement;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.LoadXML(const AXML: string);
|
||||||
|
var
|
||||||
|
stream: TStringStream;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FDoc);
|
||||||
|
stream := TStringStream.Create(AXML);
|
||||||
|
try
|
||||||
|
ReadXMLFile(FDoc, stream);
|
||||||
|
finally
|
||||||
|
stream.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.WriteReadStringRoundtrip;
|
||||||
|
begin
|
||||||
|
TXmlHelper.WriteString(Root, 'name', 'alice');
|
||||||
|
AssertEquals('alice', TXmlHelper.ReadString(Root, 'name', 'default'));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.ReadStringReturnsDefaultWhenMissing;
|
||||||
|
begin
|
||||||
|
AssertEquals('default', TXmlHelper.ReadString(Root, 'missing', 'default'));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.WriteReadIntegerRoundtrip;
|
||||||
|
begin
|
||||||
|
TXmlHelper.WriteInteger(Root, 'port', 2597);
|
||||||
|
AssertEquals(2597, TXmlHelper.ReadInteger(Root, 'port', 0));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.ReadIntegerReturnsDefaultWhenMissing;
|
||||||
|
begin
|
||||||
|
AssertEquals(1234, TXmlHelper.ReadInteger(Root, 'missing', 1234));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.ReadBooleanParsesValidValues;
|
||||||
|
begin
|
||||||
|
TXmlHelper.WriteBoolean(Root, 'yes', True);
|
||||||
|
TXmlHelper.WriteBoolean(Root, 'no', False);
|
||||||
|
AssertTrue(TXmlHelper.ReadBoolean(Root, 'yes', False));
|
||||||
|
AssertFalse(TXmlHelper.ReadBoolean(Root, 'no', True));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.ReadBooleanFallsBackToDefaultOnGarbage;
|
||||||
|
begin
|
||||||
|
LoadXML('<root><flag>garbage</flag></root>');
|
||||||
|
AssertFalse('garbage must yield default False',
|
||||||
|
TXmlHelper.ReadBoolean(Root, 'flag', False));
|
||||||
|
AssertTrue('garbage must yield default True',
|
||||||
|
TXmlHelper.ReadBoolean(Root, 'flag', True));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.ReadBooleanFallsBackToDefaultWhenMissing;
|
||||||
|
begin
|
||||||
|
AssertTrue(TXmlHelper.ReadBoolean(Root, 'missing', True));
|
||||||
|
AssertFalse(TXmlHelper.ReadBoolean(Root, 'missing', False));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestXmlHelper.ReadStringToleratesCommentChild;
|
||||||
|
var
|
||||||
|
element, text: TDOMElement;
|
||||||
|
comment: TDOMComment;
|
||||||
|
begin
|
||||||
|
element := FDoc.CreateElement('entry');
|
||||||
|
Root.AppendChild(element);
|
||||||
|
comment := FDoc.CreateComment('metadata');
|
||||||
|
element.AppendChild(comment); //comment must not be treated as the value
|
||||||
|
text := FDoc.CreateElement('value');
|
||||||
|
element.AppendChild(text);
|
||||||
|
TXmlHelper.WriteString(element, 'value', 'real');
|
||||||
|
AssertEquals('real', TXmlHelper.ReadString(element, 'value', 'default'));
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTests([TTestXmlHelper]);
|
||||||
|
|
||||||
|
end.
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="12"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
<LRSInOutputDirectory Value="False"/>
|
||||||
|
<CompatibilityMode Value="True"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
</General>
|
||||||
|
<VersionInfo>
|
||||||
|
<UseVersionInfo Value="False"/>
|
||||||
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
<Modes Count="1">
|
||||||
|
<Mode0 Name="default"/>
|
||||||
|
</Modes>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="2">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="multiloglaz"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<PackageName Value="lnetbase"/>
|
||||||
|
</Item2>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="5">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="unittests-server.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
<Unit1>
|
||||||
|
<Filename Value="UTestRegions.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit1>
|
||||||
|
<Unit2>
|
||||||
|
<Filename Value="UTestAccount.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit2>
|
||||||
|
<Unit3>
|
||||||
|
<Filename Value="UTestConfig.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit3>
|
||||||
|
<Unit4>
|
||||||
|
<Filename Value="UTestLandscapeBounds.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit4>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="bin/unittests-server"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="..;../Imaging"/>
|
||||||
|
<OtherUnitFiles Value="..;../Server;../UOLib;../MulProvider;../Imaging;../Imaging/ZLib"/>
|
||||||
|
<UnitOutputDirectory Value="obj-tests/$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
<SrcPath Value="..;../Server;../UOLib;../MulProvider;../Imaging;../Imaging/ZLib"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
|
<CStyleOperator Value="False"/>
|
||||||
|
</SyntaxOptions>
|
||||||
|
</Parsing>
|
||||||
|
<CodeGeneration>
|
||||||
|
<Checks>
|
||||||
|
<IOChecks Value="True"/>
|
||||||
|
<RangeChecks Value="True"/>
|
||||||
|
<OverflowChecks Value="True"/>
|
||||||
|
<StackChecks Value="True"/>
|
||||||
|
</Checks>
|
||||||
|
</CodeGeneration>
|
||||||
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<DebugInfoType Value="dsDwarf3"/>
|
||||||
|
</Debugging>
|
||||||
|
</Linking>
|
||||||
|
</CompilerOptions>
|
||||||
|
</CONFIG>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
program unittestsserver;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
simpletestrunner,
|
||||||
|
UTestRegions,
|
||||||
|
UTestAccount,
|
||||||
|
UTestConfig,
|
||||||
|
UTestLandscapeBounds;
|
||||||
|
|
||||||
|
begin
|
||||||
|
with TTestRunner.Create(nil) do
|
||||||
|
try
|
||||||
|
Initialize;
|
||||||
|
Run;
|
||||||
|
finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end.
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="12"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
<LRSInOutputDirectory Value="False"/>
|
||||||
|
<CompatibilityMode Value="True"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
</General>
|
||||||
|
<VersionInfo>
|
||||||
|
<UseVersionInfo Value="False"/>
|
||||||
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
<Modes Count="1">
|
||||||
|
<Mode0 Name="default"/>
|
||||||
|
</Modes>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="1">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="multiloglaz"/>
|
||||||
|
</Item1>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="14">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="unittests.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit0>
|
||||||
|
<Unit1>
|
||||||
|
<Filename Value="UTestCacheManager.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit1>
|
||||||
|
<Unit2>
|
||||||
|
<Filename Value="UTestEnhancedMemoryStream.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit2>
|
||||||
|
<Unit3>
|
||||||
|
<Filename Value="UTestStreamHelper.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit3>
|
||||||
|
<Unit4>
|
||||||
|
<Filename Value="UTestBufferedStreams.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit4>
|
||||||
|
<Unit5>
|
||||||
|
<Filename Value="UTestXmlHelper.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit5>
|
||||||
|
<Unit6>
|
||||||
|
<Filename Value="UTestLinkedList.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit6>
|
||||||
|
<Unit7>
|
||||||
|
<Filename Value="UTestPacket.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit7>
|
||||||
|
<Unit8>
|
||||||
|
<Filename Value="UTestArt.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit8>
|
||||||
|
<Unit9>
|
||||||
|
<Filename Value="UTestMap.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit9>
|
||||||
|
<Unit10>
|
||||||
|
<Filename Value="UTestStatics.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit10>
|
||||||
|
<Unit11>
|
||||||
|
<Filename Value="UTestTiledata.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit11>
|
||||||
|
<Unit12>
|
||||||
|
<Filename Value="UTestLocalization.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit12>
|
||||||
|
<Unit13>
|
||||||
|
<Filename Value="UTestPackets.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit13>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="bin/unittests"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="..;../Imaging"/>
|
||||||
|
<OtherUnitFiles Value="..;../UOLib;../MulProvider;../Imaging;../Imaging/ZLib;../Client"/>
|
||||||
|
<UnitOutputDirectory Value="obj-tests/$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
<SrcPath Value="..;../UOLib;../MulProvider;../Imaging;../Imaging/ZLib"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
|
<CStyleOperator Value="False"/>
|
||||||
|
</SyntaxOptions>
|
||||||
|
</Parsing>
|
||||||
|
<CodeGeneration>
|
||||||
|
<Checks>
|
||||||
|
<IOChecks Value="True"/>
|
||||||
|
<RangeChecks Value="True"/>
|
||||||
|
<OverflowChecks Value="True"/>
|
||||||
|
<StackChecks Value="True"/>
|
||||||
|
</Checks>
|
||||||
|
</CodeGeneration>
|
||||||
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<DebugInfoType Value="dsDwarf3"/>
|
||||||
|
<UseHeaptrc Value="True"/>
|
||||||
|
</Debugging>
|
||||||
|
</Linking>
|
||||||
|
</CompilerOptions>
|
||||||
|
</CONFIG>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
program unittests;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
simpletestrunner,
|
||||||
|
UTestCacheManager,
|
||||||
|
UTestEnhancedMemoryStream,
|
||||||
|
UTestStreamHelper,
|
||||||
|
UTestBufferedStreams,
|
||||||
|
UTestXmlHelper,
|
||||||
|
UTestLinkedList,
|
||||||
|
UTestPacket,
|
||||||
|
UTestArt,
|
||||||
|
UTestMap,
|
||||||
|
UTestStatics,
|
||||||
|
UTestTiledata,
|
||||||
|
UTestLocalization,
|
||||||
|
UTestPackets;
|
||||||
|
|
||||||
|
begin
|
||||||
|
with TTestRunner.Create(nil) do
|
||||||
|
try
|
||||||
|
Initialize;
|
||||||
|
Run;
|
||||||
|
finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end.
|
||||||
Reference in New Issue
Block a user