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.
146 lines
3.8 KiB
ObjectPascal
146 lines
3.8 KiB
ObjectPascal
{
|
|
test_read.pas - read-only smoke tests against real BBS
|
|
sample bases at /home/ken/fidonet/msg/. Validates that our
|
|
unified API returns the expected counts and first/last
|
|
records for each format.
|
|
|
|
If the sample directory isn't present the tests are skipped
|
|
(returns 0 so CI still passes on fresh checkouts).
|
|
}
|
|
|
|
program test_read;
|
|
|
|
{$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.pcboard, mb.fmt.pcboard.uni,
|
|
mb.fmt.ezycom, mb.fmt.ezycom.uni,
|
|
mb.fmt.goldbase, mb.fmt.goldbase.uni;
|
|
|
|
const
|
|
SAMPLES_ROOT = '/home/ken/fidonet/msg';
|
|
|
|
{ Walk every message in the base and return a count of successful
|
|
reads. Used to verify the adapter can iterate without crashing. }
|
|
function WalkAll(base: TMessageBase): longint;
|
|
var
|
|
i, n, ok: longint;
|
|
msg: TUniMessage;
|
|
begin
|
|
ok := 0;
|
|
n := base.MessageCount;
|
|
for i := 0 to n - 1 do
|
|
if base.ReadMessage(i, msg) then
|
|
Inc(ok);
|
|
Result := ok;
|
|
end;
|
|
|
|
procedure TestJam;
|
|
var
|
|
base: TMessageBase;
|
|
msg: TUniMessage;
|
|
walked: longint;
|
|
begin
|
|
TestBegin('JAM/10thamd (212KB .JHR, 246KB .JDT)');
|
|
if not FileExists(SAMPLES_ROOT + '/jam/10thamd.jhr') then begin
|
|
WriteLn('SKIP (sample missing)');
|
|
exit;
|
|
end;
|
|
base := MessageBaseOpen(mbfJam, SAMPLES_ROOT + '/jam/10thamd',
|
|
momReadOnly);
|
|
try
|
|
AssertTrue('Open', base.Open);
|
|
AssertEquals('MessageCount', 291, base.MessageCount);
|
|
AssertTrue('Read first', base.ReadMessage(0, msg));
|
|
AssertEquals('Msg[0].WhoFrom', 'Robert Wolfe', msg.Attributes.Get('from'));
|
|
AssertEquals('Msg[0].WhoTo', 'Chad Lynch', msg.Attributes.Get('to'));
|
|
AssertEquals('Msg[0].Subject', 'Test', msg.Attributes.Get('subject'));
|
|
AssertTrue('Read last', base.ReadMessage(base.MessageCount - 1, msg));
|
|
walked := WalkAll(base);
|
|
AssertEquals('WalkAll count', base.MessageCount, walked);
|
|
finally
|
|
base.Close;
|
|
base.Free;
|
|
end;
|
|
TestOK;
|
|
end;
|
|
|
|
procedure TestMsg;
|
|
var
|
|
base: TMessageBase;
|
|
msg: TUniMessage;
|
|
walked: longint;
|
|
begin
|
|
TestBegin('FTS-1 MSG/netmail (27 numbered files)');
|
|
if not DirectoryExists(SAMPLES_ROOT + '/netmail') then begin
|
|
WriteLn('SKIP (sample missing)');
|
|
exit;
|
|
end;
|
|
base := MessageBaseOpen(mbfMsg, SAMPLES_ROOT + '/netmail', momReadOnly);
|
|
try
|
|
AssertTrue('Open', base.Open);
|
|
AssertEquals('MessageCount', 27, base.MessageCount);
|
|
AssertTrue('Read first', base.ReadMessage(0, msg));
|
|
AssertEquals('Msg[0].MsgNum', 1, msg.Attributes.GetInt('msg.num'));
|
|
AssertTrue('Msg[0].WhoFrom not empty', Length(msg.Attributes.Get('from')) > 0);
|
|
walked := WalkAll(base);
|
|
AssertEquals('WalkAll count', 27, walked);
|
|
finally
|
|
base.Close;
|
|
base.Free;
|
|
end;
|
|
TestOK;
|
|
end;
|
|
|
|
procedure TestHudson;
|
|
var
|
|
base: TMessageBase;
|
|
begin
|
|
TestBegin('Hudson (empty sample base)');
|
|
if not FileExists(SAMPLES_ROOT + '/hudson/msginfo.bbs') then begin
|
|
WriteLn('SKIP (sample missing)');
|
|
exit;
|
|
end;
|
|
base := MessageBaseOpen(mbfHudson, SAMPLES_ROOT + '/hudson',
|
|
momReadOnly);
|
|
try
|
|
AssertTrue('Open', base.Open);
|
|
AssertEquals('MessageCount', 0, base.MessageCount);
|
|
finally
|
|
base.Close;
|
|
base.Free;
|
|
end;
|
|
TestOK;
|
|
end;
|
|
|
|
procedure TestAutoDetect;
|
|
var
|
|
fmt: TMsgBaseFormat;
|
|
begin
|
|
TestBegin('Autodetect hudson sample');
|
|
if not DirectoryExists(SAMPLES_ROOT + '/hudson') then begin
|
|
WriteLn('SKIP (sample missing)');
|
|
exit;
|
|
end;
|
|
AssertTrue('DetectFormat', DetectFormat(SAMPLES_ROOT + '/hudson', fmt));
|
|
AssertEquals('detected', ord(mbfHudson), ord(fmt));
|
|
TestOK;
|
|
end;
|
|
|
|
begin
|
|
WriteLn('fpc-msgbase: read tests');
|
|
WriteLn;
|
|
TestJam;
|
|
TestMsg;
|
|
TestHudson;
|
|
TestAutoDetect;
|
|
Halt(TestsSummary);
|
|
end.
|