ws-arch2: archive/binhex, archive/macbinary (I / II / III), archive/applesingle (AppleSingle / AppleDouble v1 / v2), read + write, over the new containers/MacFile (fork convention, Mac OS Roman names, 1904 dates)
This commit is contained in:
1 parent
fe44292f58
commit
3243291877
13 files changed
+1152
-4
No files matched your search
@@ -0,0 +1,78 @@
|
||||
-- shared by tests/archive/{binhex,macbinary,applesingle}.luau: run(name, module) checks the format's cases of
|
||||
-- tools/fixtures/mac.py against The Unarchiver's listings (fork names, sizes, data CRCs, type / creator), our writer's
|
||||
-- output read by unar (fixture step), round trips with a resource fork and Finder info, and the fuzz pass.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local E = require("@tests/archive/_entries")
|
||||
local Fx = require("@tests/gen/mac")
|
||||
|
||||
return function(name: string, mod: any, encodeVariants: { any }): (any, { string })
|
||||
local t = T.suite(name)
|
||||
t:eq(mod.name, name, "name")
|
||||
local samples = {}
|
||||
local n = 0
|
||||
for _, c in Fx.cases do
|
||||
if c.format == name then
|
||||
n += 1
|
||||
local a, err = mod.decode(Bytes.reader(buffer.fromstring(c.data)), { name = "x" })
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
if a then
|
||||
E.check(t, a, c.entries, c.name)
|
||||
local by = {}
|
||||
for _, e in a:list() do
|
||||
by[e.name] = e
|
||||
end
|
||||
for _, w in c.entries do
|
||||
local e = by[w.name]
|
||||
if e and w.macType then
|
||||
t:eq(e.macType, w.macType, c.name .. ": type")
|
||||
t:eq(e.macCreator, w.macCreator, c.name .. ": creator")
|
||||
end
|
||||
end
|
||||
end
|
||||
t:eq(F.detect(c.data), name, c.name .. ": detect")
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:check(n > 0, "has cases")
|
||||
for _, o in Fx.ours do
|
||||
if o.format == name then
|
||||
t:check(o.ok, "unar reads our output (" .. o.variant .. "): " .. o.detail)
|
||||
end
|
||||
end
|
||||
-- round trips: Finder info, dates, a resource fork
|
||||
for _, opts in encodeVariants do
|
||||
local a = mod.new()
|
||||
a:add("Caf\u{e9}", "data fork", { mtime = 1700000000 })
|
||||
a:add("Caf\u{e9}.rsrc", string.rep("R", 300), {})
|
||||
local d = a._byName["Caf\u{e9}"]
|
||||
d.macType, d.macCreator, d.finderFlags = "TEXT", "ttxt", 0x0100
|
||||
a._byName["Caf\u{e9}.rsrc"].fork = "resource"
|
||||
local out, err = a:write(opts)
|
||||
t:check(out, "write: " .. tostring(err))
|
||||
local back = out and mod.decode(Bytes.reader(out))
|
||||
t:check(back, "round trip decodes")
|
||||
if back then
|
||||
local list = back:list()
|
||||
local by = {}
|
||||
for _, e in list do
|
||||
by[e.name] = e
|
||||
end
|
||||
local rs = by["Caf\u{e9}.rsrc"]
|
||||
t:check(rs and rs.size == 300 and rs.fork == "resource", "round trip resource fork")
|
||||
t:eq(Crc32.of((back:read("Caf\u{e9}.rsrc"))), Crc32.string(string.rep("R", 300)), "round trip resource data")
|
||||
local df = by["Caf\u{e9}"]
|
||||
local fi = df or rs
|
||||
t:check(fi and fi.macType == "TEXT" and fi.macCreator == "ttxt" and fi.finderFlags == 0x0100, "round trip Finder info")
|
||||
if not (opts and opts.double) then
|
||||
t:eq(buffer.tostring((back:read("Caf\u{e9}"))), "data fork", "round trip data fork")
|
||||
if name ~= "binhex" then
|
||||
t:eq(df and df.mtime, 1700000000, "round trip mtime")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return t, samples
|
||||
end
|
||||
Reference in new issue
Block a user