Files
rosetta/tests/archive/d64.luau
T

76 lines
2.8 KiB
Luau

-- archive/d64 tests: D64 / D71 / D81 images made by VICE's c1541 (PRG / SEQ / USR, multi-sector, a deleted file, an
-- error-info block, 30 files over several directory sectors) list the files c1541 reads back (names, sizes, types,
-- data CRCs), disk name and id; our D64 / D71 / D81 output is read by c1541 (fixture step) and round-trips; PETSCII
-- names; errors; the fuzz pass. Fixtures: tools/fixtures/d64.py.
local T = require("@tests/T")
local F = require("@formats")
local D64 = require("@formats/archive/d64")
local Bytes = require("@formats/core/Bytes")
local Err = require("@formats/core/Err")
local E = require("@tests/archive/_entries")
local Fx = require("@tests/gen/d64")
local t = T.suite("d64")
t:eq(D64.name, "d64", "name")
local samples = {}
for _, c in Fx.cases do
local a, err = D64.decode(Bytes.reader(buffer.fromstring(c.data)))
t:check(a, c.name .. ": " .. tostring(err))
if a then
E.check(t, a, c.entries, c.name)
t:eq(a.meta.disk, c.disk, c.name .. ": disk name")
t:eq(a.meta.id, c.id, c.name .. ": disk id")
for _, w in c.entries do
local e = a._byName[w.name]
t:eq(e and e.type, w.type, c.name .. ": " .. w.name .. " type")
end
t:check(a._byName.gone == nil, c.name .. ": deleted file skipped")
end
t:eq(F.detect(c.data), "d64", c.name .. ": detect")
if c.name == "d64" then
table.insert(samples, c.data)
end
end
for _, o in Fx.ours do
t:check(o.ok, "c1541 reads our " .. o.variant .. ": " .. o.listing)
end
for _, v in { "d64", "d71", "d81" } do
local out = E.roundTrip(t, D64, { variant = v, disk = "round trip", id = "rt" }, "round trip " .. v)
if out then
local a = D64.decode(Bytes.reader(out)) :: any
t:eq(a.meta.variant, v, v .. ": variant")
t:eq(a.meta.disk, "round trip", v .. ": disk name")
end
end
-- PETSCII names: lower / upper case and other bytes survive a round trip
local a = D64.new()
a:add("Mixed Case 1", "x")
a:add("\u{E0D3}hift", "y")
local back = D64.decode(Bytes.reader(a:write() :: buffer)) :: any
t:check(back._byName["Mixed Case 1"] and back._byName["\u{E0D3}hift"] == nil and back._byName["Shift"], "petscii names")
-- errors
local function code(b: buffer): string?
local _, e = D64.decode(Bytes.reader(b))
return e and e.code
end
t:eq(code(buffer.create(1000)), Err.CORRUPT, "bad size")
local img = buffer.fromstring(Fx.cases[1].data)
local dir = 357 * 256 -- track 18 sector 0
buffer.writeu8(img, dir, 99)
t:eq(code(img), Err.CORRUPT, "directory link off the disk")
local many = D64.new()
for i = 1, 145 do
many:add("f" .. i, "x")
end
t:eq((select(2, many:write()) :: any).code, Err.LIMIT, "directory full")
local big = D64.new()
big:add("big", buffer.create(200000))
t:eq((select(2, big:write()) :: any).code, Err.LIMIT, "disk full")
t:fuzz("decode", function(b: buffer)
return D64.decode(Bytes.reader(b))
end, samples, { mutations = 60, garbage = 20 })
t:done()