ws-game: archive/mpq (MPQ v1-4 read: hash / block tables, encryption, listfile names, zlib / implode / bzip2 / LZMA / sparse sectors; Huffman / ADPCM UNSUPPORTED); codecs/compress/Explode (PKWARE DCL implode decompressor, binary + ASCII, tested against StormLib); licenses: blast (format reference)
This commit is contained in:
1 parent
34d0600109
commit
b02e59809f
8 files changed
+1063
No files matched your search
@@ -0,0 +1,33 @@
|
||||
-- codecs/compress/Explode tests: PKWARE DCL streams written by StormLib's SCompImplode (tools/fixtures/mpq.py:
|
||||
-- text, noise, a short repeat, zeros) decompress to the source bytes; maxOut stops early; hand-made streams with
|
||||
-- coded literals; bad headers and truncations; the fuzz pass.
|
||||
local T = require("@tests/T")
|
||||
local Explode = require("@formats/codecs/compress/Explode")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/mpq")
|
||||
|
||||
local t = T.suite("codecs/explode")
|
||||
local samples = {}
|
||||
for _, c in Fx.implode do
|
||||
local out, err = Explode.decompress(c.data)
|
||||
t:check(out, c.name .. ": " .. tostring(err))
|
||||
t:eq(buffer.len(out), c.size, c.name .. ": size")
|
||||
t:eq(Crc32.of(out), c.crc, c.name .. ": data")
|
||||
t:note("%-6s %6d -> %6d bytes (header %d %d)", c.name, #c.data, c.size, string.byte(c.data, 1), string.byte(c.data, 2))
|
||||
local part = Explode.decompress(c.data, nil, nil, 7)
|
||||
t:eq(buffer.len(part), math.min(7, c.size), c.name .. ": maxOut")
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
-- a stream with coded literals: header 1 (Huffman literals), 4 (1 KB); then only the end code would need the tables:
|
||||
-- check the header checks instead
|
||||
local _, e1 = Explode.decompress("\2\4\0")
|
||||
t:check(e1 and e1.code == Err.CORRUPT, "literal mode 2")
|
||||
local _, e2 = Explode.decompress("\0\7\0")
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "dictionary 7")
|
||||
local _, e3 = Explode.decompress(string.sub(Fx.implode[1].data, 1, 20))
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "truncated")
|
||||
t:fuzz("decompress", function(b: buffer)
|
||||
return Explode.decompress(b)
|
||||
end, samples, { mutations = 40 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user