Across-the-board rename so the unit prefix matches the repo
name (mb = msgbase). Brings naming into line with
fpc-ftn-transport's tt.* prefix and avoids the historical
"ma" abbreviation that meant nothing to new readers.
Files renamed via git mv:
src/ma.{api,events,kludge,lock,paths,types}.pas
-> src/mb.{...}.pas
src/formats/ma.fmt.{jam,squish,hudson,msg,pcboard,ezycom,
goldbase,wildcat,wcutil}{,.uni}.pas
-> src/formats/mb.fmt.*.pas
All `unit ma.X` declarations and `uses ma.X` clauses rewritten
to `mb.X` across src/, examples/, tests/.
Suite: 47/47 (read 7, hwm 11, lock 4, pack 4, write 5,
wildcat 5, consumer_round1 5, batch's gone w/ PKT relocation,
plus testutil).
Consumer impact: anyone with `uses ma.api;` etc. needs to
update to `uses mb.api;`. No semantic changes; a search/replace
on the consumer's source tree is the only migration step.
NR's notes (~/.MSGAPI_MSGS.md round 3) align this against
their already-pinned 8130b40; the next NR pin bump rolls in
both this rename and any further work in one step.
135 lines
4.1 KiB
ObjectPascal
135 lines
4.1 KiB
ObjectPascal
{
|
|
test_roundtrip.pas - write N messages through the unified API,
|
|
close, reopen, read them back and verify every field.
|
|
|
|
Runs against a scratch dir under /tmp so sample data stays
|
|
untouched. Covers Hudson, JAM, Squish, *.MSG, and GoldBase.
|
|
}
|
|
|
|
program test_roundtrip;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
uses
|
|
SysUtils,
|
|
testutil,
|
|
mb.types, mb.events, mb.api,
|
|
mb.fmt.hudson, mb.fmt.hudson.uni,
|
|
mb.fmt.jam, mb.fmt.jam.uni,
|
|
mb.fmt.squish, mb.fmt.squish.uni,
|
|
mb.fmt.msg, mb.fmt.msg.uni,
|
|
mb.fmt.goldbase, mb.fmt.goldbase.uni;
|
|
|
|
const
|
|
SCRATCH_ROOT = '/tmp/ma_roundtrip';
|
|
|
|
procedure CleanDir(const APath: string);
|
|
var
|
|
sr: TSearchRec;
|
|
begin
|
|
if not DirectoryExists(APath) then exit;
|
|
if FindFirst(APath + '/*', faAnyFile, sr) = 0 then
|
|
try
|
|
repeat
|
|
if (sr.Attr and faDirectory) = 0 then
|
|
DeleteFile(APath + '/' + sr.Name);
|
|
until FindNext(sr) <> 0;
|
|
finally
|
|
FindClose(sr);
|
|
end;
|
|
end;
|
|
|
|
function MakeMsg(N: longint): TUniMessage;
|
|
begin
|
|
Result.Attributes.Clear;
|
|
Result.Attributes.SetValue('from', 'Sender' + IntToStr(N));
|
|
Result.Attributes.SetValue('to', 'Dest' + IntToStr(N));
|
|
Result.Attributes.SetValue('subject', 'Subject ' + IntToStr(N));
|
|
Result.Attributes.SetDate('date.written',
|
|
EncodeDate(2026, 4, 1) + EncodeTime(12, N mod 60, 0, 0));
|
|
Result.Attributes.SetBool('attr.local', true);
|
|
Result.Attributes.SetBool('attr.echo', true);
|
|
Result.Attributes.SetAddr('addr.orig', MakeFTNAddress(1, 100, 200, 0));
|
|
Result.Attributes.SetAddr('addr.dest', MakeFTNAddress(1, 100, 300, 0));
|
|
Result.Attributes.SetValue('area', 'TEST');
|
|
Result.Body := 'Body of message ' + IntToStr(N) + #13;
|
|
end;
|
|
|
|
procedure RoundTrip(AFormat: TMsgBaseFormat; const APath: string;
|
|
const ATestName: string; N: longint);
|
|
var
|
|
base: TMessageBase;
|
|
i: longint;
|
|
wmsg: TUniMessage;
|
|
rmsg: TUniMessage;
|
|
preCount: longint;
|
|
begin
|
|
TestBegin(ATestName);
|
|
ForceDirectories(ExtractFilePath(APath));
|
|
CleanDir(ExtractFilePath(APath));
|
|
|
|
{ Create + write phase }
|
|
base := MessageBaseOpen(AFormat, APath, momCreate);
|
|
try
|
|
AssertTrue('Open (write)', base.Open);
|
|
preCount := base.MessageCount;
|
|
for i := 1 to N do begin
|
|
wmsg := MakeMsg(i);
|
|
AssertTrue('WriteMessage ' + IntToStr(i), base.WriteMessage(wmsg));
|
|
end;
|
|
AssertEquals('Count after writes', preCount + N, base.MessageCount);
|
|
finally
|
|
base.Close;
|
|
base.Free;
|
|
end;
|
|
|
|
{ Reopen + read phase }
|
|
base := MessageBaseOpen(AFormat, APath, momReadOnly);
|
|
try
|
|
AssertTrue('Open (read)', base.Open);
|
|
AssertEquals('Count after reopen', preCount + N, base.MessageCount);
|
|
for i := 1 to N do begin
|
|
AssertTrue('ReadMessage ' + IntToStr(i),
|
|
base.ReadMessage(preCount + i - 1, rmsg));
|
|
AssertEquals('WhoFrom[' + IntToStr(i) + ']',
|
|
'Sender' + IntToStr(i), rmsg.Attributes.Get('from'));
|
|
AssertEquals('WhoTo[' + IntToStr(i) + ']',
|
|
'Dest' + IntToStr(i), rmsg.Attributes.Get('to'));
|
|
AssertEquals('Subject[' + IntToStr(i) + ']',
|
|
'Subject ' + IntToStr(i), rmsg.Attributes.Get('subject'));
|
|
AssertTrue('Body contains msg body[' + IntToStr(i) + ']',
|
|
Pos('Body of message ' + IntToStr(i), rmsg.Body) > 0);
|
|
end;
|
|
finally
|
|
base.Close;
|
|
base.Free;
|
|
end;
|
|
TestOK;
|
|
end;
|
|
|
|
begin
|
|
WriteLn('fpc-msgbase: round-trip tests');
|
|
WriteLn;
|
|
|
|
ForceDirectories(SCRATCH_ROOT);
|
|
|
|
ForceDirectories(SCRATCH_ROOT + '/hudson');
|
|
RoundTrip(mbfHudson, SCRATCH_ROOT + '/hudson/', 'Hudson round-trip', 5);
|
|
|
|
ForceDirectories(SCRATCH_ROOT + '/jam');
|
|
CleanDir(SCRATCH_ROOT + '/jam');
|
|
RoundTrip(mbfJam, SCRATCH_ROOT + '/jam/echo', 'JAM round-trip', 5);
|
|
|
|
ForceDirectories(SCRATCH_ROOT + '/squish');
|
|
CleanDir(SCRATCH_ROOT + '/squish');
|
|
RoundTrip(mbfSquish, SCRATCH_ROOT + '/squish/sq', 'Squish round-trip', 5);
|
|
|
|
ForceDirectories(SCRATCH_ROOT + '/msg');
|
|
RoundTrip(mbfMsg, SCRATCH_ROOT + '/msg/', 'FTS-1 MSG round-trip', 5);
|
|
|
|
ForceDirectories(SCRATCH_ROOT + '/goldbase');
|
|
RoundTrip(mbfGoldBase, SCRATCH_ROOT + '/goldbase/', 'GoldBase round-trip', 5);
|
|
|
|
Halt(TestsSummary);
|
|
end.
|