-- shared by the binhex / macbinary / applesingle tests: tools/fixtures/mac.py cases against The Unarchiver's listings. local T = require("@tests/T") local F = require("@rosetta") local Bytes = require("@rosetta/core/Bytes") local Crc32 = require("@rosetta/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 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