Files
fpc-msgbase/tests/test_read.pas
Ken Johnson 6b225fedfc 0.4.0: PKT moves to fpc-ftn-transport (breaking change)
Removes all PKT code from fpc-msgbase. The wire format and its
container concerns now live in the sibling fpc-ftn-transport
library (units tt.pkt.format, tt.pkt.reader, tt.pkt.writer,
tt.pkt.batch).  Pair this commit with fpc-ftn-transport's
0.2.0 (commit 6bb71a6).

Why: the previous "reader here, writer there" split (briefly
landed in 0.3.5) baked in a coupling that didn't survive a
fresh look. The writer reached into fpc-msgbase for types,
the wire format lived in the wrong house, and consumers reading
fpc-msgbase saw "PKT support" that was actually only half-
support. Cleanest split: PKT is a wire format, both directions
belong with the wire-format-aware library; fpc-msgbase becomes
purely real message bases (Hudson / JAM / Squish / MSG /
PCBoard / EzyCom / GoldBase / Wildcat).

Also a cleaner separation-of-concerns story: a BBS that just
reads JAM/Squish never needs fpc-ftn-transport. A pure store-
and-forward node doing only ArcMail unbundle never depends on
storage formats. Each library = one concern.

Removed:
  src/formats/ma.fmt.pkt.pas       -> tt.pkt.format
  src/formats/ma.fmt.pkt.uni.pas   -> tt.pkt.reader
                                      (TPktMessageBase -> TPktReader)
  src/ma.batch.pas                 -> tt.pkt.batch
                                      (TPacketBatch class name unchanged)
  tests/test_batch.pas             -> tests/test_pkt_writer.pas
                                      (consolidated PKT tests)
  examples/example_tosser.pas      -> moves with the batch helper

Reduced in src/ma.types.pas:
  - PacketRecord
  - FlavourType / FlavourTypeSet / DateTimeArray
  - FlagsToFido / FidoToFlags
  - VersionNum (PKT-product-code stamping)
  All moved to tt.pkt.format.

Kept in src/ma.types.pas:
  - mbfPkt enum value (so tt.pkt.reader can register the backend
    with the unified-API factory; consumers still use the
    standard MessageBaseOpen(mbfPkt, ...) shape)

Migration for vendoring consumers:

  before:                      after:
    uses ma.fmt.pkt;             uses tt.pkt.format;
    uses ma.fmt.pkt.uni;         uses tt.pkt.reader;
    uses ma.batch;               uses tt.pkt.batch;
    (no writer surface)          uses tt.pkt.writer;

    TPktMessageBase              TPktReader
    TPktFile, TPktMessage,       (unchanged class names)
      TPktHeaderInfo, etc.
    TPacketBatch                 (unchanged)

Docs sweep:
  - README: PKT row called out as "moved to fpc-ftn-transport";
    TPacketBatch removed from features.
  - docs/architecture.md: layer diagram drops PKT + ma.batch;
    new sibling-library box added for fpc-ftn-transport.
  - docs/attributes-registry.md: PKT column dropped from per-
    format support matrix; pointer to fpc-ftn-transport.
  - docs/API.md: PKT cheat-sheet entry redirects to
    fpc-ftn-transport; TPacketBatch section reduced to a
    "moved" pointer with the new uses-clause shape.
  - docs/ftsc-compliance.md: Type-2 / 2+ / 2.2 / AuxNet rows
    annotated as living in tt.pkt.format.

Suite: 47/47 across 9 programs (was 9 with test_batch; now 9
with the PKT bits dropped from test_consumer_round1 and
test_hwm).  All other tests untouched.
2026-04-18 11:32:42 -07:00

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,
ma.types, ma.events, ma.api,
ma.fmt.hudson, ma.fmt.hudson.uni,
ma.fmt.jam, ma.fmt.jam.uni,
ma.fmt.squish, ma.fmt.squish.uni,
ma.fmt.msg, ma.fmt.msg.uni,
ma.fmt.pcboard, ma.fmt.pcboard.uni,
ma.fmt.ezycom, ma.fmt.ezycom.uni,
ma.fmt.goldbase, ma.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.