- ma.api: add per-instance FOpCS critical section to serialise Do* calls (fixes racing writers that dropped 8/100 messages) - .uni adapters: momCreate pre-creates empty format files - example_read/example_write/example_tosser - tests: test_read (samples), test_roundtrip (all 5 storage formats), test_lock (4 threads/100 msgs), test_batch (5 pkts*10 msgs/3 threads) - run_tests.sh: single-command test runner - build.sh: per-target binutils (i386-linux, i386-freebsd12, i386-emx)
102 lines
2.3 KiB
ObjectPascal
102 lines
2.3 KiB
ObjectPascal
{
|
|
testutil.pas - minimal assertion + reporting helpers for the
|
|
message_api test programs. Keeps tests self-contained (no
|
|
FPCUnit dependency) so they build on every target including
|
|
go32v2 / os2 where FPCUnit may be missing.
|
|
}
|
|
|
|
unit testutil;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
SysUtils;
|
|
|
|
var
|
|
TestsRun: longint = 0;
|
|
TestsPassed: longint = 0;
|
|
TestsFailed: longint = 0;
|
|
|
|
procedure TestBegin(const AName: string);
|
|
procedure TestFail(const AMsg: string);
|
|
procedure TestOK;
|
|
|
|
procedure AssertEquals(const AName: string;
|
|
Expected, Actual: longint); overload;
|
|
procedure AssertEquals(const AName: string;
|
|
const Expected, Actual: AnsiString); overload;
|
|
procedure AssertTrue(const AName: string; Cond: boolean);
|
|
procedure AssertFalse(const AName: string; Cond: boolean);
|
|
|
|
function TestsSummary: integer;
|
|
|
|
implementation
|
|
|
|
var
|
|
CurrentTest: string;
|
|
CurrentFailed: boolean;
|
|
|
|
procedure TestBegin(const AName: string);
|
|
begin
|
|
CurrentTest := AName;
|
|
CurrentFailed := False;
|
|
Inc(TestsRun);
|
|
Write(' ', AName, ' ... ');
|
|
end;
|
|
|
|
procedure TestFail(const AMsg: string);
|
|
begin
|
|
if not CurrentFailed then begin
|
|
CurrentFailed := True;
|
|
Inc(TestsFailed);
|
|
WriteLn('FAIL');
|
|
end;
|
|
WriteLn(' ', AMsg);
|
|
end;
|
|
|
|
procedure TestOK;
|
|
begin
|
|
if not CurrentFailed then begin
|
|
Inc(TestsPassed);
|
|
WriteLn('OK');
|
|
end;
|
|
end;
|
|
|
|
procedure AssertEquals(const AName: string;
|
|
Expected, Actual: longint);
|
|
begin
|
|
if Expected <> Actual then
|
|
TestFail(Format('%s: expected %d, got %d', [AName, Expected, Actual]));
|
|
end;
|
|
|
|
procedure AssertEquals(const AName: string;
|
|
const Expected, Actual: AnsiString);
|
|
begin
|
|
if Expected <> Actual then
|
|
TestFail(Format('%s: expected "%s", got "%s"', [AName, Expected, Actual]));
|
|
end;
|
|
|
|
procedure AssertTrue(const AName: string; Cond: boolean);
|
|
begin
|
|
if not Cond then
|
|
TestFail(AName + ': expected true, got false');
|
|
end;
|
|
|
|
procedure AssertFalse(const AName: string; Cond: boolean);
|
|
begin
|
|
if Cond then
|
|
TestFail(AName + ': expected false, got true');
|
|
end;
|
|
|
|
function TestsSummary: integer;
|
|
begin
|
|
WriteLn;
|
|
WriteLn(TestsRun, ' tests, ', TestsPassed, ' passed, ',
|
|
TestsFailed, ' failed');
|
|
if TestsFailed = 0 then Result := 0 else Result := 1;
|
|
end;
|
|
|
|
end.
|