ws-audio: merge master (ws/m4a codecs/Mdct already in use since 6535a3c; audio/opus encoder, data, vec, 3d, webp)
No files matched your search
@@ -0,0 +1,115 @@
|
||||
-- archive/7z tests: the contract and sniff; every archive 7-Zip wrote in tools/fixtures/7z.py (LZMA / LZMA2 / copy /
|
||||
-- Deflate, solid and not, BCJ / ARM64 / ARM / PPC + SPARC / delta chains, plain and encoded headers) lists exactly the
|
||||
-- source tree (names incl. UTF-16 surrogates, directories, empty files, mtimes) and reads every file back; unsupported
|
||||
-- methods (PPMd, BCJ2, AES) list but fail on read with Err.UNSUPPORTED naming the method; corrupt CRCs; F.load;
|
||||
-- the fuzz no-throw pass.
|
||||
local T = require("@tests/T")
|
||||
local SevenZip = require("@formats/archive/7z")
|
||||
local F = require("@formats")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/7z")
|
||||
|
||||
local t = T.suite("7z")
|
||||
|
||||
t:eq(SevenZip.name, "7z", "name")
|
||||
t:eq(SevenZip.category, "archive", "category")
|
||||
t:check(SevenZip.caps.decode and not SevenZip.caps.encode, "caps")
|
||||
|
||||
local function decode(data: string, opts: any?): (any, any)
|
||||
return SevenZip.decode(Bytes.reader(buffer.fromstring(data)), opts)
|
||||
end
|
||||
|
||||
local want: { [string]: any } = {}
|
||||
for _, f in Fx.files do
|
||||
want[f.name] = f
|
||||
end
|
||||
|
||||
local nfiles = 0
|
||||
for _, c in Fx.cases do
|
||||
t:eq(SevenZip.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, c.name .. ": sniff")
|
||||
local a, err = decode(c.data)
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
local list = a:list()
|
||||
if c.empty then
|
||||
t:eq(#list, 0, c.name .. ": no entries")
|
||||
continue
|
||||
end
|
||||
local seen = {}
|
||||
for _, e in list do
|
||||
local w = want[e.name]
|
||||
t:check(w ~= nil, c.name .. ": unexpected entry " .. e.name)
|
||||
seen[e.name] = true
|
||||
t:eq(e.dir, w.dir, c.name .. ": " .. e.name .. ": dir")
|
||||
t:eq(e.mtime, w.mtime, c.name .. ": " .. e.name .. ": mtime")
|
||||
if not w.dir then
|
||||
t:eq(e.size, #w.data, c.name .. ": " .. e.name .. ": size")
|
||||
local b, rerr = a:read(e.name)
|
||||
if c.unsupported and #w.data > 0 then
|
||||
t:check(b == nil and rerr and rerr.code == Err.UNSUPPORTED and string.find(rerr.message, c.unsupported, 1, true) ~= nil,
|
||||
c.name .. ": " .. e.name .. ": unsupported: " .. tostring(rerr))
|
||||
else
|
||||
t:check(b and buffer.tostring(b) == w.data, c.name .. ": " .. e.name .. ": data: " .. tostring(rerr))
|
||||
nfiles += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
for name in want do
|
||||
t:check(seen[name], c.name .. ": missing " .. name)
|
||||
end
|
||||
end
|
||||
t:note("%d archives, %d files read", #Fx.cases, nfiles)
|
||||
|
||||
-- corrupt data: a flipped byte in a stored file is a CRC error on read; a flipped header byte a header CRC error
|
||||
do
|
||||
local c
|
||||
for _, x in Fx.cases do
|
||||
if x.name == "copy" then
|
||||
c = x
|
||||
end
|
||||
end
|
||||
local s = c.data
|
||||
local at = string.find(s, "deep\ndeep", 1, true) :: number
|
||||
local bad = string.sub(s, 1, at - 1) .. "D" .. string.sub(s, at + 1)
|
||||
local a = decode(bad)
|
||||
t:check(a, "copy archive with a flipped data byte still lists")
|
||||
local b, e = a:read("a/b/c/deep.txt")
|
||||
t:check(b == nil and e and e.code == Err.CHECKSUM, "data CRC: " .. tostring(e))
|
||||
local _, e2 = decode(string.sub(s, 1, #s - 3) .. "\0\0\0")
|
||||
t:check(e2 and (e2.code == Err.CHECKSUM or e2.code == Err.CORRUPT), "header CRC: " .. tostring(e2))
|
||||
local _, e3 = decode(string.sub(s, 1, 20))
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "truncated: " .. tostring(e3))
|
||||
local a4 = decode(bad, { checkCrc = false })
|
||||
t:check(a4 and a4:read("a/b/c/deep.txt"), "checkCrc = false")
|
||||
end
|
||||
|
||||
-- through the api
|
||||
do
|
||||
local c = Fx.cases[2]
|
||||
local a, err = F.load(c.data)
|
||||
t:check(a and a.format == "7z", "F.load: " .. tostring(err))
|
||||
t:eq(F.detect(c.data), "7z", "F.detect")
|
||||
local r = a:read("readme.txt")
|
||||
t:check(r and buffer.tostring(r) == want["readme.txt"].data, "F.load read")
|
||||
end
|
||||
|
||||
-- fuzz: decode + read every entry
|
||||
do
|
||||
local samples = {}
|
||||
for _, c in Fx.cases do
|
||||
if #c.data < 60000 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
local a = SevenZip.decode(Bytes.reader(b), { maxBytes = 2 ^ 21 })
|
||||
if a then
|
||||
for _, e in a:list() do
|
||||
a:read(e.name)
|
||||
end
|
||||
end
|
||||
return a
|
||||
end, samples, { mutations = 12, garbage = 300 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,97 @@
|
||||
-- archive/br tests: the contract; fixture streams (tools/fixtures/brotli.py) load as a one-entry stream archive named
|
||||
-- after the file; detection through F.load (sniff + extension); sniff rejects garbage and other formats; errors as
|
||||
-- Err values; the fuzz no-throw pass.
|
||||
local T = require("@tests/T")
|
||||
local Br = require("@formats/archive/br")
|
||||
local F = require("@formats")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/brotli")
|
||||
|
||||
local t = T.suite("br")
|
||||
|
||||
-- 1. the contract
|
||||
t:eq(Br.name, "br", "name")
|
||||
t:eq(Br.category, "archive", "category")
|
||||
t:check(Br.caps.decode and not Br.caps.encode, "caps")
|
||||
|
||||
-- 2. fixtures
|
||||
local n = 0
|
||||
for i, c in Fx.cases do
|
||||
if i % 4 == 0 then
|
||||
local a, err = Br.decode(Bytes.reader(buffer.fromstring(c.data)), { name = "dir/file.txt.br" })
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
t:check(a.kind == "archive" and a.format == "br" and a.meta.stream, c.name .. ": a stream archive")
|
||||
local list = a:list()
|
||||
t:eq(#list, 1, c.name .. ": one entry")
|
||||
t:eq(list[1].name, "file.txt", c.name .. ": entry name")
|
||||
t:eq(list[1].size, #Fx.corpora[c.corpus], c.name .. ": entry size")
|
||||
t:eq(list[1].compressedSize, #c.data, c.name .. ": compressed size")
|
||||
local data = a:read("file.txt")
|
||||
t:check(data and buffer.tostring(data) == Fx.corpora[c.corpus], c.name .. ": entry data")
|
||||
n += 1
|
||||
end
|
||||
end
|
||||
t:note("%d streams", n)
|
||||
|
||||
-- default entry name
|
||||
do
|
||||
local a = Br.decode(Bytes.reader(buffer.fromstring(Fx.cases[5].data)))
|
||||
t:eq(a:list()[1].name, "data", "default entry name")
|
||||
end
|
||||
|
||||
-- 3. through the api: by sniff (with and without the extension) and by format name
|
||||
do
|
||||
local c = Fx.cases[40]
|
||||
local a, err = F.load(c.data, { name = "x.br" })
|
||||
t:check(a and a.format == "br", "F.load by sniff + extension: " .. tostring(err))
|
||||
t:eq(a:list()[1].name, "x", "F.load names the entry")
|
||||
local a2 = F.load(c.data)
|
||||
t:check(a2 and a2.format == "br", "F.load by sniff alone")
|
||||
local a3 = F.archive.load(c.data, { format = "br" })
|
||||
t:check(a3 and a3.format == "br", "F.archive.load with format")
|
||||
t:eq(F.detect(c.data, { name = "x.br" }), "br", "F.detect")
|
||||
local _, e = F.save(a3, nil, { format = "br" })
|
||||
t:check(e and e.code == Err.UNSUPPORTED, "no encoder: " .. tostring(e))
|
||||
end
|
||||
|
||||
-- 4. sniff: garbage and plain text are rejected
|
||||
do
|
||||
local rand = T.rng(99)
|
||||
local hits = 0
|
||||
for _ = 1, 300 do
|
||||
local len = 16 + rand(400)
|
||||
local b = buffer.create(len)
|
||||
for k = 0, len - 1 do
|
||||
buffer.writeu8(b, k, rand(256))
|
||||
end
|
||||
if Br.sniff(Bytes.reader(b)) > 0 then
|
||||
hits += 1
|
||||
end
|
||||
end
|
||||
t:note("sniff accepted %d of 300 random buffers", hits)
|
||||
t:check(hits <= 3, "sniff rejects random data")
|
||||
t:eq(Br.sniff(Bytes.reader(buffer.fromstring("Hello, world! This is plain text.\n"))), 0, "sniff rejects text")
|
||||
t:eq(Br.sniff(Bytes.reader(buffer.create(0))), 0, "sniff of nothing")
|
||||
t:check(Br.sniff(Bytes.reader(buffer.fromstring(Fx.cases[40].data))) > 0, "sniff accepts a stream")
|
||||
local _, e = Br.decode(Bytes.reader(buffer.fromstring("\x1b\xff\xff")))
|
||||
t:check(e and Err.is(e) and (e.code == Err.CORRUPT or e.code == Err.TRUNCATED), "bad data: " .. tostring(e))
|
||||
end
|
||||
|
||||
-- 5. fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if i % 23 == 0 and #c.data > 8 then
|
||||
table.insert(samples, if #c.data > 8000 then string.sub(c.data, 1, 8000) else c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Br.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 4, garbage = 500 })
|
||||
t:fuzz("sniff", function(b: buffer)
|
||||
return Br.sniff(Bytes.reader(b))
|
||||
end, samples, { mutations = 2, garbage = 300 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,65 @@
|
||||
-- archive/bz2 tests: the contract, sniff, a .bz2 as a one-entry single-stream archive (entry named after the file),
|
||||
-- the api path (F.load by sniff, .tar.bz2 unwrap is the api's: covered once tar exists), errors, the fuzz pass.
|
||||
-- Fixtures: tools/fixtures/bzip2.py.
|
||||
local T = require("@tests/T")
|
||||
local Bz2 = require("@formats/archive/bz2")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local F = require("@formats")
|
||||
local Fx = require("@tests/gen/bzip2")
|
||||
|
||||
local t = T.suite("bz2")
|
||||
|
||||
t:eq(Bz2.name, "bz2", "name")
|
||||
t:eq(Bz2.category, "archive", "category")
|
||||
t:check(Bz2.caps.decode and not Bz2.caps.encode, "caps")
|
||||
|
||||
for _, c in Fx.cases do
|
||||
t:eq(Bz2.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, c.name .. ": sniff")
|
||||
end
|
||||
t:eq(Bz2.sniff(Bytes.reader(buffer.fromstring("BZh9hello"))), 0, "sniff: no block magic")
|
||||
t:eq(Bz2.sniff(Bytes.reader(buffer.fromstring("\x1f\x8b\x08\x00"))), 0, "sniff: gzip")
|
||||
|
||||
do
|
||||
local c = Fx.cases[1]
|
||||
for _, x in Fx.cases do
|
||||
if x.name == "text/l9" then
|
||||
c = x
|
||||
end
|
||||
end
|
||||
local a, err = Bz2.decode(Bytes.reader(buffer.fromstring(c.data)), { name = "dir/notes.txt.bz2" })
|
||||
t:check(a, "decode: " .. tostring(err))
|
||||
t:check(a.kind == "archive" and a.format == "bz2" and a.meta.stream, "a single-stream archive")
|
||||
local list = a:list()
|
||||
t:eq(#list, 1, "one entry")
|
||||
t:eq(list[1].name, "notes.txt", "entry named after the file")
|
||||
t:eq(list[1].size, #Fx.corpora.text, "entry size")
|
||||
t:eq(list[1].compressedSize, #c.data, "compressed size")
|
||||
t:check(buffer.tostring((a:read("notes.txt"))) == Fx.corpora.text, "read")
|
||||
local _, re = a:read("nope")
|
||||
t:check(re and re.code == Err.ARG, "read of a missing entry")
|
||||
local _, we = a:write()
|
||||
t:check(we and we.code == Err.UNSUPPORTED, "read-only")
|
||||
local a2 = Bz2.decode(Bytes.reader(buffer.fromstring(c.data)), { name = "x.tbz2" })
|
||||
t:eq(a2:list()[1].name, "x.tar", ".tbz2 -> .tar")
|
||||
local a3 = Bz2.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:eq(a3:list()[1].name, "data", "no name -> data")
|
||||
-- through the api
|
||||
local v, ferr = F.load(c.data)
|
||||
t:check(v and v.kind == "archive" and v.format == "bz2", "F.load sniffs bz2: " .. tostring(ferr))
|
||||
t:eq(F.detect(c.data), "bz2", "F.detect")
|
||||
local _, de = Bz2.decode(Bytes.reader(buffer.fromstring(string.sub(c.data, 1, 100))))
|
||||
t:check(de and de.code == Err.TRUNCATED, "truncated: " .. tostring(de))
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if i % 6 == 0 and #c.data < 30000 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Bz2.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 6, garbage = 300 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,93 @@
|
||||
-- archive/gzip tests: members from Python's gzip and the gzip CLI (FNAME, MTIME, levels, concatenated members) decode
|
||||
-- to one entry with the right name / mtime / data; the writer round-trips (buffer, string, one-entry archive, several
|
||||
-- entries as a .tar.gz) and keeps FNAME / MTIME; the api; errors; the fuzz pass. Fixtures: tools/fixtures/tar.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Gzip = require("@formats/archive/gzip")
|
||||
local Deflate = require("@formats/codecs/Deflate")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/tar")
|
||||
|
||||
local t = T.suite("gzip")
|
||||
t:eq(Gzip.name, "gzip", "name")
|
||||
|
||||
for _, c in Fx.gzips do
|
||||
local a, err = Gzip.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
t:check(a.meta.stream, c.name .. ": single stream")
|
||||
local l = a:list()
|
||||
t:eq(#l, 1, c.name .. ": one entry")
|
||||
t:eq(l[1].name, c.entry, c.name .. ": entry name")
|
||||
t:eq(l[1].mtime, if c.mtime > 0 then c.mtime else nil, c.name .. ": mtime")
|
||||
t:eq(l[1].size, c.size, c.name .. ": size")
|
||||
t:eq(Crc32.of((a:read(l[1].name))), c.crc, c.name .. ": data")
|
||||
t:eq(F.detect(c.data), "gzip", c.name .. ": F.detect")
|
||||
end
|
||||
|
||||
-- the file name names the entry when there is no FNAME
|
||||
do
|
||||
local a = F.load(Fx.gzips[2].data, { name = "dir/notes.txt.gz" })
|
||||
t:eq(a:list()[1].name, "notes.txt", "entry named after the file")
|
||||
local b = F.load(Fx.gzips[2].data, { name = "x.tgz" })
|
||||
t:eq(b:list()[1].name, "x.tar", ".tgz entry is a .tar")
|
||||
end
|
||||
|
||||
-- writing
|
||||
do
|
||||
local text = string.rep("gzip round trip ", 500)
|
||||
for _, level in { 0, 1, 6, 9 } do
|
||||
local z = Gzip.encode(text, { level = level }) :: buffer
|
||||
t:eq(buffer.tostring((Deflate.gunzip(z))), text, "string level " .. level)
|
||||
end
|
||||
local one = Gzip.new(text, "notes.txt")
|
||||
one._byName["notes.txt"].mtime = 1600000000
|
||||
local z = one:write()
|
||||
local back = Gzip.decode(Bytes.reader(z :: buffer))
|
||||
t:eq(back:list()[1].name, "notes.txt", "FNAME written")
|
||||
t:eq(back:list()[1].mtime, 1600000000, "MTIME written")
|
||||
t:eq(buffer.tostring((back:read("notes.txt"))), text, "one-entry archive round trip")
|
||||
-- a decoded gzip saves back as gzip (its source format)
|
||||
local g = F.load(Fx.gzips[1].data)
|
||||
local again = F.load(F.save(g))
|
||||
t:eq(again:list()[1].name, "story.txt", "F.save(gzip) keeps the name")
|
||||
-- several entries: a .tar.gz, which the api unwraps
|
||||
local multi = Gzip.new()
|
||||
multi:add("a.txt", "A")
|
||||
multi:add("b.txt", "BB")
|
||||
local tgz = multi:write()
|
||||
local tar = F.load(tgz)
|
||||
t:eq(tar.format, "tar", "several entries write a .tar.gz")
|
||||
t:eq(tar.meta.compression, "gzip", "unwrapped")
|
||||
t:eq(buffer.tostring((tar:read("b.txt"))), "BB", ".tar.gz entry")
|
||||
-- any archive converts: tar -> gzip -> tar
|
||||
local tb = F.convert(Fx.tars[1].data, "gzip")
|
||||
local t2 = F.load(tb)
|
||||
t:eq(#t2:list(), #Fx.tars[1].entries, "tar -> tar.gz -> tar")
|
||||
local _, e = Gzip.encode(text, { level = 12 })
|
||||
t:check(e and e.code == Err.ARG, "bad level")
|
||||
local _, e2 = Gzip.encode({ kind = "image" })
|
||||
t:check(e2 and e2.code == Err.ARG, "not an archive")
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local d = Fx.gzips[1].data
|
||||
local _, e1 = Gzip.decode(Bytes.reader(buffer.fromstring(string.sub(d, 1, 20))))
|
||||
t:check(e1 and e1.code == Err.TRUNCATED, "truncated: " .. tostring(e1))
|
||||
local b = buffer.fromstring(d)
|
||||
buffer.writeu8(b, #d - 6, bit32.bxor(buffer.readu8(b, #d - 6), 1))
|
||||
local _, e2 = Gzip.decode(Bytes.reader(b))
|
||||
t:check(e2 and e2.code == Err.CHECKSUM, "crc: " .. tostring(e2))
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx.gzips do
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Gzip.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 20 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,156 @@
|
||||
-- archive/tar tests: archives from Python's tarfile (ustar / GNU / pax) and GNU tar (ustar / gnu / posix / v7) list
|
||||
-- the same entries as tarfile reads (names, types, sizes, links, mtimes, modes, data CRCs); the writer produces the same
|
||||
-- bytes as tarfile for the same entries in all three formats and round-trips; Archive values (add / read / write,
|
||||
-- conversion of a gzip / any archive to tar); .tar.gz / .tgz / .tar.bz2 / .tar.xz / .tar.zst / .tar.br load through the
|
||||
-- api as the tar inside; errors; the fuzz pass. Fixtures: tools/fixtures/tar.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local TarF = require("@formats/archive/tar")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/tar")
|
||||
|
||||
local t = T.suite("tar")
|
||||
t:eq(TarF.name, "tar", "name")
|
||||
|
||||
local function check(a: any, want: any, label: string)
|
||||
local list = a:list()
|
||||
t:eq(#list, #want, label .. ": entry count")
|
||||
local by = {}
|
||||
for _, e in list do
|
||||
by[e.name] = e
|
||||
end
|
||||
for _, w in want do
|
||||
local e = by[w.name]
|
||||
t:check(e, label .. ": has " .. w.name)
|
||||
t:eq(e.type, w.type, label .. ": " .. w.name .. " type")
|
||||
t:eq(e.size, w.size, label .. ": " .. w.name .. " size")
|
||||
t:eq(e.mtime, w.mtime, label .. ": " .. w.name .. " mtime")
|
||||
t:eq(e.mode, w.mode, label .. ": " .. w.name .. " mode")
|
||||
t:eq(e.link, w.link, label .. ": " .. w.name .. " link")
|
||||
t:eq(e.dir, w.type == "5", label .. ": " .. w.name .. " dir")
|
||||
if w.crc then
|
||||
local b, err = a:read(w.name)
|
||||
t:check(b, label .. ": read " .. w.name .. ": " .. tostring(err))
|
||||
t:eq(Crc32.of(b), w.crc, label .. ": " .. w.name .. " data")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 1. reading
|
||||
for _, c in Fx.tars do
|
||||
local a, err = TarF.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
check(a, c.entries, c.name)
|
||||
t:eq(F.detect(c.data), "tar", c.name .. ": F.detect")
|
||||
t:note("%-18s %2d entries", c.name, #c.entries)
|
||||
end
|
||||
|
||||
-- 2. writing: byte-identical to Python's tarfile (which pads to 10240-byte records)
|
||||
for _, w in Fx.writes do
|
||||
local list = {}
|
||||
for _, e in w.entries do
|
||||
table.insert(list, {
|
||||
name = e.name,
|
||||
data = if e.data then buffer.fromstring(e.data) else nil,
|
||||
dir = e.dir,
|
||||
type = e.type,
|
||||
link = e.link,
|
||||
mode = e.mode or (if e.dir then 0x1ED else 0x1A4),
|
||||
mtime = 1700000000,
|
||||
uname = "user",
|
||||
gname = "group",
|
||||
})
|
||||
end
|
||||
local a = TarF.new()
|
||||
for _, e in list do
|
||||
a:add(e.name, e.data or "", { dir = e.dir, mtime = e.mtime, mode = e.mode })
|
||||
local ent = a._byName[e.name]
|
||||
ent.type, ent.link, ent.uname, ent.gname = e.type, e.link, e.uname, e.gname
|
||||
end
|
||||
local out, err = a:write({ format = w.format })
|
||||
t:check(out, w.format .. ": write: " .. tostring(err))
|
||||
local s = buffer.tostring(out :: buffer)
|
||||
local ref = w.data
|
||||
t:check(#s <= #ref and string.sub(ref, 1, #s) == s and not string.find(string.sub(ref, #s + 1), "[^%z]"), w.format .. ": bytes identical to tarfile")
|
||||
local back = TarF.decode(Bytes.reader(out :: buffer))
|
||||
t:eq(#back:list(), #list, w.format .. ": round trip count")
|
||||
for _, e in w.entries do
|
||||
if e.data then
|
||||
t:eq(buffer.tostring((back:read(e.name))), e.data, w.format .. ": round trip " .. e.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 3. Archive values: add / read / write, other archives to tar
|
||||
do
|
||||
local a = TarF.new()
|
||||
a:add("a.txt", "alpha", { mtime = 5 })
|
||||
a:add("b/", "", { dir = true })
|
||||
a:add("b/c.bin", buffer.fromstring("\0\1\2"))
|
||||
a:add("a.txt", "replaced")
|
||||
t:eq(#a:list(), 3, "add replaces by name")
|
||||
local buf = F.save(a)
|
||||
t:check(buf, "F.save(tar archive) uses the source format")
|
||||
local back = F.load(buf)
|
||||
t:eq(buffer.tostring(back:read("a.txt")), "replaced", "read back")
|
||||
t:check(back:list()[2].dir, "directory entry")
|
||||
local _, e = back:read("missing")
|
||||
t:check(e and e.code == Err.ARG, "missing entry")
|
||||
-- a gzip (single-stream archive) converts to a tar holding its one entry
|
||||
local g = F.load(Fx.gzips[1].data)
|
||||
local tb = F.save(g, nil, { format = "tar" })
|
||||
local ta = F.load(tb)
|
||||
t:eq(ta:list()[1].name, "story.txt", "gzip -> tar entry name")
|
||||
t:eq(ta:list()[1].size, Fx.gzips[1].size, "gzip -> tar entry size")
|
||||
end
|
||||
|
||||
-- 4. compressed tars through the api
|
||||
for _, w in Fx.wrapped do
|
||||
local a, err = F.load(w.data, { name = w.name })
|
||||
t:check(a, w.name .. ": " .. tostring(err))
|
||||
t:eq(a.format, "tar", w.name .. ": unwrapped to the tar")
|
||||
t:eq(a.meta.compression, w.outer, w.name .. ": meta.compression")
|
||||
check(a, Fx.innerEntries, w.name)
|
||||
local outer = F.load(w.data, { name = w.name, unwrap = false })
|
||||
t:eq(outer.format, w.outer, w.name .. ": unwrap = false keeps the outer archive")
|
||||
t:eq(outer:list()[1].name, "a.tar", w.name .. ": inner entry named after the file")
|
||||
end
|
||||
|
||||
-- 5. errors
|
||||
do
|
||||
local good = Fx.tars[1].data
|
||||
local b = buffer.fromstring(good)
|
||||
buffer.writeu8(b, 10, buffer.readu8(b, 10) + 1)
|
||||
local _, e1 = TarF.decode(Bytes.reader(b))
|
||||
t:check(e1 and e1.code == Err.CORRUPT, "first header checksum: " .. tostring(e1))
|
||||
local _, e2 = TarF.decode(Bytes.reader(buffer.fromstring(string.sub(good, 1, 700))))
|
||||
t:check(e2 and e2.code == Err.TRUNCATED, "truncated data: " .. tostring(e2))
|
||||
local _, e3 = TarF.encode({ kind = "image" })
|
||||
t:check(e3 and e3.code == Err.ARG, "encode a non-archive")
|
||||
local u = TarF.new()
|
||||
u:add(string.rep("y", 120), "x")
|
||||
local _, e4 = u:write({ format = "ustar" })
|
||||
t:check(e4 and e4.code == Err.ARG, "ustar cannot hold a 120-byte name without a slash")
|
||||
t:eq(TarF.sniff(Bytes.reader(buffer.fromstring(string.rep("\0", 1024)))), 0, "zeros are not a tar")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx.tars do
|
||||
if #c.data <= 30000 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
local a = TarF.decode(Bytes.reader(b))
|
||||
if a then
|
||||
for _, e in a:list() do
|
||||
a:read(e.name)
|
||||
end
|
||||
a:write()
|
||||
end
|
||||
return a
|
||||
end, samples, { mutations = 30, keepHeader = 0 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,78 @@
|
||||
-- archive/xz tests: the contract, sniffing (.xz magic, conservative .lzma), every xz / .lzma fixture of
|
||||
-- tools/fixtures/lzma.py read as a one-entry archive (entry names from opts.name), F.load through the registry, errors,
|
||||
-- and the fuzz no-throw pass.
|
||||
local T = require("@tests/T")
|
||||
local Xz = require("@formats/archive/xz")
|
||||
local F = require("@formats")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/lzma")
|
||||
|
||||
local t = T.suite("xz")
|
||||
|
||||
t:eq(Xz.name, "xz", "name")
|
||||
t:eq(Xz.category, "archive", "category")
|
||||
t:check(Xz.caps.decode and not Xz.caps.encode, "caps")
|
||||
|
||||
local function reader(s: string): Bytes.Reader
|
||||
return Bytes.reader(buffer.fromstring(s))
|
||||
end
|
||||
|
||||
local n = 0
|
||||
for _, c in Fx.cases do
|
||||
if c.kind == "xz" or c.kind == "alone" then
|
||||
local want = Fx.corpora[c.corpus]
|
||||
t:check(Xz.sniff(reader(c.data)) > 0, c.name .. ": sniff")
|
||||
local a, err = Xz.decode(reader(c.data), { name = "dir/file.txt." .. (if c.kind == "xz" then "xz" else "lzma") })
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
local list = a:list()
|
||||
t:eq(#list, 1, c.name .. ": one entry")
|
||||
t:eq(list[1].name, "file.txt", c.name .. ": entry name")
|
||||
t:eq(list[1].size, #want, c.name .. ": size")
|
||||
t:check(a.meta.stream == true, c.name .. ": meta.stream")
|
||||
local b = a:read("file.txt")
|
||||
t:check(b and buffer.tostring(b) == want, c.name .. ": data")
|
||||
n += 1
|
||||
end
|
||||
end
|
||||
t:note("%d xz / lzma files", n)
|
||||
|
||||
-- sniff: not xz
|
||||
t:eq(Xz.sniff(reader("PK\3\4 hello")), 0, "zip is not xz")
|
||||
t:eq(Xz.sniff(reader("")), 0, "empty")
|
||||
t:eq(Xz.sniff(reader(string.rep("\0", 40))), 0, "zeros are not .lzma")
|
||||
|
||||
-- through the api
|
||||
do
|
||||
local c = Fx.cases[1]
|
||||
for _, x in Fx.cases do
|
||||
if x.name == "text/xz-6" then
|
||||
c = x
|
||||
end
|
||||
end
|
||||
local a, err = F.load(c.data, { name = "notes.txz" })
|
||||
t:check(a and a.kind == "archive" and a.format == "xz", "F.load: " .. tostring(err))
|
||||
t:eq(a:list()[1].name, "notes.tar", "txz -> tar entry name")
|
||||
t:eq(F.detect(c.data), "xz", "F.detect")
|
||||
local a2 = F.archive.load(c.data)
|
||||
t:eq(a2:list()[1].name, "data", "unnamed entry")
|
||||
local _, e2 = F.save(a2, nil, { format = "xz" })
|
||||
t:check(e2 and e2.code == Err.UNSUPPORTED, "xz is read-only: " .. tostring(e2))
|
||||
local _, e3 = F.load(string.sub(c.data, 1, 100), { format = "xz" })
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "truncated: " .. tostring(e3))
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if (c.kind == "xz" or c.kind == "alone") and i % 5 == 0 and #c.data < 30000 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Xz.decode(Bytes.reader(b), { maxBytes = 2 ^ 20 })
|
||||
end, samples, { mutations = 6, garbage = 400 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,90 @@
|
||||
-- archive/zst tests: the contract, sniff (zstd and skippable-frame magic), decode of zstd CLI output into a one-entry
|
||||
-- single-stream archive (entry name from opts.name, size, read), F.load detection by content, read-only errors, and
|
||||
-- the fuzz no-throw pass. Fixtures: tools/fixtures/zstd.py (shared with tests/codecs/zstd.luau).
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Zst = require("@formats/archive/zst")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/zstd")
|
||||
|
||||
local t = T.suite("zst")
|
||||
|
||||
-- contract
|
||||
t:eq(Zst.name, "zst", "name")
|
||||
t:eq(Zst.category, "archive", "category")
|
||||
t:check(Zst.caps.decode and not Zst.caps.encode, "caps")
|
||||
|
||||
local function case(name: string): any
|
||||
for _, c in Fx.cases do
|
||||
if c.name == name then
|
||||
return c
|
||||
end
|
||||
end
|
||||
error("no case " .. name)
|
||||
end
|
||||
|
||||
-- sniff
|
||||
t:eq(Zst.sniff(Bytes.reader(buffer.fromstring(case("text/l3").data))), 1, "sniff zstd")
|
||||
t:eq(Zst.sniff(Bytes.reader(buffer.fromstring(case("skipfirst/frames").data))), 0.5, "sniff skippable frame")
|
||||
t:eq(Zst.sniff(Bytes.reader(buffer.fromstring("PK\3\4"))), 0, "sniff other")
|
||||
t:eq(Zst.sniff(Bytes.reader(buffer.create(0))), 0, "sniff empty")
|
||||
|
||||
-- decode: one entry, named after the file
|
||||
for _, name in { "text/l3", "runs/ultra22", "multi/frames", "empty/l3", "big/l19" } do
|
||||
local c = case(name)
|
||||
local a, err = Zst.decode(Bytes.reader(buffer.fromstring(c.data)), { name = "dir/notes.txt.zst" })
|
||||
t:check(a, name .. ": " .. tostring(err))
|
||||
local list = a:list()
|
||||
t:eq(#list, 1, name .. ": one entry")
|
||||
t:eq(list[1].name, "notes.txt", name .. ": entry name")
|
||||
t:eq(list[1].size, #Fx.corpora[c.corpus], name .. ": size")
|
||||
t:eq(list[1].compressedSize, #c.data, name .. ": compressedSize")
|
||||
t:check(a.meta.stream == true and a.kind == "archive" and a.format == "zst", name .. ": archive fields")
|
||||
local data = a:read(list[1].name)
|
||||
t:check(data and buffer.tostring(data) == Fx.corpora[c.corpus], name .. ": read")
|
||||
end
|
||||
do
|
||||
local c = case("short/l3")
|
||||
local a = Zst.decode(Bytes.reader(buffer.fromstring(c.data))) :: any
|
||||
t:eq(a:list()[1].name, "data", "no name -> data")
|
||||
local a2 = Zst.decode(Bytes.reader(buffer.fromstring(c.data)), { name = "backup.tzst" }) :: any
|
||||
t:eq(a2:list()[1].name, "backup.tar", ".tzst -> .tar")
|
||||
local _, e = a:read("nope")
|
||||
t:check(e and e.code == Err.ARG, "missing entry")
|
||||
local _, we = a:write()
|
||||
t:check(we and we.code == Err.UNSUPPORTED, "read-only: " .. tostring(we))
|
||||
-- inside a bigger buffer (the reader's range)
|
||||
local big = buffer.create(#c.data + 10)
|
||||
buffer.writestring(big, 5, c.data)
|
||||
local a3 = Zst.decode(Bytes.reader(big, 5, #c.data)) :: any
|
||||
t:check(a3 and buffer.tostring(a3:read("data")) == Fx.corpora.short, "reader range")
|
||||
end
|
||||
|
||||
-- the api: detection by content, the name from opts
|
||||
do
|
||||
local c = case("text/l5")
|
||||
local a, err = F.load(c.data, { name = "x/readme.md.zst" })
|
||||
t:check(a and a.format == "zst", "F.load detects zst: " .. tostring(err))
|
||||
t:eq(a:list()[1].name, "readme.md", "F.load entry name")
|
||||
t:eq(F.detect(c.data), "zst", "F.detect")
|
||||
local _, e = F.load(string.sub(c.data, 1, 30), { format = "zst" })
|
||||
t:check(e and e.code == Err.TRUNCATED, "truncated through the api: " .. tostring(e))
|
||||
local _, se = F.save(a, nil, { format = "zst" })
|
||||
t:check(se and se.code == Err.UNSUPPORTED, "no encoder")
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if i % 11 == 0 and #c.data < 30000 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Zst.decode(Bytes.reader(b), { maxBytes = 1e6 })
|
||||
end, samples, { mutations = 10, garbage = 500 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,12 @@
|
||||
-- tests/audio/_encode_cases: the files our ALAC / CAF writers produce for the reference check (tools/fixtures/m4a.py
|
||||
-- runs tools/fixtures/_m4a_encode.luau over them; tests/audio/m4a.luau and caf.luau re-encode and compare).
|
||||
return {
|
||||
{ name = "ours_alac16_stereo", container = "m4a", rate = 44100, frames = 4096 * 3 + 1234, channels = 2, bits = 16, seed = 1, tags = { title = "Our Title \u{e9}", artist = "formats-luau", album = "Tests", track = "5", tracktotal = "10", date = "2026", genre = "Test", comment = "round trip" } },
|
||||
{ name = "ours_alac16_mono", container = "m4a", rate = 22050, frames = 5000, channels = 1, bits = 16, seed = 2 },
|
||||
{ name = "ours_alac24_stereo", container = "m4a", rate = 48000, frames = 9000, channels = 2, bits = 24, seed = 3 },
|
||||
{ name = "ours_alac16_6ch", container = "m4a", rate = 48000, frames = 4500, channels = 6, bits = 16, seed = 4 },
|
||||
{ name = "ours_alac20_stereo", container = "m4a", rate = 96000, frames = 3000, channels = 2, bits = 20, seed = 5 },
|
||||
{ name = "ours_caf_alac16", container = "caf", codec = "alac", rate = 44100, frames = 7000, channels = 2, bits = 16, seed = 6 },
|
||||
{ name = "ours_caf_pcm16", container = "caf", codec = "pcm", rate = 44100, frames = 3000, channels = 2, bits = 16, seed = 7 },
|
||||
{ name = "ours_caf_pcm24", container = "caf", codec = "pcm", rate = 48000, frames = 2000, channels = 1, bits = 24, seed = 8 },
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
-- tests/audio/_opus_cases: the inputs of the CELT encoder reference check (tools/fixtures/opus_celt.py runs
|
||||
-- tools/fixtures/_opus_encode.luau over them; tests/audio/opus_encode.luau re-encodes and compares): a deterministic
|
||||
-- music-like signal (chord + vibrato + chirp + clicks + a silent stretch) at a given rate / channel count.
|
||||
local Types = require("@formats/Types")
|
||||
|
||||
local Cases = {}
|
||||
|
||||
Cases.list = {
|
||||
{ name = "celt_mono_64k", rate = 48000, channels = 1, seconds = 1.5, bitrate = 64000, minSnr = 15 },
|
||||
{ name = "celt_stereo_128k", rate = 48000, channels = 2, seconds = 1.5, bitrate = 128000, minSnr = 15 },
|
||||
{ name = "celt_stereo_256k", rate = 48000, channels = 2, seconds = 1, bitrate = 256000, minSnr = 22 },
|
||||
{ name = "celt_mono_24k", rate = 48000, channels = 1, seconds = 1, bitrate = 24000, minSnr = 8 },
|
||||
{ name = "celt_44k_stereo_96k", rate = 44100, channels = 2, seconds = 1, bitrate = 96000, minSnr = 0, tags = { title = "Celt \u{e9}", artist = "formats-luau", album = "Opus" } },
|
||||
{ name = "celt_short", rate = 48000, channels = 1, seconds = 0.01, bitrate = 48000, minSnr = -100 },
|
||||
}
|
||||
|
||||
function Cases.signal(c: any): Types.Audio
|
||||
local n = math.floor(c.seconds * c.rate + 0.5)
|
||||
local a = Types.Audio.new(c.rate, c.channels, n)
|
||||
local s = 7
|
||||
for i = 0, n - 1 do
|
||||
local t = i / c.rate
|
||||
for ch = 0, c.channels - 1 do
|
||||
s = (s * 48271) % 2147483647
|
||||
local v = 0.18 * math.sin(2 * math.pi * 220 * t + 2 * math.sin(2 * math.pi * 5 * t))
|
||||
v += 0.12 * math.sin(2 * math.pi * (277.2 + ch * 2) * t) + 0.1 * math.sin(2 * math.pi * 329.6 * t)
|
||||
v += 0.08 * math.sin(2 * math.pi * (1000 + 3000 * t) * t)
|
||||
v += 0.01 * (s / 2147483647 - 0.5)
|
||||
if i % (c.rate // 4) < 30 then
|
||||
v += 0.4 * (if (i // 5) % 2 == 0 then 1 else -1)
|
||||
end
|
||||
if t > 0.6 and t < 0.75 then
|
||||
v = 0 -- digital silence (the encoder's silence frames)
|
||||
end
|
||||
buffer.writef32(a.samples, (i * c.channels + ch) * 4, v)
|
||||
end
|
||||
end
|
||||
a.tags = c.tags or {}
|
||||
return a
|
||||
end
|
||||
|
||||
return Cases
|
||||
@@ -0,0 +1,42 @@
|
||||
-- tests/audio/_signal: the deterministic integer test signal of tools/fixtures/_m4a_signal.py (the same numbers), as
|
||||
-- an interleaved integer array and as a Types.Audio (f32, exact for up to 24 bits). Used by the m4a / caf tests and the
|
||||
-- fixture-time encoder runs (tools/fixtures/_m4a_encode.luau).
|
||||
local Types = require("@formats/Types")
|
||||
|
||||
local Signal = {}
|
||||
|
||||
function Signal.ints(frames: number, channels: number, bits: number, seed: number): { number }
|
||||
local s = seed
|
||||
local peak = 2 ^ (bits - 1) - 1
|
||||
local out = table.create(frames * channels, 0)
|
||||
local k = 1
|
||||
for i = 0, frames - 1 do
|
||||
for c = 0, channels - 1 do
|
||||
s = (s * 48271) % 2147483647
|
||||
local p1 = 97 + 31 * c
|
||||
local tri = math.abs((i % p1) * 2 - p1) * 2 - p1
|
||||
local v = tri * (peak // (4 * p1))
|
||||
local p2 = 1500 + 200 * c
|
||||
v += if (i // p2) % 2 == 0 then peak // 6 else -(peak // 6)
|
||||
v += ((s // 65536) % 4096 - 2048) * (peak // 65536 + 1)
|
||||
if i % 7001 < 3 then
|
||||
v += peak // 2
|
||||
end
|
||||
out[k] = math.clamp(v, -peak - 1, peak)
|
||||
k += 1
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
function Signal.audio(rate: number, frames: number, channels: number, bits: number, seed: number): Types.Audio
|
||||
local ints = Signal.ints(frames, channels, bits, seed)
|
||||
local a = Types.Audio.new(rate, channels, frames)
|
||||
local scale = 1 / 2 ^ (bits - 1)
|
||||
for i, v in ints do
|
||||
buffer.writef32(a.samples, (i - 1) * 4, v * scale)
|
||||
end
|
||||
return a
|
||||
end
|
||||
|
||||
return Signal
|
||||
@@ -0,0 +1,117 @@
|
||||
-- audio/aac tests: ADTS streams from ffmpeg and fdkaac (stereo, mono 32 kHz) against ffmpeg's float decode (SNR,
|
||||
-- length); an HE-AAC ADTS stream plays its core; a leading ID3v2 tag (skipped, text frames as tags) and garbage before
|
||||
-- the first frame (resync); a truncated last frame; streaming + seek; sniff; errors; the fuzz no-throw pass.
|
||||
-- Fixtures: tools/fixtures/m4a.py.
|
||||
local T = require("@tests/T")
|
||||
local AacF = require("@formats/audio/aac")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/m4a_aac")
|
||||
local He = require("@tests/gen/m4a_he")
|
||||
|
||||
local t = T.suite("aac")
|
||||
|
||||
local function reader(s: string): Bytes.Reader
|
||||
return Bytes.reader(buffer.fromstring(s))
|
||||
end
|
||||
|
||||
local function snr(a: any, ref: string, skip: number?): number
|
||||
local off = (skip or 0) * a.channels
|
||||
local n = math.min(a.frames * a.channels - off, #ref // 4)
|
||||
local rb = buffer.fromstring(ref)
|
||||
local sig, err = 0, 0
|
||||
for i = 0, n - 1 do
|
||||
local r = buffer.readf32(rb, i * 4)
|
||||
local d = buffer.readf32(a.samples, (off + i) * 4) - r
|
||||
sig += r * r
|
||||
err += d * d
|
||||
end
|
||||
return if err == 0 then math.huge else 10 * math.log10(sig / err)
|
||||
end
|
||||
|
||||
t:eq(AacF.name, "aac", "name")
|
||||
t:check(AacF.caps.decode and not AacF.caps.encode and AacF.encode == nil, "caps: decode only")
|
||||
|
||||
local first
|
||||
for _, c in Fx do
|
||||
if c.container ~= "adts" then
|
||||
continue
|
||||
end
|
||||
first = first or c
|
||||
local r = reader(c.data)
|
||||
t:check(AacF.sniff(r) >= 0.9, c.name .. ": sniff")
|
||||
local a, err = AacF.decode(r)
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
t:check(a.channels == c.channels and a.sampleRate == c.rate, c.name .. ": format")
|
||||
t:eq(a.frames, c.frames, c.name .. ": frames (ADTS keeps the priming)")
|
||||
local s = snr(a, c.ref)
|
||||
t:check(s > 90, string.format("%s: SNR %.1f dB", c.name, s))
|
||||
t:note("%s: %d ch %d Hz, %d frames, SNR %.1f dB vs ffmpeg", c.name, c.channels, c.rate, a.frames, s)
|
||||
end
|
||||
|
||||
-- HE-AAC ADTS: the core
|
||||
for _, c in He do
|
||||
if string.sub(c.name, -4) == ".aac" then
|
||||
local a, err = AacF.decode(reader(c.data))
|
||||
t:check(a and a.sampleRate == c.rate // 2 and a.frames > 0, c.name .. ": core decode: " .. tostring(err))
|
||||
end
|
||||
end
|
||||
|
||||
-- ID3v2 in front + garbage, truncated tail
|
||||
do
|
||||
local function frame(id: string, text: string): string
|
||||
local body = "\3" .. text
|
||||
local n = #body
|
||||
return id .. string.char(0, 0, n // 128, n % 128) .. "\0\0" .. body
|
||||
end
|
||||
local frames = frame("TIT2", "Adts Title") .. frame("TPE1", "Someone")
|
||||
local n = #frames
|
||||
local id3 = "ID3\4\0\0" .. string.char(0, 0, n // 128, n % 128) .. frames
|
||||
local data = id3 .. "\0\1\2garbage" .. first.data
|
||||
local a, err = AacF.decode(reader(data))
|
||||
t:check(a, "id3 + garbage: " .. tostring(err))
|
||||
t:check(a.tags.title == "Adts Title" and a.tags.artist == "Someone", "id3 tags")
|
||||
t:eq(a.frames, first.frames, "id3 + garbage: same frames")
|
||||
t:check(snr(a, first.ref) > 90, "id3 + garbage: same audio")
|
||||
local cut = AacF.decode(reader(string.sub(first.data, 1, #first.data - 5))) :: any
|
||||
t:check(cut and cut.frames == first.frames - 1024, "truncated last frame dropped")
|
||||
end
|
||||
|
||||
-- streaming + seek
|
||||
do
|
||||
local whole = AacF.decode(reader(first.data)) :: any
|
||||
local dec = AacF.open(reader(first.data)) :: any
|
||||
for _, at in { 0.3, 0.0, 0.5123 } do
|
||||
dec:seek(at)
|
||||
local b, n = dec:read(600)
|
||||
local f0 = math.floor(at * whole.sampleRate + 0.5)
|
||||
local maxd = 0
|
||||
for i = 0, n * whole.channels - 1 do
|
||||
maxd = math.max(maxd, math.abs(buffer.readf32(b, i * 4) - buffer.readf32(whole.samples, (f0 * whole.channels + i) * 4)))
|
||||
end
|
||||
-- (the stream has no PNS: noise substitution would draw different noise after a seek)
|
||||
t:check(n == 600 and maxd < 1e-6, string.format("seek %.3f s (max diff %g)", at, maxd))
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
t:eq(AacF.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV")
|
||||
local _, e = AacF.decode(reader(string.rep("\0", 100)))
|
||||
t:check(e and e.code == Err.CORRUPT, "no frames: " .. tostring(e))
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for _, c in Fx do
|
||||
if c.container == "adts" then
|
||||
table.insert(samples, string.sub(c.data, 1, 6000))
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return AacF.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 30 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,177 @@
|
||||
-- audio/caf tests: ALAC CAF from ffmpeg bit-exact; AAC CAF (ffmpeg's ADTS frames wrapped by the fixture) against
|
||||
-- ffmpeg's float decode; our CAF writer (PCM 16 / 24-bit, ALAC; re-encoded here and compared with the bytes ffmpeg
|
||||
-- decoded bit-exactly); PCM layouts (little / big endian, float) through our writer + a hand-built header; info tags;
|
||||
-- seek; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/m4a.py.
|
||||
local T = require("@tests/T")
|
||||
local Caf = require("@formats/audio/caf")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Signal = require("@tests/audio/_signal")
|
||||
local Cases = require("@tests/audio/_encode_cases")
|
||||
local Alac = require("@tests/gen/m4a_alac")
|
||||
local Aac = require("@tests/gen/m4a_aac")
|
||||
local Ours = require("@tests/gen/m4a_ours")
|
||||
|
||||
local t = T.suite("caf")
|
||||
|
||||
local function reader(s: string | buffer): Bytes.Reader
|
||||
return Bytes.reader(if type(s) == "string" then buffer.fromstring(s) else s)
|
||||
end
|
||||
|
||||
local function intCrc(a: any, bits: number): number
|
||||
local n = a.frames * a.channels
|
||||
local b = buffer.create(n * 4)
|
||||
local scale = 2 ^ (bits - 1)
|
||||
for i = 0, n - 1 do
|
||||
buffer.writei32(b, i * 4, math.floor(buffer.readf32(a.samples, i * 4) * scale + 0.5))
|
||||
end
|
||||
return Crc32.of(b)
|
||||
end
|
||||
|
||||
t:eq(Caf.name, "caf", "name")
|
||||
t:check(Caf.caps.decode and Caf.caps.encode, "caps")
|
||||
|
||||
for _, c in Alac do
|
||||
if c.container == "caf" then
|
||||
local r = reader(c.data)
|
||||
t:eq(Caf.sniff(r), 1, c.name .. ": sniff")
|
||||
local a, err = Caf.decode(r)
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
t:check(a.channels == c.channels and a.sampleRate == c.rate and a.frames == c.frames, c.name .. ": format / length (pakt)")
|
||||
t:eq(intCrc(a, c.bits), c.crc, c.name .. ": bit-exact")
|
||||
end
|
||||
end
|
||||
|
||||
for _, c in Aac do
|
||||
if c.container == "caf" then
|
||||
local a, err = Caf.decode(reader(c.data))
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
t:eq(a.frames, c.frames, c.name .. ": frames")
|
||||
local rb = buffer.fromstring(c.ref)
|
||||
local sig, e = 0, 0
|
||||
for i = 0, a.frames * a.channels - 1 do
|
||||
local r = buffer.readf32(rb, i * 4)
|
||||
sig += r * r
|
||||
e += (buffer.readf32(a.samples, i * 4) - r) ^ 2
|
||||
end
|
||||
local snr = if e == 0 then math.huge else 10 * math.log10(sig / e)
|
||||
t:check(snr > 90, string.format("%s: SNR %.1f dB", c.name, snr))
|
||||
t:note("%s: SNR %.1f dB vs ffmpeg", c.name, snr)
|
||||
end
|
||||
end
|
||||
|
||||
-- our writer: the bytes ffmpeg validated
|
||||
do
|
||||
local byName = {}
|
||||
for _, o in Ours do
|
||||
byName[o.name] = o
|
||||
end
|
||||
for _, c in Cases do
|
||||
if c.container ~= "caf" then
|
||||
continue
|
||||
end
|
||||
local o = byName[c.name]
|
||||
t:check(o and o.ffmpeg, c.name .. ": ffmpeg decoded it bit-exactly")
|
||||
local a = Signal.audio(c.rate, c.frames, c.channels, c.bits, c.seed)
|
||||
local file = Caf.encode(a, { codec = c.codec, bitDepth = c.bits }) :: buffer
|
||||
t:eq(string.format("%08x", Crc32.of(file)), string.format("%08x", o.crc), c.name .. ": the validated bytes")
|
||||
local back = Caf.decode(reader(file)) :: any
|
||||
t:check(back and back.frames == c.frames, c.name .. ": our length")
|
||||
local ints = Signal.ints(c.frames, c.channels, c.bits, c.seed)
|
||||
local ok = true
|
||||
local scale = 2 ^ (c.bits - 1)
|
||||
for i = 1, #ints do
|
||||
ok = ok and math.floor(buffer.readf32(back.samples, (i - 1) * 4) * scale + 0.5) == ints[i]
|
||||
end
|
||||
t:check(ok, c.name .. ": round trip")
|
||||
end
|
||||
end
|
||||
|
||||
-- float PCM, tags, a decoder as the source, a hand-built little-endian header
|
||||
do
|
||||
local a = Signal.audio(32000, 3000, 3, 16, 12)
|
||||
a.tags = { title = "Caf Title", artist = "A", date = "1999", comment = "c", custom = "x" }
|
||||
local file = Caf.encode(a, { codec = "pcm", bitDepth = 32 }) :: buffer
|
||||
local back = Caf.decode(reader(file)) :: any
|
||||
t:check(back.frames == 3000 and buffer.tostring(back.samples) == buffer.tostring(a.samples), "float PCM round trip")
|
||||
for k, v in a.tags do
|
||||
t:eq(back.tags[k], v, "tag " .. k)
|
||||
end
|
||||
local dec = Caf.open(reader(file)) :: any
|
||||
local again = Caf.encode(dec, { codec = "alac" }) :: buffer
|
||||
local b2 = Caf.decode(reader(again)) :: any
|
||||
t:check(b2.frames == 3000 and buffer.tostring(b2.samples) == buffer.tostring(a.samples), "ALAC from a streaming decoder")
|
||||
-- little-endian 24-bit integer PCM, data chunk of unknown size (-1)
|
||||
local w = Bytes.writer(64)
|
||||
w:string("caff")
|
||||
w:u16be(1)
|
||||
w:u16be(0)
|
||||
w:string("desc")
|
||||
w:u64be(32)
|
||||
w:f64be(8000)
|
||||
w:string("lpcm")
|
||||
w:u32be(2)
|
||||
w:u32be(3)
|
||||
w:u32be(1)
|
||||
w:u32be(1)
|
||||
w:u32be(24)
|
||||
w:string("data")
|
||||
w:u32be(0xFFFFFFFF)
|
||||
w:u32be(0xFFFFFFFF)
|
||||
w:u32be(0)
|
||||
for _, v in { 0, 4194304, -4194304, 8388607, -8388608 } do
|
||||
w:u24le(v % 16777216)
|
||||
end
|
||||
local le = Caf.decode(Bytes.reader(w:finish())) :: any
|
||||
t:check(le and le.frames == 5, "24-bit LE, data size -1")
|
||||
t:check(le and math.abs(buffer.readf32(le.samples, 4) - 0.5) < 1e-7 and math.abs(buffer.readf32(le.samples, 16) + 1) < 1e-7, "24-bit LE values")
|
||||
end
|
||||
|
||||
-- seek
|
||||
do
|
||||
local c = Alac[#Alac]
|
||||
local whole = Caf.decode(reader(c.data)) :: any
|
||||
local dec = Caf.open(reader(c.data)) :: any
|
||||
for _, at in { 0.1, 0.0, 0.15 } do
|
||||
dec:seek(at)
|
||||
local b, n = dec:read(400)
|
||||
local f0 = math.floor(at * whole.sampleRate + 0.5)
|
||||
local same = n == 400
|
||||
for i = 0, n * whole.channels - 1 do
|
||||
same = same and buffer.readf32(b, i * 4) == buffer.readf32(whole.samples, (f0 * whole.channels + i) * 4)
|
||||
end
|
||||
t:check(same, string.format("seek %.2f s", at))
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
t:eq(Caf.sniff(reader("caff\0\2\0\0")), 0, "sniff: wrong version")
|
||||
local _, e = Caf.decode(reader("caff\0\1\0\0"))
|
||||
t:check(e and e.code == Err.CORRUPT, "no desc: " .. tostring(e))
|
||||
local _, e2 = Caf.encode(Signal.audio(8000, 10, 1, 16, 1), { codec = "mp3" } :: any)
|
||||
t:check(e2 and e2.code == Err.ARG, "bad codec: " .. tostring(e2))
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for _, c in Alac do
|
||||
if c.container == "caf" then
|
||||
table.insert(samples, string.sub(c.data, 1, 9000))
|
||||
end
|
||||
end
|
||||
for _, c in Aac do
|
||||
if c.container == "caf" then
|
||||
table.insert(samples, string.sub(c.data, 1, 6000))
|
||||
end
|
||||
end
|
||||
local pcm = Caf.encode(Signal.audio(8000, 300, 2, 16, 3), { codec = "pcm" }) :: buffer
|
||||
table.insert(samples, buffer.tostring(pcm))
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Caf.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 30 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,218 @@
|
||||
-- audio/m4a tests: ALAC files from ffmpeg decode bit-exactly (16 / 24-bit, mono / stereo / 5.1, partial frames);
|
||||
-- AAC-LC files from ffmpeg and fdkaac (stereo / mono / 5.1, 8 - 96 kHz, PNS / intensity / M/S / TNS) against ffmpeg's
|
||||
-- float decode (SNR, gapless length through the edit list); HE-AAC / HE-AACv2 play their core; our ALAC writer
|
||||
-- (re-encoded here, compared with the bytes ffmpeg decoded bit-exactly and MP4Box accepted in the fixture step); tags
|
||||
-- and cover art round trips; streaming reads, seeking; the contract; the fuzz no-throw pass.
|
||||
-- Fixtures: tools/fixtures/m4a.py.
|
||||
local T = require("@tests/T")
|
||||
local M4a = require("@formats/audio/m4a")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Signal = require("@tests/audio/_signal")
|
||||
local Cases = require("@tests/audio/_encode_cases")
|
||||
local Alac = require("@tests/gen/m4a_alac")
|
||||
local Aac = require("@tests/gen/m4a_aac")
|
||||
local He = require("@tests/gen/m4a_he")
|
||||
local Ours = require("@tests/gen/m4a_ours")
|
||||
|
||||
local t = T.suite("m4a")
|
||||
|
||||
local function reader(s: string | buffer): Bytes.Reader
|
||||
return Bytes.reader(if type(s) == "string" then buffer.fromstring(s) else s)
|
||||
end
|
||||
|
||||
-- the integers of a decoded Audio (exact for <= 24-bit sources), CRC-32 as little-endian int32
|
||||
local function intCrc(a: any, bits: number): number
|
||||
local n = a.frames * a.channels
|
||||
local b = buffer.create(n * 4)
|
||||
local scale = 2 ^ (bits - 1)
|
||||
for i = 0, n - 1 do
|
||||
buffer.writei32(b, i * 4, math.floor(buffer.readf32(a.samples, i * 4) * scale + 0.5))
|
||||
end
|
||||
return Crc32.of(b)
|
||||
end
|
||||
|
||||
local function snr(a: any, ref: string): (number, number)
|
||||
local n = math.min(a.frames * a.channels, #ref // 4)
|
||||
local rb = buffer.fromstring(ref)
|
||||
local sig, err = 0, 0
|
||||
for i = 0, n - 1 do
|
||||
local r = buffer.readf32(rb, i * 4)
|
||||
local d = buffer.readf32(a.samples, i * 4) - r
|
||||
sig += r * r
|
||||
err += d * d
|
||||
end
|
||||
if err == 0 then
|
||||
return math.huge, n
|
||||
end
|
||||
return 10 * math.log10(sig / err), n
|
||||
end
|
||||
|
||||
-- the contract
|
||||
t:eq(M4a.name, "m4a", "name")
|
||||
t:eq(M4a.category, "audio", "category")
|
||||
t:check(M4a.caps.decode and M4a.caps.encode, "caps")
|
||||
|
||||
-- ALAC from ffmpeg: bit-exact
|
||||
for _, c in Alac do
|
||||
if c.container ~= "m4a" then
|
||||
continue
|
||||
end
|
||||
local r = reader(c.data)
|
||||
t:check(M4a.sniff(r) == 1, c.name .. ": sniff")
|
||||
local a, err = M4a.decode(r)
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
t:check(a.channels == c.channels and a.sampleRate == c.rate, c.name .. ": format")
|
||||
t:eq(a.frames, c.frames, c.name .. ": frames")
|
||||
t:eq(intCrc(a, c.bits), c.crc, c.name .. ": samples bit-exact")
|
||||
t:eq(a.meta.source.codec, "alac", c.name .. ": codec")
|
||||
end
|
||||
t:note("%d ffmpeg ALAC files decode bit-exactly", #Alac - 1)
|
||||
|
||||
-- AAC: against ffmpeg's float decode
|
||||
local worst = math.huge
|
||||
for _, c in Aac do
|
||||
if c.container ~= "m4a" then
|
||||
continue
|
||||
end
|
||||
local a, err = M4a.decode(reader(c.data))
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
t:check(a.channels == c.channels and a.sampleRate == c.rate, c.name .. ": format")
|
||||
t:eq(a.frames, c.frames, c.name .. ": gapless length")
|
||||
local s = snr(a, c.ref)
|
||||
worst = math.min(worst, s)
|
||||
t:check(s > 90, string.format("%s: SNR %.1f dB vs ffmpeg", c.name, s))
|
||||
t:note("%s: %d ch %d Hz, %d frames, SNR %.1f dB vs ffmpeg", c.name, c.channels, c.rate, a.frames, s)
|
||||
end
|
||||
|
||||
-- HE-AAC: the AAC-LC core at half the rate, SBR seen
|
||||
for _, c in He do
|
||||
if string.sub(c.name, -4) ~= ".m4a" then
|
||||
continue
|
||||
end
|
||||
local dec, err = M4a.open(reader(c.data))
|
||||
t:check(dec, c.name .. ": " .. tostring(err))
|
||||
t:eq(dec.sampleRate, c.rate // 2, c.name .. ": core rate")
|
||||
local b, n = dec:read(8192)
|
||||
local e = 0
|
||||
for i = 0, n * dec.channels - 1 do
|
||||
e += buffer.readf32(b, i * 4) ^ 2
|
||||
end
|
||||
t:check(n == 8192 and e > 1, c.name .. ": the core decodes (energy " .. e .. ")")
|
||||
end
|
||||
|
||||
-- our ALAC writer: the bytes ffmpeg validated
|
||||
do
|
||||
local byName = {}
|
||||
for _, o in Ours do
|
||||
byName[o.name] = o
|
||||
end
|
||||
for _, c in Cases do
|
||||
if c.container ~= "m4a" then
|
||||
continue
|
||||
end
|
||||
local o = byName[c.name]
|
||||
t:check(o and o.ffmpeg and o.mp4box and o.codec == "alac", c.name .. ": ffmpeg decoded it bit-exactly, MP4Box read it")
|
||||
t:eq(o.frames, c.frames, c.name .. ": ffmpeg's length")
|
||||
local a = Signal.audio(c.rate, c.frames, c.channels, c.bits, c.seed)
|
||||
a.tags = c.tags or {}
|
||||
local file, err = M4a.encode(a, { bitDepth = c.bits })
|
||||
t:check(file, c.name .. ": encode: " .. tostring(err))
|
||||
t:eq(string.format("%08x", Crc32.of(file :: buffer)), string.format("%08x", o.crc), c.name .. ": the validated bytes")
|
||||
-- and our own decoder gets the integers back
|
||||
local back = M4a.decode(Bytes.reader(file :: buffer)) :: any
|
||||
local ints = Signal.ints(c.frames, c.channels, c.bits, c.seed)
|
||||
local ok = back.frames == c.frames
|
||||
local scale = 2 ^ (c.bits - 1)
|
||||
for i = 1, #ints, 7 do
|
||||
ok = ok and math.floor(buffer.readf32(back.samples, (i - 1) * 4) * scale + 0.5) == ints[i]
|
||||
end
|
||||
t:check(ok, c.name .. ": round trip")
|
||||
if c.tags then
|
||||
for k, v in c.tags do
|
||||
t:eq(back.tags[k], v, c.name .. ": tag " .. k)
|
||||
end
|
||||
t:eq(o.tags.title, c.tags.title, c.name .. ": ffprobe title")
|
||||
t:eq(o.tags.track, c.tags.track .. "/" .. c.tags.tracktotal, c.name .. ": ffprobe track")
|
||||
t:eq(o.tags.artist, c.tags.artist, c.name .. ": ffprobe artist")
|
||||
end
|
||||
t:note("%s: %d bytes (%.0f%% of PCM)", c.name, buffer.len(file :: buffer), 100 * buffer.len(file :: buffer) / (c.frames * c.channels * c.bits / 8))
|
||||
end
|
||||
end
|
||||
|
||||
-- cover art + streaming a decoder into the encoder
|
||||
do
|
||||
local a = Signal.audio(44100, 5000, 2, 16, 9)
|
||||
a.meta.pictures = { { mime = "image/png", data = buffer.fromstring("\137PNG fake") } }
|
||||
a.tags = { title = "Pic" }
|
||||
local file = M4a.encode(a) :: buffer
|
||||
local back = M4a.decode(Bytes.reader(file)) :: any
|
||||
t:check(back.meta.pictures and #back.meta.pictures == 1 and back.meta.pictures[1].mime == "image/png", "cover art round trip")
|
||||
local dec = M4a.open(Bytes.reader(file)) :: any
|
||||
local again = M4a.encode(dec) :: buffer
|
||||
local back2 = M4a.decode(Bytes.reader(again)) :: any
|
||||
t:check(back2.frames == 5000 and buffer.tostring(back2.samples) == buffer.tostring(back.samples), "encode from a streaming decoder")
|
||||
local _, e = M4a.encode({} :: any)
|
||||
t:check(e and e.code == Err.ARG, "encode of a non-audio returns Err.ARG")
|
||||
local _, e2 = M4a.encode(a, { bitDepth = 12 })
|
||||
t:check(e2 and e2.code == Err.ARG, "bad bitDepth returns Err.ARG")
|
||||
end
|
||||
|
||||
-- streaming + seek (AAC without PNS: its noise is random, so a seek changes it; and ALAC)
|
||||
for _, c in { Aac[1], Alac[1] } do
|
||||
local whole = M4a.decode(reader(c.data)) :: any
|
||||
local dec = M4a.open(reader(c.data)) :: any
|
||||
t:eq(dec.frames, whole.frames, c.name .. ": decoder frames")
|
||||
-- read in odd chunks
|
||||
local got, out = 0, buffer.create(whole.frames * whole.channels * 4)
|
||||
while true do
|
||||
local b, n = dec:read(777)
|
||||
if n == 0 then
|
||||
break
|
||||
end
|
||||
buffer.copy(out, got * whole.channels * 4, b, 0, n * whole.channels * 4)
|
||||
got += n
|
||||
end
|
||||
t:check(got == whole.frames and buffer.tostring(out) == buffer.tostring(whole.samples), c.name .. ": chunked reads equal the whole decode")
|
||||
for _, at in { 0.1, 0.0, 0.05 } do
|
||||
dec:seek(at)
|
||||
local b, n = dec:read(500)
|
||||
local f0 = math.floor(at * whole.sampleRate + 0.5)
|
||||
local maxd = 0
|
||||
for i = 0, n * whole.channels - 1 do
|
||||
maxd = math.max(maxd, math.abs(buffer.readf32(b, i * 4) - buffer.readf32(whole.samples, (f0 * whole.channels + i) * 4)))
|
||||
end
|
||||
t:check(n == 500 and maxd < 1e-6, string.format("%s: seek %.2f s (max diff %g)", c.name, at, maxd))
|
||||
t:check(math.abs(dec:position() - (f0 + 500) / whole.sampleRate) < 1e-9, c.name .. ": position after seek")
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e = M4a.decode(reader("\0\0\0\8ftypM4A "))
|
||||
t:check(e ~= nil, "a lone ftyp: " .. tostring(e))
|
||||
local _, e2 = M4a.decode(reader("hello world, not an mp4"))
|
||||
t:check(e2 ~= nil and Err.is(e2), "junk: " .. tostring(e2))
|
||||
t:eq(M4a.sniff(reader("hello")), 0, "sniff junk")
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Alac do
|
||||
if c.container == "m4a" and i <= 2 then
|
||||
table.insert(samples, string.sub(c.data, 1, 12000))
|
||||
end
|
||||
end
|
||||
for i, c in Aac do
|
||||
if c.container == "m4a" and i <= 2 then
|
||||
table.insert(samples, string.sub(c.data, 1, 9000))
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return M4a.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 25 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -81,7 +81,7 @@ end
|
||||
-- ------------------------------------------------------------------------------------------------ contract
|
||||
t:eq(Opus.name, "opus", "name")
|
||||
t:eq(Opus.category, "audio", "category")
|
||||
t:check(Opus.caps.decode and not Opus.caps.encode and Opus.open ~= nil and Opus.decode ~= nil, "caps")
|
||||
t:check(Opus.caps.decode and Opus.caps.encode and Opus.open ~= nil and Opus.decode ~= nil and Opus.encode ~= nil, "caps (the CELT encoder: tests/audio/opus_encode.luau)")
|
||||
t:eq(Opus.sniff(Bytes.reader(FX.celt_st_128.data)), 1, "sniff an Opus file")
|
||||
t:eq(Opus.sniff(Bytes.reader(buffer.fromstring("OggS" .. string.rep("\0", 40)))), 0, "sniff another Ogg")
|
||||
t:eq(Opus.sniff(Bytes.reader(buffer.create(0))), 0, "sniff nothing")
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
-- audio/opus encoder tests (the CELT-only writer, ws-m4a; mono and mid / side stereo): our Ogg Opus files (re-encoded here, compared with the bytes
|
||||
-- checked in the fixture step) decode in libopus' opusdec to the input's exact length (pre-skip + end trimming) with a
|
||||
-- minimum SNR, opusinfo finds no problem, ffmpeg reads them, OpusTags carry the tags; our decoder agrees with opusdec;
|
||||
-- resampled 44.1 kHz input; silence frames; streaming input; errors; a fuzz no-throw pass over our files.
|
||||
-- Fixtures: tools/fixtures/opus_celt.py.
|
||||
local T = require("@tests/T")
|
||||
local Opus = require("@formats/audio/opus")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Cases = require("@tests/audio/_opus_cases")
|
||||
local Fx = require("@tests/gen/opus_celt")
|
||||
|
||||
local t = T.suite("opus-encode")
|
||||
|
||||
t:check(Opus.caps.encode and Opus.encode ~= nil, "caps: encode")
|
||||
|
||||
local byName = {}
|
||||
for _, f in Fx do
|
||||
byName[f.name] = f
|
||||
end
|
||||
|
||||
local function snr(ref: buffer, refBase: number, got: buffer, n: number): number
|
||||
local s, e = 0, 0
|
||||
for i = 0, n - 1 do
|
||||
local x = buffer.readf32(ref, (refBase + i) * 4)
|
||||
local d = buffer.readf32(got, (refBase + i) * 4) - x
|
||||
s += x * x
|
||||
e += d * d
|
||||
end
|
||||
return if e == 0 then math.huge else 10 * math.log10(s / math.max(e, 1e-30))
|
||||
end
|
||||
|
||||
local files = {}
|
||||
for _, c in Cases.list do
|
||||
local fx = byName[c.name]
|
||||
t:check(fx, c.name .. ": fixture")
|
||||
local input = Cases.signal(c)
|
||||
local file, err = Opus.encode(input, { bitrate = c.bitrate })
|
||||
t:check(file, c.name .. ": encode: " .. tostring(err))
|
||||
table.insert(files, file)
|
||||
t:eq(string.format("%08x", Crc32.of(file :: buffer)), string.format("%08x", fx.crc), c.name .. ": the bytes the reference tools checked")
|
||||
t:check(fx.opusinfo, c.name .. ": opusinfo reports no problem")
|
||||
t:check(fx.ffmpeg, c.name .. ": ffmpeg decodes it")
|
||||
local frames48 = math.floor(input.frames * 48000 / c.rate + 0.5)
|
||||
local ch = c.channels
|
||||
t:eq(#fx.opusdec // (4 * ch), frames48, c.name .. ": opusdec length = the input's (pre-skip + end trimming)")
|
||||
t:eq(fx.ffmpegFrames, frames48, c.name .. ": ffmpeg length")
|
||||
-- our decoder vs opusdec
|
||||
local ours = Opus.decode(Bytes.reader(file :: buffer)) :: any
|
||||
t:eq(ours.frames, frames48, c.name .. ": our decoder's length")
|
||||
local ref = buffer.fromstring(fx.opusdec)
|
||||
local agree = snr(ref, 0, ours.samples, frames48 * ch)
|
||||
t:check(agree > 60, string.format("%s: our decoder vs opusdec %.1f dB", c.name, agree))
|
||||
-- quality vs the input (48 kHz inputs; skip the edges)
|
||||
if c.rate == 48000 and frames48 > 4000 then
|
||||
local s = snr(input.samples, 960 * ch, ref, (frames48 - 1920) * ch)
|
||||
t:check(s >= c.minSnr, string.format("%s: SNR %.1f dB (minimum %d)", c.name, s, c.minSnr))
|
||||
t:note("%s: %d bytes, SNR %.1f dB vs the input, our decoder vs opusdec %.1f dB", c.name, buffer.len(file :: buffer), s, agree)
|
||||
end
|
||||
if c.tags then
|
||||
for k, v in c.tags do
|
||||
t:eq(fx.comments[k], v, c.name .. ": opusinfo comment " .. k)
|
||||
t:eq(ours.tags[k], v, c.name .. ": our tag " .. k)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- silence frames decode to silence
|
||||
do
|
||||
local c = Cases.list[1]
|
||||
local ref = buffer.fromstring(byName[c.name].opusdec)
|
||||
local peak = 0
|
||||
for i = math.floor(0.62 * 48000), math.floor(0.73 * 48000) do
|
||||
peak = math.max(peak, math.abs(buffer.readf32(ref, i * 4)))
|
||||
end
|
||||
t:check(peak < 1e-3, "digital silence stays silent (peak " .. peak .. ")")
|
||||
end
|
||||
|
||||
-- a streaming decoder as the input
|
||||
do
|
||||
local c = Cases.list[1]
|
||||
local dec = Opus.open(Bytes.reader(files[1] :: buffer)) :: any
|
||||
local again, err = Opus.encode(dec, { bitrate = 64000 })
|
||||
t:check(again, "encode from a decoder: " .. tostring(err))
|
||||
local back = Opus.decode(Bytes.reader(again :: buffer)) :: any
|
||||
t:eq(back.frames, math.floor(c.seconds * 48000 + 0.5), "re-encoded length")
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local three = Cases.signal({ rate = 48000, channels = 3, seconds = 0.05 })
|
||||
local _, e = Opus.encode(three)
|
||||
t:check(e and e.code == Err.UNSUPPORTED, "3 channels: " .. tostring(e))
|
||||
local _, e2 = Opus.encode(Cases.signal(Cases.list[6]), { bitrate = 1000 })
|
||||
t:check(e2 and e2.code == Err.ARG, "bitrate too low")
|
||||
local _, e3 = Opus.encode({} :: any)
|
||||
t:check(e3 and e3.code == Err.ARG, "not audio")
|
||||
end
|
||||
|
||||
-- fuzz the decoder over our files
|
||||
do
|
||||
local samples = {}
|
||||
for i, f in files do
|
||||
if i <= 3 then
|
||||
table.insert(samples, string.sub(buffer.tostring(f :: buffer), 1, 4000))
|
||||
end
|
||||
end
|
||||
t:fuzz("decode our files", function(b: buffer)
|
||||
return Opus.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 10, garbage = 30 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,182 @@
|
||||
-- codecs/Aac tests: AudioSpecificConfig parsing (every fixture's esds, explicit SBR / PS signalling from fdkaac,
|
||||
-- crafted configs: PCE channel counts, 960-sample frames, Main / LTP object types), ADTS headers, raw frames decoded
|
||||
-- straight from ADTS against ffmpeg's float decode, the FIL extension hook on HE-AAC (implicit SBR), reset, errors,
|
||||
-- the fuzz no-throw pass on raw frames. Fixtures: tools/fixtures/m4a.py.
|
||||
local T = require("@tests/T")
|
||||
local Aac = require("@formats/codecs/Aac")
|
||||
local IsoBmff = require("@formats/containers/IsoBmff")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Bits = require("@formats/core/Bits")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/m4a_aac")
|
||||
local He = require("@tests/gen/m4a_he")
|
||||
|
||||
local t = T.suite("aac-codec")
|
||||
|
||||
-- ADTS frames of a stream: { offset, size } of the raw blocks
|
||||
local function frames(data: buffer): ({ { number } }, Aac.Adts?)
|
||||
local out, p, first = {}, 0, nil
|
||||
while true do
|
||||
local h = Aac.adts(data, p, buffer.len(data))
|
||||
if not h or p + h.frameSize > buffer.len(data) then
|
||||
break
|
||||
end
|
||||
first = first or h
|
||||
table.insert(out, { p + h.headerSize, h.frameSize - h.headerSize })
|
||||
p += h.frameSize
|
||||
end
|
||||
return out, first
|
||||
end
|
||||
|
||||
-- ASCs from the M4A fixtures
|
||||
for _, c in Fx do
|
||||
if c.container == "m4a" then
|
||||
local r = Bytes.reader(buffer.fromstring(c.data))
|
||||
local movie = IsoBmff.parse(r) :: IsoBmff.Movie
|
||||
local cfg, err = Aac.config(movie.tracks[1].config :: buffer)
|
||||
t:check(cfg, c.name .. ": " .. tostring(err))
|
||||
t:check(cfg.objectType == 2 and cfg.sampleRate == c.rate and cfg.channels == c.channels and not cfg.sbr, c.name .. ": AAC-LC config")
|
||||
end
|
||||
end
|
||||
for _, c in He do
|
||||
if string.sub(c.name, -4) == ".m4a" then
|
||||
local r = Bytes.reader(buffer.fromstring(c.data))
|
||||
local movie = IsoBmff.parse(r) :: IsoBmff.Movie
|
||||
local cfg, err = Aac.config(movie.tracks[1].config :: buffer)
|
||||
t:check(cfg, c.name .. ": " .. tostring(err))
|
||||
t:check(cfg.sbr and cfg.sampleRate == c.rate // 2 and cfg.extensionRate == c.rate, c.name .. ": SBR signalled, core at half rate")
|
||||
t:eq(cfg.ps, c.ps, c.name .. ": PS signalled")
|
||||
end
|
||||
end
|
||||
|
||||
-- crafted configs
|
||||
do
|
||||
local asc = Aac.asc(2, 4, 2)
|
||||
local cfg = Aac.config(asc) :: Aac.Config
|
||||
t:check(cfg and cfg.sampleRate == 44100 and cfg.channels == 2, "asc(2, 44.1 kHz, stereo)")
|
||||
local _, e1 = Aac.config(Aac.asc(1, 4, 2))
|
||||
t:check(e1 and e1.code == Err.UNSUPPORTED, "AAC Main: " .. tostring(e1))
|
||||
local _, e2 = Aac.config(Aac.asc(23, 4, 2))
|
||||
t:check(e2 and e2.code == Err.UNSUPPORTED, "ER AAC LD")
|
||||
local b960 = Aac.asc(2, 3, 1)
|
||||
buffer.writeu8(b960, 1, bit32.bor(buffer.readu8(b960, 1), 4)) -- frameLengthFlag
|
||||
local _, e3 = Aac.config(b960)
|
||||
t:check(e3 and e3.code == Err.UNSUPPORTED, "960-sample frames")
|
||||
-- channel configuration 0 with a PCE: front C (SCE) + L/R (CPE), back L/R (CPE), one LFE = 6 channels
|
||||
local bw = Bits.msbWriter()
|
||||
bw:write(2, 5)
|
||||
bw:write(3, 4)
|
||||
bw:write(0, 4)
|
||||
bw:write(0, 3) -- GASpecificConfig flags
|
||||
bw:write(0, 4) -- PCE: tag
|
||||
bw:write(1, 2)
|
||||
bw:write(3, 4)
|
||||
bw:write(2, 4) -- front
|
||||
bw:write(0, 4) -- side
|
||||
bw:write(1, 4) -- back
|
||||
bw:write(1, 2) -- lfe
|
||||
bw:write(0, 3)
|
||||
bw:write(0, 4)
|
||||
bw:write(0, 3) -- mixdowns
|
||||
bw:write(0, 5)
|
||||
bw:write(16 + 1, 5) -- front: SCE 0, CPE 1
|
||||
bw:write(16 + 2, 5) -- back: CPE 2
|
||||
bw:write(0, 4) -- lfe tag
|
||||
bw:align()
|
||||
bw:write(0, 8) -- comment
|
||||
local pcfg, perr = Aac.config(bw:finish())
|
||||
t:check(pcfg and pcfg.channels == 6 and pcfg.channelConfig == 0, "PCE: 6 channels: " .. tostring(perr))
|
||||
local _, e4 = Aac.decoder("nope" :: any)
|
||||
t:check(e4 and e4.code == Err.ARG, "decoder of a string")
|
||||
end
|
||||
|
||||
-- ADTS headers + raw frames against ffmpeg
|
||||
for _, c in Fx do
|
||||
if c.container ~= "adts" then
|
||||
continue
|
||||
end
|
||||
local data = buffer.fromstring(c.data)
|
||||
local list, h = frames(data)
|
||||
t:check(h and h.objectType == 2 and h.sampleRate == c.rate, c.name .. ": ADTS header")
|
||||
local dec = Aac.decoder({ sfIndex = (h :: Aac.Adts).sfIndex, channels = c.channels }) :: Aac.Decoder
|
||||
local ref = buffer.fromstring(c.ref)
|
||||
local sig, err = 0, 0
|
||||
local o = 0
|
||||
for _, f in list do
|
||||
local n, e = dec:decode(data, f[1], f[2])
|
||||
t:check(n == 1024, c.name .. ": frame: " .. tostring(e))
|
||||
for k = 1, 1024 * c.channels do
|
||||
local r = buffer.readf32(ref, o)
|
||||
sig += r * r
|
||||
err += (dec.pcm[k] - r) ^ 2
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
local snr = 10 * math.log10(sig / math.max(err, 1e-30))
|
||||
t:check(snr > 90, string.format("%s: SNR %.1f dB", c.name, snr))
|
||||
t:note("%s: %d raw frames, SNR %.1f dB vs ffmpeg", c.name, #list, snr)
|
||||
-- reset: decoding again from the start gives the same first frames
|
||||
dec:reset()
|
||||
dec:decode(data, list[1][1], list[1][2])
|
||||
local again = table.clone(dec.pcm)
|
||||
local dec2 = Aac.decoder({ sfIndex = (h :: Aac.Adts).sfIndex, channels = c.channels }) :: Aac.Decoder
|
||||
dec2:decode(data, list[1][1], list[1][2])
|
||||
local same = true
|
||||
for k = 1, 1024 * c.channels do
|
||||
same = same and again[k] == dec2.pcm[k]
|
||||
end
|
||||
t:check(same, c.name .. ": reset clears the overlap")
|
||||
end
|
||||
|
||||
-- the extension hook on HE-AAC (implicit SBR in ADTS)
|
||||
for _, c in He do
|
||||
if string.sub(c.name, -4) == ".aac" then
|
||||
local data = buffer.fromstring(c.data)
|
||||
local list, h = frames(data)
|
||||
local dec = Aac.decoder({ sfIndex = (h :: Aac.Adts).sfIndex, channels = 2 }) :: Aac.Decoder
|
||||
local seen, bits = 0, 0
|
||||
dec.onExtension = function(kind: number, _element: number, _buf: buffer, _pos: number, n: number)
|
||||
if kind == 13 or kind == 14 then
|
||||
seen += 1
|
||||
bits += n
|
||||
end
|
||||
end
|
||||
for _, f in list do
|
||||
dec:decode(data, f[1], f[2])
|
||||
end
|
||||
t:check(seen == #list and dec.sbr, string.format("%s: an SBR payload per frame (%d of %d, %d bits)", c.name, seen, #list, bits))
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local dec = Aac.decoder(Aac.asc(2, 4, 2)) :: Aac.Decoder
|
||||
local _, e = dec:decode(buffer.fromstring("\x20\x00\x00\x00\x00"))
|
||||
t:check(e and e.code == Err.CORRUPT, "garbage frame: " .. tostring(e))
|
||||
local _, e2 = dec:decode(buffer.create(4), 3, 10)
|
||||
t:check(e2 and e2.code == Err.ARG, "range out of the buffer")
|
||||
t:check(Aac.adts(buffer.fromstring("\255\241"), 0, 2) == nil, "short ADTS header")
|
||||
end
|
||||
|
||||
-- fuzz raw frames (stereo with every tool, mono, 5.1)
|
||||
do
|
||||
local pick = {}
|
||||
for _, c in Fx do
|
||||
if c.container == "adts" then
|
||||
local data = buffer.fromstring(c.data)
|
||||
local list, h = frames(data)
|
||||
local f = list[math.min(#list, 9)]
|
||||
local raw = buffer.create(f[2])
|
||||
buffer.copy(raw, 0, data, f[1], f[2])
|
||||
table.insert(pick, { raw, (h :: Aac.Adts).sfIndex, c.channels })
|
||||
end
|
||||
end
|
||||
for _, p in pick do
|
||||
local dec = Aac.decoder({ sfIndex = p[2], channels = p[3] }) :: Aac.Decoder
|
||||
t:fuzz("raw frame " .. p[3] .. " ch", function(b: buffer)
|
||||
return dec:decode(b)
|
||||
end, { p[1] }, { mutations = 60, garbage = 100 })
|
||||
end
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,181 @@
|
||||
-- codecs/Alac tests: encoder -> decoder round trips over silence (zero runs), full-scale noise (uncompressed frames),
|
||||
-- tones, steps, 1 - 8 channels, 16 / 20 / 24 bits, partial and tiny frames, custom frame lengths; ffmpeg's ALAC
|
||||
-- packets (through containers/IsoBmff) decode to the source integers; the magic cookie (plain, behind frma / alac atoms,
|
||||
-- bad versions / depths); errors; the fuzz no-throw pass on packets. Fixtures: tools/fixtures/m4a.py.
|
||||
local T = require("@tests/T")
|
||||
local Alac = require("@formats/codecs/Alac")
|
||||
local IsoBmff = require("@formats/containers/IsoBmff")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/m4a_alac")
|
||||
|
||||
local t = T.suite("alac")
|
||||
local rand = T.rng(42)
|
||||
|
||||
local function roundTrip(label: string, ch: number, bits: number, frames: number, gen: (number, number) -> number, fl: number?)
|
||||
local enc = Alac.encoder({ sampleRate = 44100, channels = ch, bitDepth = bits, frameLength = fl }) :: Alac.Encoder
|
||||
t:check(enc, label .. ": encoder")
|
||||
local per = enc.config.frameLength
|
||||
local src = table.create(frames * ch, 0)
|
||||
for i = 0, frames - 1 do
|
||||
for c = 1, ch do
|
||||
src[i * ch + c] = gen(i, c)
|
||||
end
|
||||
end
|
||||
local packets = {}
|
||||
local bytes = 0
|
||||
local f = 0
|
||||
while f < frames do
|
||||
local n = math.min(per, frames - f)
|
||||
local p, err = enc:encode(src, f * ch + 1, n)
|
||||
t:check(p, label .. ": encode: " .. tostring(err))
|
||||
table.insert(packets, { p, n })
|
||||
bytes += buffer.len(p :: buffer)
|
||||
f += n
|
||||
end
|
||||
local cfg = Alac.config(Alac.cookie(enc.config)) :: Alac.Config
|
||||
t:check(cfg and cfg.maxFrameBytes >= 1 and cfg.channels == ch and cfg.bitDepth == bits, label .. ": cookie")
|
||||
local dec = Alac.decoder(cfg)
|
||||
local ok = true
|
||||
local at = 0
|
||||
for _, pk in packets do
|
||||
local n, err = dec:decode(pk[1])
|
||||
if n ~= pk[2] then
|
||||
ok = false
|
||||
t:check(false, label .. ": decode: " .. tostring(err))
|
||||
break
|
||||
end
|
||||
for k = 1, n * ch do
|
||||
if dec.pcm[k] ~= src[at * ch + k] then
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
at += n
|
||||
end
|
||||
t:check(ok, label .. ": round trip")
|
||||
return bytes / (frames * ch * bits / 8)
|
||||
end
|
||||
|
||||
local peakOf = function(bits: number): number
|
||||
return 2 ^ (bits - 1)
|
||||
end
|
||||
|
||||
for _, bits in { 16, 20, 24 } do
|
||||
local pk = peakOf(bits)
|
||||
for _, ch in { 1, 2, 3, 6, 8 } do
|
||||
local r1 = roundTrip(string.format("tone %d-bit %d ch", bits, ch), ch, bits, 9000, function(i, c)
|
||||
return math.floor(math.sin(i * 0.031 * c) * (pk * 0.6) + math.sin(i * 0.0071) * pk * 0.2)
|
||||
end)
|
||||
if ch == 2 then
|
||||
t:note("%d-bit stereo tone: %.0f%% of PCM", bits, r1 * 100)
|
||||
end
|
||||
end
|
||||
roundTrip(bits .. "-bit silence (zero runs)", 2, bits, 10000, function()
|
||||
return 0
|
||||
end)
|
||||
local r = roundTrip(bits .. "-bit full-scale noise (escape frames)", 2, bits, 5000, function()
|
||||
return rand(2 ^ bits) - pk
|
||||
end)
|
||||
t:check(r < 1.01, bits .. "-bit noise stays near PCM size")
|
||||
roundTrip(bits .. "-bit extremes", 1, bits, 600, function(i)
|
||||
return if i % 2 == 0 then pk - 1 else -pk
|
||||
end)
|
||||
roundTrip(bits .. "-bit sparse clicks (zero runs + values)", 2, bits, 7000, function(i, c)
|
||||
return if i % 997 == c then pk // 3 else 0
|
||||
end)
|
||||
end
|
||||
for _, n in { 1, 2, 3, 5, 9, 17, 4095 } do
|
||||
roundTrip("partial frame of " .. n, 2, 16, n, function(i, c)
|
||||
return (i * 37 + c * 1000) % 3000 - 1500
|
||||
end)
|
||||
end
|
||||
roundTrip("frame length 1024", 2, 16, 5000, function(i)
|
||||
return math.floor(math.sin(i * 0.05) * 10000)
|
||||
end, 1024)
|
||||
roundTrip("identical channels", 2, 16, 5000, function(i)
|
||||
return math.floor(math.sin(i * 0.02) * 20000)
|
||||
end)
|
||||
|
||||
-- ffmpeg's packets
|
||||
for _, c in Fx do
|
||||
if c.container == "m4a" then
|
||||
local r = Bytes.reader(buffer.fromstring(c.data))
|
||||
local movie = IsoBmff.parse(r) :: IsoBmff.Movie
|
||||
local tr = movie.tracks[1]
|
||||
local cfg = Alac.config(tr.config :: buffer) :: Alac.Config
|
||||
t:check(cfg and cfg.bitDepth == c.bits and cfg.channels == c.channels, c.name .. ": cookie")
|
||||
local dec = Alac.decoder(cfg)
|
||||
local out = buffer.create(c.frames * c.channels * 4)
|
||||
local o = 0
|
||||
for i = 1, tr.sampleCount do
|
||||
local n, err = dec:decode(r.buf, tr.offsets[i], tr.sizes[i])
|
||||
t:check(n, c.name .. ": packet " .. i .. ": " .. tostring(err))
|
||||
for k = 1, (n :: number) * c.channels do
|
||||
buffer.writei32(out, o, dec.pcm[k])
|
||||
o += 4
|
||||
end
|
||||
end
|
||||
t:eq(Crc32.of(out), c.crc, c.name .. ": ffmpeg's packets decode to the source")
|
||||
end
|
||||
end
|
||||
|
||||
-- the cookie behind QuickTime atoms, bad cookies
|
||||
do
|
||||
local enc = Alac.encoder({ sampleRate = 48000, channels = 2 }) :: Alac.Encoder
|
||||
local plain = Alac.cookie(enc.config)
|
||||
local w = Bytes.writer(64)
|
||||
w:u32be(12)
|
||||
w:string("frma")
|
||||
w:string("alac")
|
||||
w:u32be(36)
|
||||
w:string("alac")
|
||||
w:u32be(0)
|
||||
w:bytes(plain)
|
||||
local cfg = Alac.config(w:finish())
|
||||
t:check(cfg and cfg.sampleRate == 48000 and cfg.frameLength == 4096, "cookie behind frma / alac atoms")
|
||||
local bad = buffer.fromstring(buffer.tostring(plain))
|
||||
buffer.writeu8(bad, 5, 12)
|
||||
local _, e = Alac.config(bad)
|
||||
t:check(e and e.code == Err.UNSUPPORTED, "12-bit cookie: " .. tostring(e))
|
||||
local _, e2 = Alac.config(buffer.create(10))
|
||||
t:check(e2 and e2.code == Err.TRUNCATED, "short cookie")
|
||||
local _, e3 = Alac.encoder({ sampleRate = 44100, channels = 9 })
|
||||
t:check(e3 and e3.code == Err.ARG, "9 channels")
|
||||
local _, e4 = enc:encode({ 1, 2 }, 1, 5)
|
||||
t:check(e4 and e4.code == Err.ARG, "too few samples")
|
||||
local dec = Alac.decoder(cfg :: Alac.Config)
|
||||
local _, e5 = dec:decode(buffer.fromstring("\1\255\255\255"))
|
||||
t:check(e5 and e5.code == Err.CORRUPT, "bad packet: " .. tostring(e5))
|
||||
end
|
||||
|
||||
-- fuzz the packet decoder
|
||||
do
|
||||
local enc = Alac.encoder({ sampleRate = 44100, channels = 2, bitDepth = 16 }) :: Alac.Encoder
|
||||
local src = table.create(2 * 3000, 0)
|
||||
for i = 1, #src do
|
||||
src[i] = math.floor(math.sin(i * 0.01) * 8000) + rand(64)
|
||||
end
|
||||
local samples = {}
|
||||
table.insert(samples, (enc:encode(src, 1, 3000)))
|
||||
for i = 1, #src do
|
||||
src[i] = if i % 300 < 3 then 5000 else 0
|
||||
end
|
||||
table.insert(samples, (enc:encode(src, 1, 3000)))
|
||||
local dec = Alac.decoder(enc.config)
|
||||
local enc24 = Alac.encoder({ sampleRate = 44100, channels = 1, bitDepth = 24 }) :: Alac.Encoder
|
||||
local dec24 = Alac.decoder(enc24.config)
|
||||
local s24 = table.create(2000, 0)
|
||||
for i = 1, 2000 do
|
||||
s24[i] = rand(2 ^ 24) - 2 ^ 23
|
||||
end
|
||||
local p24 = enc24:encode(s24, 1, 2000) :: buffer
|
||||
t:fuzz("decode packet", function(b: buffer)
|
||||
return dec:decode(b)
|
||||
end, samples, { mutations = 40 })
|
||||
t:fuzz("decode 24-bit escape packet", function(b: buffer)
|
||||
return dec24:decode(b)
|
||||
end, { p24 }, { mutations = 20, garbage = 50 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,46 @@
|
||||
-- codecs/Base64 tests: encode / decode against Python's base64 (standard, URL-safe, unpadded) for every length 0..70
|
||||
-- and some large inputs, whitespace and missing padding on decode, data: URIs, bad input, and the fuzz no-throw pass.
|
||||
-- Fixtures: tools/fixtures/base64.py.
|
||||
local T = require("@tests/T")
|
||||
local Base64 = require("@formats/codecs/Base64")
|
||||
local Cases = require("@tests/gen/base64_cases")
|
||||
|
||||
local t = T.suite("base64")
|
||||
|
||||
for _, c in Cases do
|
||||
local b = buffer.fromstring(c.data)
|
||||
t:eq(Base64.encode(b), c.std, "encode " .. #c.data)
|
||||
t:eq(Base64.encode(b, { url = true }), c.url, "encode url " .. #c.data)
|
||||
t:eq(Base64.encode(b, { pad = false }), c.nopad, "encode unpadded " .. #c.data)
|
||||
for _, s in { c.std, c.url, c.nopad } do
|
||||
local d, err = Base64.decode(s)
|
||||
t:check(d and buffer.tostring(d) == c.data, "decode " .. #c.data .. ": " .. tostring(err))
|
||||
end
|
||||
-- with line breaks every 76 characters (MIME)
|
||||
local wrapped = string.gsub(c.std, "(" .. string.rep(".", 76) .. ")", "%1\r\n")
|
||||
local d = Base64.decode(wrapped)
|
||||
t:check(d and buffer.tostring(d) == c.data, "decode wrapped " .. #c.data)
|
||||
end
|
||||
-- a sub-range
|
||||
t:eq(Base64.encode(buffer.fromstring("xxhelloyy"), nil, 2, 5), "aGVsbG8=", "encode a range")
|
||||
-- data URIs
|
||||
local b, mime = Base64.decodeDataUri("data:application/gltf-buffer;base64,AAEC")
|
||||
t:check(b and buffer.len(b) == 3 and buffer.readu8(b, 2) == 2 and mime == "application/gltf-buffer", "data URI")
|
||||
local b2, m2 = Base64.decodeDataUri("data:,a%20b")
|
||||
t:check(b2 and buffer.tostring(b2) == "a b" and m2 == "text/plain", "percent-encoded data URI")
|
||||
t:eq(Base64.dataUri(buffer.fromstring("hi"), "text/plain"), "data:text/plain;base64,aGk=", "dataUri")
|
||||
-- bad input
|
||||
t:check(Base64.decode("ab$d") == nil, "bad character")
|
||||
t:check(Base64.decode("abcde") == nil, "a lone last character")
|
||||
t:check(Base64.decode("ab==cd") == nil, "data after padding")
|
||||
t:check(Base64.decodeDataUri("http://x") == nil, "not a data URI")
|
||||
local samples = {}
|
||||
for i, c in Cases do
|
||||
if i % 10 == 0 then
|
||||
table.insert(samples, c.std)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(x: buffer)
|
||||
return Base64.decode(x)
|
||||
end, samples)
|
||||
t:done()
|
||||
@@ -0,0 +1,126 @@
|
||||
-- codecs/Brotli tests: every fixture stream (reference encoder: qualities 0..11, windows 10..24, text / font / generic
|
||||
-- modes, large windows) decodes to its corpus; consumedEnd; offsets inside a bigger buffer; the static dictionary;
|
||||
-- hand-made streams (empty, metadata, uncompressed); maxBytes; truncated / corrupted / random input returns nil, Err
|
||||
-- and never throws. Fixtures: tools/fixtures/brotli.py.
|
||||
local T = require("@tests/T")
|
||||
local Brotli = require("@formats/codecs/Brotli")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Fx = require("@tests/gen/brotli")
|
||||
|
||||
local t = T.suite("brotli")
|
||||
|
||||
-- the static dictionary
|
||||
do
|
||||
local d = Brotli.dictionary()
|
||||
t:check(d and buffer.len(d) == 122784, "dictionary size")
|
||||
t:eq(buffer.readstring(d :: buffer, 0, 8), "timedown", "dictionary starts with the length-4 words")
|
||||
end
|
||||
|
||||
-- every case
|
||||
local nbytes = 0
|
||||
for _, c in Fx.cases do
|
||||
local want = Fx.corpora[c.corpus]
|
||||
local out, e = Brotli.decompress(c.data)
|
||||
t:check(out ~= nil, c.name .. ": " .. tostring(e))
|
||||
if buffer.tostring(out :: buffer) ~= want then
|
||||
t:check(false, c.name .. ": output differs (" .. buffer.len(out :: buffer) .. " bytes, want " .. #want .. ")")
|
||||
end
|
||||
t:eq(e, #c.data, c.name .. ": consumed")
|
||||
nbytes += #want
|
||||
end
|
||||
t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6)
|
||||
|
||||
-- at an offset inside a bigger buffer, with trailing bytes
|
||||
do
|
||||
local c = Fx.cases[30]
|
||||
local big = buffer.create(#c.data + 13)
|
||||
buffer.fill(big, 0, 0xAB)
|
||||
buffer.writestring(big, 5, c.data)
|
||||
local out, e = Brotli.decompress(big, 5, #c.data + 8)
|
||||
t:check(out and buffer.tostring(out) == Fx.corpora[c.corpus] and e == 5 + #c.data, "at an offset")
|
||||
end
|
||||
|
||||
-- hand-made streams
|
||||
do
|
||||
local bytes = T.bytes
|
||||
-- WBITS 16 (bit 0), ISLAST, ISLASTEMPTY: 0b110 = 6
|
||||
local o, e = Brotli.decompress(bytes({ 6 }))
|
||||
t:check(o and buffer.len(o) == 0 and e == 1, "empty stream: " .. tostring(e))
|
||||
-- 0x3b: python brotli's empty stream (WBITS 22)
|
||||
local o2 = Brotli.decompress(bytes({ 0x3b }))
|
||||
t:check(o2 and buffer.len(o2) == 0, "empty stream (WBITS 22)")
|
||||
local _, e0 = Brotli.decompress(bytes({}))
|
||||
t:check(e0 and e0.code == Err.TRUNCATED, "empty input is TRUNCATED")
|
||||
-- an uncompressed meta-block "hi": WBITS 16 [0], ISLAST 0, MNIBBLES 4 [00], MLEN-1 = 1 [1000 0000 0000 0000],
|
||||
-- ISUNCOMPRESSED 1, pad, "hi", then ISLAST 1 ISLASTEMPTY 1
|
||||
-- bits LSB first: 0 | 0 | 00 | 1000 | 0000 0000 0000 | 1 -> byte0 = 0b00010000 = 0x10 (bits 0..7: 0,0,0,0,1,0,0,0)
|
||||
-- byte1 = 0, byte2 = bits 16..23: 0,0,0,0 (rest of nibbles) 1 (ISUNCOMPRESSED) + pad 000 = 0x10
|
||||
local o3 = Brotli.decompress(bytes({ 0x10, 0x00, 0x10, 0x68, 0x69, 0x03 }))
|
||||
t:check(o3 and buffer.tostring(o3) == "hi", "uncompressed meta-block")
|
||||
local _, e3 = Brotli.decompress(bytes({ 0x10, 0x00, 0x10, 0x68 }))
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "truncated uncompressed block: " .. tostring(e3))
|
||||
-- nonzero padding at the end
|
||||
local _, e4 = Brotli.decompress(bytes({ 0x10, 0x00, 0x10, 0x68, 0x69, 0x0b }))
|
||||
t:check(e4 and e4.code == Err.CORRUPT, "nonzero padding: " .. tostring(e4))
|
||||
-- a metadata block (MNIBBLES 3, 1 byte length, 2 bytes skipped) before the last empty one
|
||||
-- bits: WBITS 0 | ISLAST 0 | MNIBBLES 11 | reserved 0 | MSKIPBYTES 01 | len-1 = 1 (8 bits) | pad | 2 bytes | 11
|
||||
-- 0,0,1,1,0,1,0, then 8 bits of 1: 1,0,0,0,0,0,0,0, pad to 16 -> byte0 = 0b0 1 0 1 1 0 0 = bits0..7: 0,0,1,1,0,1,0,1
|
||||
local o5 = Brotli.decompress(bytes({ 0xAC, 0x00, 0xEE, 0xEE, 0x03 }))
|
||||
t:check(o5 and buffer.len(o5) == 0, "metadata block skipped")
|
||||
local ok, r1, r2 = pcall(Brotli.decompress, 5 :: any)
|
||||
t:check(ok and r1 == nil and r2.code == Err.ARG, "a non-buffer argument returns Err.ARG")
|
||||
end
|
||||
|
||||
-- maxBytes
|
||||
do
|
||||
local c
|
||||
for _, x in Fx.cases do
|
||||
if x.corpus == "english" then
|
||||
c = x
|
||||
break
|
||||
end
|
||||
end
|
||||
local _, e = Brotli.decompress(c.data, nil, nil, { maxBytes = 1000 })
|
||||
t:check(e and e.code == Err.LIMIT, "maxBytes: " .. tostring(e))
|
||||
local big
|
||||
for _, x in Fx.cases do
|
||||
if string.find(x.name, "large", 1, true) then
|
||||
big = x
|
||||
break
|
||||
end
|
||||
end
|
||||
local _, e2 = Brotli.decompress(big.data, nil, nil, { largeWindow = false })
|
||||
t:check(e2 and e2.code == Err.UNSUPPORTED, "largeWindow = false: " .. tostring(e2))
|
||||
end
|
||||
|
||||
-- a corrupted stream reports CORRUPT or TRUNCATED, never a wrong success with the right CRC
|
||||
do
|
||||
local bad = 0
|
||||
for i, c in Fx.cases do
|
||||
if i % 17 == 0 and #c.data > 20 then
|
||||
local b = buffer.fromstring(c.data)
|
||||
buffer.writeu8(b, #c.data // 2, bit32.bxor(buffer.readu8(b, #c.data // 2), 0x5A))
|
||||
local out = Brotli.decompress(b)
|
||||
if out and Crc32.of(out) == Crc32.of(buffer.fromstring(Fx.corpora[c.corpus])) then
|
||||
bad += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
t:eq(bad, 0, "corrupted streams never decode to the original")
|
||||
end
|
||||
|
||||
-- truncation, corruption and garbage never throw
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if i % 11 == 0 and #c.data > 8 then
|
||||
table.insert(samples, if #c.data > 20000 then string.sub(c.data, 1, 20000) else c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decompress", function(b: buffer)
|
||||
return Brotli.decompress(b)
|
||||
end, samples, { mutations = 6, garbage = 3000 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,103 @@
|
||||
-- codecs/Bzip2 tests: every fixture stream (Python bz2 = libbzip2, block sizes 1..9, RLE1 run edges, block-boundary
|
||||
-- runs, random / skewed data, concatenated streams with trailing garbage) decodes exactly; offsets / consumedEnd;
|
||||
-- maxBytes; CRC mismatches are Err.CHECKSUM; truncations are Err.TRUNCATED; the fuzz no-throw pass.
|
||||
-- Fixtures: tools/fixtures/bzip2.py.
|
||||
local T = require("@tests/T")
|
||||
local Bzip2 = require("@formats/codecs/Bzip2")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/bzip2")
|
||||
|
||||
local t = T.suite("bzip2")
|
||||
|
||||
t:eq(Bzip2.crc(buffer.fromstring("123456789")), 0xFC891918, "CRC-32/BZIP2 check value")
|
||||
|
||||
local nbytes = 0
|
||||
for _, c in Fx.cases do
|
||||
local want = Fx.corpora[c.corpus]
|
||||
local out, consumed = Bzip2.decompress(c.data)
|
||||
t:check(out ~= nil, c.name .. ": " .. tostring(consumed))
|
||||
t:check(buffer.tostring(out :: buffer) == want, c.name .. ": output differs")
|
||||
if c.name ~= "multi/trailing" then
|
||||
t:eq(consumed, #c.data, c.name .. ": consumedEnd")
|
||||
end
|
||||
nbytes += #want
|
||||
end
|
||||
t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6)
|
||||
|
||||
local function case(name: string): any
|
||||
for _, c in Fx.cases do
|
||||
if c.name == name then
|
||||
return c
|
||||
end
|
||||
end
|
||||
error("no case " .. name)
|
||||
end
|
||||
|
||||
-- inside a bigger buffer, at an offset
|
||||
do
|
||||
local c = case("text/l9")
|
||||
local big = buffer.create(#c.data + 20)
|
||||
buffer.fill(big, 0, 0xAB)
|
||||
buffer.writestring(big, 7, c.data)
|
||||
local out, consumed = Bzip2.decompress(big, 7, #c.data + 5)
|
||||
t:check(out and buffer.tostring(out) == Fx.corpora.text, "at an offset")
|
||||
t:eq(consumed, 7 + #c.data, "consumedEnd at an offset")
|
||||
end
|
||||
|
||||
-- maxBytes
|
||||
do
|
||||
local c = case("zeros/l9")
|
||||
local _, e = Bzip2.decompress(c.data, nil, nil, { maxBytes = 1000 })
|
||||
t:check(e and e.code == Err.LIMIT, "maxBytes: " .. tostring(e))
|
||||
local ok = Bzip2.decompress(c.data, nil, nil, { maxBytes = 250000 })
|
||||
t:check(ok ~= nil, "maxBytes = exact size")
|
||||
end
|
||||
|
||||
-- block CRC / stream CRC mismatches
|
||||
do
|
||||
local c = case("text/l9")
|
||||
local b = buffer.fromstring(c.data)
|
||||
-- block CRC sits at bytes 10..13 (after "BZh9" + 6 magic bytes)
|
||||
buffer.writeu8(b, 11, bit32.bxor(buffer.readu8(b, 11), 0x10))
|
||||
local _, e = Bzip2.decompress(b)
|
||||
t:check(e and e.code == Err.CHECKSUM, "block CRC mismatch: " .. tostring(e))
|
||||
local s = case("one/l9")
|
||||
local b2 = buffer.fromstring(s.data)
|
||||
local n = buffer.len(b2)
|
||||
buffer.writeu8(b2, n - 2, bit32.bxor(buffer.readu8(b2, n - 2), 0x01))
|
||||
local _, e2 = Bzip2.decompress(b2)
|
||||
t:check(e2 and (e2.code == Err.CHECKSUM or e2.code == Err.CORRUPT), "stream CRC mismatch: " .. tostring(e2))
|
||||
end
|
||||
|
||||
-- truncation -> TRUNCATED, bad magic -> CORRUPT, bad args -> ARG
|
||||
do
|
||||
local c = case("text/l1")
|
||||
for _, cut in { 3, 10, 40, #c.data // 2, #c.data - 3 } do
|
||||
local _, e = Bzip2.decompress(string.sub(c.data, 1, cut))
|
||||
t:check(e and e.code == Err.TRUNCATED, "truncated at " .. cut .. ": " .. tostring(e))
|
||||
end
|
||||
local _, e = Bzip2.decompress("BZx9abcdefgh")
|
||||
t:check(e and e.code == Err.CORRUPT, "bad magic")
|
||||
local _, e2 = Bzip2.decompress(5 :: any)
|
||||
t:check(e2 and e2.code == Err.ARG, "non-buffer")
|
||||
local _, e3 = Bzip2.decompress("BZh9", -1)
|
||||
t:check(e3 and e3.code == Err.ARG, "bad offset")
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if i % 4 == 0 and #c.data < 40000 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decompress", function(b: buffer)
|
||||
return Bzip2.decompress(b)
|
||||
end, samples, { mutations = 12, garbage = 1000, keepHeader = 4 })
|
||||
t:fuzz("decompress (no header kept)", function(b: buffer)
|
||||
return Bzip2.decompress(b)
|
||||
end, samples, { mutations = 4, garbage = 200 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,158 @@
|
||||
-- codecs/Dct tests: the islow inverse DCT against a double-precision reference (within 1 level per sample, as T.81
|
||||
-- annex A accuracy needs), forward DCT + quantiser against the reference transform (round to nearest of v / (8 q)),
|
||||
-- fdct -> idct round trips at q = 1 within 1 level, edge replication of fdctQuantize, and garbage coefficients never
|
||||
-- throw (outputs stay clamped). The bit-exact djpeg / cjpeg checks are in tests/image/jpeg.luau.
|
||||
local T = require("@tests/T")
|
||||
local Dct = require("@formats/codecs/Dct")
|
||||
|
||||
local t = T.suite("dct")
|
||||
local rand = T.rng(11)
|
||||
|
||||
local C = {}
|
||||
for u = 0, 7 do
|
||||
C[u] = if u == 0 then math.sqrt(0.5) else 1
|
||||
end
|
||||
local cosT = {}
|
||||
for x = 0, 7 do
|
||||
for u = 0, 7 do
|
||||
cosT[x * 8 + u] = math.cos((2 * x + 1) * u * math.pi / 16)
|
||||
end
|
||||
end
|
||||
|
||||
local ones = buffer.create(128)
|
||||
for i = 0, 63 do
|
||||
buffer.writeu16(ones, i * 2, 1)
|
||||
end
|
||||
|
||||
-- inverse: random sparse coefficients, compare with the float IDCT
|
||||
do
|
||||
local worst = 0
|
||||
for trial = 1, 300 do
|
||||
local coef = buffer.create(128)
|
||||
local F = {}
|
||||
for i = 0, 63 do
|
||||
local v = 0
|
||||
if rand(4) == 0 or i == 0 then
|
||||
v = rand(512) - 256
|
||||
if i == 0 then
|
||||
v = rand(2048) - 1024
|
||||
end
|
||||
end
|
||||
F[i] = v
|
||||
buffer.writei16(coef, i * 2, v)
|
||||
end
|
||||
local plane = buffer.create(128)
|
||||
Dct.idctBlock(coef, 0, ones, plane, 0, 8, 2, 128, 255)
|
||||
for y = 0, 7 do
|
||||
for x = 0, 7 do
|
||||
local s = 0
|
||||
for v = 0, 7 do
|
||||
for u = 0, 7 do
|
||||
s += C[u] * C[v] * F[v * 8 + u] * cosT[x * 8 + u] * cosT[y * 8 + v]
|
||||
end
|
||||
end
|
||||
local want = math.clamp(math.floor(s / 4 + 128 + 0.5), 0, 255)
|
||||
local got = buffer.readu16(plane, (y * 8 + x) * 2)
|
||||
worst = math.max(worst, math.abs(got - want))
|
||||
end
|
||||
end
|
||||
local _ = trial
|
||||
end
|
||||
t:check(worst <= 1, "idct within 1 of the float reference: " .. worst)
|
||||
t:note("idct: worst error %d over 300 random blocks", worst)
|
||||
end
|
||||
|
||||
-- forward + quantiser
|
||||
do
|
||||
local worst = 0
|
||||
for _ = 1, 200 do
|
||||
local src = buffer.create(64)
|
||||
for i = 0, 63 do
|
||||
buffer.writeu8(src, i, rand(256))
|
||||
end
|
||||
local q = buffer.create(128)
|
||||
for i = 0, 63 do
|
||||
buffer.writeu16(q, i * 2, 1 + rand(40))
|
||||
end
|
||||
local coef = buffer.create(128)
|
||||
Dct.fdctQuantize(src, 8, 0, 0, 8, 8, q, coef, 0)
|
||||
for v = 0, 7 do
|
||||
for u = 0, 7 do
|
||||
local s = 0
|
||||
for y = 0, 7 do
|
||||
for x = 0, 7 do
|
||||
s += (buffer.readu8(src, y * 8 + x) - 128) * cosT[x * 8 + u] * cosT[y * 8 + v]
|
||||
end
|
||||
end
|
||||
s *= C[u] * C[v] / 4
|
||||
local want = s / buffer.readu16(q, (v * 8 + u) * 2)
|
||||
worst = math.max(worst, math.abs(buffer.readi16(coef, (v * 8 + u) * 2) - want))
|
||||
end
|
||||
end
|
||||
end
|
||||
t:check(worst <= 0.75, "fdct + quantise within rounding of the float reference: " .. worst)
|
||||
-- round trip at q = 1
|
||||
local rt = 0
|
||||
for _ = 1, 100 do
|
||||
local src = buffer.create(64)
|
||||
for i = 0, 63 do
|
||||
buffer.writeu8(src, i, rand(256))
|
||||
end
|
||||
local coef = buffer.create(128)
|
||||
Dct.fdctQuantize(src, 8, 0, 0, 8, 8, ones, coef, 0)
|
||||
local plane = buffer.create(128)
|
||||
Dct.idctBlock(coef, 0, ones, plane, 0, 8, 2, 128, 255)
|
||||
for i = 0, 63 do
|
||||
rt = math.max(rt, math.abs(buffer.readu16(plane, i * 2) - buffer.readu8(src, i)))
|
||||
end
|
||||
end
|
||||
t:check(rt <= 1, "fdct -> idct round trip at q = 1: " .. rt)
|
||||
-- edge replication: a 3x2 image is the same as its 8x8 edge-extended version
|
||||
local small = T.bytes({ 10, 200, 30, 40, 50, 250 })
|
||||
local ext = buffer.create(64)
|
||||
for y = 0, 7 do
|
||||
for x = 0, 7 do
|
||||
buffer.writeu8(ext, y * 8 + x, buffer.readu8(small, math.min(y, 1) * 3 + math.min(x, 2)))
|
||||
end
|
||||
end
|
||||
local a, b = buffer.create(128), buffer.create(128)
|
||||
Dct.fdctQuantize(small, 3, 0, 0, 3, 2, ones, a, 0)
|
||||
Dct.fdctQuantize(ext, 8, 0, 0, 8, 8, ones, b, 0)
|
||||
t:check(buffer.tostring(a) == buffer.tostring(b), "edge replication")
|
||||
end
|
||||
|
||||
-- components and garbage: clamped output, no throw
|
||||
do
|
||||
local coef = buffer.create(4 * 3 * 128)
|
||||
for i = 0, buffer.len(coef) // 2 - 1 do
|
||||
buffer.writei16(coef, i * 2, rand(65536) - 32768)
|
||||
end
|
||||
local q = buffer.create(128)
|
||||
for i = 0, 63 do
|
||||
buffer.writeu16(q, i * 2, rand(65536))
|
||||
end
|
||||
for _, size in { 8, 4, 2, 1 } do
|
||||
for _, prec in { { 2, 128, 255 }, { 1, 2048, 4095 } } do
|
||||
local plane = buffer.create(4 * size * 3 * size * 2)
|
||||
local ok = pcall(Dct.idctComponent, coef, q, 4, 3, size, plane, prec[1], prec[2], prec[3])
|
||||
t:check(ok, "idctComponent size " .. size .. " on garbage")
|
||||
local inRange = true
|
||||
for i = 0, buffer.len(plane) // 2 - 1 do
|
||||
if buffer.readu16(plane, i * 2) > prec[3] then
|
||||
inRange = false
|
||||
end
|
||||
end
|
||||
t:check(inRange, "clamped output, size " .. size)
|
||||
end
|
||||
end
|
||||
local samples = { string.rep("\0", 128) }
|
||||
t:fuzz("idctBlock", function(b: buffer)
|
||||
local cb = buffer.create(128)
|
||||
buffer.copy(cb, 0, b, 0, math.min(128, buffer.len(b)))
|
||||
local plane = buffer.create(128)
|
||||
Dct.idctBlock(cb, 0, q, plane, 0, 8, 2, 128, 255)
|
||||
return plane
|
||||
end, samples, { garbage = 50 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,210 @@
|
||||
-- codecs/Json tests: the JSONTestSuite parsing corpus (y_ must parse to Python's value, n_ must fail, i_ must not
|
||||
-- throw), Python json.dumps output in four styles parsed and reproduced byte for byte (compact sorted, ordered,
|
||||
-- indent 2, ensure_ascii), events / lines / decodeAt / writer, options, error codes, and the fuzz pass.
|
||||
-- Fixtures: tools/fixtures/json.py.
|
||||
local T = require("@tests/T")
|
||||
local Json = require("@formats/codecs/Json")
|
||||
local Types = require("@formats/Types")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Suite = require("@tests/gen/json_suite")
|
||||
local Corpus = require("@tests/gen/json_corpus")
|
||||
|
||||
local t = T.suite("json")
|
||||
|
||||
-- events() rebuilt into a value (checks the pull tokenizer agrees with decode)
|
||||
local function fromEvents(s: string): (any, any)
|
||||
local stack, keys = {}, {}
|
||||
local top: any = nil
|
||||
local key: any = nil
|
||||
local function add(v: any)
|
||||
local cur = stack[#stack]
|
||||
if cur == nil then
|
||||
top = v
|
||||
elseif keys[#stack] ~= false then
|
||||
cur[key] = v
|
||||
else
|
||||
table.insert(cur, v)
|
||||
end
|
||||
end
|
||||
for ev, v in Json.events(s) do
|
||||
if ev == "error" then
|
||||
return nil, v
|
||||
elseif ev == "object" or ev == "array" then
|
||||
local tbl = if ev == "object" then Types.object() else {}
|
||||
add(tbl)
|
||||
table.insert(stack, tbl)
|
||||
keys[#stack] = if ev == "object" then true else false
|
||||
elseif ev == "endObject" or ev == "endArray" then
|
||||
keys[#stack] = nil
|
||||
table.remove(stack)
|
||||
elseif ev == "key" then
|
||||
key = v
|
||||
else
|
||||
add(v)
|
||||
end
|
||||
end
|
||||
return top, nil
|
||||
end
|
||||
|
||||
-- 1. JSONTestSuite
|
||||
local counts = { y = 0, n = 0, i = 0, iok = 0 }
|
||||
for _, c in Suite do
|
||||
local v, err = Json.decode(c.data)
|
||||
local ev, everr = fromEvents(c.data)
|
||||
if c.expect == "y" then
|
||||
t:check(v ~= nil, c.name .. ": parses (" .. tostring(err) .. ")")
|
||||
t:eq(Canon.of(v), c.canon, c.name .. ": value")
|
||||
t:check(ev ~= nil, c.name .. ": events parse (" .. tostring(everr) .. ")")
|
||||
t:eq(Canon.of(ev), c.canon, c.name .. ": events value")
|
||||
-- and our output reads back the same
|
||||
local s = Json.encode(v)
|
||||
t:check(s ~= nil, c.name .. ": encodes")
|
||||
t:eq(Canon.of(Json.decode(s :: string)), c.canon, c.name .. ": round trip")
|
||||
elseif c.expect == "n" then
|
||||
t:check(v == nil and Err.is(err), c.name .. ": rejected")
|
||||
t:check(ev == nil, c.name .. ": events reject")
|
||||
else
|
||||
counts.iok += if v ~= nil then 1 else 0
|
||||
end
|
||||
counts[c.expect] += 1
|
||||
end
|
||||
t:note("JSONTestSuite: %d y_ accepted, %d n_ rejected, %d of %d i_ accepted", counts.y, counts.n, counts.iok, counts.i)
|
||||
|
||||
-- 2. Python's json.dumps output: parse, compare, re-encode byte for byte
|
||||
for i, c in Corpus do
|
||||
local v, err = Json.decode(c.compact)
|
||||
t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(v), c.canon, "corpus " .. i .. ": value")
|
||||
t:eq(Json.encode(v), c.compact, "corpus " .. i .. ": compact text")
|
||||
t:eq(Json.encode(v, { indent = 2 }), c.pretty, "corpus " .. i .. ": indent 2 text")
|
||||
t:eq(Json.encode(v, { ascii = true }), c.ascii, "corpus " .. i .. ": ensure_ascii text")
|
||||
local o = Json.decode(c.ordered, { ordered = true })
|
||||
t:eq(Json.encode(o), c.ordered, "corpus " .. i .. ": ordered text")
|
||||
t:eq(Canon.of(Json.decode(c.ascii)), c.canon, "corpus " .. i .. ": ascii parse")
|
||||
t:eq(Canon.of(Json.decode(c.pretty)), c.canon, "corpus " .. i .. ": pretty parse")
|
||||
end
|
||||
|
||||
-- 3. options and API
|
||||
do
|
||||
local v = Json.decode('[12345678901234567890, -9007199254740993, 9007199254740991, 1.5e300]', { bigInts = "string" })
|
||||
t:eq(v[1], "12345678901234567890", "bigInts string")
|
||||
t:eq(v[2], "-9007199254740993", "bigInts negative")
|
||||
t:eq(v[3], 9007199254740991, "2^53 - 1 stays a number")
|
||||
t:eq(v[4], 1.5e300, "floats stay numbers")
|
||||
t:eq(Json.decode("[null]", { null = false })[1], false, "opts.null")
|
||||
t:eq(Json.decode("null"), Types.null, "top-level null")
|
||||
t:eq(Json.decode("\239\187\191[1]")[1], 1, "BOM skipped")
|
||||
t:eq(Json.decode(buffer.fromstring(" 7 ")), 7, "buffer input")
|
||||
local e = Json.decode('{"b":1,"a":{},"c":[]}')
|
||||
t:eq(Json.encode(e), '{"a":{},"b":1,"c":[]}', "empty object stays an object")
|
||||
local o = Json.decode('{"z":1,"a":2,"m":{"y":1,"b":2}}', { ordered = true })
|
||||
t:eq(Json.encode(o), '{"z":1,"a":2,"m":{"y":1,"b":2}}', "ordered keys")
|
||||
Types.set(o, "b", 3)
|
||||
o.a = nil
|
||||
t:eq(Json.encode(o), '{"z":1,"m":{"y":1,"b":2},"b":3}', "ordered set / remove")
|
||||
t:eq(Json.encode({}, { emptyTable = "object" }), "{}", "emptyTable object")
|
||||
t:eq(Json.encode({ [1] = "a", [3] = "c" }), '{"1":"a","3":"c"}', "sparse array -> object")
|
||||
t:eq(Json.encode({ 1, 2, x = 1 }), '{"1":1,"2":2,"x":1}', "mixed table -> object")
|
||||
t:eq(Json.encode("a/b", { escapeSlash = true }), '"a\\/b"', "escapeSlash")
|
||||
t:eq(Json.encode(0 / 0, { nan = "null" }), "null", "nan null")
|
||||
local _, ne = Json.encode(math.huge)
|
||||
t:eq(ne and ne.code, Err.ARG, "inf is an error")
|
||||
local cyc = {}
|
||||
cyc.self = cyc
|
||||
local _, ce = Json.encode(cyc)
|
||||
t:eq(ce and ce.code, Err.ARG, "cycle is an error")
|
||||
local _, fe = Json.encode({ f = print })
|
||||
t:eq(fe and fe.code, Err.ARG, "function is an error")
|
||||
t:eq(Json.encode(Types.Date.parse("1979-05-27T07:32:00Z")), '"1979-05-27T07:32:00Z"', "dates as strings")
|
||||
for _, x in { 0.1, 1 / 3, -2.5e-8, 1e300, 123456789012345, 2 ^ 53, 5e-324, 1.7976931348623157e308 } do
|
||||
t:eq(Json.decode(Json.encode(x) :: string), x, "number round trip " .. string.format("%.17g", x))
|
||||
end
|
||||
end
|
||||
|
||||
-- 4. streaming: lines, decodeAt, writer
|
||||
do
|
||||
local got = {}
|
||||
for _, v in Json.lines('{"a":1}\n[2]\n"x"\n 3 ') do
|
||||
table.insert(got, (Json.encode(v)))
|
||||
end
|
||||
t:eq(table.concat(got, "|"), '{"a":1}|[2]|"x"|3', "lines")
|
||||
local n, last = 0, nil
|
||||
for _, v, e in Json.lines("1 2 [") do
|
||||
if e then
|
||||
last = e
|
||||
else
|
||||
n += 1
|
||||
end
|
||||
end
|
||||
t:eq(n, 2, "lines stop at the bad value")
|
||||
t:eq(last and last.code, Err.TRUNCATED, "lines report the error")
|
||||
local v, p = Json.decodeAt("[1] [2]", 1)
|
||||
t:eq(v[1], 1, "decodeAt value")
|
||||
t:eq(p, 4, "decodeAt next")
|
||||
t:eq(Json.decodeAt(" ", 1), nil, "decodeAt at the end")
|
||||
|
||||
local w = Json.writer({ indent = 2 })
|
||||
w:beginObject():key("a"):value({ 1, 2 }):key("b"):beginArray():value("x"):beginObject():endObject():endArray():endObject()
|
||||
local s = w:tostring()
|
||||
t:eq(s, Json.encode(Json.decode('{"a":[1,2],"b":["x",{}]}', { ordered = true }), { indent = 2 }), "writer pretty")
|
||||
local w2 = Json.writer()
|
||||
w2:beginArray()
|
||||
local parts = {}
|
||||
for i = 1, 5 do
|
||||
w2:value(i)
|
||||
table.insert(parts, w2:flush())
|
||||
end
|
||||
w2:endArray()
|
||||
table.insert(parts, w2:flush())
|
||||
t:eq(table.concat(parts), "[1,2,3,4,5]", "writer flush chunks")
|
||||
t:eq(w2:tostring(), "[1,2,3,4,5]", "writer tostring after flushes")
|
||||
local w3 = Json.writer()
|
||||
w3:beginArray():key("x")
|
||||
t:check(w3.err ~= nil, "writer: key in array")
|
||||
local w4 = Json.writer()
|
||||
w4:beginObject():value(1)
|
||||
t:check(w4.err ~= nil, "writer: value without key")
|
||||
local w5 = Json.writer()
|
||||
w5:beginObject()
|
||||
t:check(w5:tostring() == nil, "writer: unclosed")
|
||||
end
|
||||
|
||||
-- 5. errors
|
||||
local function code(s: string, opts: any?): string?
|
||||
local _, e = Json.decode(s, opts)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code('{"a":'), Err.TRUNCATED, "truncated object")
|
||||
t:eq(code('"abc'), Err.TRUNCATED, "truncated string")
|
||||
t:eq(code("[1 2]"), Err.CORRUPT, "missing comma")
|
||||
t:eq(code("[1] x"), Err.CORRUPT, "trailing data")
|
||||
t:eq(code(string.rep("[", 50) .. string.rep("]", 50), { maxDepth = 10 }), Err.LIMIT, "maxDepth")
|
||||
t:eq(code(string.rep("[", 100000)), Err.LIMIT, "100000 opening brackets")
|
||||
t:eq(code(""), Err.TRUNCATED, "empty input")
|
||||
local _, ae = Json.decode(42 :: any)
|
||||
t:eq(ae and ae.code, Err.ARG, "bad argument")
|
||||
do
|
||||
local _, e = Json.decode('{"a": tru}')
|
||||
t:eq(e and e.offset, 6, "error offset")
|
||||
end
|
||||
|
||||
-- 6. fuzz
|
||||
local samples = {}
|
||||
for i = 1, 40 do
|
||||
table.insert(samples, Corpus[i].compact)
|
||||
end
|
||||
for _, c in Suite do
|
||||
if #samples < 120 and c.expect == "y" and #c.data < 200 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Json.decode(b)
|
||||
end, samples)
|
||||
t:fuzz("events", function(b: buffer)
|
||||
for _ in Json.events(b) do
|
||||
end
|
||||
return nil
|
||||
end, samples, { garbage = 50 })
|
||||
t:done()
|
||||
@@ -0,0 +1,142 @@
|
||||
-- codecs/Lzma tests: every fixture (liblzma through Python's lzma module and the xz CLI: presets 0-9 and -e, lc / lp /
|
||||
-- pb variants, raw LZMA1 / LZMA2, .lzma files, xz with every check type, BCJ and delta filters, multiple blocks,
|
||||
-- multiple streams and stream padding) decodes to its corpus; consumed offsets; checksum / size / truncation errors;
|
||||
-- maxBytes; the fuzz no-throw pass. Fixtures: tools/fixtures/lzma.py.
|
||||
local T = require("@tests/T")
|
||||
local Lzma = require("@formats/codecs/Lzma")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/lzma")
|
||||
|
||||
local t = T.suite("lzma")
|
||||
|
||||
local function decode(c: any, b: buffer, opts: any?): (buffer?, any)
|
||||
if c.kind == "raw" then
|
||||
return Lzma.lzma(b, 0, nil, c.props, c.size, opts)
|
||||
elseif c.kind == "raw2" then
|
||||
return Lzma.lzma2(b, 0, nil, nil, nil, opts)
|
||||
elseif c.kind == "alone" then
|
||||
return Lzma.alone(b, 0, nil, opts)
|
||||
end
|
||||
return Lzma.xz(b, 0, nil, opts)
|
||||
end
|
||||
|
||||
local nbytes = 0
|
||||
for _, c in Fx.cases do
|
||||
local want = Fx.corpora[c.corpus]
|
||||
local b = buffer.fromstring(c.data)
|
||||
local out, res = decode(c, b)
|
||||
t:check(out ~= nil, c.name .. ": " .. tostring(res))
|
||||
t:check(buffer.tostring(out :: buffer) == want, c.name .. ": output differs")
|
||||
if c.kind ~= "raw" then
|
||||
t:eq(res, #c.data, c.name .. ": consumed")
|
||||
end
|
||||
nbytes += #want
|
||||
end
|
||||
t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6)
|
||||
|
||||
-- at an offset inside a bigger buffer, with trailing bytes
|
||||
do
|
||||
for _, c in Fx.cases do
|
||||
if c.kind == "xz" and c.name == "text/xz-6" then
|
||||
local big = buffer.create(#c.data + 11)
|
||||
buffer.fill(big, 0, 0xAB)
|
||||
buffer.writestring(big, 3, c.data)
|
||||
local out, res = Lzma.xz(big, 3, #c.data)
|
||||
t:check(out and buffer.tostring(out) == Fx.corpora.text and res == 3 + #c.data, "xz at an offset")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local xz, xzc
|
||||
for _, c in Fx.cases do
|
||||
if c.name == "text/xz-check-crc32" then
|
||||
xz = c
|
||||
elseif c.name == "text/xz-6" then
|
||||
xzc = c
|
||||
end
|
||||
end
|
||||
-- the check field: the last bytes before the index; flip a data bit near the end of the block instead
|
||||
local b = buffer.fromstring(xzc.data)
|
||||
local n = buffer.len(b)
|
||||
-- footer magic
|
||||
buffer.writeu8(b, n - 1, 0)
|
||||
local _, e1 = Lzma.xz(b)
|
||||
t:check(e1 and (e1.code == Err.CORRUPT or e1.code == Err.CHECKSUM), "bad footer: " .. tostring(e1))
|
||||
-- the stream header CRC
|
||||
local b2 = buffer.fromstring(xz.data)
|
||||
buffer.writeu8(b2, 8, bit32.bxor(buffer.readu8(b2, 8), 1))
|
||||
local _, e2 = Lzma.xz(b2)
|
||||
t:check(e2 and e2.code == Err.CHECKSUM, "header crc: " .. tostring(e2))
|
||||
-- the block check (CRC-32 / CRC-64): flip a byte of the check field (found from the index: the 4 / 8 bytes before
|
||||
-- the index indicator, which follows the block padding)
|
||||
for _, c in { xz, xzc } do
|
||||
local b3 = buffer.fromstring(c.data)
|
||||
local n3 = buffer.len(b3)
|
||||
local backward = (buffer.readu32(b3, n3 - 8) + 1) * 4
|
||||
local indexAt = n3 - 12 - backward
|
||||
buffer.writeu8(b3, indexAt - 1, bit32.bxor(buffer.readu8(b3, indexAt - 1), 0x10))
|
||||
local _, e3 = Lzma.xz(b3)
|
||||
t:check(e3 and e3.code == Err.CHECKSUM, c.name .. ": block check: " .. tostring(e3))
|
||||
end
|
||||
-- truncations are TRUNCATED or CORRUPT, never a throw
|
||||
local _, e4 = Lzma.xz(buffer.fromstring(string.sub(xzc.data, 1, #xzc.data // 2)))
|
||||
t:check(e4 and e4.code == Err.TRUNCATED, "truncated xz: " .. tostring(e4))
|
||||
-- maxBytes
|
||||
local _, e5 = Lzma.xz(xzc.data, nil, nil, { maxBytes = 1000 })
|
||||
t:check(e5 and e5.code == Err.LIMIT, "maxBytes: " .. tostring(e5))
|
||||
local ok, r1, r2 = pcall(Lzma.xz, 5 :: any)
|
||||
t:check(ok and r1 == nil and r2.code == Err.ARG, "a non-buffer argument returns Err.ARG")
|
||||
local _, e6 = Lzma.lzma("\0\0\0\0\0", 0, nil, "\255")
|
||||
t:check(e6 and e6.code == Err.CORRUPT, "bad props byte: " .. tostring(e6))
|
||||
end
|
||||
|
||||
-- raw LZMA with the size known: decoding stops at the size even without an end marker
|
||||
do
|
||||
for _, c in Fx.cases do
|
||||
if c.kind == "raw" and #Fx.corpora[c.corpus] > 1000 then
|
||||
local want = Fx.corpora[c.corpus]
|
||||
local out = Lzma.lzma(c.data, 0, nil, { lc = 3, lp = 0, pb = 2 }, nil)
|
||||
if c.name == c.corpus .. "/raw-lc3-lp0-pb2" then
|
||||
t:check(out and buffer.tostring(out) == want, c.name .. ": table props, end marker")
|
||||
end
|
||||
local part = Lzma.lzma(c.data, 0, nil, c.props, 500)
|
||||
t:check(part and buffer.tostring(part) == string.sub(want, 1, 500), c.name .. ": a prefix by size")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if i % 7 == 0 and #c.data > 16 and #c.data < 40000 then
|
||||
table.insert(samples, c)
|
||||
end
|
||||
end
|
||||
local xs, as, rs = {}, {}, {}
|
||||
for _, c in samples do
|
||||
if c.kind == "xz" then
|
||||
table.insert(xs, c.data)
|
||||
elseif c.kind == "alone" then
|
||||
table.insert(as, c.data)
|
||||
else
|
||||
table.insert(rs, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("xz", function(b: buffer)
|
||||
return Lzma.xz(b, 0, nil, { maxBytes = 1 * 2 ^ 20 })
|
||||
end, xs, { mutations = 6, garbage = 300 })
|
||||
t:fuzz("alone", function(b: buffer)
|
||||
return Lzma.alone(b, 0, nil, { maxBytes = 1 * 2 ^ 20 })
|
||||
end, as, { mutations = 6, garbage = 300 })
|
||||
t:fuzz("lzma2", function(b: buffer)
|
||||
return Lzma.lzma2(b, 0, nil, nil, nil, { maxBytes = 1 * 2 ^ 20 })
|
||||
end, rs, { mutations = 4, garbage = 1000 })
|
||||
t:fuzz("lzma", function(b: buffer)
|
||||
return Lzma.lzma(b, 0, nil, "\93", nil, { maxBytes = 1 * 2 ^ 20 })
|
||||
end, rs, { mutations = 2, garbage = 1000 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,119 @@
|
||||
-- codecs/Lzw tests: GIF (LSB) and TIFF (MSB, early change) code streams from Pillow / libtiff decode to their data;
|
||||
-- our encoder round-trips random and structured data at every GIF minimum code size and through table resets; the
|
||||
-- output limit, truncated and corrupt streams; the fuzz no-throw pass. Fixtures: tools/fixtures/lzw.py.
|
||||
local T = require("@tests/T")
|
||||
local Lzw = require("@formats/codecs/Lzw")
|
||||
local Fx = require("@tests/gen/lzw")
|
||||
|
||||
local t = T.suite("lzw")
|
||||
|
||||
local function dec(codes: buffer, n: number, variant: string, min: number?): (string, number, string?)
|
||||
local out = buffer.create(n)
|
||||
local got, err = Lzw.decode(codes, 0, buffer.len(codes), out, 0, n, variant, min)
|
||||
return buffer.tostring(out), got, err
|
||||
end
|
||||
|
||||
-- reference streams
|
||||
for _, c in Fx.gif do
|
||||
local s, n, err = dec(buffer.fromstring(c.codes), #c.data, "gif", c.min)
|
||||
t:check(err == nil, "gif " .. c.name .. ": " .. tostring(err))
|
||||
t:eq(n, #c.data, "gif " .. c.name .. ": length")
|
||||
t:check(s == c.data, "gif " .. c.name .. ": data")
|
||||
end
|
||||
for _, c in Fx.tiff do
|
||||
local s, n, err = dec(buffer.fromstring(c.codes), #c.data, "tiff")
|
||||
t:check(err == nil, "tiff " .. c.name .. ": " .. tostring(err))
|
||||
t:eq(n, #c.data, "tiff " .. c.name .. ": length")
|
||||
t:check(s == c.data, "tiff " .. c.name .. ": data")
|
||||
end
|
||||
t:note("%d GIF and %d TIFF reference streams decode", #Fx.gif, #Fx.tiff)
|
||||
|
||||
-- round trips
|
||||
local rand = T.rng(3)
|
||||
local function data(n: number, kind: number, max: number): buffer
|
||||
local b = buffer.create(n)
|
||||
for i = 0, n - 1 do
|
||||
local v
|
||||
if kind == 0 then
|
||||
v = rand(max)
|
||||
elseif kind == 1 then
|
||||
v = (i // 7) % max
|
||||
else
|
||||
v = if rand(10) == 0 then rand(max) else (i % 13) % max
|
||||
end
|
||||
buffer.writeu8(b, i, v)
|
||||
end
|
||||
return b
|
||||
end
|
||||
local trips = 0
|
||||
for _, n in { 0, 1, 2, 3, 100, 5000, 70000 } do
|
||||
for kind = 0, 2 do
|
||||
for min = 2, 8 do
|
||||
local d = data(n, kind, 2 ^ min)
|
||||
local codes = Lzw.encode(d, 0, n, "gif", min)
|
||||
local s, got, err = dec(codes, n, "gif", min)
|
||||
t:check(err == nil and got == n and s == buffer.tostring(d), string.format("gif round trip n=%d kind=%d min=%d: %s", n, kind, min, tostring(err)))
|
||||
trips += 1
|
||||
end
|
||||
local d = data(n, kind, 256)
|
||||
local codes = Lzw.encode(d, 0, n, "tiff")
|
||||
local s, got, err = dec(codes, n, "tiff")
|
||||
t:check(err == nil and got == n and s == buffer.tostring(d), string.format("tiff round trip n=%d kind=%d: %s", n, kind, tostring(err)))
|
||||
trips += 1
|
||||
end
|
||||
end
|
||||
t:note("%d round trips", trips)
|
||||
|
||||
-- compression actually happens; a range inside a bigger buffer
|
||||
do
|
||||
local d = buffer.create(10000)
|
||||
local codes = Lzw.encode(d, 0, 10000, "tiff")
|
||||
t:check(buffer.len(codes) < 400, "zeros compress: " .. buffer.len(codes))
|
||||
local big = data(300, 1, 256)
|
||||
local codes2 = Lzw.encode(big, 100, 100, "gif", 8)
|
||||
local out = buffer.create(120)
|
||||
local n = Lzw.decode(codes2, 0, buffer.len(codes2), out, 10, 100, "gif", 8)
|
||||
t:eq(n, 100, "sub-range length")
|
||||
t:check(buffer.readstring(out, 10, 100) == buffer.readstring(big, 100, 100), "sub-range data")
|
||||
end
|
||||
|
||||
-- limits, truncation, corruption
|
||||
do
|
||||
local d = data(1000, 2, 16)
|
||||
local codes = Lzw.encode(d, 0, 1000, "gif", 4)
|
||||
local s, n, err = dec(codes, 500, "gif", 4)
|
||||
t:check(n == 500 and err == nil and s == buffer.readstring(d, 0, 500), "output limit")
|
||||
local cut = buffer.create(buffer.len(codes) // 2)
|
||||
buffer.copy(cut, 0, codes, 0, buffer.len(cut))
|
||||
local _, n2, err2 = dec(cut, 1000, "gif", 4)
|
||||
t:check(err2 == "truncated" and n2 > 0 and n2 < 1000, "truncated: " .. tostring(err2))
|
||||
local bad = buffer.fromstring("\255\255\255\255")
|
||||
local _, _, err3 = dec(bad, 100, "gif", 2)
|
||||
t:check(err3 == "corrupt", "corrupt: " .. tostring(err3))
|
||||
local _, _, err4 = dec(codes, 100, "gif", 0)
|
||||
t:check(err4 == "corrupt", "bad min code size")
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.gif do
|
||||
if i % 2 == 1 then
|
||||
table.insert(samples, c.codes)
|
||||
end
|
||||
end
|
||||
for i, c in Fx.tiff do
|
||||
if i % 2 == 0 then
|
||||
table.insert(samples, c.codes)
|
||||
end
|
||||
end
|
||||
local out = buffer.create(100000)
|
||||
t:fuzz("decode gif", function(b: buffer)
|
||||
return Lzw.decode(b, 0, buffer.len(b), out, 0, 100000, "gif", 8)
|
||||
end, samples)
|
||||
t:fuzz("decode tiff", function(b: buffer)
|
||||
return Lzw.decode(b, 0, buffer.len(b), out, 0, 100000, "tiff")
|
||||
end, samples)
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,135 @@
|
||||
-- codecs/Quantize tests: palette size bounds for every method and colour budget, the exact (lossless) palette at
|
||||
-- <= maxColors colours, transparency handling, PSNR of quantized images above thresholds, determinism of both
|
||||
-- methods and of Floyd-Steinberg dithering (the same CRC on both runtimes), bad arguments, and a no-throw pass.
|
||||
local T = require("@tests/T")
|
||||
local Quantize = require("@formats/codecs/Quantize")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
|
||||
local t = T.suite("quantize")
|
||||
local rand = T.rng(5)
|
||||
|
||||
local function photo(w: number, h: number): buffer
|
||||
local px = buffer.create(w * h * 4)
|
||||
for i = 0, w * h - 1 do
|
||||
local x, y = i % w, i // w
|
||||
local r = (x * 255) // (w - 1)
|
||||
local g = (y * 255) // (h - 1)
|
||||
local b = math.floor(128 + 100 * math.sin(x * 0.11) * math.cos(y * 0.07)) + rand(9)
|
||||
buffer.writeu32(px, i * 4, r + g * 256 + math.clamp(b, 0, 255) * 65536 + 0xFF000000)
|
||||
end
|
||||
return px
|
||||
end
|
||||
|
||||
local function render(idx: buffer, pal: { { number } }, n: number): buffer
|
||||
local out = buffer.create(n * 4)
|
||||
for i = 0, n - 1 do
|
||||
local c = pal[buffer.readu8(idx, i) + 1]
|
||||
buffer.writeu32(out, i * 4, c[1] + c[2] * 256 + c[3] * 65536 + 0xFF000000)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
local function psnr(a: buffer, b: buffer): number
|
||||
local se, n = 0, 0
|
||||
for o = 0, buffer.len(a) - 4, 4 do
|
||||
for k = 0, 2 do
|
||||
local d = buffer.readu8(a, o + k) - buffer.readu8(b, o + k)
|
||||
se += d * d
|
||||
n += 1
|
||||
end
|
||||
end
|
||||
return if se == 0 then 99 else 10 * math.log10(255 * 255 * n / se)
|
||||
end
|
||||
|
||||
local W, H = 128, 96
|
||||
local px = photo(W, H)
|
||||
-- palette bounds and quality
|
||||
local MIN_PSNR = { [256] = 30, [64] = 24, [16] = 17, [2] = 10 }
|
||||
for _, method in { "mediancut", "octree" } do
|
||||
for _, k in { 2, 16, 64, 256 } do
|
||||
local pal, exact = Quantize.palette(px, W, H, k, { method = method })
|
||||
t:check(#pal >= 1 and #pal <= k, string.format("%s %d: palette size %d", method, k, #pal))
|
||||
t:check(not exact, method .. ": not exact")
|
||||
for _, c in pal do
|
||||
t:check(#c == 4 and c[4] == 255 and c[1] % 1 == 0 and c[1] >= 0 and c[1] <= 255, "palette entries")
|
||||
end
|
||||
for _, dither in { false, true } do
|
||||
local idx = Quantize.map(px, W, H, pal, { dither = dither })
|
||||
t:eq(buffer.len(idx), W * H, "index buffer size")
|
||||
local p = psnr(render(idx, pal, W * H), px)
|
||||
local want = MIN_PSNR[k] - (if dither then 4 else 0)
|
||||
t:check(p > want, string.format("%s %d dither=%s: PSNR %.1f > %d", method, k, tostring(dither), p, want))
|
||||
if k == 256 or k == 16 then
|
||||
t:note("%-9s %3d colours dither=%-5s PSNR %.1f dB, crc %08x", method, k, tostring(dither), p, Crc32.of(idx))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- exact palettes: lossless
|
||||
do
|
||||
local n = 50 * 40
|
||||
local b = buffer.create(n * 4)
|
||||
for i = 0, n - 1 do
|
||||
local k = (i * 7 + i // 50) % 200
|
||||
buffer.writeu32(b, i * 4, (k * 3) % 256 + ((k * 11) % 256) * 256 + k * 65536 + 0xFF000000)
|
||||
end
|
||||
local pal, exact = Quantize.palette(b, 50, 40, 256)
|
||||
t:check(exact and #pal == 200, "exact palette of 200 colours: " .. #pal)
|
||||
local idx = Quantize.map(b, 50, 40, pal, { dither = true })
|
||||
t:check(buffer.tostring(render(idx, pal, n)) == buffer.tostring(b), "exact palette maps losslessly (dither too)")
|
||||
local pal2, exact2 = Quantize.palette(b, 50, 40, 199)
|
||||
t:check(not exact2 and #pal2 <= 199, "199 colours is not exact")
|
||||
local i3, p3, e3 = Quantize.quantize(b, 50, 40, 256, { dither = true })
|
||||
t:check(e3 and #p3 == 200 and buffer.tostring(render(i3, p3, n)) == buffer.tostring(b), "quantize() exact")
|
||||
end
|
||||
|
||||
-- transparency
|
||||
do
|
||||
local b = buffer.create(16 * 4)
|
||||
for i = 0, 15 do
|
||||
buffer.writeu32(b, i * 4, if i % 3 == 0 then 0x10FFFFFF else 0xFF0000FF + i * 256)
|
||||
end
|
||||
local pal, exact = Quantize.palette(b, 4, 4, 255)
|
||||
t:check(exact and #pal == 10, "transparent pixels are not in the palette")
|
||||
table.insert(pal, { 0, 0, 0, 0 })
|
||||
local idx = Quantize.map(b, 4, 4, pal, { transparentIndex = #pal - 1, dither = true })
|
||||
for i = 0, 15 do
|
||||
local v = buffer.readu8(idx, i)
|
||||
t:check((i % 3 == 0) == (v == #pal - 1), "transparent index " .. i)
|
||||
end
|
||||
end
|
||||
|
||||
-- determinism (also across runtimes: these CRCs are pinned)
|
||||
do
|
||||
local pal = Quantize.palette(px, W, H, 64, { method = "mediancut" })
|
||||
local a = Crc32.of(Quantize.map(px, W, H, pal, { dither = true }))
|
||||
local pal2 = Quantize.palette(px, W, H, 64, { method = "mediancut" })
|
||||
t:eq(Crc32.of(Quantize.map(px, W, H, pal2, { dither = true })), a, "mediancut + dither deterministic")
|
||||
t:eq(a, 0x50c4e466, "mediancut 64 + dither: the pinned CRC (the same on both runtimes)")
|
||||
local o1 = Quantize.palette(px, W, H, 37, { method = "octree" })
|
||||
local o2 = Quantize.palette(px, W, H, 37, { method = "octree" })
|
||||
t:check(#o1 == #o2 and o1[#o1][1] == o2[#o2][1], "octree deterministic")
|
||||
end
|
||||
|
||||
-- bad arguments never throw
|
||||
do
|
||||
t:eq(#Quantize.palette(nil :: any, 1, 1, 4), 0, "nil pixels")
|
||||
t:eq(#Quantize.palette(buffer.create(3), 1, 1, 4), 0, "short buffer")
|
||||
t:eq(buffer.len(Quantize.map(px, W, H, {})), W * H, "empty palette")
|
||||
t:eq(buffer.len(Quantize.map(buffer.create(1), 2, 2, { { 1, 2, 3, 255 } })), 0, "short buffer map")
|
||||
local ok = pcall(function()
|
||||
for i = 1, 20 do
|
||||
local w, h = 1 + rand(20), 1 + rand(20)
|
||||
local b = buffer.create(w * h * 4)
|
||||
for k = 0, w * h * 4 - 1 do
|
||||
buffer.writeu8(b, k, rand(256))
|
||||
end
|
||||
local pal = Quantize.palette(b, w, h, 1 + rand(256), { method = if i % 2 == 0 then "octree" else "mediancut" })
|
||||
Quantize.map(b, w, h, pal, { dither = i % 3 == 0, transparentIndex = if i % 4 == 0 then 0 else nil })
|
||||
end
|
||||
end)
|
||||
t:check(ok, "random images never throw")
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,259 @@
|
||||
-- codecs/Raster tests: exact coverage of axis-aligned rectangles at fractional positions; areas of circles; random
|
||||
-- polygons and curves under random transforms against an independent 12 x 12 supersampled winding-number reference
|
||||
-- (both fill rules); clipping, the stroker (width, caps, joins against analytic areas), fill() compositing and paint
|
||||
-- functions; malformed paths never throw. Glyph rendering against FreeType is in tests/font/ttf.luau.
|
||||
local T = require("@tests/T")
|
||||
local R = require("@formats/codecs/Raster")
|
||||
local Types = require("@formats/Types")
|
||||
|
||||
local t = T.suite("raster")
|
||||
|
||||
local function sum(m: any): number
|
||||
if not m then
|
||||
return 0
|
||||
end
|
||||
local s = 0
|
||||
for i = 0, m.width * m.height - 1 do
|
||||
s += buffer.readu8(m.coverage, i)
|
||||
end
|
||||
return s / 255
|
||||
end
|
||||
|
||||
local function at(m: any, x: number, y: number): number
|
||||
local i, j = x - m.x, y - m.y
|
||||
if i < 0 or j < 0 or i >= m.width or j >= m.height then
|
||||
return 0
|
||||
end
|
||||
return buffer.readu8(m.coverage, j * m.width + i)
|
||||
end
|
||||
|
||||
-- 1. rectangles: exact per-pixel coverage
|
||||
do
|
||||
local p = R.path():rect(1.25, 2.5, 3.5, 2)
|
||||
local m = R.mask(p) :: any
|
||||
t:check(m, "rect mask")
|
||||
t:eq(m.x, 1, "rect x")
|
||||
t:eq(m.y, 2, "rect y")
|
||||
t:eq(m.width, 4, "rect width")
|
||||
t:eq(m.height, 3, "rect height")
|
||||
-- row 2 covers y 2.5..3 (half), columns: 1 covers 0.75, 2-3 full, 4 covers 0.75
|
||||
t:eq(at(m, 1, 2), math.floor(0.75 * 0.5 * 255 + 0.5), "corner pixel")
|
||||
t:eq(at(m, 2, 2), math.floor(0.5 * 255 + 0.5), "top edge pixel")
|
||||
t:eq(at(m, 2, 3), 255, "interior pixel")
|
||||
t:eq(at(m, 4, 3), math.floor(0.75 * 255 + 0.5), "right edge pixel")
|
||||
t:check(math.abs(sum(m) - 7) < 0.02, "rect area 7: " .. sum(m))
|
||||
-- reversed orientation gives the same coverage
|
||||
local q = R.path():moveTo(1.25, 2.5):lineTo(1.25, 4.5):lineTo(4.75, 4.5):lineTo(4.75, 2.5):close()
|
||||
t:check(math.abs(sum(R.mask(q)) - 7) < 0.02, "reversed rect")
|
||||
end
|
||||
|
||||
-- 2. circles: area pi r^2 (cubic approximation error ~ 2.7e-4 r)
|
||||
for _, r in { 3, 10.5, 40 } do
|
||||
local m = R.mask(R.path():ellipse(50.3, 50.7, r, r))
|
||||
local a = sum(m)
|
||||
t:check(math.abs(a - math.pi * r * r) < 0.01 * math.pi * r * r + 1, string.format("circle r=%g area %.2f", r, a))
|
||||
end
|
||||
|
||||
-- 3. random paths against a supersampled winding reference
|
||||
local function wind(polys: { { number } }, px: number, py: number): number
|
||||
local w = 0
|
||||
for _, poly in polys do
|
||||
local n = #poly
|
||||
local x0, y0 = poly[n - 1], poly[n]
|
||||
for i = 1, n - 1, 2 do
|
||||
local x1, y1 = poly[i], poly[i + 1]
|
||||
if y0 <= py then
|
||||
if y1 > py and (x1 - x0) * (py - y0) - (px - x0) * (y1 - y0) > 0 then
|
||||
w += 1
|
||||
end
|
||||
elseif y1 <= py and (x1 - x0) * (py - y0) - (px - x0) * (y1 - y0) < 0 then
|
||||
w -= 1
|
||||
end
|
||||
x0, y0 = x1, y1
|
||||
end
|
||||
end
|
||||
return w
|
||||
end
|
||||
|
||||
local rand = T.rng(7)
|
||||
local function rf(a: number, b: number): number
|
||||
return a + (b - a) * rand(100000) / 100000
|
||||
end
|
||||
|
||||
local worst, total, count = 0, 0, 0
|
||||
for case = 1, 24 do
|
||||
local p = R.path()
|
||||
for _ = 1, 1 + rand(3) do
|
||||
p:moveTo(rf(0, 28), rf(0, 28))
|
||||
for _ = 1, 2 + rand(5) do
|
||||
local k = rand(3)
|
||||
if k == 0 then
|
||||
p:lineTo(rf(0, 28), rf(0, 28))
|
||||
elseif k == 1 then
|
||||
p:quadTo(rf(0, 28), rf(0, 28), rf(0, 28), rf(0, 28))
|
||||
else
|
||||
p:cubicTo(rf(0, 28), rf(0, 28), rf(0, 28), rf(0, 28), rf(0, 28), rf(0, 28))
|
||||
end
|
||||
end
|
||||
p:close()
|
||||
end
|
||||
local ang = rf(0, 6.28)
|
||||
local tr = R.multiply(R.translate(rf(-5, 5), rf(-5, 5)), R.multiply(R.rotate(ang), R.scale(rf(0.5, 1.2), rf(0.5, 1.2))))
|
||||
local rule = if case % 2 == 0 then "evenodd" else "nonzero"
|
||||
local clip = { 0, 0, 32, 32 }
|
||||
local m = R.mask(p, { transform = tr, rule = rule :: any, clip = clip, tolerance = 0.05 })
|
||||
local polys = R.flatten(p, tr, 0.01)
|
||||
local err, n, mx = 0, 0, 0
|
||||
for y = 0, 31 do
|
||||
for x = 0, 31 do
|
||||
local inside = 0
|
||||
for sy = 0, 11 do
|
||||
for sx = 0, 11 do
|
||||
local w = wind(polys, x + (sx + 0.5) / 12, y + (sy + 0.5) / 12)
|
||||
if (rule == "nonzero" and w ~= 0) or (rule == "evenodd" and w % 2 == 1) then
|
||||
inside += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
local want = inside / 144
|
||||
local got = if m then at(m, x, y) / 255 else 0
|
||||
local d = math.abs(got - want)
|
||||
err += d
|
||||
n += 1
|
||||
if d > mx then
|
||||
mx = d
|
||||
end
|
||||
end
|
||||
end
|
||||
total += err
|
||||
count += n
|
||||
worst = math.max(worst, err / n)
|
||||
-- the area rules approximate where edges of opposite winding meet inside one pixel; on average they agree
|
||||
t:check(err / n < 0.015, string.format("case %d (%s): mean abs error %.4f (max %.3f)", case, rule, err / n, mx))
|
||||
end
|
||||
t:note("random paths: mean abs coverage error %.4f (worst case mean %.4f) vs 12x12 supersampling", total / count, worst)
|
||||
|
||||
-- 4. even-odd vs nonzero on two nested squares of the same orientation
|
||||
do
|
||||
local p = R.path():rect(0, 0, 10, 10):rect(3, 3, 4, 4)
|
||||
t:check(math.abs(sum(R.mask(p)) - 100) < 0.01, "nonzero fills the hole")
|
||||
t:check(math.abs(sum(R.mask(p, { rule = "evenodd" })) - 84) < 0.01, "evenodd leaves the hole")
|
||||
-- opposite orientation: a hole under both rules
|
||||
local q = R.path():rect(0, 0, 10, 10):moveTo(3, 3):lineTo(3, 7):lineTo(7, 7):lineTo(7, 3):close()
|
||||
t:check(math.abs(sum(R.mask(q)) - 84) < 0.01, "nonzero hole with opposite winding")
|
||||
end
|
||||
|
||||
-- 5. clipping: a shape larger than the clip, partly outside on every side
|
||||
do
|
||||
local m = R.mask(R.path():rect(-20.5, -3.25, 100, 50), { clip = { 0, 0, 16, 8 } }) :: any
|
||||
t:check(m and m.x == 0 and m.y == 0 and m.width == 16 and m.height == 8, "clipped bounds")
|
||||
t:check(math.abs(sum(m) - 128) < 0.01, "clipped area " .. sum(m))
|
||||
local m2 = R.mask(R.path():moveTo(-50, 4):lineTo(60, 4.5):lineTo(60, 6):lineTo(-50, 5):close(), { clip = { 0, 0, 10, 10 } })
|
||||
t:check(m2 ~= nil, "a sliver crossing the clip")
|
||||
t:check(R.mask(R.path():rect(20, 20, 5, 5), { clip = { 0, 0, 10, 10 } }) == nil, "outside the clip is empty")
|
||||
end
|
||||
|
||||
-- 6. strokes: a line of length L and width w covers L*w (butt), L*w + w^2 (square), L*w + pi w^2/4 (round)
|
||||
do
|
||||
local line = R.path():moveTo(5, 10):lineTo(35, 10)
|
||||
local a = sum(R.mask(R.stroke(line, { width = 4 })))
|
||||
t:check(math.abs(a - 120) < 0.05, "butt stroke area " .. a)
|
||||
a = sum(R.mask(R.stroke(line, { width = 4, cap = "square" })))
|
||||
t:check(math.abs(a - 136) < 0.05, "square cap area " .. a)
|
||||
a = sum(R.mask(R.stroke(line, { width = 4, cap = "round", tolerance = 0.01 })))
|
||||
t:check(math.abs(a - (120 + math.pi * 4)) < 0.3, "round cap area " .. a)
|
||||
-- a closed square outline of side 20, width 2, miter joins: outer 22^2 - inner 18^2
|
||||
local sq = R.path():rect(10, 10, 20, 20)
|
||||
a = sum(R.mask(R.stroke(sq, { width = 2 })))
|
||||
t:check(math.abs(a - (484 - 324)) < 0.1, "mitered square outline " .. a)
|
||||
a = sum(R.mask(R.stroke(sq, { width = 2, join = "bevel" })))
|
||||
t:check(math.abs(a - (160 - 4 * 0.5)) < 0.1, "bevelled square outline " .. a)
|
||||
a = sum(R.mask(R.stroke(sq, { width = 2, join = "round", tolerance = 0.01 })))
|
||||
t:check(math.abs(a - (160 - 4 * (1 - math.pi / 4))) < 0.15, "rounded square outline " .. a)
|
||||
-- a sharp zig-zag past the miter limit falls back to bevels; still covered without holes
|
||||
local zig = R.path():moveTo(0, 0):lineTo(20, 2):lineTo(0, 4)
|
||||
t:check(sum(R.mask(R.stroke(zig, { width = 1, miterLimit = 4 }))) > 30, "zig-zag stroke")
|
||||
-- a curve stroke: a circle outline of radius 10, width 1: area 2 pi r w
|
||||
a = sum(R.mask(R.stroke(R.path():ellipse(20, 20, 10, 10), { width = 1, join = "round", tolerance = 0.01 })))
|
||||
t:check(math.abs(a - 2 * math.pi * 10) < 1, "circle outline " .. a)
|
||||
end
|
||||
|
||||
-- 7. fill onto an image: colours, opacity, paint functions, compositing over existing pixels
|
||||
do
|
||||
local img = Types.Image.new(8, 8)
|
||||
t:check(R.fill(img, R.path():rect(0, 0, 4, 8), { 255, 0, 0, 255 }), "fill red")
|
||||
t:eq(buffer.readu32(img.pixels, 0), 0xFF0000FF, "opaque red pixel")
|
||||
t:eq(buffer.readu32(img.pixels, 4 * 5), 0, "untouched pixel")
|
||||
R.fill(img, R.path():rect(2, 0, 4, 8), { 0, 0, 255, 255 }, { opacity = 0.5 })
|
||||
local p = 4 * 3
|
||||
t:check(buffer.readu8(img.pixels, p) == 128 and buffer.readu8(img.pixels, p + 2) == 128 and buffer.readu8(img.pixels, p + 3) == 255, "half blue over red")
|
||||
p = 4 * 5
|
||||
t:check(buffer.readu8(img.pixels, p + 2) == 255 and buffer.readu8(img.pixels, p + 3) == 128, "half blue over transparent")
|
||||
local calls = 0
|
||||
R.fill(img, R.path():rect(0, 7, 8, 1), function(x: number, _y: number)
|
||||
calls += 1
|
||||
return x * 30, 0, 0, 255
|
||||
end)
|
||||
t:eq(calls, 8, "paint function per covered pixel")
|
||||
t:eq(buffer.readu8(img.pixels, (7 * 8 + 2) * 4), math.floor(2.5 * 30 + 0.5), "paint at the pixel centre")
|
||||
-- a transform scaling a unit square to the whole image
|
||||
local img2 = Types.Image.new(4, 4)
|
||||
R.fill(img2, R.path():rect(0, 0, 1, 1), { 0, 255, 0, 255 }, { transform = R.scale(4) })
|
||||
t:eq(buffer.readu32(img2.pixels, 4 * 15), 0xFF00FF00, "transformed fill")
|
||||
local inv = R.invert({ 2, 0, 0, 4, 3, 5 }) :: any
|
||||
local x, y = R.apply(inv, R.apply({ 2, 0, 0, 4, 3, 5 }, 7, 11))
|
||||
t:check(math.abs(x - 7) < 1e-9 and math.abs(y - 11) < 1e-9, "invert")
|
||||
t:check(R.fill(img2, R.path():rect(0, 0, 1, 1), function()
|
||||
error("boom")
|
||||
end) == false, "a failing paint function returns false")
|
||||
end
|
||||
|
||||
-- 8. malformed paths and huge / non-finite coordinates never throw
|
||||
do
|
||||
local bad: { any } = {
|
||||
{ { op = "moveTo" }, { op = "lineTo", 1 }, { op = "quadTo", 1, 2, "x", 4 }, { op = "close" } },
|
||||
{ { op = "lineTo", 0 / 0, 1 }, { op = "lineTo", 5, 5 }, { op = "lineTo", 0, 5 } },
|
||||
{ { op = "moveTo", 0, 0 }, { op = "lineTo", math.huge, 1 }, { op = "lineTo", 1, 1e300 } },
|
||||
{ { op = "moveTo", -1e6, -1e6 }, { op = "lineTo", 1e6, -1e6 }, { op = "lineTo", 1e6, 1e6 } },
|
||||
{ 5, "x", { op = "cubicTo" }, { op = 3 } },
|
||||
{},
|
||||
}
|
||||
local threw = 0
|
||||
for i, p in bad do
|
||||
for _, rule in { "nonzero", "evenodd" } do
|
||||
local ok = pcall(function()
|
||||
R.mask(p, { rule = rule :: any, clip = { 0, 0, 64, 64 } })
|
||||
R.mask(p, { transform = { 0 / 0, 0, 0, 1, 0, 0 } })
|
||||
R.stroke(p, { width = 3, cap = "round", join = "round" })
|
||||
R.fill(Types.Image.new(16, 16), p, { 1, 2, 3, 4 }, { transform = { 1e9, 0, 0, 1e9, 0, 0 } })
|
||||
end)
|
||||
if not ok then
|
||||
threw += 1
|
||||
print(" threw on bad path " .. i)
|
||||
end
|
||||
end
|
||||
end
|
||||
local _, why = R.mask(R.path():rect(0, 0, 5000, 5000), { maxPixels = 1000 })
|
||||
t:eq(why, "limit", "over maxPixels")
|
||||
t:check(R.mask("nope") == nil and R.mask(nil) == nil, "non-paths")
|
||||
-- random command soup through the fuzz helper: bytes -> commands
|
||||
t:fuzz("mask", function(b: buffer)
|
||||
local cmds = {}
|
||||
local ops = { "moveTo", "lineTo", "quadTo", "cubicTo", "close" }
|
||||
local i = 0
|
||||
while i + 1 < buffer.len(b) do
|
||||
local c: any = { op = ops[buffer.readu8(b, i) % 5 + 1] }
|
||||
for k = 1, 6 do
|
||||
local q = i + k
|
||||
c[k] = if q < buffer.len(b) then (buffer.readi8(b, q)) * 0.73 else 0
|
||||
end
|
||||
table.insert(cmds, c)
|
||||
i += 7
|
||||
end
|
||||
R.mask(cmds, { rule = if buffer.len(b) % 2 == 0 then "evenodd" else "nonzero", clip = { -10, -10, 40, 40 } })
|
||||
return R.stroke(cmds, { width = 2.5, cap = "square", join = "miter" })
|
||||
end, { "\0\1\2\3\4\5\6\1\9\9\9\9\9\9\2\1\2\3\4\5\6\3\1\2\3\4\5\6\4" }, { garbage = 400 })
|
||||
t:eq(threw, 0, "malformed paths never throw")
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,108 @@
|
||||
-- codecs/Url + codecs/Text tests: every example of RFC 3986 section 5.4 (normal and abnormal), dot-segment removal,
|
||||
-- splitting, encoding and the location helpers (ported from playlist-luau tests/url.luau); random references against
|
||||
-- Python's urllib.parse.urljoin; Url.locate / Url.base; Windows-1252 decoding against Python's cp1252 codec; lines,
|
||||
-- BOM, trim; the fuzz pass. Fixtures: tools/fixtures/playlist.py.
|
||||
local T = require("@tests/T")
|
||||
local Url = require("@formats/codecs/Url")
|
||||
local Text = require("@formats/codecs/Text")
|
||||
local Ref = require("@tests/gen/playlist_url")
|
||||
local Cp = require("@tests/gen/playlist_cp1252")
|
||||
|
||||
local t = T.suite("url")
|
||||
local function eq(got: any, want: any, label: string)
|
||||
t:eq(got, want, label)
|
||||
end
|
||||
|
||||
local BASE = "http://a/b/c/d;p?q"
|
||||
local cases = {
|
||||
-- 5.4.1 normal
|
||||
{ "g:h", "g:h" }, { "g", "http://a/b/c/g" }, { "./g", "http://a/b/c/g" }, { "g/", "http://a/b/c/g/" },
|
||||
{ "/g", "http://a/g" }, { "//g", "http://g" }, { "?y", "http://a/b/c/d;p?y" }, { "g?y", "http://a/b/c/g?y" },
|
||||
{ "#s", "http://a/b/c/d;p?q#s" }, { "g#s", "http://a/b/c/g#s" }, { "g?y#s", "http://a/b/c/g?y#s" },
|
||||
{ ";x", "http://a/b/c/;x" }, { "g;x", "http://a/b/c/g;x" }, { "g;x?y#s", "http://a/b/c/g;x?y#s" },
|
||||
{ "", "http://a/b/c/d;p?q" }, { ".", "http://a/b/c/" }, { "./", "http://a/b/c/" }, { "..", "http://a/b/" },
|
||||
{ "../", "http://a/b/" }, { "../g", "http://a/b/g" }, { "../..", "http://a/" }, { "../../", "http://a/" },
|
||||
{ "../../g", "http://a/g" },
|
||||
-- 5.4.2 abnormal
|
||||
{ "../../../g", "http://a/g" }, { "../../../../g", "http://a/g" }, { "/./g", "http://a/g" },
|
||||
{ "/../g", "http://a/g" }, { "g.", "http://a/b/c/g." }, { ".g", "http://a/b/c/.g" }, { "g..", "http://a/b/c/g.." },
|
||||
{ "..g", "http://a/b/c/..g" }, { "./../g", "http://a/b/g" }, { "./g/.", "http://a/b/c/g/" },
|
||||
{ "g/./h", "http://a/b/c/g/h" }, { "g/../h", "http://a/b/c/h" }, { "g;x=1/./y", "http://a/b/c/g;x=1/y" },
|
||||
{ "g;x=1/../y", "http://a/b/c/y" }, { "g?y/./x", "http://a/b/c/g?y/./x" }, { "g?y/../x", "http://a/b/c/g?y/../x" },
|
||||
{ "g#s/./x", "http://a/b/c/g#s/./x" }, { "g#s/../x", "http://a/b/c/g#s/../x" }, { "http:g", "http:g" },
|
||||
}
|
||||
for _, c in cases do
|
||||
eq(Url.resolve(c[1], BASE), c[2], "resolve " .. c[1])
|
||||
end
|
||||
-- base with an empty path
|
||||
eq(Url.resolve("g", "http://a"), "http://a/g", "empty base path")
|
||||
eq(Url.resolve("g", "http://a?x"), "http://a/g", "empty base path with query")
|
||||
|
||||
eq(Url.removeDotSegments("/a/b/c/./../../g"), "/a/g", "remove_dot_segments 1")
|
||||
eq(Url.removeDotSegments("mid/content=5/../6"), "mid/6", "remove_dot_segments 2")
|
||||
|
||||
local p = Url.split("https://user@host:8080/p/a.mp3?x=1&y#frag")
|
||||
eq(p.scheme, "https", "split scheme")
|
||||
eq(p.authority, "user@host:8080", "split authority")
|
||||
eq(p.path, "/p/a.mp3", "split path")
|
||||
eq(p.query, "x=1&y", "split query")
|
||||
eq(p.fragment, "frag", "split fragment")
|
||||
eq(Url.join(p), "https://user@host:8080/p/a.mp3?x=1&y#frag", "join")
|
||||
local q = Url.split("a/b")
|
||||
eq(q.scheme, nil, "relative has no scheme")
|
||||
eq(q.authority, nil, "relative has no authority")
|
||||
|
||||
eq(Url.encodeUnsafe("a b/ü%20?x=\"1\"#f"), "a%20b/%C3%BC%20?x=%221%22#f", "encodeUnsafe")
|
||||
eq(Url.isWindowsPath("C:\\Music\\a.mp3"), true, "windows drive")
|
||||
eq(Url.isWindowsPath("d:/x.mp3"), true, "windows drive with slash")
|
||||
eq(Url.isWindowsPath("\\\\server\\share\\a.mp3"), true, "UNC")
|
||||
eq(Url.isWindowsPath("http://x/a"), false, "http is not windows")
|
||||
eq(Url.scheme("C:\\a.mp3"), nil, "a drive letter is not a scheme")
|
||||
eq(Url.scheme("HTTPS://x"), "https", "scheme lower-cased")
|
||||
eq(Url.scheme("music/a.mp3"), nil, "relative has no scheme")
|
||||
|
||||
|
||||
-- Python's urljoin
|
||||
for _, c in Ref do
|
||||
eq(Url.resolve(c[1], c[2]), c[3], "urljoin " .. c[1] .. " against " .. c[2])
|
||||
end
|
||||
t:note("%d random references resolve as urllib.parse.urljoin", #Ref)
|
||||
|
||||
-- locate / base
|
||||
do
|
||||
local w = {}
|
||||
local base, scheme = Url.base("https://h/a/list.m3u", w)
|
||||
t:check(base == "https://h/a/list.m3u" and scheme == "https", "base")
|
||||
local l = Url.locate(" b c.mp3 ", base, scheme)
|
||||
t:check(l.url == "https://h/a/b%20c.mp3" and l.playable, "locate relative")
|
||||
t:check(Url.locate("C:\\x.mp3", base, scheme).reason == "local path", "locate windows")
|
||||
t:check(Url.locate("ftp://x/y", base, scheme).reason == "scheme ftp", "locate ftp")
|
||||
local nb, ns = Url.base("lists/x.m3u", w)
|
||||
t:check(nb == nil and ns == nil and #w == 1, "a relative base is ignored with a warning")
|
||||
t:check(select(2, Url.base("C:\\Music\\l.m3u")) == "windows", "windows base")
|
||||
end
|
||||
|
||||
-- Text
|
||||
do
|
||||
for _, c in Cp do
|
||||
eq(Text.toUtf8("x" .. string.char(c[1]) .. "y"), "x" .. c[2] .. "y", string.format("cp1252 0x%02x", c[1]))
|
||||
end
|
||||
local w = {}
|
||||
Text.toUtf8("\150", w)
|
||||
t:check(#w == 1, "cp1252 warning")
|
||||
eq(Text.toUtf8("\239\187\191abc"), "abc", "BOM stripped")
|
||||
eq(Text.toUtf8("h\u{e9}"), "h\u{e9}", "UTF-8 kept")
|
||||
local ls = Text.lines("a\r\nb\rc\nd")
|
||||
t:check(#ls == 4 and ls[1] == "a" and ls[2] == "b" and ls[3] == "c" and ls[4] == "d", "lines")
|
||||
eq(Text.trim(" x y \t"), "x y", "trim")
|
||||
end
|
||||
|
||||
t:fuzz("resolve + locate", function(b: buffer)
|
||||
local s = buffer.tostring(b)
|
||||
Url.resolve(s, "http://a/b/c/d;p?q")
|
||||
Url.resolve("g/../h", s)
|
||||
Url.locate(s, "http://h/", "http")
|
||||
return Text.lines(Text.toUtf8(s))
|
||||
end, { "http://a/b/../c?x#y", "C:\\a\\b.mp3", "\239\187\191#EXTM3U\r\n" }, { mutations = 30 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,80 @@
|
||||
-- codecs/Vp8 tests: the VP8 key frames of the WebP fixtures (cwebp at many settings and libvpx through ffmpeg, with
|
||||
-- 1..8 token partitions) decoded through the codec API: the yuv420p planes against dwebp -yuv, toRgba against
|
||||
-- dwebp -pam (fancy upsampling) and -nofancy, the decoder object over successive frames, headers, error codes and the
|
||||
-- fuzz no-throw pass on raw frames. Fixtures: tools/fixtures/webp.py.
|
||||
local T = require("@tests/T")
|
||||
local Vp8 = require("@formats/codecs/Vp8")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Cases = require("@tests/gen/webp_cases")
|
||||
|
||||
local t = T.suite("vp8")
|
||||
|
||||
local function chunk(data: string): (buffer?, number, number)
|
||||
if string.sub(data, 13, 16) ~= "VP8 " then
|
||||
return nil, 0, 0
|
||||
end
|
||||
local b = buffer.fromstring(data)
|
||||
return b, 20, buffer.readu32(b, 16)
|
||||
end
|
||||
|
||||
local n, vpx = 0, 0
|
||||
local frames = {}
|
||||
local dec = Vp8.newDecoder()
|
||||
for _, c in Cases do
|
||||
local b, off, len = chunk(c.data)
|
||||
if b then
|
||||
local img, err = Vp8.decodeFrame(b, off, len)
|
||||
t:check(img, c.name .. ": " .. tostring(err))
|
||||
t:check(img.format == "yuv420p" and img.width == c.width and img.height == c.height, c.name .. ": size")
|
||||
t:eq(Crc32.of(img.pixels), c.yuv, c.name .. ": yuv420p (dwebp -yuv)")
|
||||
local rgba = Vp8.toRgba(img) :: any
|
||||
t:eq(Crc32.of(rgba.pixels), c.crc, c.name .. ": rgba (dwebp -pam)")
|
||||
local nf = Vp8.toRgba(img, false) :: any
|
||||
t:eq(Crc32.of(nf.pixels), c.nofancy, c.name .. ": rgba (dwebp -nofancy -pam)")
|
||||
-- the same frame through one long-lived decoder
|
||||
local again = dec:decodeFrame(b, off, len)
|
||||
t:check(again and Crc32.of(again.pixels) == c.yuv, c.name .. ": decoder object")
|
||||
local y, u, v, w, h = Vp8.decodePlanes(b, off, len)
|
||||
t:check(y and w == c.width and h == c.height and buffer.len(u) == buffer.len(v :: buffer), c.name .. ": decodePlanes")
|
||||
local info = Vp8.info(b, off, len)
|
||||
t:check(info and info.keyFrame and info.show and info.width == c.width, c.name .. ": info")
|
||||
n += 1
|
||||
if string.find(c.name, "vpx", 1, true) then
|
||||
vpx += 1
|
||||
end
|
||||
if #frames < 10 and len < 6000 then
|
||||
table.insert(frames, buffer.readstring(b, off, len))
|
||||
end
|
||||
end
|
||||
end
|
||||
t:note("%d VP8 key frames (%d from libvpx) match dwebp: planes, fancy and point upsampling", n, vpx)
|
||||
|
||||
-- errors
|
||||
do
|
||||
local f = buffer.fromstring(frames[1])
|
||||
local inter = buffer.fromstring(frames[1])
|
||||
buffer.writeu8(inter, 0, bit32.bor(buffer.readu8(inter, 0), 1))
|
||||
local _, e1 = Vp8.decodeFrame(inter)
|
||||
t:check(e1 and e1.code == Err.UNSUPPORTED, "inter frame: " .. tostring(e1))
|
||||
local bad = buffer.fromstring(frames[1])
|
||||
buffer.writeu8(bad, 3, 0)
|
||||
local _, e2 = Vp8.decodeFrame(bad)
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "bad start code: " .. tostring(e2))
|
||||
local _, e3 = Vp8.decodeFrame(f, 0, 12)
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "truncated: " .. tostring(e3))
|
||||
local _, e4 = Vp8.decodeFrame(f, 0, buffer.len(f), { maxPixels = 4 })
|
||||
t:check(e4 and e4.code == Err.LIMIT, "maxPixels: " .. tostring(e4))
|
||||
local _, e5 = Vp8.toRgba({} :: any)
|
||||
t:check(e5 and e5.code == Err.ARG, "toRgba of a non-yuv image")
|
||||
end
|
||||
|
||||
-- fuzz on raw frames
|
||||
t:fuzz("decodeFrame", function(b: buffer)
|
||||
return Vp8.decodeFrame(b, 0, buffer.len(b), { maxPixels = 2 ^ 20 })
|
||||
end, frames, { mutations = 12, keepHeader = 10 })
|
||||
t:fuzz("decodeFrame (headers too)", function(b: buffer)
|
||||
return Vp8.decodeFrame(b, 0, buffer.len(b), { maxPixels = 2 ^ 20 })
|
||||
end, frames, { mutations = 4, garbage = 100 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,120 @@
|
||||
-- codecs/Vp8L tests: the VP8L bitstreams of the WebP fixtures (cwebp -z 0..9, -exact, near-lossless) decoded through
|
||||
-- the codec API against dwebp, the encoder at every effort on generated images (gradients, noise, palettes of 1..300
|
||||
-- colours, odd sizes, alpha), headerless alpha streams, error codes, and the fuzz no-throw pass on raw bitstreams.
|
||||
-- Fixtures: tools/fixtures/webp.py.
|
||||
local T = require("@tests/T")
|
||||
local Vp8L = require("@formats/codecs/Vp8L")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Cases = require("@tests/gen/webp_cases")
|
||||
|
||||
local t = T.suite("vp8l")
|
||||
|
||||
-- the VP8L chunk of a simple-format file
|
||||
local function chunk(data: string): (buffer?, number, number)
|
||||
if string.sub(data, 13, 16) ~= "VP8L" then
|
||||
return nil, 0, 0
|
||||
end
|
||||
local b = buffer.fromstring(data)
|
||||
return b, 20, buffer.readu32(b, 16)
|
||||
end
|
||||
|
||||
local n = 0
|
||||
local streams = {}
|
||||
for _, c in Cases do
|
||||
local b, off, len = chunk(c.data)
|
||||
if b then
|
||||
local px, w, h = Vp8L.decode(b, off, len)
|
||||
t:check(px, c.name .. ": " .. tostring(w))
|
||||
t:check(w == c.width and h == c.height, c.name .. ": size")
|
||||
t:eq(Crc32.of(px :: buffer), c.crc, c.name .. ": pixels (dwebp)")
|
||||
local info = Vp8L.info(b, off, len)
|
||||
t:check(info and info.width == c.width and info.height == c.height and info.alpha == c.alpha, c.name .. ": info")
|
||||
local argb = Vp8L.decodeArgb(b, off, len)
|
||||
t:check(argb and Crc32.of(Vp8L.toRgba(argb, c.width * c.height)) == c.crc, c.name .. ": decodeArgb + toRgba")
|
||||
n += 1
|
||||
if #streams < 12 and len < 8000 then
|
||||
table.insert(streams, buffer.readstring(b, off, len))
|
||||
end
|
||||
end
|
||||
end
|
||||
t:note("%d VP8L bitstreams match dwebp", n)
|
||||
|
||||
-- the encoder: round trips at every effort
|
||||
local rand = T.rng(5)
|
||||
local function gen(w: number, h: number, kind: string): buffer
|
||||
local px = buffer.create(w * h * 4)
|
||||
local pal = {}
|
||||
local np = if kind == "pal1" then 1 elseif kind == "pal4" then 4 elseif kind == "pal40" then 40 elseif kind == "pal300" then 300 else 0
|
||||
for i = 1, np do
|
||||
pal[i] = rand(2 ^ 24) * 256 + (if i % 3 == 0 then rand(256) else 255)
|
||||
end
|
||||
for y = 0, h - 1 do
|
||||
for x = 0, w - 1 do
|
||||
local o = (y * w + x) * 4
|
||||
if np > 0 then
|
||||
local v = pal[(x * 7 + y * 3 + (x * y) % 5) % np + 1]
|
||||
buffer.writeu32(px, o, v)
|
||||
elseif kind == "noise" then
|
||||
buffer.writeu32(px, o, rand(2 ^ 16) * 65536 + rand(2 ^ 16))
|
||||
else
|
||||
buffer.writeu8(px, o, (x * 4 + y) % 256)
|
||||
buffer.writeu8(px, o + 1, (y * 3) % 256)
|
||||
buffer.writeu8(px, o + 2, (x * y) % 256)
|
||||
buffer.writeu8(px, o + 3, if kind == "alpha" then (x * 9) % 256 else 255)
|
||||
end
|
||||
end
|
||||
end
|
||||
return px
|
||||
end
|
||||
local count = 0
|
||||
for _, kind in { "grad", "alpha", "noise", "pal1", "pal4", "pal40", "pal300" } do
|
||||
for _, size in { { 1, 1 }, { 2, 3 }, { 17, 5 }, { 64, 33 }, { 130, 2 } } do
|
||||
local w, h = size[1], size[2]
|
||||
local px = gen(w, h, kind)
|
||||
for effort = 0, 9 do
|
||||
local bits, err = Vp8L.encode(px, w, h, { effort = effort, exact = true })
|
||||
t:check(bits, kind .. ": encode: " .. tostring(err))
|
||||
local back, bw, bh = Vp8L.decode(bits :: buffer)
|
||||
t:check(back and bw == w and bh == h, string.format("%s %dx%d effort %d: decode: %s", kind, w, h, effort, tostring(bw)))
|
||||
t:check(buffer.tostring(back :: buffer) == buffer.tostring(px), string.format("%s %dx%d effort %d: round trip", kind, w, h, effort))
|
||||
count += 1
|
||||
end
|
||||
-- a headerless alpha plane
|
||||
local a = buffer.create(w * h)
|
||||
for i = 0, w * h - 1 do
|
||||
buffer.writeu8(a, i, buffer.readu8(px, i * 4 + 1))
|
||||
end
|
||||
local s = Vp8L.encodeAlpha(a, w, h) :: buffer
|
||||
local ab = Vp8L.decodeAlpha(s, 0, buffer.len(s), w, h)
|
||||
t:check(ab and buffer.tostring(ab) == buffer.tostring(a), kind .. ": alpha stream round trip")
|
||||
end
|
||||
end
|
||||
t:note("%d encoder round trips", count)
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e1 = Vp8L.decode(buffer.fromstring("\x2e\0\0\0\0"))
|
||||
t:check(e1 and e1.code == Err.CORRUPT, "bad signature: " .. tostring(e1))
|
||||
local _, e2 = Vp8L.decode(buffer.fromstring("\x2f\0\0\0\x20"))
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "bad version: " .. tostring(e2))
|
||||
local _, e3 = Vp8L.decode(buffer.fromstring("\x2f\0"))
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "short header: " .. tostring(e3))
|
||||
local big = Vp8L.encode(gen(64, 33, "grad"), 64, 33) :: buffer
|
||||
local _, e4 = Vp8L.decode(big, 0, buffer.len(big), 100)
|
||||
t:check(e4 and e4.code == Err.LIMIT, "maxPixels: " .. tostring(e4))
|
||||
local _, e5 = Vp8L.decode(big, 0, buffer.len(big) // 2)
|
||||
t:check(e5 and e5.code == Err.TRUNCATED, "truncated stream: " .. tostring(e5))
|
||||
local _, e6 = Vp8L.encode(buffer.create(4), 2, 2)
|
||||
t:check(e6 and e6.code == Err.ARG, "encode: short pixel buffer")
|
||||
end
|
||||
|
||||
-- fuzz on raw bitstreams
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Vp8L.decode(b, 0, buffer.len(b), 2 ^ 20)
|
||||
end, streams, { mutations = 10, keepHeader = 5 })
|
||||
t:fuzz("decodeAlpha", function(b: buffer)
|
||||
return Vp8L.decodeAlpha(b, 0, buffer.len(b), 37, 11)
|
||||
end, streams, { mutations = 4, garbage = 100 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,197 @@
|
||||
-- codecs/Xml tests: random documents (namespaces, escapes, CDATA, comments, PIs, DOCTYPE entities, UTF-16, Latin-1)
|
||||
-- against Python's ElementTree trees; encode -> decode round trips; well-formedness verdicts against expat
|
||||
-- (hand-written cases and random mutations); events, helpers, options, error codes; the fuzz pass.
|
||||
-- Fixtures: tools/fixtures/xml.py.
|
||||
local T = require("@tests/T")
|
||||
local Xml = require("@formats/codecs/Xml")
|
||||
local Types = require("@formats/Types")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Docs = require("@tests/gen/xml_docs")
|
||||
local Wf = require("@tests/gen/xml_wf")
|
||||
|
||||
local t = T.suite("xml")
|
||||
|
||||
-- ElementTree's view of an element (tools/fixtures/xml.py canon): Clark names, xmlns attributes dropped, text / tail
|
||||
local function s(x: string?): string
|
||||
x = x or ""
|
||||
return #(x :: string) .. ":" .. (x :: string)
|
||||
end
|
||||
local function canon(e: any, tail: string?): string
|
||||
local out = { "(" .. s(Xml.clark(e)) }
|
||||
local keys = {}
|
||||
local vals = {}
|
||||
for _, k in Types.keys(e.attrs) do
|
||||
if k ~= "xmlns" and string.sub(k, 1, 6) ~= "xmlns:" then
|
||||
local ck = Xml.clark(e, k)
|
||||
table.insert(keys, ck)
|
||||
vals[ck] = e.attrs[k]
|
||||
end
|
||||
end
|
||||
table.sort(keys)
|
||||
for _, k in keys do
|
||||
table.insert(out, "|" .. s(k) .. "=" .. s(vals[k]))
|
||||
end
|
||||
-- text: strings before the first element child; each child's tail: strings after it
|
||||
local text = {}
|
||||
local i = 1
|
||||
local ch = e.children
|
||||
while i <= #ch and (type(ch[i]) == "string" or ch[i].name == "#cdata") do
|
||||
table.insert(text, Xml.text(ch[i]))
|
||||
i += 1
|
||||
end
|
||||
table.insert(out, "|t" .. s(table.concat(text)))
|
||||
while i <= #ch do
|
||||
local c = ch[i]
|
||||
i += 1
|
||||
local tl = {}
|
||||
while i <= #ch and (type(ch[i]) == "string" or ch[i].name == "#cdata") do
|
||||
table.insert(tl, Xml.text(ch[i]))
|
||||
i += 1
|
||||
end
|
||||
table.insert(out, canon(c, table.concat(tl)))
|
||||
end
|
||||
return table.concat(out) .. ")t" .. s(tail)
|
||||
end
|
||||
|
||||
-- 1. documents vs ElementTree, and round trips
|
||||
for i, d in Docs do
|
||||
local doc, err = Xml.decode(d.data, { whitespace = true })
|
||||
t:check(doc, "doc " .. i .. ": " .. tostring(err))
|
||||
t:eq(canon((doc :: any).root), d.canon, "doc " .. i .. ": tree")
|
||||
-- keep everything, encode, decode again: the same tree
|
||||
local full = Xml.decode(d.data, { whitespace = true, comments = true, cdata = true, pi = true }) :: any
|
||||
local out, eerr = Xml.encode(full)
|
||||
t:check(out, "doc " .. i .. ": encodes (" .. tostring(eerr) .. ")")
|
||||
local again, aerr = Xml.decode(out :: string, { whitespace = true })
|
||||
t:check(again, "doc " .. i .. ": re-decodes (" .. tostring(aerr) .. ")")
|
||||
t:eq(canon((again :: any).root), d.canon, "doc " .. i .. ": round trip")
|
||||
local pretty = Xml.encode(full, { indent = 2 }) :: string
|
||||
t:check(Xml.decode(pretty), "doc " .. i .. ": pretty output parses")
|
||||
-- the namespace option agrees with the clark helper
|
||||
local nsdoc = Xml.decode(d.data, { namespaces = true }) :: any
|
||||
local root = nsdoc.root
|
||||
local want = string.match(Xml.clark(root), "^{([^}]*)}")
|
||||
t:eq(root.ns, want, "doc " .. i .. ": node.ns")
|
||||
end
|
||||
|
||||
-- 2. well-formedness against expat
|
||||
local agree, total, accepted, rejected = 0, 0, 0, 0
|
||||
for i, c in Wf do
|
||||
local doc = Xml.decode(c.data)
|
||||
local ok = doc ~= nil
|
||||
total += 1
|
||||
if ok == c.ok then
|
||||
agree += 1
|
||||
elseif i <= 60 then
|
||||
t:check(false, "wf case " .. i .. " " .. string.format("%q", c.data) .. ": expat says " .. tostring(c.ok))
|
||||
end
|
||||
if c.ok then
|
||||
accepted += 1
|
||||
else
|
||||
rejected += 1
|
||||
end
|
||||
end
|
||||
t:note("well-formedness: %d of %d verdicts agree with expat (%d well-formed, %d not)", agree, total, accepted, rejected)
|
||||
t:check(agree >= total * 0.99, "well-formedness agreement >= 99%")
|
||||
|
||||
-- 3. API details
|
||||
do
|
||||
local src = '<?xml version="1.0"?>\n<!DOCTYPE r [<!ENTITY e "E&#38;">]>\n<!--c--><r xmlns="urn:d" xmlns:p="urn:p" z="1" a="2"><p:x p:k="v">t<![CDATA[<c>]]>u</p:x><?go now?><y/>\n</r>'
|
||||
local doc = Xml.decode(src, { comments = true, cdata = true, pi = true, namespaces = true }) :: any
|
||||
t:eq(doc.declaration.version, "1.0", "declaration")
|
||||
t:eq(doc.doctype.name, "r", "doctype name")
|
||||
t:eq(doc.doctype.entities.e, "E&", "doctype entities (char refs expanded once)")
|
||||
t:eq(doc.children[1].name, "#comment", "prolog comment kept")
|
||||
local r = doc.root
|
||||
t:eq(table.concat(Types.keys(r.attrs), ","), "xmlns,xmlns:p,z,a", "attribute order")
|
||||
t:eq(r.ns, "urn:d", "default namespace")
|
||||
local x = Xml.child(r, "x") :: any
|
||||
t:eq(x.name, "p:x", "child by local name")
|
||||
t:eq(x.ns, "urn:p", "prefixed namespace")
|
||||
t:eq(Xml.clark(x, "p:k"), "{urn:p}k", "attribute clark")
|
||||
t:eq(x.children[2].name, "#cdata", "cdata node")
|
||||
t:eq(Xml.text(x), "t<c>u", "text with cdata")
|
||||
t:eq(r.children[2].name, "#pi", "pi node")
|
||||
t:eq(r.children[2].target .. "|" .. r.children[2].text, "go|now", "pi target / data")
|
||||
t:eq(#Xml.children(r), 2, "element children")
|
||||
t:eq(#Xml.descendants(doc), 3, "descendants")
|
||||
t:eq(x.parent, r, "parent link")
|
||||
t:eq(Xml.decode("<a>&e;</a>") == nil, true, "undefined entity")
|
||||
local d2 = Xml.decode('<!DOCTYPE r [<!ENTITY e "E&#38;">]><r a="&e;">&e;</r>') :: any
|
||||
t:eq(d2.root.attrs.a, "E&", "entity in attribute")
|
||||
t:eq(Xml.text(d2.root), "E&", "entity in text")
|
||||
-- whitespace handling
|
||||
local w = Xml.decode("<a>\n <b> x </b>\n <c xml:space='preserve'> </c>\n</a>") :: any
|
||||
t:eq(#w.root.children, 2, "whitespace-only text dropped")
|
||||
t:eq(Xml.text(w.root.children[1]), " x ", "other text kept as is")
|
||||
t:eq(w.root.children[2].children[1], " ", "xml:space preserve")
|
||||
t:eq(#(Xml.decode("<a>\n <b/>\n</a>", { whitespace = true }) :: any).root.children, 3, "opts.whitespace")
|
||||
-- attribute normalization and line endings
|
||||
local n = Xml.decode("<a b='x\ty\r\nz '>l1\r\nl2\rl3</a>") :: any
|
||||
t:eq(n.root.attrs.b, "x y z\n", "attribute value normalization")
|
||||
t:eq(Xml.text(n.root), "l1\nl2\nl3", "line endings")
|
||||
-- builders and encode
|
||||
local e = Xml.element("svg", { width = "10", height = "5" }, { Xml.element("rect", { x = "1" }), "a<b & \"c\"" })
|
||||
Xml.setAttr(e, "id", "q\"\n")
|
||||
t:eq(Xml.encode(e), '<svg height="5" width="10" id="q" "><rect x="1"/>a<b & "c"</svg>', "encode element")
|
||||
local d3 = Xml.document(Xml.element("r", nil, { Xml.element("a"), Xml.element("b", nil, { "t" }) }))
|
||||
t:eq(Xml.encode(d3, { indent = 2 }), '<?xml version="1.0" encoding="UTF-8"?>\n<r>\n <a/>\n <b>t</b>\n</r>\n', "pretty document")
|
||||
t:eq(Xml.encode(Xml.element("a"), { selfClose = false }), "<a></a>", "selfClose false")
|
||||
local _, be = Xml.encode(Xml.element("1bad"))
|
||||
t:eq(be and be.code, Err.ARG, "bad name on encode")
|
||||
local cyc = Xml.element("a")
|
||||
table.insert(cyc.children, cyc)
|
||||
local _, ce = Xml.encode(cyc)
|
||||
t:eq(ce and ce.code, Err.ARG, "cycle on encode")
|
||||
t:eq(Xml.encode({ name = "#cdata", attrs = Types.object(), children = {}, text = "a]]>b" } :: any), "<![CDATA[a]]]]><![CDATA[>b]]>", "cdata split")
|
||||
-- events
|
||||
local evs = {}
|
||||
for ev, a in Xml.events("<a x='1'><b>t</b><!--c--></a>") do
|
||||
table.insert(evs, ev .. (if type(a) == "string" then ":" .. a else ""))
|
||||
end
|
||||
t:eq(table.concat(evs, " "), "start:a start:b text:t end:b comment:c end:a", "events")
|
||||
local last
|
||||
for ev, a in Xml.events("<a><b></a>") do
|
||||
last = { ev, a }
|
||||
end
|
||||
t:eq(last[1], "error", "events error")
|
||||
t:eq(last[2].code, Err.CORRUPT, "events error code")
|
||||
-- UTF-16 without BOM and encodings
|
||||
local u16 = buffer.create(8)
|
||||
for k, ch in { 60, 0, 97, 0, 47, 0, 62, 0 } do
|
||||
buffer.writeu8(u16, k - 1, ch)
|
||||
end
|
||||
t:eq((Xml.decode(u16) :: any).root.name, "a", "UTF-16LE without BOM")
|
||||
local _, ue = Xml.decode("<?xml version='1.0' encoding='EBCDIC'?><a/>")
|
||||
t:eq(ue and ue.code, Err.UNSUPPORTED, "unsupported encoding")
|
||||
end
|
||||
|
||||
-- 4. errors and limits
|
||||
local function code(src: string, opts: any?): string?
|
||||
local _, e = Xml.decode(src, opts)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("<a><b>"), Err.TRUNCATED, "unclosed")
|
||||
t:eq(code("<a></b>"), Err.CORRUPT, "mismatch")
|
||||
t:eq(code("<a b='1' b='2'/>"), Err.CORRUPT, "duplicate attribute")
|
||||
t:eq(code(string.rep("<a>", 60) .. string.rep("</a>", 60), { maxDepth = 50 }), Err.LIMIT, "maxDepth")
|
||||
t:eq(code('<!DOCTYPE r [<!ENTITY a "aaaaaaaaaa"><!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;"><!ENTITY c "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"><!ENTITY d "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;"><!ENTITY e "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">]><r>&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;</r>', { maxExpansion = 100000 }), Err.LIMIT, "billion laughs")
|
||||
t:eq(code('<!DOCTYPE r [<!ENTITY a "&a;">]><r>&a;</r>'), Err.CORRUPT, "recursive entity")
|
||||
t:eq(code('<!DOCTYPE r [<!ENTITY x SYSTEM "file.xml">]><r>&x;</r>'), Err.UNSUPPORTED, "external entity")
|
||||
t:eq(code("<p:a/>", { namespaces = true }), Err.CORRUPT, "undeclared prefix")
|
||||
local _, ae = Xml.decode(5 :: any)
|
||||
t:eq(ae and ae.code, Err.ARG, "bad argument")
|
||||
|
||||
-- 5. fuzz
|
||||
local samples = {}
|
||||
for i = 1, 40 do
|
||||
table.insert(samples, Docs[i].data)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Xml.decode(b, { comments = true, namespaces = true })
|
||||
end, samples)
|
||||
t:fuzz("encode(decode)", function(b: buffer)
|
||||
local d = Xml.decode(b, { comments = true, cdata = true, pi = true })
|
||||
return d and Xml.encode(d, { indent = 1 })
|
||||
end, samples, { garbage = 20 })
|
||||
t:done()
|
||||
@@ -0,0 +1,115 @@
|
||||
-- codecs/Zstd tests: every fixture case (the zstd CLI at levels 1..19, --ultra -22, --fast, --long, small windows,
|
||||
-- with / without checksum and content size, multi-frame and skippable frames, empty input) decodes to its corpus;
|
||||
-- offsets / consumedEnd; XXH64 vectors; checksum, limit and error codes; truncated / corrupted / random input never
|
||||
-- throws. Fixtures: tools/fixtures/zstd.py.
|
||||
local T = require("@tests/T")
|
||||
local Zstd = require("@formats/codecs/Zstd")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/zstd")
|
||||
|
||||
local t = T.suite("zstd")
|
||||
|
||||
-- XXH64 reference values (xxhsum -H64)
|
||||
do
|
||||
local function hex(s: string): string
|
||||
local hi, lo = Zstd.xxh64(buffer.fromstring(s))
|
||||
return string.format("%08x%08x", hi, lo)
|
||||
end
|
||||
t:eq(hex(""), "ef46db3751d8e999", "xxh64 empty")
|
||||
t:eq(hex("a"), "d24ec4f1a98c6e5b", "xxh64 a")
|
||||
t:eq(hex("abc"), "44bc2cf5ad770999", "xxh64 abc")
|
||||
t:eq(hex("Nobody inspects the spammish repetition"), "fbcea83c8a378bf1", "xxh64 sentence")
|
||||
t:eq(hex(string.rep("0123456789", 10)), "f80e7b96315afffa", "xxh64 100 bytes")
|
||||
end
|
||||
|
||||
-- every case decodes to its corpus
|
||||
local nbytes = 0
|
||||
for _, c in Fx.cases do
|
||||
local want = Fx.corpora[c.corpus]
|
||||
local b = buffer.fromstring(c.data)
|
||||
local out, consumed = Zstd.decompress(b)
|
||||
t:check(out ~= nil, c.name .. ": " .. tostring(consumed))
|
||||
t:check(buffer.tostring(out :: buffer) == want, c.name .. ": output differs")
|
||||
t:eq(consumed, #c.data, c.name .. ": consumed")
|
||||
nbytes += #want
|
||||
end
|
||||
t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6)
|
||||
|
||||
local function case(name: string): any
|
||||
for _, c in Fx.cases do
|
||||
if c.name == name then
|
||||
return c
|
||||
end
|
||||
end
|
||||
error("no case " .. name)
|
||||
end
|
||||
|
||||
-- at an offset inside a bigger buffer, and string input
|
||||
do
|
||||
local c = case("text/l3")
|
||||
local big = buffer.create(#c.data + 20)
|
||||
buffer.fill(big, 0, 0xAB)
|
||||
buffer.writestring(big, 7, c.data)
|
||||
local out, consumed = Zstd.decompress(big, 7, #c.data)
|
||||
t:check(out and buffer.tostring(out) == Fx.corpora.text, "at an offset")
|
||||
t:eq(consumed, 7 + #c.data, "consumed at an offset")
|
||||
t:check(buffer.tostring((Zstd.decompress(c.data))) == Fx.corpora.text, "string input")
|
||||
t:check(Zstd.isFrame(buffer.fromstring(c.data)), "isFrame")
|
||||
t:check(not Zstd.isFrame(buffer.fromstring("abcd")), "isFrame on other data")
|
||||
-- trailing garbage is an error, as zstd -d says
|
||||
local _, e = Zstd.decompress(c.data .. "junk")
|
||||
t:check(e and e.code == Err.CORRUPT, "trailing garbage: " .. tostring(e))
|
||||
end
|
||||
|
||||
-- checksum mismatch (the last 4 bytes), and verify = false skips it
|
||||
do
|
||||
local c = case("text/l9")
|
||||
local b = buffer.fromstring(c.data)
|
||||
local n = buffer.len(b)
|
||||
buffer.writeu8(b, n - 1, bit32.bxor(buffer.readu8(b, n - 1), 0x10))
|
||||
local out, e = Zstd.decompress(b)
|
||||
t:check(out == nil and Err.is(e) and e.code == Err.CHECKSUM, "checksum mismatch: " .. tostring(e))
|
||||
local out2 = Zstd.decompress(b, nil, nil, { verify = false })
|
||||
t:check(out2 and buffer.tostring(out2) == Fx.corpora.text, "verify = false")
|
||||
end
|
||||
|
||||
-- limits and arguments
|
||||
do
|
||||
local c = case("text/l3")
|
||||
local _, e = Zstd.decompress(c.data, nil, nil, { maxBytes = 1000 })
|
||||
t:check(e and e.code == Err.LIMIT, "maxBytes with a content size: " .. tostring(e))
|
||||
local s = case("text/stdin")
|
||||
local _, e2 = Zstd.decompress(s.data, nil, nil, { maxBytes = 1000 })
|
||||
t:check(e2 and e2.code == Err.LIMIT, "maxBytes without a content size: " .. tostring(e2))
|
||||
local ok, r1, r2 = pcall(Zstd.decompress, 5 :: any)
|
||||
t:check(ok and r1 == nil and r2.code == Err.ARG, "a non-buffer argument returns Err.ARG")
|
||||
local _, e3 = Zstd.decompress("")
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "empty input is TRUNCATED: " .. tostring(e3))
|
||||
local _, e4 = Zstd.decompress("\40\181\47\253\0")
|
||||
t:check(e4 and e4.code == Err.TRUNCATED, "header only: " .. tostring(e4))
|
||||
-- a dictionary ID: FHD with Dictionary_ID_flag = 1, single segment, then a 1-byte dictionary id and 1-byte size
|
||||
local _, e5 = Zstd.decompress("\40\181\47\253\33\7\0\1\0\0")
|
||||
t:check(e5 and e5.code == Err.UNSUPPORTED, "dictionary: " .. tostring(e5))
|
||||
-- reserved block type
|
||||
local _, e6 = Zstd.decompress("\40\181\47\253\32\0\7\0\0")
|
||||
t:check(e6 and e6.code == Err.CORRUPT, "reserved block type: " .. tostring(e6))
|
||||
end
|
||||
|
||||
-- truncation, corruption and garbage never throw
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
if i % 5 == 0 and #c.data > 8 and #c.data < 40000 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decompress", function(b: buffer)
|
||||
return Zstd.decompress(b)
|
||||
end, samples, { mutations = 12, garbage = 2000 })
|
||||
-- keep the frame header intact so the mutations reach the blocks
|
||||
t:fuzz("decompress (blocks)", function(b: buffer)
|
||||
return Zstd.decompress(b, nil, nil, { verify = false, maxBytes = 1e6 })
|
||||
end, samples, { mutations = 40, garbage = 0, keepHeader = 12, seed = 99 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -212,6 +212,12 @@ do
|
||||
count += 1
|
||||
end
|
||||
t:eq(count, 3, "for over a mixed table visits every key")
|
||||
local zero = { [0] = 5, 6, 7 }
|
||||
local zsum = 0
|
||||
for _, v in zero do
|
||||
zsum += v
|
||||
end
|
||||
t:eq(zsum, 18, "for over a table with key 0 visits it (LuaJIT keeps t[0] in the array part)")
|
||||
local w = {}
|
||||
for word in string.gmatch("a b c", "%a") do
|
||||
table.insert(w, word)
|
||||
@@ -272,4 +278,25 @@ do
|
||||
t:eq(0x7FFFFFFF + 1, 2147483648, "no integer overflow")
|
||||
end
|
||||
|
||||
do -- float reads: NaNs with a payload come back as the canonical NaN (LuaJIT: never an aliased object value)
|
||||
local b = buffer.create(16)
|
||||
buffer.writeu32(b, 0, 0x7fc12345)
|
||||
buffer.writeu32(b, 4, 0x7f800000)
|
||||
buffer.writeu32(b, 8, 0xdeadbeef)
|
||||
buffer.writeu32(b, 12, 0xfff12345)
|
||||
local a, i, c = buffer.readf32(b, 0), buffer.readf32(b, 4), buffer.readf64(b, 8)
|
||||
t:eq(type(a), "number", "f32 NaN payload is a number")
|
||||
t:check(a ~= a, "f32 NaN payload reads as NaN")
|
||||
t:eq(i, math.huge, "f32 +inf")
|
||||
t:eq(type(c), "number", "f64 NaN payload is a number")
|
||||
t:check(c ~= c, "f64 NaN payload reads as NaN")
|
||||
buffer.writeu32(b, 8, 0)
|
||||
buffer.writeu32(b, 12, 0xfff00000)
|
||||
t:eq(buffer.readf64(b, 8), -math.huge, "f64 -inf")
|
||||
buffer.writef32(b, 0, 1.5)
|
||||
buffer.writef64(b, 8, -2.25)
|
||||
t:eq(buffer.readf32(b, 0), 1.5, "f32 normal")
|
||||
t:eq(buffer.readf64(b, 8), -2.25, "f64 normal")
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,241 @@
|
||||
-- containers/IsoBmff tests: ffmpeg / MP4Box files (H.264 + AAC with B-frames, fast start, QuickTime MJPEG + PCM, HEVC,
|
||||
-- fragmented by ffmpeg and MP4Box, stz2 + co64, ALAC) demuxed packet for packet against ffprobe (-ignore_editlist);
|
||||
-- track facts and codec configurations; iTunes tags and cover art; AVIF items (libavif, plain and with alpha); the
|
||||
-- muxer round-trips through the demuxer (sizes, times, cts, sync, tags, 64-bit sizes); a sub-range reader; the fuzz
|
||||
-- no-throw pass. Fixtures: tools/fixtures/isobmff.py.
|
||||
local T = require("@tests/T")
|
||||
local IsoBmff = require("@formats/containers/IsoBmff")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Fx = require("@tests/gen/isobmff")
|
||||
|
||||
local t = T.suite("isobmff")
|
||||
|
||||
local CODEC = { h264 = "h264", aac = "aac", mjpeg = "mjpeg", pcm_s16be = "pcm", hevc = "hevc", alac = "alac" }
|
||||
|
||||
local function reader(s: string, pad: number?): Bytes.Reader
|
||||
if pad then
|
||||
local b = buffer.create(#s + pad * 2)
|
||||
buffer.writestring(b, pad, s)
|
||||
return Bytes.reader(b, pad, #s)
|
||||
end
|
||||
return Bytes.reader(buffer.fromstring(s))
|
||||
end
|
||||
|
||||
-- every fixture against ffprobe
|
||||
for _, c in Fx.cases do
|
||||
for _, pad in { 0, 5 } do
|
||||
local r = reader(c.data, if pad > 0 then pad else nil)
|
||||
local label = c.name .. (if pad > 0 then " (sub-range)" else "")
|
||||
t:check(IsoBmff.sniff(r) ~= nil, label .. ": sniff")
|
||||
local dmx, err = IsoBmff.demux(r)
|
||||
t:check(dmx, label .. ": " .. tostring(err))
|
||||
t:eq(#dmx.tracks, #c.streams, label .. ": track count")
|
||||
for i, s in c.streams do
|
||||
local tr = dmx.tracks[i]
|
||||
t:eq(tr.kind, s.kind, label .. ": track " .. i .. " kind")
|
||||
t:eq(tr.codec, CODEC[s.codec] or s.codec, label .. ": track " .. i .. " codec")
|
||||
t:eq(tr.timescale, s.timescale, label .. ": timescale")
|
||||
if s.width then
|
||||
t:check(tr.width == s.width and tr.height == s.height, label .. ": video size")
|
||||
end
|
||||
if s.sampleRate then
|
||||
t:check(tr.sampleRate == s.sampleRate and tr.channels == s.channels, label .. ": audio format")
|
||||
end
|
||||
if s.extradata > 0 and s.codec ~= "alac" then
|
||||
t:eq(if tr.config then buffer.len(tr.config) else 0, s.extradata, label .. ": codec config size")
|
||||
end
|
||||
end
|
||||
-- packets in file order
|
||||
local n, bad = 0, nil
|
||||
local base = r.base
|
||||
for p in dmx:packets() do
|
||||
n += 1
|
||||
local want = c.packets[n]
|
||||
if not want then
|
||||
bad = bad or ("extra packet " .. n)
|
||||
break
|
||||
end
|
||||
local tr = dmx.tracks[want.stream]
|
||||
if p.track ~= tr.id then
|
||||
bad = bad or ("packet " .. n .. " track")
|
||||
end
|
||||
local off = tr.offsets[p.index]
|
||||
if off - base ~= want.pos or buffer.len(p.data) ~= want.size or p.dts ~= want.dts or p.pts ~= want.pts or p.keyframe ~= want.key then
|
||||
bad = bad or string.format("packet %d: pos %d/%d size %d/%d dts %d/%d pts %d/%d key %s/%s", n, off - base, want.pos, buffer.len(p.data), want.size, p.dts, want.dts, p.pts, want.pts, tostring(p.keyframe), tostring(want.key))
|
||||
end
|
||||
end
|
||||
t:check(bad == nil, label .. ": " .. tostring(bad))
|
||||
t:eq(n, #c.packets, label .. ": packet count")
|
||||
if pad == 0 then
|
||||
t:note("%s: %d tracks, %d packets match ffprobe", c.name, #c.streams, n)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- per-track packets, seek
|
||||
do
|
||||
local c = Fx.cases[1]
|
||||
local dmx = IsoBmff.demux(reader(c.data))
|
||||
local v = dmx.tracks[1]
|
||||
local count = 0
|
||||
for p in dmx:packets(v.id) do
|
||||
count += 1
|
||||
t:eq(p.track, v.id, "per-track packets")
|
||||
end
|
||||
t:eq(count, v.sampleCount, "per-track packet count")
|
||||
dmx:seek(0.75)
|
||||
local p = dmx:packets(v.id)()
|
||||
t:check(p and p.keyframe and p.dts / v.timescale <= 0.75, "seek lands on a keyframe before the time")
|
||||
t:check(v.skip >= 0 and v.edits ~= nil, "edit list parsed")
|
||||
end
|
||||
|
||||
-- tags and cover
|
||||
do
|
||||
local r = reader(Fx.tagged.data)
|
||||
local movie = IsoBmff.parse(r) :: IsoBmff.Movie
|
||||
local tags, pics = IsoBmff.tags(r, movie)
|
||||
for k, v in Fx.tagged.tags do
|
||||
t:eq(tags[k], v, "tag " .. k)
|
||||
end
|
||||
t:check(tags.encoder ~= nil, "encoder tag")
|
||||
t:eq(#pics, 1, "one cover")
|
||||
t:eq(pics[1] and buffer.len(pics[1].data), Fx.tagged.cover, "cover bytes")
|
||||
t:eq(pics[1] and pics[1].mime, "image/png", "cover mime")
|
||||
end
|
||||
|
||||
-- AVIF items
|
||||
for _, c in Fx.avif do
|
||||
local r = reader(c.data)
|
||||
t:check(IsoBmff.sniff(r) == "avif", c.name .. ": brand")
|
||||
local movie = IsoBmff.parse(r) :: IsoBmff.Movie
|
||||
t:check(movie and #movie.tracks == 0, c.name .. ": no tracks")
|
||||
local items, err = IsoBmff.items(r, movie)
|
||||
t:check(items, c.name .. ": items: " .. tostring(err))
|
||||
local prim = items.items[items.primary]
|
||||
t:check(prim and prim.type == "av01", c.name .. ": primary item is av01")
|
||||
local ispe, av1C
|
||||
for _, p in prim.properties do
|
||||
if p.type == "ispe" then
|
||||
ispe = p
|
||||
elseif p.type == "av1C" then
|
||||
av1C = p
|
||||
end
|
||||
end
|
||||
t:check(ispe and ispe.width == c.width and ispe.height == c.height, c.name .. ": ispe")
|
||||
t:check(av1C and av1C.config and buffer.readu8(av1C.config, 0) == 0x81, c.name .. ": av1C marker / version")
|
||||
local data = IsoBmff.itemData(r, items, items.primary :: number)
|
||||
t:check(data and buffer.len(data) > 10, c.name .. ": item data")
|
||||
-- an AV1 OBU stream: the first OBU is a sequence header (type 1) or a temporal delimiter (2)
|
||||
local obu = data and bit32.band(bit32.rshift(buffer.readu8(data, 0), 3), 15)
|
||||
t:check(obu == 1 or obu == 2, c.name .. ": AV1 OBU stream")
|
||||
local auxl = nil
|
||||
for _, id in items.order do
|
||||
local it = items.items[id]
|
||||
if it.refs.auxl then
|
||||
auxl = it
|
||||
end
|
||||
end
|
||||
t:eq(auxl ~= nil, c.alpha, c.name .. ": alpha auxiliary item")
|
||||
end
|
||||
|
||||
-- the muxer: round trip through the demuxer
|
||||
do
|
||||
local rand = T.rng(5)
|
||||
local function sample(n: number): buffer
|
||||
local b = buffer.create(n)
|
||||
for i = 0, n - 1 do
|
||||
buffer.writeu8(b, i, rand(256))
|
||||
end
|
||||
return b
|
||||
end
|
||||
local aud, vid = {}, {}
|
||||
for i = 1, 90 do
|
||||
aud[i] = sample(50 + rand(200))
|
||||
end
|
||||
for i = 1, 30 do
|
||||
vid[i] = sample(100 + rand(900))
|
||||
end
|
||||
local cts = {}
|
||||
local sync = {}
|
||||
for i = 1, 30 do
|
||||
cts[i] = (i % 3) * 512
|
||||
sync[i] = i % 10 == 1
|
||||
end
|
||||
local cfg = buffer.fromstring("\x12\x10")
|
||||
local file, err = IsoBmff.mux({
|
||||
brand = "mp42",
|
||||
compatible = { "mp42", "isom" },
|
||||
tracks = {
|
||||
{ kind = "video", entry = "avc1", timescale = 15360, samples = vid, durations = 512, cts = cts, sync = sync, width = 64, height = 48, config = buffer.fromstring("\1\100\0\10\255") },
|
||||
{ kind = "audio", entry = "mp4a", timescale = 44100, samples = aud, durations = 1024, sampleRate = 44100, channels = 2, config = cfg, skip = 1024, playDuration = 44100 * 2 },
|
||||
},
|
||||
tags = { title = "Mux Test", artist = "Me", track = "2", tracktotal = "9", custom = "free form", bpm = "120" },
|
||||
pictures = { { mime = "image/jpeg", data = buffer.fromstring("\255\216\255\217") } },
|
||||
chunkDuration = 0.25,
|
||||
})
|
||||
t:check(file, "mux: " .. tostring(err))
|
||||
local r = Bytes.reader(file :: buffer)
|
||||
local dmx = IsoBmff.demux(r)
|
||||
t:check(dmx and #dmx.tracks == 2, "mux: demux our file")
|
||||
local v, a = dmx.tracks[1], dmx.tracks[2]
|
||||
t:check(v.codec == "h264" and v.width == 64 and v.height == 48 and v.config and buffer.len(v.config) == 5, "mux: video track")
|
||||
t:check(a.codec == "aac" and a.sampleRate == 44100 and a.channels == 2 and a.config and buffer.tostring(a.config) == "\x12\x10", "mux: audio track + esds")
|
||||
t:check(a.skip == 1024 and a.playDuration == 88200, "mux: edit list")
|
||||
local ok = true
|
||||
for i = 1, 30 do
|
||||
local s = IsoBmff.sample(r, v, i) :: buffer
|
||||
ok = ok and buffer.tostring(s) == buffer.tostring(vid[i]) and v.dts[i] == (i - 1) * 512 and (v.cts :: any)[i] == cts[i] and ((v.sync :: any)[i] == true) == sync[i]
|
||||
end
|
||||
t:check(ok, "mux: video samples, times, cts, sync")
|
||||
ok = true
|
||||
for i = 1, 90 do
|
||||
ok = ok and buffer.tostring(IsoBmff.sample(r, a, i) :: buffer) == buffer.tostring(aud[i]) and a.durations[i] == 1024
|
||||
end
|
||||
t:check(ok, "mux: audio samples")
|
||||
-- interleaved: offsets alternate between the tracks
|
||||
t:check(v.offsets[30] > a.offsets[1] and a.offsets[90] > v.offsets[1], "mux: interleaved chunks")
|
||||
local tags, pics = IsoBmff.tags(r, dmx.movie)
|
||||
t:check(tags.title == "Mux Test" and tags.artist == "Me" and tags.track == "2" and tags.tracktotal == "9" and tags.custom == "free form" and tags.bpm == "120", "mux: tags round trip")
|
||||
t:check(#pics == 1 and buffer.len(pics[1].data) == 4, "mux: cover round trip")
|
||||
t:note("mux: %d bytes, crc %08x", buffer.len(file :: buffer), Crc32.of(file :: buffer))
|
||||
-- data + sizes form, bad specs
|
||||
local f2 = IsoBmff.mux({ tracks = { { kind = "audio", entry = "alac", timescale = 8000, data = buffer.create(30), sizes = { 10, 10, 10 }, durations = { 4096, 4096, 100 }, config = buffer.create(24) } } })
|
||||
local d2 = IsoBmff.demux(Bytes.reader(f2 :: buffer))
|
||||
t:check(d2 and d2.tracks[1].codec == "alac" and d2.tracks[1].sampleCount == 3 and d2.tracks[1].durations[3] == 100 and buffer.len(d2.tracks[1].config) == 24, "mux: data + sizes, alac cookie")
|
||||
for _, bad in { {}, { tracks = {} }, { tracks = { { kind = "audio", entry = "toolong", timescale = 1, samples = {}, durations = 1 } } }, { tracks = { { kind = "x", entry = "abcd", timescale = 1, samples = {}, durations = 1 } } }, { tracks = { { kind = "audio", entry = "abcd", timescale = 1 } } } } do
|
||||
local f, e = IsoBmff.mux(bad :: any)
|
||||
t:check(f == nil and e and e.code == "ARG", "mux: bad spec -> ARG")
|
||||
end
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for _, c in Fx.cases do
|
||||
table.insert(samples, string.sub(c.data, 1, 6000))
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
for _, c in Fx.avif do
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
t:fuzz("demux", function(b: buffer)
|
||||
local r = Bytes.reader(b)
|
||||
local dmx = IsoBmff.demux(r)
|
||||
if dmx then
|
||||
for p in dmx:packets() do
|
||||
local _ = p
|
||||
end
|
||||
IsoBmff.tags(r, dmx.movie)
|
||||
local items = IsoBmff.items(r, dmx.movie)
|
||||
if items then
|
||||
for _, id in items.order do
|
||||
IsoBmff.itemData(r, items, id)
|
||||
end
|
||||
end
|
||||
end
|
||||
return dmx
|
||||
end, samples, { mutations = 12 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,165 @@
|
||||
-- containers/Tar and containers/Archive tests: hand-made headers for the edge cases the reference archives do not hit
|
||||
-- (base-256 numbers, the historical signed checksum, GNU 'K' long links, pax 'g' global records, pax size overrides,
|
||||
-- v7 headers without magic, a missing end-of-archive marker), the writer's GNU / pax extensions (long links, fractional
|
||||
-- and negative mtimes), and Archive helpers (streamName, entries of foreign archive values, failing loaders).
|
||||
local T = require("@tests/T")
|
||||
local Tar = require("@formats/containers/Tar")
|
||||
local Archive = require("@formats/containers/Archive")
|
||||
local Err = require("@formats/core/Err")
|
||||
|
||||
local t = T.suite("containers/tar")
|
||||
|
||||
-- a header block built by hand
|
||||
local function hdr(fields: { [string]: any }): buffer
|
||||
local h = buffer.create(512)
|
||||
buffer.writestring(h, 0, fields.name or "f")
|
||||
buffer.writestring(h, 100, fields.mode or "0000644\0")
|
||||
buffer.writestring(h, 124, fields.size or "00000000000\0")
|
||||
buffer.writestring(h, 136, fields.mtime or "00000000000\0")
|
||||
buffer.writestring(h, 156, fields.type or "0")
|
||||
if fields.link then
|
||||
buffer.writestring(h, 157, fields.link)
|
||||
end
|
||||
if fields.magic ~= false then
|
||||
buffer.writestring(h, 257, "ustar\00000")
|
||||
end
|
||||
if fields.raw then
|
||||
for at, v in fields.raw do
|
||||
buffer.writeu8(h, at, v)
|
||||
end
|
||||
end
|
||||
buffer.writestring(h, 148, " ")
|
||||
local sum, signed = 0, 0
|
||||
for i = 0, 511 do
|
||||
local v = buffer.readu8(h, i)
|
||||
sum += v
|
||||
signed += if v >= 128 then v - 256 else v
|
||||
end
|
||||
buffer.writestring(h, 148, string.format("%06o\0 ", if fields.signed then signed % 0x40000 else sum))
|
||||
return h
|
||||
end
|
||||
local function cat(parts: { any }): buffer
|
||||
local s = {}
|
||||
for _, p in parts do
|
||||
table.insert(s, if type(p) == "string" then p else buffer.tostring(p))
|
||||
end
|
||||
return buffer.fromstring(table.concat(s))
|
||||
end
|
||||
local function block(s: string): string
|
||||
return s .. string.rep("\0", (512 - #s % 512) % 512)
|
||||
end
|
||||
local END = string.rep("\0", 1024)
|
||||
|
||||
-- base-256 size (GNU), checksum with the signed sum, no end marker
|
||||
do
|
||||
local raw = { [124] = 0x80 }
|
||||
for i = 125, 134 do
|
||||
raw[i] = 0
|
||||
end
|
||||
raw[135] = 5
|
||||
local b = cat({ hdr({ name = "big\200", raw = raw, signed = true }), block("hello") })
|
||||
local list, err = Tar.read(b)
|
||||
t:check(list, "base-256 / signed checksum: " .. tostring(err))
|
||||
t:eq(list[1].size, 5, "base-256 size")
|
||||
t:check(Tar.valid(b, 0), "valid() accepts the signed sum")
|
||||
end
|
||||
|
||||
-- GNU long link ('K'), pax global + per-file records, v7 header
|
||||
do
|
||||
local rec = "21 path=from/pax.txt\n"
|
||||
local glob = "20 uname=globaluser\n"
|
||||
local b = cat({
|
||||
hdr({ name = "././@LongLink", type = "K", size = string.format("%011o\0", 131) }),
|
||||
block(string.rep("L", 130) .. "\0"),
|
||||
hdr({ name = "sym", type = "2", link = "short" }),
|
||||
hdr({ name = "pax_global", type = "g", size = string.format("%011o\0", #glob) }),
|
||||
block(glob),
|
||||
hdr({ name = "PaxHeaders/x", type = "x", size = string.format("%011o\0", #rec + 15) }),
|
||||
block(rec .. "15 size=000003\n"),
|
||||
hdr({ name = "ignored-name", size = "00000000077\0" }),
|
||||
block("abc"),
|
||||
hdr({ name = "v7file", magic = false, size = "00000000002\0", mtime = "12345670123\0" }),
|
||||
block("v7"),
|
||||
END,
|
||||
})
|
||||
local list, err = Tar.read(b)
|
||||
t:check(list, "extensions: " .. tostring(err))
|
||||
t:eq(#list, 3, "meta records are not entries")
|
||||
t:eq(list[1].link, string.rep("L", 130), "GNU long link")
|
||||
t:eq(list[2].name, "from/pax.txt", "pax path")
|
||||
t:eq(list[2].size, 3, "pax size overrides the header")
|
||||
t:eq(list[2].uname, "globaluser", "pax global record")
|
||||
t:eq(list[3].name, "v7file", "v7 header")
|
||||
t:eq(list[3].mtime, tonumber("12345670123", 8), "octal mtime")
|
||||
t:eq(list[3].uname, "globaluser", "global records apply to later entries")
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e1 = Tar.read(cat({ hdr({ size = "00000002000\0" }), block("x") }))
|
||||
t:check(e1 and e1.code == Err.TRUNCATED, "data past the end: " .. tostring(e1))
|
||||
local _, e2 = Tar.read(cat({ hdr({ type = "x", size = "00000000010\0" }), block("garbage!"), END }))
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "bad pax record: " .. tostring(e2))
|
||||
local good = hdr({})
|
||||
local bad = cat({ good, hdr({ name = "two" }) })
|
||||
buffer.writeu8(bad, 513, 77)
|
||||
local _, e3 = Tar.read(bad)
|
||||
t:check(e3 and e3.code == Err.CHECKSUM, "second header checksum: " .. tostring(e3))
|
||||
local list = Tar.read(buffer.create(0))
|
||||
t:check(list and #list == 0, "empty input is an empty archive")
|
||||
end
|
||||
|
||||
-- writer extensions
|
||||
do
|
||||
local long = string.rep("n", 120)
|
||||
for _, fmt in { "gnu", "pax" } do
|
||||
local out = Tar.write({
|
||||
{ name = long, data = buffer.fromstring("x"), mtime = -5.25 },
|
||||
{ name = "l", type = "2", link = string.rep("k", 150) },
|
||||
}, { format = fmt :: any }) :: buffer
|
||||
local list = Tar.read(out) :: any
|
||||
t:eq(list[1].name, long, fmt .. ": long name")
|
||||
t:eq(list[2].link, string.rep("k", 150), fmt .. ": long link")
|
||||
if fmt == "pax" then
|
||||
t:eq(list[1].mtime, -5.25, "pax fractional negative mtime")
|
||||
end
|
||||
end
|
||||
local _, e = Tar.write({ { name = "" } })
|
||||
t:check(e and e.code == Err.ARG, "empty name")
|
||||
end
|
||||
|
||||
-- Archive helpers
|
||||
do
|
||||
t:eq(Archive.streamName({ name = "/x/y/notes.txt.gz" }, { "gz" }), "notes.txt", "streamName strips the extension")
|
||||
t:eq(Archive.streamName({ name = "a.tbz2" }, { "bz2" }), "a.tar", "streamName .tbz2")
|
||||
t:eq(Archive.streamName(nil, { "gz" }), "data", "streamName default")
|
||||
t:eq(Archive.streamName({ name = "plain" }, { "gz" }), "plain", "streamName without an extension")
|
||||
local foreign = {
|
||||
kind = "archive",
|
||||
list = function()
|
||||
return { { name = "a", size = 1, dir = false } }
|
||||
end,
|
||||
read = function()
|
||||
error("boom")
|
||||
end,
|
||||
}
|
||||
local items = Archive.entries(foreign) :: any
|
||||
t:eq(#items, 1, "entries of a foreign archive")
|
||||
local b, e = items[1].read()
|
||||
t:check(b == nil and e and e.code == Err.CORRUPT, "a throwing read() becomes an Err")
|
||||
t:check(Archive.entries({ kind = "image" }) == nil, "not an archive")
|
||||
local a = Archive.new("x")
|
||||
Archive.put(a, { name = "f", size = 1, dir = false, load = function()
|
||||
error("bad")
|
||||
end })
|
||||
local _, e2 = a:read("f")
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "a throwing loader becomes an Err")
|
||||
local _, e3 = a:write()
|
||||
t:check(e3 and e3.code == Err.UNSUPPORTED, "read-only archives")
|
||||
end
|
||||
|
||||
t:fuzz("read", function(b: buffer)
|
||||
return Tar.read(b)
|
||||
end, { buffer.tostring(Tar.write({ { name = string.rep("p", 130), data = buffer.fromstring("abc") }, { name = "d", dir = true } }) :: buffer) }, { mutations = 60 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,25 @@
|
||||
-- core/Base64 tests: the RFC 4648 vectors, whitespace / missing padding / URL-safe input, bad characters, random
|
||||
-- round trips.
|
||||
local T = require("@tests/T")
|
||||
local Base64 = require("@formats/core/Base64")
|
||||
|
||||
local t = T.suite("base64")
|
||||
for _, v in { { "", "" }, { "f", "Zg==" }, { "fo", "Zm8=" }, { "foo", "Zm9v" }, { "foob", "Zm9vYg==" }, { "fooba", "Zm9vYmE=" }, { "foobar", "Zm9vYmFy" } } do
|
||||
t:eq(Base64.encode(v[1]), v[2], "encode " .. v[1])
|
||||
t:eq(buffer.tostring(Base64.decode(v[2]) :: buffer), v[1], "decode " .. v[2])
|
||||
end
|
||||
t:eq(buffer.tostring(Base64.decode(" Zm9v\nYmE ") :: buffer), "fooba", "whitespace and no padding")
|
||||
t:eq(buffer.tostring(Base64.decode("-_8=") :: buffer), "\251\255", "URL-safe alphabet")
|
||||
local b, err = Base64.decode("Zm9v!")
|
||||
t:check(b == nil and err, "bad character")
|
||||
local b2 = Base64.decode("Zg==Zg")
|
||||
t:check(b2 == nil, "data after padding")
|
||||
local rand = T.rng(5)
|
||||
for n = 0, 40 do
|
||||
local s = buffer.create(n)
|
||||
for i = 0, n - 1 do
|
||||
buffer.writeu8(s, i, rand(256))
|
||||
end
|
||||
t:eq(buffer.tostring(Base64.decode(Base64.encode(s)) :: buffer), buffer.tostring(s), "round trip " .. n)
|
||||
end
|
||||
t:done()
|
||||
@@ -0,0 +1,86 @@
|
||||
-- tests/data/Canon: the canonical text of a decoded data value, the same as tools/fixtures/_data_common.py canon() on
|
||||
-- Python's parse: null n, true t, false f, numbers #%d (integral under 2^53) or #%.17g, strings s<len>:<bytes>,
|
||||
-- buffers b<len>:<bytes>, arrays [x,...], objects {k=v,...} sorted by key text, dates d<rfc3339>. A module the data
|
||||
-- tests require (running it alone does nothing).
|
||||
local Types = require("@formats/Types")
|
||||
|
||||
local Canon = {}
|
||||
|
||||
local function num(x: number): string
|
||||
if x ~= x then
|
||||
return "#nan"
|
||||
elseif x == math.huge then
|
||||
return "#inf"
|
||||
elseif x == -math.huge then
|
||||
return "#-inf"
|
||||
elseif x == math.floor(x) and math.abs(x) < 2 ^ 53 then
|
||||
return string.format("#%d", x)
|
||||
end
|
||||
return "#" .. string.format("%.17g", x)
|
||||
end
|
||||
|
||||
local function isArray(t: { [any]: any }): boolean
|
||||
if Types.isObject(t) then
|
||||
return false
|
||||
end
|
||||
local n = #t
|
||||
local c = 0
|
||||
for _ in next, t do
|
||||
c += 1
|
||||
end
|
||||
return c == n
|
||||
end
|
||||
|
||||
local function canon(v: any, out: { string })
|
||||
local tv = type(v)
|
||||
if v == Types.null then
|
||||
table.insert(out, "n")
|
||||
elseif tv == "boolean" then
|
||||
table.insert(out, if v then "t" else "f")
|
||||
elseif tv == "number" then
|
||||
table.insert(out, num(v))
|
||||
elseif tv == "string" then
|
||||
table.insert(out, "s" .. #v .. ":" .. v)
|
||||
elseif tv == "buffer" then
|
||||
table.insert(out, "b" .. buffer.len(v) .. ":" .. buffer.tostring(v))
|
||||
elseif tv == "table" and Types.Date.is(v) then
|
||||
table.insert(out, "d" .. tostring(v))
|
||||
elseif tv == "table" then
|
||||
if isArray(v) then
|
||||
table.insert(out, "[")
|
||||
for i = 1, #v do
|
||||
canon(v[i], out)
|
||||
table.insert(out, ",")
|
||||
end
|
||||
table.insert(out, "]")
|
||||
else
|
||||
local items = {}
|
||||
for k, x in next, v do
|
||||
local ko = {}
|
||||
canon(k, ko)
|
||||
table.insert(items, { table.concat(ko), x })
|
||||
end
|
||||
table.sort(items, function(a, b)
|
||||
return a[1] < b[1]
|
||||
end)
|
||||
table.insert(out, "{")
|
||||
for _, it in items do
|
||||
table.insert(out, it[1] .. "=")
|
||||
canon(it[2], out)
|
||||
table.insert(out, ",")
|
||||
end
|
||||
table.insert(out, "}")
|
||||
end
|
||||
else
|
||||
table.insert(out, "?" .. tv)
|
||||
end
|
||||
end
|
||||
|
||||
-- of(v) -> the canonical text
|
||||
function Canon.of(v: any): string
|
||||
local out = {}
|
||||
canon(v, out)
|
||||
return table.concat(out)
|
||||
end
|
||||
|
||||
return Canon
|
||||
@@ -0,0 +1,121 @@
|
||||
-- data/cbor tests: the RFC 8949 Appendix A examples and random items encoded by Python's cbor2 decode to cbor2's
|
||||
-- values (canonical form), re-encode to the same bytes, big integers as doubles and exact text, indefinite lengths,
|
||||
-- tags / simple values / undefined, half floats, sequences, options, error codes, and the fuzz pass.
|
||||
-- Fixtures: tools/fixtures/cbor.py.
|
||||
local T = require("@tests/T")
|
||||
local Cbor = require("@formats/data/cbor")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Fx = require("@tests/gen/cbor")
|
||||
|
||||
local t = T.suite("data/cbor")
|
||||
|
||||
t:eq(Cbor.name, "cbor", "name")
|
||||
t:check(Cbor.caps.decode and Cbor.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string | buffer, opts: any?): (any, any)
|
||||
local b = if type(s) == "string" then buffer.fromstring(s) else s
|
||||
return Cbor.decode(Bytes.reader(b), opts)
|
||||
end
|
||||
|
||||
-- the fixture's view of tags / simple values / undefined
|
||||
local function plain(v: any): any
|
||||
if v == Cbor.undefined then
|
||||
return { "undefined" }
|
||||
elseif Cbor.isSimple(v) then
|
||||
return { "simple", v.value }
|
||||
elseif Cbor.isTagged(v) then
|
||||
return { "tag", v.tag, plain(v.value) }
|
||||
elseif type(v) == "table" and not Types.Date.is(v) and v ~= Types.null then
|
||||
local o = if Types.isObject(v) then Types.object() else {}
|
||||
for k, x in next, v do
|
||||
o[plain(k)] = plain(x)
|
||||
end
|
||||
return o
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
local nApp = 0
|
||||
for _, c in Fx.appendix do
|
||||
local v, err = dec(c.data)
|
||||
if c.error then
|
||||
t:check(v == nil and err ~= nil, c.hex .. ": rejected like cbor2")
|
||||
else
|
||||
t:check(v ~= nil or err == nil, c.hex .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(plain(v)), c.canon, c.hex .. ": value")
|
||||
t:eq(Canon.of(plain(dec(c.data, { bigInts = "string" }))), c.canonStr, c.hex .. ": exact")
|
||||
t:eq(Canon.of(plain(dec(Cbor.encode(v) :: buffer))), c.canon, c.hex .. ": round trip")
|
||||
t:eq(Canon.of(plain(dec(Cbor.encode(v, { compactFloats = true }) :: buffer))), c.canon, c.hex .. ": compact round trip")
|
||||
end
|
||||
nApp += 1
|
||||
end
|
||||
t:note("RFC 8949 appendix A: %d examples", nApp)
|
||||
|
||||
for i, c in Fx.safe do
|
||||
local v, err = dec(c.data)
|
||||
t:check(v ~= nil, "safe " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(plain(v)), c.canon, "safe " .. i .. ": value")
|
||||
local b = Cbor.encode(v) :: buffer
|
||||
t:check(b and buffer.tostring(b) == c.data, "safe " .. i .. ": same bytes")
|
||||
end
|
||||
for i, c in Fx.wide do
|
||||
local v, err = dec(c.data)
|
||||
t:check(v ~= nil, "wide " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(plain(v)), c.canon, "wide " .. i .. ": value")
|
||||
t:eq(Canon.of(plain(dec(c.data, { bigInts = "string" }))), c.canonStr, "wide " .. i .. ": exact")
|
||||
end
|
||||
|
||||
-- details
|
||||
do
|
||||
local function hex(b: buffer): string
|
||||
return (string.gsub(buffer.tostring(b), ".", function(ch)
|
||||
return string.format("%02x", string.byte(ch))
|
||||
end))
|
||||
end
|
||||
t:eq(hex(Cbor.encode(1.5, { compactFloats = true }) :: buffer), "f93e00", "half float")
|
||||
t:eq(hex(Cbor.encode(100000.0 + 0.5, { compactFloats = true }) :: buffer), "fa47c35040", "single float")
|
||||
t:eq(hex(Cbor.encode(1.1) :: buffer), "fb3ff199999999999a", "double float")
|
||||
t:eq(hex(Cbor.encode(-0.0, { compactFloats = true }) :: buffer), "f98000", "negative zero")
|
||||
t:eq(hex(Cbor.encode(0 / 0, { compactFloats = true }) :: buffer), "f97e00", "nan")
|
||||
t:eq(hex(Cbor.encode(-2 ^ 64) :: buffer), "3bffffffffffffffff", "-2^64")
|
||||
t:eq(hex(Cbor.encode(Cbor.tagged(32, "x")) :: buffer), "d8206178", "tagged")
|
||||
t:eq(hex(Cbor.encode(Cbor.simple(255)) :: buffer), "f8ff", "simple")
|
||||
t:eq(hex(Cbor.encode(Cbor.undefined) :: buffer), "f7", "undefined")
|
||||
t:eq(hex(Cbor.encode(Types.Date.parse("2013-03-21T20:04:00Z")) :: buffer), "c074323031332d30332d32315432303a30343a30305a", "date tag 0")
|
||||
t:eq(hex(Cbor.encode(Types.Date.parse("2013-03-21T20:04:00Z"), { dates = "epoch" }) :: buffer), "c11a514b67b0", "date tag 1")
|
||||
t:eq(hex(Cbor.encode({ 1 }, { selfDescribe = true }) :: buffer), "d9d9f78101", "self-describe")
|
||||
t:eq(dec("\217\217\247\1"), 1, "self-describe stripped")
|
||||
t:eq(Cbor.sniff(Bytes.reader(buffer.fromstring("\217\217\247\1"))), 1, "sniff self-describe")
|
||||
t:eq(#dec("\1\2\3", { all = true }), 3, "sequence")
|
||||
t:eq(hex(Cbor.encode({ 1, "a" }, { all = true }) :: buffer), "016161", "encode sequence")
|
||||
local function code(s: string): string?
|
||||
local _, e = dec(s)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("\x9b\xff\xff\xff\xff\xff\xff\xff\xff"), Err.TRUNCATED, "huge array count")
|
||||
t:eq(code("\x5f\x61\x61\xff"), Err.CORRUPT, "text chunk in a byte string")
|
||||
t:eq(code("\xff"), Err.CORRUPT, "lone break")
|
||||
t:eq(code("\x1c"), Err.CORRUPT, "reserved additional info")
|
||||
t:eq(code("\x62\xc3\x28"), Err.CORRUPT, "invalid UTF-8")
|
||||
t:eq(code("\x01\x02"), Err.CORRUPT, "trailing data")
|
||||
t:eq(code("\xc0\x01"), Err.CORRUPT, "tag 0 on a number")
|
||||
t:eq(code(string.rep("\x81", 600) .. "\x01"), Err.LIMIT, "depth")
|
||||
t:eq(code("\x9f\x01"), Err.TRUNCATED, "unterminated indefinite array")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx.appendix do
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
for i = 1, 40 do
|
||||
if #Fx.safe[i].data < 3000 then
|
||||
table.insert(samples, Fx.safe[i].data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Cbor.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 4 })
|
||||
t:done()
|
||||
@@ -0,0 +1,76 @@
|
||||
-- data/csv tests: tables written by Python's csv.writer / DictWriter (every delimiter, quotes, line breaks inside
|
||||
-- fields, empty fields) read back as csv.reader does, re-encoded byte for byte, keyed rows with a header, options,
|
||||
-- error codes, and the fuzz pass. Fixtures: tools/fixtures/csv.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Csv = require("@formats/data/csv")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Fx = require("@tests/gen/csv")
|
||||
|
||||
local t = T.suite("data/csv")
|
||||
|
||||
t:eq(Csv.name, "csv", "name")
|
||||
t:check(Csv.caps.decode and Csv.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string, opts: any?): (any, any)
|
||||
return Csv.decode(Bytes.reader(buffer.fromstring(s)), opts)
|
||||
end
|
||||
|
||||
for i, c in Fx do
|
||||
local rows, err = dec(c.data, { delimiter = c.delimiter })
|
||||
t:check(rows ~= nil, "case " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(rows), Canon.of(c.rows), "case " .. i .. ": rows")
|
||||
local b = Csv.encode(rows, { delimiter = c.delimiter, newline = c.newline }) :: buffer
|
||||
t:eq(buffer.tostring(b), c.data, "case " .. i .. ": same text")
|
||||
if c.delimiter ~= "," or i % 3 == 0 then
|
||||
local auto = dec(c.data, { delimiter = "auto" })
|
||||
if c.rows[1] and #c.rows[1] > 1 and auto then
|
||||
-- auto only has the first line to go on; it must at least split like the real delimiter there
|
||||
t:check(#auto[1] >= 1, "case " .. i .. ": auto")
|
||||
end
|
||||
end
|
||||
if c.keyed then
|
||||
local keyed = dec(c.data, { header = true }) :: any
|
||||
t:eq(#keyed, #c.rows - 1, "case " .. i .. ": keyed row count")
|
||||
t:eq(table.concat(Types.keys(keyed[1]), "|"), table.concat(c.rows[1], "|"), "case " .. i .. ": column order")
|
||||
local kb = Csv.encode(keyed) :: buffer
|
||||
t:eq(buffer.tostring(kb), c.data, "case " .. i .. ": keyed re-encode (DictWriter text)")
|
||||
end
|
||||
end
|
||||
|
||||
-- details
|
||||
do
|
||||
t:eq(Canon.of(dec("a,b\n\n1,2\r\n3,4\r5,6")), Canon.of({ { "a", "b" }, { "1", "2" }, { "3", "4" }, { "5", "6" } }), "line ends, blank lines")
|
||||
t:eq(Canon.of(dec('"a""b",c"d,"e"x')), Canon.of({ { 'a"b', 'c"d', "ex" } }), "lenient quotes like Python")
|
||||
t:eq(Canon.of(dec("a;b|c", { delimiter = "auto" })), Canon.of({ { "a", "b|c" } }), "auto delimiter")
|
||||
t:eq(Canon.of(dec("x,1.5,-2,1e3,abc, 7 ", { numbers = true })), Canon.of({ { "x", 1.5, -2, 1000, "abc", 7 } }), "numbers")
|
||||
t:eq(Canon.of(dec("a,b,c\n1,2")[1]), Canon.of({ "a", "b", "c" }), "ragged rows kept")
|
||||
local k = dec("a,b\n1,2,3\n4", { header = true })
|
||||
t:eq(k[1].b, "2", "keyed")
|
||||
t:eq(k[2].b, nil, "short keyed row")
|
||||
t:eq(buffer.tostring(Csv.encode({ { 1, true, F.null, 0.5 } }) :: buffer), "1,true,,0.5\r\n", "field types")
|
||||
t:eq(buffer.tostring(Csv.encode({ { "a", "b" } }, { quoteAll = true, newline = "\n" }) :: buffer), '"a","b"\n', "quoteAll")
|
||||
t:eq(buffer.tostring(Csv.encode({ { "" } }) :: buffer), '""\r\n', "single empty field quoted")
|
||||
local _, e = dec('a,"b')
|
||||
t:eq(e and e.code, Err.TRUNCATED, "unterminated quote")
|
||||
local _, e2 = dec("a", { delimiter = "ab" })
|
||||
t:eq(e2 and e2.code, Err.ARG, "bad delimiter")
|
||||
local _, e3 = Csv.encode({ { {} } })
|
||||
t:eq(e3 and e3.code, Err.ARG, "bad field")
|
||||
local _, e4 = dec("1\n2\n3", { maxRows = 2 })
|
||||
t:eq(e4 and e4.code, Err.LIMIT, "maxRows")
|
||||
local v = F.load(buffer.fromstring("a,b\r\n1,2\r\n"), { format = "csv", header = true })
|
||||
t:eq(v[1].a, "1", "through the API")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for i = 1, 40 do
|
||||
table.insert(samples, Fx[i].data)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Csv.decode(Bytes.reader(b), { delimiter = "auto", header = true, numbers = true })
|
||||
end, samples)
|
||||
t:done()
|
||||
@@ -0,0 +1,71 @@
|
||||
-- data/ini tests: configs written by Python's configparser read back to configparser's values and re-encoded byte for
|
||||
-- byte, messy hand-written files read as configparser(strict = false) reads them, options (inline comments, keys
|
||||
-- without values, types, strict), top-level keys, error codes, and the fuzz pass. Fixtures: tools/fixtures/ini.py.
|
||||
local T = require("@tests/T")
|
||||
local Ini = require("@formats/data/ini")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Fx = require("@tests/gen/ini")
|
||||
|
||||
local t = T.suite("data/ini")
|
||||
|
||||
t:eq(Ini.name, "ini", "name")
|
||||
t:check(Ini.caps.decode and Ini.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string, opts: any?): (any, any)
|
||||
return Ini.decode(Bytes.reader(buffer.fromstring(s)), opts)
|
||||
end
|
||||
|
||||
for i, c in Fx.written do
|
||||
local v, err = dec(c.data)
|
||||
t:check(v ~= nil, "written " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(v), c.canon, "written " .. i .. ": values")
|
||||
t:eq(buffer.tostring(Ini.encode(v) :: buffer), c.data, "written " .. i .. ": same text")
|
||||
end
|
||||
for i, c in Fx.read do
|
||||
local v, err = dec(c.data)
|
||||
t:check(v ~= nil, "messy " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(v), c.canon, "messy " .. i .. ": values")
|
||||
end
|
||||
|
||||
do
|
||||
local v = dec("top = 1\n[s]\na = 2 ; c\nflag\nn = 0x10\nb = Yes\n", { inlineComments = true, allowNoValue = true, types = true })
|
||||
t:eq(v.top, 1, "top-level key, typed")
|
||||
t:eq(v.s.a, 2, "inline comment stripped")
|
||||
t:eq(v.s.flag, true, "key without value")
|
||||
t:eq(v.s.n, 16, "hex number")
|
||||
t:eq(v.s.b, true, "yes -> true")
|
||||
t:eq(table.concat(Types.keys(v), ","), "top,s", "order")
|
||||
local o = Types.object()
|
||||
Types.set(o, "name", "x")
|
||||
local sub = Types.object()
|
||||
Types.set(sub, "k", "multi\nline")
|
||||
Types.set(sub, "inner", { z = 1 })
|
||||
Types.set(o, "sec", sub)
|
||||
t:eq(buffer.tostring(Ini.encode(o) :: buffer), "name = x\n\n[sec]\nk = multi\n\tline\n\n[sec.inner]\nz = 1\n\n", "encode nested")
|
||||
local function code(s: string, opts: any?): string?
|
||||
local _, e = dec(s, opts)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("[a]\njunk line\n"), Err.CORRUPT, "line without delimiter")
|
||||
t:eq(code("[a]\nk=1\nk=2\n", { strict = true }), Err.CORRUPT, "strict duplicate key")
|
||||
t:eq(code("[a]\n[a]\n", { strict = true }), Err.CORRUPT, "strict duplicate section")
|
||||
t:eq(code("[a]\n= v\n"), Err.CORRUPT, "empty key")
|
||||
local _, ee = Ini.encode({ ["bad=key"] = "v" })
|
||||
t:eq(ee and ee.code, Err.ARG, "unwritable key")
|
||||
t:eq(Ini.sniff(Bytes.reader(buffer.fromstring("; c\n[section]\nk=v"))), 0.2, "sniff")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx.read do
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
for i = 1, 20 do
|
||||
table.insert(samples, Fx.written[i].data)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Ini.decode(Bytes.reader(b), { types = true, inlineComments = true })
|
||||
end, samples)
|
||||
t:done()
|
||||
@@ -0,0 +1,71 @@
|
||||
-- data/json tests: the contract, the format through the API (F.load / F.save / sniffing), JSON Lines, Python's
|
||||
-- json.dumps corpus through the format, and the fuzz pass. The codec itself is tested in tests/codecs/json.luau.
|
||||
-- Fixtures: tools/fixtures/json.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local JsonF = require("@formats/data/json")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Corpus = require("@tests/gen/json_corpus")
|
||||
|
||||
local t = T.suite("data/json")
|
||||
|
||||
t:eq(JsonF.name, "json", "name")
|
||||
t:eq(JsonF.category, "data", "category")
|
||||
t:check(JsonF.caps.decode and JsonF.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string, opts: any?): (any, any)
|
||||
return JsonF.decode(Bytes.reader(buffer.fromstring(s)), opts)
|
||||
end
|
||||
|
||||
for i, c in Corpus do
|
||||
local v, err = dec(c.pretty)
|
||||
t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(v), c.canon, "corpus " .. i)
|
||||
local b = JsonF.encode(v, { indent = 2 }) :: buffer
|
||||
t:eq(buffer.tostring(b), c.pretty .. "\n", "corpus " .. i .. ": encode")
|
||||
end
|
||||
|
||||
-- through the API: sniffed, by name, saved
|
||||
do
|
||||
local v, err = F.load(buffer.fromstring('{"a": [1, 2], "b": null}'))
|
||||
t:check(v ~= nil, "F.load sniffs json: " .. tostring(err))
|
||||
t:eq(v.b, F.null, "F.null")
|
||||
local v2 = F.load(buffer.fromstring("[1, 2]"), { format = "json" })
|
||||
t:eq(v2[2], 2, "F.load format = json")
|
||||
local s = F.saveString({ x = 1, y = { true, false } }, { format = "json" })
|
||||
t:eq(s, '{"x":1,"y":[true,false]}', "F.saveString json")
|
||||
local back = F.data.load(buffer.fromstring(s :: string), { format = "json" })
|
||||
t:eq(back.y[1], true, "F.data.load")
|
||||
end
|
||||
|
||||
-- JSON Lines
|
||||
do
|
||||
local v = dec('{"a":1}\n{"a":2}\n\n[3]\n', { lines = true })
|
||||
t:eq(#v, 3, "lines decode count")
|
||||
t:eq(v[2].a, 2, "lines decode value")
|
||||
local b = JsonF.encode({ { a = 1 }, { 2, 3 } }, { lines = true }) :: buffer
|
||||
t:eq(buffer.tostring(b), '{"a":1}\n[2,3]\n', "lines encode")
|
||||
local _, e = dec("1\n[", { lines = true })
|
||||
t:eq(e and e.code, Err.TRUNCATED, "lines error")
|
||||
end
|
||||
|
||||
-- reader range: the data inside a bigger buffer
|
||||
do
|
||||
local big = buffer.fromstring("xx[1,2,3]yy")
|
||||
local v = JsonF.decode(Bytes.reader(big, 2, 7))
|
||||
t:eq(#v, 3, "reader range")
|
||||
end
|
||||
|
||||
t:eq(JsonF.sniff(Bytes.reader(buffer.fromstring(' {"a":1}'))), 0.6, "sniff object")
|
||||
t:eq(JsonF.sniff(Bytes.reader(buffer.fromstring("hello"))), 0, "sniff text")
|
||||
|
||||
local samples = {}
|
||||
for i = 1, 30 do
|
||||
table.insert(samples, Corpus[i].pretty)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return JsonF.decode(Bytes.reader(b))
|
||||
end, samples)
|
||||
t:done()
|
||||
@@ -0,0 +1,96 @@
|
||||
-- data/msgpack tests: values packed by Python's msgpack decode to msgpack's own values (canonical form), re-encode to
|
||||
-- the same bytes, 64-bit integers as doubles and as exact strings, timestamps / ext, streams, options, error codes,
|
||||
-- and the fuzz pass. Fixtures: tools/fixtures/msgpack.py.
|
||||
local T = require("@tests/T")
|
||||
local Mp = require("@formats/data/msgpack")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Fx = require("@tests/gen/msgpack")
|
||||
|
||||
local t = T.suite("data/msgpack")
|
||||
|
||||
t:eq(Mp.name, "msgpack", "name")
|
||||
t:check(Mp.caps.decode and Mp.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string | buffer, opts: any?): (any, any)
|
||||
local b = if type(s) == "string" then buffer.fromstring(s) else s
|
||||
return Mp.decode(Bytes.reader(b), opts)
|
||||
end
|
||||
|
||||
-- ext values canonicalise like the fixture's ["ext", code, data]
|
||||
local function plain(v: any): any
|
||||
if Mp.isExt(v) then
|
||||
return { "ext", v.type, v.data }
|
||||
elseif type(v) == "table" and not Types.Date.is(v) and v ~= Types.null then
|
||||
local o = if Types.isObject(v) then Types.object() else {}
|
||||
for k, x in next, v do
|
||||
o[k] = plain(x)
|
||||
end
|
||||
return o
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
for i, c in Fx.safe do
|
||||
local v, err = dec(c.data)
|
||||
t:check(v ~= nil, "safe " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(plain(v)), c.canon, "safe " .. i .. ": value")
|
||||
local b = Mp.encode(v) :: buffer
|
||||
t:check(b and buffer.tostring(b) == c.data, "safe " .. i .. ": same bytes")
|
||||
end
|
||||
for i, c in Fx.wide do
|
||||
local v, err = dec(c.data)
|
||||
t:check(v ~= nil, "wide " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(plain(v)), c.canon, "wide " .. i .. ": value")
|
||||
local vs = dec(c.data, { bigInts = "string" })
|
||||
t:eq(Canon.of(plain(vs)), c.canonStr, "wide " .. i .. ": exact big integers")
|
||||
t:eq(Canon.of(plain(dec(Mp.encode(v) :: buffer))), c.canon, "wide " .. i .. ": round trip")
|
||||
end
|
||||
|
||||
-- details
|
||||
do
|
||||
t:eq(Mp.isExt(dec("\xd4\x05\x07")), true, "fixext1")
|
||||
local d = dec("\xd6\xff\x00\x00\x00\x00")
|
||||
t:check(Types.Date.is(d) and tostring(d) == "1970-01-01T00:00:00Z", "timestamp32")
|
||||
t:eq(dec("\xcf\xff\xff\xff\xff\xff\xff\xff\xff", { bigInts = "string" }), "18446744073709551615", "u64 max text")
|
||||
t:eq(dec("\xd3\x80\x00\x00\x00\x00\x00\x00\x00", { bigInts = "string" }), "-9223372036854775808", "i64 min text")
|
||||
t:eq(dec("\xd3\xff\xff\xff\xff\xff\xff\xff\xff"), -1, "i64 -1")
|
||||
t:eq(buffer.tostring(Mp.encode(-2 ^ 40) :: buffer), "\xd3\xff\xff\xff\x00\x00\x00\x00\x00", "encode i64")
|
||||
t:eq(buffer.tostring(Mp.encode(1.5, { float32 = true }) :: buffer), "\xca\x3f\xc0\x00\x00", "float32")
|
||||
t:eq(buffer.tostring(Mp.encode({}) :: buffer), "\x90", "empty table = array")
|
||||
t:eq(buffer.tostring(Mp.encode({}, { emptyTable = "map" }) :: buffer), "\x80", "emptyTable map")
|
||||
t:eq(buffer.tostring(Mp.encode(Types.object()) :: buffer), "\x80", "Types.object = map")
|
||||
t:eq(buffer.tostring(Mp.encode({ b = 1, a = 2 }) :: buffer), "\x82\xa1a\x02\xa1b\x01", "plain keys sorted")
|
||||
t:eq(buffer.tostring(Mp.encode("ab", { stringsAsBin = true }) :: buffer), "\xc4\x02ab", "stringsAsBin")
|
||||
t:eq(buffer.tostring(Mp.encode(Mp.ext(3, buffer.fromstring("xyz"))) :: buffer), "\xc7\x03\x03xyz", "ext8")
|
||||
local all = dec("\x01\x02\xa1x", { all = true })
|
||||
t:eq(#all, 3, "stream")
|
||||
t:eq(buffer.tostring(Mp.encode({ 1, "x" }, { all = true }) :: buffer), "\x01\xa1x", "encode stream")
|
||||
t:eq(dec("\xc0"), Types.null, "nil -> null")
|
||||
local cyc = {}
|
||||
cyc[1] = cyc
|
||||
local _, ce = Mp.encode(cyc)
|
||||
t:eq(ce and ce.code, Err.ARG, "cycle")
|
||||
local function code(s: string, o: any?): string?
|
||||
local _, e = dec(s, o)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("\xdd\xff\xff\xff\xff"), Err.TRUNCATED, "huge array count")
|
||||
t:eq(code("\xa5ab"), Err.TRUNCATED, "short string")
|
||||
t:eq(code("\xc1"), Err.CORRUPT, "reserved byte")
|
||||
t:eq(code("\x01\x02"), Err.CORRUPT, "trailing data")
|
||||
t:eq(code(string.rep("\x91", 600) .. "\x01"), Err.LIMIT, "depth")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for i = 5, 60 do
|
||||
if #Fx.safe[i].data < 3000 then
|
||||
table.insert(samples, Fx.safe[i].data)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Mp.decode(Bytes.reader(b))
|
||||
end, samples)
|
||||
t:done()
|
||||
@@ -0,0 +1,86 @@
|
||||
-- data/plist tests: values written by Python's plistlib as XML and binary decode to plistlib's values; our XML writer
|
||||
-- reproduces plistlib's XML byte for byte; binary-only values (UIDs, 64-bit integers); a hand-written XML plist;
|
||||
-- error codes; the fuzz pass (XML and binary). Fixtures: tools/fixtures/plist.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Plist = require("@formats/data/plist")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Fx = require("@tests/gen/plist")
|
||||
|
||||
local t = T.suite("data/plist")
|
||||
|
||||
t:eq(Plist.name, "plist", "name")
|
||||
t:check(Plist.caps.decode and Plist.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string, opts: any?): (any, any)
|
||||
return Plist.decode(Bytes.reader(buffer.fromstring(s)), opts)
|
||||
end
|
||||
local function plain(v: any): any
|
||||
if Plist.isUid(v) then
|
||||
return { "uid", v.uid }
|
||||
elseif type(v) == "table" and not Types.Date.is(v) then
|
||||
local o = if Types.isObject(v) then Types.object() else {}
|
||||
for k, x in next, v do
|
||||
o[k] = plain(x)
|
||||
end
|
||||
return o
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
for i, c in Fx.cases do
|
||||
local v, err = dec(c.xml)
|
||||
t:check(v ~= nil, "xml " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(v), c.canon, "xml " .. i .. ": value")
|
||||
local vb, berr = dec(c.binary)
|
||||
t:check(vb ~= nil, "binary " .. i .. ": " .. tostring(berr))
|
||||
t:eq(Canon.of(vb), c.canon, "binary " .. i .. ": value")
|
||||
t:eq(buffer.tostring(Plist.encode(v) :: buffer), c.xml, "xml " .. i .. ": same text as plistlib")
|
||||
end
|
||||
for i, c in Fx.wide do
|
||||
local v, err = dec(c.binary)
|
||||
t:check(v ~= nil, "wide " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(plain(v)), c.canon, "wide " .. i .. ": value")
|
||||
end
|
||||
do
|
||||
local v = dec(Fx.extra)
|
||||
t:eq(Canon.of(v), Fx.extraCanon, "hand-written plist")
|
||||
t:eq(v.hex, 31, "hex integer")
|
||||
local f = F.load(buffer.fromstring(Fx.cases[1].binary))
|
||||
t:check(f ~= nil, "F.load sniffs binary plists")
|
||||
local fx = F.load(buffer.fromstring(Fx.cases[1].xml))
|
||||
t:eq(Canon.of(fx), Fx.cases[1].canon, "F.load sniffs XML plists over plain XML")
|
||||
t:eq(dec("<plist><string>x</string></plist>"), "x", "bare root value")
|
||||
local function code(s: string): string?
|
||||
local _, e = dec(s)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("<plist><dict><key>a</key></dict></plist>"), Err.CORRUPT, "key without value")
|
||||
t:eq(code("<plist><integer>x</integer></plist>"), Err.CORRUPT, "bad integer")
|
||||
t:eq(code("<plist><data>!!</data></plist>"), Err.CORRUPT, "bad base64")
|
||||
t:eq(code("<plist><foo/></plist>"), Err.CORRUPT, "unknown element")
|
||||
t:eq(code("bplist00"), Err.TRUNCATED, "short binary")
|
||||
local _, ne = Plist.encode({ a = F.null })
|
||||
t:eq(ne and ne.code, Err.ARG, "null cannot be written")
|
||||
local _, ke = Plist.encode({ [1] = 1, x = 2 })
|
||||
t:eq(ke and ke.code, Err.ARG, "non-string key")
|
||||
-- a binary plist with a cycle: array 0 -> [array 0]
|
||||
local cyc = "bplist00" .. "\xa1\x00" .. "\x08" .. string.rep("\0", 6) .. "\1\1" .. "\0\0\0\0\0\0\0\1" .. "\0\0\0\0\0\0\0\0" .. "\0\0\0\0\0\0\0\10"
|
||||
t:eq(code(cyc), Err.CORRUPT, "reference cycle")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for i = 1, 25 do
|
||||
table.insert(samples, Fx.cases[i].xml)
|
||||
table.insert(samples, Fx.cases[i].binary)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Plist.decode(Bytes.reader(b))
|
||||
end, samples, { keepHeader = 0 })
|
||||
t:fuzz("decode binary (header kept)", function(b: buffer)
|
||||
return Plist.decode(Bytes.reader(b))
|
||||
end, { Fx.cases[3].binary, Fx.cases[4].binary, Fx.wide[1].binary }, { keepHeader = 8, mutations = 200, garbage = 0 })
|
||||
t:done()
|
||||
@@ -0,0 +1,121 @@
|
||||
-- data/toml tests: the toml-test suite's TOML 1.0 files (every valid/ case decodes to its expected value, every
|
||||
-- invalid/ case fails), a tomli-w corpus against Python's tomllib, encoder round trips (decode(encode(v)) is the same
|
||||
-- value) and exact encoder output, options, error codes, the contract and the fuzz pass. Fixtures: tools/fixtures/toml.py.
|
||||
local T = require("@tests/T")
|
||||
local Toml = require("@formats/data/toml")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Suite = require("@tests/gen/toml_suite")
|
||||
local Corpus = require("@tests/gen/toml_corpus")
|
||||
|
||||
local t = T.suite("data/toml")
|
||||
|
||||
t:eq(Toml.name, "toml", "name")
|
||||
t:eq(Toml.category, "data", "category")
|
||||
t:check(Toml.caps.decode and Toml.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string, opts: any?): (any, any)
|
||||
return Toml.decode(Bytes.reader(buffer.fromstring(s)), opts)
|
||||
end
|
||||
local function enc(v: any, opts: any?): (string?, any)
|
||||
local b, e = Toml.encode(v, opts)
|
||||
return if b then buffer.tostring(b) else nil, e
|
||||
end
|
||||
|
||||
-- 1. toml-test
|
||||
local nv, ni, rt = 0, 0, 0
|
||||
for _, c in Suite do
|
||||
local v, err = dec(c.data)
|
||||
if c.valid then
|
||||
t:check(v ~= nil, c.name .. ": parses (" .. tostring(err) .. ")")
|
||||
t:eq(Canon.of(v), c.canon, c.name .. ": value")
|
||||
-- the encoder's output reads back as the same value (floats that are integral become integers, so compare
|
||||
-- the decoded values, not the toml-test canon)
|
||||
local s, eerr = enc(v)
|
||||
t:check(s ~= nil, c.name .. ": encodes (" .. tostring(eerr) .. ")")
|
||||
local back, berr = dec(s :: string)
|
||||
t:check(back ~= nil, c.name .. ": re-decodes (" .. tostring(berr) .. ")\n" .. tostring(s))
|
||||
t:eq(Canon.of(back), Canon.of(v), c.name .. ": round trip")
|
||||
nv += 1
|
||||
rt += 1
|
||||
else
|
||||
t:check(v == nil and Err.is(err), c.name .. ": rejected")
|
||||
ni += 1
|
||||
end
|
||||
end
|
||||
t:note("toml-test 1.0: %d valid decoded and round-tripped, %d invalid rejected", nv, ni)
|
||||
|
||||
-- 2. tomli-w corpus vs tomllib
|
||||
for i, c in Corpus do
|
||||
local v, err = dec(c.data)
|
||||
t:check(v ~= nil, "corpus " .. i .. ": " .. tostring(err))
|
||||
t:eq(Canon.of(v), c.canon, "corpus " .. i .. ": value")
|
||||
local s = enc(v) :: string
|
||||
t:eq(Canon.of(dec(s)), c.canon, "corpus " .. i .. ": round trip")
|
||||
t:eq(Canon.of(dec(enc(v, { inline = true }) :: string)), c.canon, "corpus " .. i .. ": inline round trip")
|
||||
end
|
||||
|
||||
-- 3. API details
|
||||
do
|
||||
local v = dec('z = 1\na = 2\n[t]\ny = "x"\nb = 1979-05-27T07:32:00.5-07:00\n[[arr]]\nk = 1\n[[arr]]\nk = 2\n')
|
||||
t:eq(table.concat(Types.keys(v), ","), "z,a,t,arr", "key order")
|
||||
t:check(Types.Date.is(v.t.b) and v.t.b.kind == "datetime" and v.t.b.offset == -420, "datetime value")
|
||||
t:eq(tostring(v.t.b), "1979-05-27T07:32:00.5-07:00", "datetime text")
|
||||
t:eq(v.arr[2].k, 2, "array of tables")
|
||||
t:eq(enc(v), 'z = 1\na = 2\n\n[t]\ny = "x"\nb = 1979-05-27T07:32:00.5-07:00\n\n[[arr]]\nk = 1\n\n[[arr]]\nk = 2\n', "encode text")
|
||||
t:eq(enc({ b = { 1, 2.5, "s" }, a = { x = true } }), 'b = [1, 2.5, "s"]\n\n[a]\nx = true\n', "plain tables: scalars first, sorted")
|
||||
t:eq(enc({ ["a b"] = "q\"\n\1" }), '"a b" = "q\\"\\n\\u0001"\n', "key / string escapes")
|
||||
t:eq(enc({ a = { x = 1 } }, { inline = true }), "a = { x = 1 }\n", "inline option")
|
||||
t:eq(enc({ f = 0 / 0, g = math.huge, h = 1e300, i = -0.5 }), "f = nan\ng = inf\nh = 1e+300\ni = -0.5\n", "floats")
|
||||
t:eq(enc({ a = { b = { c = 1 } } }, { indent = 2 }), "[a]\n\n [a.b]\n c = 1\n", "indent")
|
||||
local big = dec("a = 9223372036854775807\nb = 0x7fffffffffffffff\nc = 12", { bigInts = "string" })
|
||||
t:eq(big.a, "9223372036854775807", "bigInts string")
|
||||
t:eq(big.b, "0x7fffffffffffffff", "bigInts string hex")
|
||||
t:eq(big.c, 12, "small ints stay numbers")
|
||||
t:eq(dec("a = 9223372036854775807").a, 9223372036854775807, "bigInts number")
|
||||
local _, e1 = enc({ a = Types.null })
|
||||
t:eq(e1 and e1.code, Err.ARG, "null is an error")
|
||||
local cyc = {}
|
||||
cyc.self = cyc
|
||||
local _, e2 = enc(cyc)
|
||||
t:eq(e2 and e2.code, Err.ARG, "cycle is an error")
|
||||
local _, e3 = enc({ 1, 2 })
|
||||
t:eq(e3 and e3.code, Err.ARG, "top level must be a table")
|
||||
local _, e4 = enc({ [1] = 1, x = 2 })
|
||||
t:eq(e4 and e4.code, Err.ARG, "non-string key")
|
||||
end
|
||||
|
||||
-- 4. errors
|
||||
local function code(s: string): (string?, number?)
|
||||
local _, e = dec(s)
|
||||
return e and e.code, e and e.offset
|
||||
end
|
||||
t:eq(code('a = "abc'), Err.TRUNCATED, "unterminated string")
|
||||
t:eq(code("a = 1\na = 2"), Err.CORRUPT, "duplicate key")
|
||||
t:eq(code("[a]\n[a]"), Err.CORRUPT, "duplicate table")
|
||||
t:eq(code("a = 01"), Err.CORRUPT, "leading zero")
|
||||
t:eq(code("a = 9223372036854775808"), Err.CORRUPT, "int64 overflow")
|
||||
t:eq(select(2, code("x = 1\na = tru")), 10, "error offset")
|
||||
t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("# c\n[server]\nport = 80\n"))), 0.2, "sniff")
|
||||
t:eq(Toml.sniff(Bytes.reader(buffer.fromstring("{\"a\": 1}"))), 0, "sniff json")
|
||||
|
||||
-- 5. fuzz
|
||||
local samples = {}
|
||||
for _, c in Suite do
|
||||
if c.valid and #samples < 80 and #c.data < 400 then
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
end
|
||||
for i = 1, 20 do
|
||||
table.insert(samples, Corpus[i].data)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Toml.decode(Bytes.reader(b))
|
||||
end, samples)
|
||||
t:fuzz("encode(decode)", function(b: buffer)
|
||||
local v = Toml.decode(Bytes.reader(b))
|
||||
return v and Toml.encode(v)
|
||||
end, samples, { garbage = 20 })
|
||||
t:done()
|
||||
@@ -0,0 +1,49 @@
|
||||
-- data/xml tests: the contract, the format through the API (F.load / F.save / sniffing), documents from Python's
|
||||
-- ElementTree fixtures decoded and re-encoded through the format, and the fuzz pass. The codec itself is tested in
|
||||
-- tests/codecs/xml.luau. Fixtures: tools/fixtures/xml.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local XmlF = require("@formats/data/xml")
|
||||
local Xml = require("@formats/codecs/Xml")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Docs = require("@tests/gen/xml_docs")
|
||||
|
||||
local t = T.suite("data/xml")
|
||||
|
||||
t:eq(XmlF.name, "xml", "name")
|
||||
t:eq(XmlF.category, "data", "category")
|
||||
t:check(XmlF.caps.decode and XmlF.caps.encode, "caps")
|
||||
|
||||
for i = 1, 60 do
|
||||
local d = Docs[i]
|
||||
local doc, err = XmlF.decode(Bytes.reader(buffer.fromstring(d.data)), { comments = true, cdata = true, whitespace = true })
|
||||
t:check(doc ~= nil, "doc " .. i .. ": " .. tostring(err))
|
||||
local b, eerr = XmlF.encode(doc :: any)
|
||||
t:check(b ~= nil, "doc " .. i .. ": encode " .. tostring(eerr))
|
||||
local again = XmlF.decode(Bytes.reader(b :: buffer), { comments = true, cdata = true, whitespace = true })
|
||||
t:check(again ~= nil, "doc " .. i .. ": re-decode")
|
||||
t:eq(Xml.text((again :: any).root), Xml.text((doc :: any).root), "doc " .. i .. ": same text")
|
||||
end
|
||||
|
||||
do
|
||||
local doc, err = F.load(buffer.fromstring('<?xml version="1.0"?><r><a k="v">t</a></r>'))
|
||||
t:check(doc ~= nil, "F.load sniffs xml: " .. tostring(err))
|
||||
t:eq(doc.root.name, "r", "root")
|
||||
local s = F.saveString(doc, { format = "xml" })
|
||||
t:eq(s, '<?xml version="1.0" encoding="UTF-8"?>\n<r><a k="v">t</a></r>', "F.saveString")
|
||||
local _, e = XmlF.encode(5 :: any)
|
||||
t:eq(e and e.code, Err.ARG, "encode argument check")
|
||||
local _, e2 = F.load(buffer.fromstring("<r><a></r>"), { format = "xml" })
|
||||
t:eq(e2 and e2.code, Err.CORRUPT, "error through the API")
|
||||
t:eq(e2 and e2.format, "xml", "error tagged with the format")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for i = 1, 30 do
|
||||
table.insert(samples, Docs[i].data)
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return XmlF.decode(Bytes.reader(b))
|
||||
end, samples)
|
||||
t:done()
|
||||
@@ -0,0 +1,198 @@
|
||||
-- data/yaml tests: the yaml-test-suite (every case with an in.json must decode to it, every error case must be
|
||||
-- rejected, the valid cases without JSON must decode), a random corpus dumped by PyYAML in five styles (block, flow,
|
||||
-- indent 4 with explicit markers, sorted / narrow, multi-document) compared with Python's values, encoder round trips,
|
||||
-- options, errors and limits, the API, and the fuzz pass. Fixtures: tools/fixtures/yaml.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Yaml = require("@formats/data/yaml")
|
||||
local Json = require("@formats/codecs/Json")
|
||||
local Types = require("@formats/Types")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Canon = require("@tests/data/Canon")
|
||||
local Suite = require("@tests/gen/yaml_suite")
|
||||
local Corpus = require("@tests/gen/yaml_corpus")
|
||||
|
||||
local t = T.suite("data/yaml")
|
||||
|
||||
t:eq(Yaml.name, "yaml", "name")
|
||||
t:eq(Yaml.category, "data", "category")
|
||||
t:check(Yaml.caps.decode and Yaml.caps.encode, "caps")
|
||||
|
||||
local function dec(s: string, opts: any?): (any, any)
|
||||
return Yaml.decode(Bytes.reader(buffer.fromstring(s)), opts)
|
||||
end
|
||||
local function enc(v: any, opts: any?): string?
|
||||
local b = Yaml.encode(v, opts)
|
||||
return if b then buffer.tostring(b) else nil
|
||||
end
|
||||
|
||||
-- 1. yaml-test-suite
|
||||
local SKIP = { -- !!binary decodes to a buffer; the suite's JSON keeps the base64 text
|
||||
["565N"] = true,
|
||||
["name/construct-binary"] = true,
|
||||
}
|
||||
local pass, valid, rejected, errors, other, otherOk = 0, 0, 0, 0, 0, 0
|
||||
for _, c in Suite do
|
||||
local v, e = dec(c.yaml, { all = true, tags = "ignore" })
|
||||
t:check(e == nil or not string.find(e.message, "internal error", 1, true), c.name .. ": " .. tostring(e))
|
||||
if c.error then
|
||||
errors += 1
|
||||
t:check(v == nil, c.name .. ": an error case is rejected")
|
||||
rejected += if v == nil then 1 else 0
|
||||
elseif c.json and not SKIP[c.name] then
|
||||
valid += 1
|
||||
t:check(v ~= nil, c.name .. ": decodes (" .. tostring(e) .. ")")
|
||||
local want = {}
|
||||
for _, x in Json.lines(c.json) do
|
||||
table.insert(want, Canon.of(x))
|
||||
end
|
||||
local got = {}
|
||||
for _, d in v do
|
||||
local s = Json.encode(d, { nan = "null" })
|
||||
table.insert(got, if s then Canon.of(Json.decode(s)) else "?")
|
||||
end
|
||||
t:eq(table.concat(got, "|"), table.concat(want, "|"), c.name .. ": value")
|
||||
pass += 1
|
||||
elseif not c.json then
|
||||
other += 1
|
||||
otherOk += if v ~= nil or (e and e.code == Err.UNSUPPORTED) then 1 else 0
|
||||
end
|
||||
end
|
||||
t:note("yaml-test-suite: %d of %d JSON cases match, %d of %d error cases rejected, %d of %d other valid cases decode or say UNSUPPORTED", pass, valid, rejected, errors, otherOk, other)
|
||||
t:check(otherOk == other, "valid cases without JSON never fail as CORRUPT")
|
||||
|
||||
-- 2. PyYAML's output in five styles
|
||||
for i, c in Corpus do
|
||||
for style, text in c.texts do
|
||||
if style == "multi" then
|
||||
local v, e = dec(text, { all = true })
|
||||
t:check(v ~= nil, "corpus " .. i .. " " .. style .. ": " .. tostring(e))
|
||||
t:eq(Canon.of(v), c.multi, "corpus " .. i .. " " .. style)
|
||||
else
|
||||
local v, e = dec(text)
|
||||
t:check(v ~= nil or e == nil, "corpus " .. i .. " " .. style .. ": " .. tostring(e))
|
||||
t:eq(Canon.of(v), c.canon, "corpus " .. i .. " " .. style)
|
||||
end
|
||||
end
|
||||
-- our own output reads back the same (indent 2 and 4, explicit start)
|
||||
local v = dec(c.texts.block)
|
||||
for _, o in { {}, { indent = 4 }, { explicitStart = true } } do
|
||||
local s = enc(v, o)
|
||||
t:check(s ~= nil, "corpus " .. i .. ": encodes")
|
||||
t:eq(Canon.of(dec(s :: string)), c.canon, "corpus " .. i .. ": round trip " .. tostring(s))
|
||||
end
|
||||
local m = dec(c.texts.multi, { all = true })
|
||||
t:eq(Canon.of(dec(enc(m, { all = true }) :: string, { all = true })), c.multi, "corpus " .. i .. ": multi round trip")
|
||||
end
|
||||
|
||||
-- 3. details
|
||||
do
|
||||
local v = dec("b: 1\na: 2\nc: {}\nd: []\ne:\nf: ~\n")
|
||||
t:eq(table.concat(Types.keys(v), ","), "b,a,c,d,e,f", "key order")
|
||||
t:check(Types.isObject(v.c), "empty flow map is an object")
|
||||
t:eq(v.e, Types.null, "empty value is null")
|
||||
t:eq(enc(v), "b: 1\na: 2\nc: {}\nd: []\ne: null\nf: null\n", "encode keeps the order")
|
||||
local s = dec("a: &x [1, 2]\nb: *x\n")
|
||||
t:check(s.a == s.b, "aliases are shared references")
|
||||
t:eq(enc(s), "a: &id001\n - 1\n - 2\nb: *id001\n", "shared tables get anchors")
|
||||
local n = dec("[0o17, 0x1F, +12, -0.5e1, .5, .inf, -.Inf, .nan, 1_000, 0b11, yes, ~, Null, TRUE]")
|
||||
t:eq(n[1], 15, "0o")
|
||||
t:eq(n[2], 31, "0x")
|
||||
t:eq(n[3], 12, "+int")
|
||||
t:eq(n[4], -5, "float exp")
|
||||
t:eq(n[5], 0.5, ".5")
|
||||
t:eq(n[6], math.huge, ".inf")
|
||||
t:eq(n[7], -math.huge, "-.Inf")
|
||||
t:check(n[8] ~= n[8], ".nan")
|
||||
t:eq(n[9], "1_000", "1.1 ints are strings")
|
||||
t:eq(n[10], "0b11", "0b is a string")
|
||||
t:eq(n[11], "yes", "yes is a string")
|
||||
t:eq(n[12], Types.null, "~")
|
||||
t:eq(n[13], Types.null, "Null")
|
||||
t:eq(n[14], true, "TRUE")
|
||||
local tg = dec("a: !!str 12\nb: !!float 3\nc: !!binary aGVsbG8=\nd: !!timestamp 2001-12-14T21:59:43Z\ne: !!int '7'\n")
|
||||
t:eq(tg.a, "12", "!!str")
|
||||
t:eq(tg.b, 3, "!!float")
|
||||
t:eq(buffer.tostring(tg.c), "hello", "!!binary")
|
||||
t:check(Types.Date.is(tg.d), "!!timestamp")
|
||||
t:eq(tg.e, 7, "!!int on a quoted scalar")
|
||||
local _, te = dec("a: !custom x")
|
||||
t:eq(te and te.code, Err.UNSUPPORTED, "unknown tags are UNSUPPORTED")
|
||||
t:eq(dec("a: !custom x", { tags = "ignore" }).a, "x", "tags = ignore")
|
||||
t:eq(dec("--- 1\n--- 2\n"), 1, "the first document")
|
||||
t:eq(#dec("--- 1\n--- 2\n", { all = true }), 2, "all documents")
|
||||
t:eq(dec(""), Types.null, "empty stream")
|
||||
t:eq(dec("k: |\n a\n b\n\nz: >+\n f\n g\n\n").k, "a\nb\n", "literal")
|
||||
t:eq(dec("k: |\n a\n b\n\nz: >+\n f\n g\n\n").z, "f g\n\n", "folded keep")
|
||||
t:eq(dec("? a\n: b\n").a, "b", "explicit key")
|
||||
t:eq(dec("[a: 1, {b: 2}]")[1].a, 1, "single-pair flow mapping")
|
||||
-- strings that need quoting survive
|
||||
for _, str in { "", "true", "null", "12", "1.5", "- x", "a: b", "# c", "x #y", " lead", "tail ", "multi\nline", "two\n\n", "\ttab", "é", "\0\1", "'", '"', "yes", "on", "~", "[", "@", "&a", "*a", "!t", "%", "---", "...", "a\u{2028}b", ".inf", "0x10", "0o7", "-", "?", ":" } do
|
||||
local v2 = dec(enc({ k = str }) :: string)
|
||||
t:eq(v2 and v2.k, str, "string round trip " .. string.format("%q", str))
|
||||
end
|
||||
for _, x in { 0.1, -2.5e-8, 1e300, 2 ^ 53, -0.0, 123456789, math.huge, -math.huge } do
|
||||
t:eq(dec(enc({ x }) :: string)[1], x, "number round trip " .. tostring(x))
|
||||
end
|
||||
local cyc = {}
|
||||
cyc.self = cyc
|
||||
local _, ce = Yaml.encode(cyc)
|
||||
t:eq(ce and ce.code, Err.ARG, "cycles are an error")
|
||||
local _, fe = Yaml.encode({ f = print })
|
||||
t:eq(fe and fe.code, Err.ARG, "functions are an error")
|
||||
t:eq(enc(buffer.fromstring("hi")), "!!binary aGk=\n", "buffers as !!binary")
|
||||
end
|
||||
|
||||
-- 4. errors and limits
|
||||
local function code(s: string, opts: any?): string?
|
||||
local _, e = dec(s, opts)
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("a: [1, 2"), Err.TRUNCATED, "unterminated flow")
|
||||
t:eq(code('a: "x'), Err.TRUNCATED, "unterminated quote")
|
||||
t:eq(code("a: b: c"), Err.CORRUPT, "mapping on its key's line")
|
||||
t:eq(code("a: *nope"), Err.CORRUPT, "undefined alias")
|
||||
t:eq(code("a:\n b: 1\n c: 2"), Err.CORRUPT, "bad indentation")
|
||||
t:eq(code("[[1]]: x"), Err.UNSUPPORTED, "collection keys")
|
||||
t:eq(code(string.rep("[", 600) .. string.rep("]", 600)), Err.LIMIT, "depth limit")
|
||||
do
|
||||
local bomb = { "a: &a [x, x, x, x, x, x, x, x, x, x]" }
|
||||
for i = 2, 8 do
|
||||
local prev = string.char(96 + i - 1)
|
||||
table.insert(bomb, string.format("%s: &%s [*%s, *%s, *%s, *%s, *%s, *%s, *%s, *%s, *%s, *%s]", string.char(96 + i), string.char(96 + i), prev, prev, prev, prev, prev, prev, prev, prev, prev, prev))
|
||||
end
|
||||
t:eq(code(table.concat(bomb, "\n")), Err.LIMIT, "alias bomb")
|
||||
t:check(dec(table.concat(bomb, "\n", 1, 3)) ~= nil, "small alias trees are fine")
|
||||
end
|
||||
do
|
||||
local _, e = dec("a: 1\nb: [1, }\n")
|
||||
t:eq(e and e.offset, 12, "error offset")
|
||||
end
|
||||
|
||||
-- 5. API
|
||||
do
|
||||
local v, err = F.load(buffer.fromstring("---\nname: x\nlist:\n - 1\n"))
|
||||
t:check(v ~= nil, "F.load sniffs yaml: " .. tostring(err))
|
||||
t:eq(v.list[1], 1, "F.load value")
|
||||
t:eq(F.saveString(v, { format = "yaml" }), "name: x\nlist:\n - 1\n", "F.saveString yaml")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for i = 1, 30 do
|
||||
table.insert(samples, Corpus[i].texts.block)
|
||||
table.insert(samples, Corpus[i].texts.flow)
|
||||
end
|
||||
for i = 1, 400, 7 do
|
||||
if Suite[i] then
|
||||
table.insert(samples, Suite[i].yaml)
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Yaml.decode(Bytes.reader(b), { all = true })
|
||||
end, samples)
|
||||
t:fuzz("encode(decode)", function(b: buffer)
|
||||
local v = Yaml.decode(Bytes.reader(b))
|
||||
return v and Yaml.encode(v)
|
||||
end, samples, { garbage = 20 })
|
||||
t:done()
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Animated Morph Cube
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,259 @@
|
||||
{
|
||||
"buffers":[
|
||||
{
|
||||
"uri":"AnimatedMorphCube.bin",
|
||||
"byteLength":1700
|
||||
}
|
||||
],
|
||||
"asset":{
|
||||
"version":"2.0",
|
||||
"generator":"gltfpack 0.13"
|
||||
},
|
||||
"extensionsUsed":[
|
||||
"KHR_mesh_quantization"
|
||||
],
|
||||
"extensionsRequired":[
|
||||
"KHR_mesh_quantization"
|
||||
],
|
||||
"bufferViews":[
|
||||
{
|
||||
"buffer":0,
|
||||
"byteOffset":0,
|
||||
"byteLength":288,
|
||||
"byteStride":4,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteOffset":288,
|
||||
"byteLength":576,
|
||||
"byteStride":8,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteOffset":864,
|
||||
"byteLength":72,
|
||||
"target":34963
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteOffset":936,
|
||||
"byteLength":508
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteOffset":1444,
|
||||
"byteLength":254
|
||||
}
|
||||
],
|
||||
"accessors":[
|
||||
{
|
||||
"bufferView":0,
|
||||
"byteOffset":0,
|
||||
"componentType":5120,
|
||||
"count":24,
|
||||
"type":"VEC3",
|
||||
"normalized":true
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"byteOffset":0,
|
||||
"componentType":5123,
|
||||
"count":24,
|
||||
"type":"VEC3",
|
||||
"min":[
|
||||
0,
|
||||
5451,
|
||||
0
|
||||
],
|
||||
"max":[
|
||||
5481,
|
||||
10932,
|
||||
5481
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":0,
|
||||
"byteOffset":96,
|
||||
"componentType":5120,
|
||||
"count":24,
|
||||
"type":"VEC3",
|
||||
"normalized":true
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"byteOffset":192,
|
||||
"componentType":5122,
|
||||
"count":24,
|
||||
"type":"VEC3",
|
||||
"min":[
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max":[
|
||||
0,
|
||||
5188,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":0,
|
||||
"byteOffset":192,
|
||||
"componentType":5120,
|
||||
"count":24,
|
||||
"type":"VEC3",
|
||||
"normalized":true
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"byteOffset":384,
|
||||
"componentType":5122,
|
||||
"count":24,
|
||||
"type":"VEC3",
|
||||
"min":[
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"max":[
|
||||
0,
|
||||
5451,
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":2,
|
||||
"byteOffset":0,
|
||||
"componentType":5123,
|
||||
"count":36,
|
||||
"type":"SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView":3,
|
||||
"byteOffset":0,
|
||||
"componentType":5126,
|
||||
"count":127,
|
||||
"type":"SCALAR",
|
||||
"min":[
|
||||
0
|
||||
],
|
||||
"max":[
|
||||
4.19999981
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":4,
|
||||
"byteOffset":0,
|
||||
"componentType":5121,
|
||||
"count":254,
|
||||
"type":"SCALAR",
|
||||
"normalized":true
|
||||
}
|
||||
],
|
||||
"materials":[
|
||||
{
|
||||
"name":"Material",
|
||||
"pbrMetallicRoughness":{
|
||||
"baseColorFactor":[
|
||||
0.603827417,
|
||||
0.603827417,
|
||||
0.603827417,
|
||||
1
|
||||
],
|
||||
"metallicFactor":0,
|
||||
"roughnessFactor":0.5
|
||||
}
|
||||
}
|
||||
],
|
||||
"meshes":[
|
||||
{
|
||||
"primitives":[
|
||||
{
|
||||
"attributes":{
|
||||
"NORMAL":0,
|
||||
"POSITION":1
|
||||
},
|
||||
"mode":4,
|
||||
"targets":[
|
||||
{
|
||||
"NORMAL":2,
|
||||
"POSITION":3
|
||||
},
|
||||
{
|
||||
"NORMAL":4,
|
||||
"POSITION":5
|
||||
}
|
||||
],
|
||||
"indices":6,
|
||||
"material":0
|
||||
}
|
||||
],
|
||||
"weights":[
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"animations":[
|
||||
{
|
||||
"name":"Square",
|
||||
"samplers":[
|
||||
{
|
||||
"input":7,
|
||||
"output":8
|
||||
}
|
||||
],
|
||||
"channels":[
|
||||
{
|
||||
"sampler":0,
|
||||
"target":{
|
||||
"node":0,
|
||||
"path":"weights"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes":[
|
||||
{
|
||||
"mesh":0,
|
||||
"translation":[
|
||||
-0.0100000044,
|
||||
-0.0298908409,
|
||||
-0.00999999978
|
||||
],
|
||||
"scale":[
|
||||
3.64900689e-06,
|
||||
3.64900689e-06,
|
||||
3.64900689e-06
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"AnimatedMorphCube",
|
||||
"rotation":[
|
||||
0,
|
||||
0.707106709,
|
||||
-0.707106829,
|
||||
0
|
||||
],
|
||||
"scale":[
|
||||
100,
|
||||
100,
|
||||
100
|
||||
],
|
||||
"children":[
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"scenes":[
|
||||
{
|
||||
"nodes":[
|
||||
1
|
||||
]
|
||||
}
|
||||
],
|
||||
"scene":0
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Animated Triangle
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,118 @@
|
||||
{
|
||||
"scene" : 0,
|
||||
"scenes" : [
|
||||
{
|
||||
"nodes" : [ 0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"nodes" : [
|
||||
{
|
||||
"mesh" : 0,
|
||||
"rotation" : [ 0.0, 0.0, 0.0, 1.0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"meshes" : [
|
||||
{
|
||||
"primitives" : [ {
|
||||
"attributes" : {
|
||||
"POSITION" : 1
|
||||
},
|
||||
"indices" : 0
|
||||
} ]
|
||||
}
|
||||
],
|
||||
|
||||
"animations": [
|
||||
{
|
||||
"samplers" : [
|
||||
{
|
||||
"input" : 2,
|
||||
"interpolation" : "LINEAR",
|
||||
"output" : 3
|
||||
}
|
||||
],
|
||||
"channels" : [ {
|
||||
"sampler" : 0,
|
||||
"target" : {
|
||||
"node" : 0,
|
||||
"path" : "rotation"
|
||||
}
|
||||
} ]
|
||||
}
|
||||
],
|
||||
|
||||
"buffers" : [
|
||||
{
|
||||
"uri" : "AnimatedTriangle_geometry.bin",
|
||||
"byteLength" : 44
|
||||
},
|
||||
{
|
||||
"uri" : "AnimatedTriangle_animation.bin",
|
||||
"byteLength" : 100
|
||||
}
|
||||
],
|
||||
"bufferViews" : [
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 0,
|
||||
"byteLength" : 6,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 8,
|
||||
"byteLength" : 36,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 1,
|
||||
"byteOffset" : 0,
|
||||
"byteLength" : 100
|
||||
}
|
||||
],
|
||||
"accessors" : [
|
||||
{
|
||||
"bufferView" : 0,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5123,
|
||||
"count" : 3,
|
||||
"type" : "SCALAR",
|
||||
"max" : [ 2 ],
|
||||
"min" : [ 0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 1,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 3,
|
||||
"type" : "VEC3",
|
||||
"max" : [ 1.0, 1.0, 0.0 ],
|
||||
"min" : [ 0.0, 0.0, 0.0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 2,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 5,
|
||||
"type" : "SCALAR",
|
||||
"max" : [ 1.0 ],
|
||||
"min" : [ 0.0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 2,
|
||||
"byteOffset" : 20,
|
||||
"componentType" : 5126,
|
||||
"count" : 5,
|
||||
"type" : "VEC4",
|
||||
"max" : [ 0.0, 0.0, 1.0, 1.0 ],
|
||||
"min" : [ 0.0, 0.0, 0.0, -0.707 ]
|
||||
}
|
||||
],
|
||||
|
||||
"asset" : {
|
||||
"version" : "2.0"
|
||||
}
|
||||
|
||||
}
|
||||
|
After Width: | Height: | Size: 44 B |
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Anisotropy Strength Test
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Attenuation Test
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Box
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,142 @@
|
||||
{
|
||||
"asset": {
|
||||
"generator": "COLLADA2GLTF",
|
||||
"version": "2.0"
|
||||
},
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"children": [
|
||||
1
|
||||
],
|
||||
"matrix": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh": 0
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"NORMAL": 1,
|
||||
"POSITION": 2
|
||||
},
|
||||
"indices": 0,
|
||||
"mode": 4,
|
||||
"material": 0
|
||||
}
|
||||
],
|
||||
"name": "Mesh"
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5123,
|
||||
"count": 36,
|
||||
"max": [
|
||||
23
|
||||
],
|
||||
"min": [
|
||||
0
|
||||
],
|
||||
"type": "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"min": [
|
||||
-1.0,
|
||||
-1.0,
|
||||
-1.0
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 288,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"min": [
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5
|
||||
],
|
||||
"type": "VEC3"
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorFactor": [
|
||||
0.800000011920929,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"metallicFactor": 0.0
|
||||
},
|
||||
"name": "Red"
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 576,
|
||||
"byteLength": 72,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 576,
|
||||
"byteStride": 12,
|
||||
"target": 34962
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 648,
|
||||
"uri": "Box0.bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Box with interleaved position and normal attributes
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,19 @@
|
||||
# LICENSE file for the model: Box Textured
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* [Cesium Trademark or Logo](../../LICENSES/LicenseRef-LegalMark-Cesium.txt)
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,181 @@
|
||||
{
|
||||
"asset": {
|
||||
"generator": "COLLADA2GLTF",
|
||||
"version": "2.0"
|
||||
},
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"children": [
|
||||
1
|
||||
],
|
||||
"matrix": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh": 0
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"NORMAL": 1,
|
||||
"POSITION": 2,
|
||||
"TEXCOORD_0": 3
|
||||
},
|
||||
"indices": 0,
|
||||
"mode": 4,
|
||||
"material": 0
|
||||
}
|
||||
],
|
||||
"name": "Mesh"
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5123,
|
||||
"count": 36,
|
||||
"max": [
|
||||
23
|
||||
],
|
||||
"min": [
|
||||
0
|
||||
],
|
||||
"type": "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"min": [
|
||||
-1.0,
|
||||
-1.0,
|
||||
-1.0
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 288,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"min": [
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 2,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
6.0,
|
||||
1.0
|
||||
],
|
||||
"min": [
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"type": "VEC2"
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorTexture": {
|
||||
"index": 0
|
||||
},
|
||||
"metallicFactor": 0.0
|
||||
},
|
||||
"name": "Texture"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"sampler": 0,
|
||||
"source": 0
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"uri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAYFBMVEXc3Ny+1ejU2t6tzOaXwuVyseJprN9srd9gqd9/tuKHuuPh7vn////1+fnL2+ns8Onm6+B+nlyyw6GXsH1zl0ljjTBahiFchydRggWLp2u9yq+mupHM1MPg3+HY3NPf3t2inO6qAAAOAUlEQVR42uzWh7nkOAwDYIkBINmE+u/yJl3aHDyW9NZ/B4D1wWznuVwul8vlchnf8AdEb03+1aX3Ll3+1T50DXLXVc2sKv0GN36TVWWm2uWufUCjSVezdD44/wMg6XTeed6LkDY+0LNvomqV6e4k7kiCXwCA9JusZws3m4d/vvhyR+CO34Unet1L6DJutv3y9/TJCAD8SQAimGbaRfbrYDQR6ZaIAPjLgIhIU5HtRkHUHDf8fQDcVHZ6/E0tnYdytz1+DY/Zq3QCPBAAz7Lexlh+9a0cAA8HhJeprNvBGK/dA98EEW4qsmgDImoIgG8ERJSKtBVpOXgCoFTaYoZoOU/jpTLWim9JgCcBkLZOBaN1TQR4IgRS1/gpjiZaCPBkCNQSp5F0C4ATAFFdpuc3B6eBm8x9/lpOcBrQS9uYd/lZApwKSJM5WzikmwOcDHDrMqMB0QxwAYhUmbl+84WbnH77pHMhnr2NU0/f5FJAVxkn5vcAl4I4sQExD04zfwikAC4IOOcy7g5wSYD3E47f5MLy7YexJsBlAan751+4AVEHuLZwlfflB7g84G0NqHMHCJXxlv13cAtwlTF//+Y2sH/+1RroCXAfh9+EkgQ3Ah7awJDidqqP4/IbwN3AZByVXx3cDvywBjSDG4rUw34A3FJkbweQcnBL4F/cnAdiAykMRZcBPqJI3gtkuf8pt6VnKshjxnkXiIYItS8cp3sEQB+eldcwoA6AYTQAqHPlVt0VVJMwvLkjn5xLEUToCANVeQFo+LzfWSOSRYx17XIEKS/B+Aog2lzeye0TWcCpMmCi0d+fy1eyD41QMhoJKGBsHnO5fCenRpMQ0vPOgMjl8pPc6pTw3VrB5Mc6ACUpcyRSa2c8PWcPCLJc5rBtTAXo7QsNwlAQpSwhEc0n2ekAYShkc1kiWwptoGs4MlwFISnLGGrXSnpqYApjoVyWkWbLqMMFnMdlDwA4vx40kcJVDyD7nqZI4QDXuwLomAy06gAIoyFRxACdUlIvsQZKhssSbCh0kFqqIePDeMit1AF9Mwpvnk0IgZeyhPE4WSip+39iYCnIjnr10np4FYauInKXOd09+uHFkWochUuAJPpWqL0jqJeRAhGS+ZkB+nV6wNaDgzC60vJrLp9k1Z4uuemYA1xICwTISeZXsjiCLqYccoFrLQOAKFojIsZGIihjyjExlMLF8MH74IMaRDNQC1GAVx60PHZ9NVyTVfbD4DTg+0duz02z56B//Gqmqe4uxP1mDwhx9wD83cIW/Qf+4xJhlF4xewshemsBIvLOWmPEWKv+RTUt/5uTXs0xdjpbDQFRdEZyzvw/OWcxTl3D6H576Ys5t5ftRjBCv9Ahmct3sljnCSM8P1rz3ZzbX5t9ACl7l2RzWSTb5IGHxzw3GyzeThyFwLtcVskPXzjzSbj8hF/O2okCvf69VVgS4aHvx3jBHv7znE4YIJu5bMLZgsKDmP87du9ArdZDNbrYJZsHxUKQW3NHXo+CtfsGANFwOQBr397ooxGfMQxDNGUNxVRP8f28bsHL/dcCEUw5jIk43/+5rMK3radxehlvH+sxQFTbiYIaTRxkc2mALeGB63UNQcAF9O5zNpFPlZ4QhDsPIHV9P1IujeQzU4G3e+VIbduK0CeAGSx+SAJ4rwXrHV9HAba0w6cFwiP+eKt3fB64FQB5IxmfJL9QlPIPb1eiHSEOw/Yaz7HjwnA45mj4/7/cx170sFoETPUDTTSOoigOhVDgBMDn0fYpbjn21TBU/VjeYZ/H8RAkAJrn8VT9mBURsKkxSE6x4hbj0PgMb4YxHhLb9b1nQ9ap7/wfdGOpiAB0JcITXgytu6Vkydy9KjT0xCI/JAA6dvNw7J/xdBkRQJt0pLjlwyz9D/Mux4vgeBUI16MOracF3vQZJOJCC8Cf8fxbS29g1pUhAzseZIATiYbzb8zSAkvNGIvgWQ5R3KlzS+9gbVfGbkCe7wC0as3eD8fGHNqAsxwhAOXglj7AvC5jN3CcEEpcjzq29un36PMU2YCzHNHFNrinTzCvNGTgLE9+YJK7T8OxtjqCALmGAjA2ngKYj+FeyPkhPpIoBk+fCRjGIwh4iQXQLUXwLmSAkwHekQ7BcCzV4+teAuQcCoB2raUQ5nXBdz7vrcc+qEdIAEoDiNBRK7ME4M2gcTYgRxAQOtL8iMfTEQRwimuWILwNTTF+DEt1foQbUp2i8RhHAK+4ANZaBu8A5SkOoOjd0lMIEMGKmzDMu+kZIalInMmNjuqxIQhgFBcI4ALkBkR2hqBoQ47RIgL4MxdWXCCE4/HZgFzCeixrt0RVwG116hgrboMUEBwMiWyAqEdwBKSXAK+4XaS4AQPFsdkAEAAF9UgQQCpu5ZZWwFvgBrbOP65HzS2ev+0hQC6E4kaw2A3oRjeA6rFJlo6vAOwAxoentQS0U9g7sUkG5Izq8cshrCMAKK5SihsAZAPwtTJ/Daoj2JAJI7RbcTHMh4JyA7wD6DwRBIDTIKG42HIAIeyVcQP8EcDTLgIwTqEAAsXF8Mcx2YDE9bgcgQC25gEoBHyAP0i7gZcL+fyBcQAgD1iACVgWgPJHIKDDdbgIKBmQsB41gx0QRGJEKowcQOuJhrX93mzgghypWfqWgDzhewGsuHQGgGHWxDJwEyFCebYeQSqMb4Z4xSXcQHgsCtwA40i1d1tTfoCALYprlrbBB40YWCkDQmQAgRunL0eR4lYNP/+lELdnA7KE8rwjtTZPRH8Aqbj73cB1syPXIJMKD4N5IjtEoOK6pc0wA1emsrExT/vWV5VeTADuEYKKW3naA0tDsaWBStCtnJmtIqDLE9UlhjKAWHEJmMfZwFKKTGNeXlmP1gx5ovoE2QyAgDMh6XIrd99Tj95UmeoUlQupuAS8y/hLOfhIztcjbpHBn07AX7bkMwA6G7gIduQ769EfmegW36m4a+oRXJnixjxCAMD9FPFeQM6h5dLRKQvI35WAQ4FIvCHVra0/iU7E1zOQ4vICiI9FJWinFqIRKvl6xgfizRBohS4HT0fB2m61G0Ct+dkZA9oTr8ZiAbz3Zuk4WK8rGbiA+TfGbDzjim9IAQdEKy4vAzgmhpFEOThDQD2t+ZQsmD/ohHyOG3j3zhQ/zdWKDOVfv/mPyv/QLiKnxXGwisu7gZiBq7wZDngLytWjN9VMAGbgejrLjPPpFq9/7fkjMHtlulwX3U7zeObhXMHTrJJbjz7fCWAUOrM+44pegmRLh8O8GRW8LvrjfBG5wOFox9WjzychjFLv81cvXuYvToD5Y8J3wNKjBBOch/MCh6MVN3/zeQVgvBbvHtcQiksB9FEi4OHoSOqRNf1MAMYyCkC4edoP1EBFgw7lfbkUAiVwByAVl4d5f2fB30r5ciUACMA/A1ZcHqidmgS/Hm0pgBgTXANAcZ8vAxhV4/S5YyGAXwM6AAfwZDcABTBohSYuxQAmxQLIFhzPQKWMACbjTx145ngNHJsBcTExRuYzSRyIYxnEfQfP2gp09fwTgSAPhtC4/o+fP3BqvAEgLuN+WYFCoxPgnltArkyXkyFGj9c/htkSBXAyqLluseAeroT1+K3/4fR/WQELAYwdLvsdCQgP964vv9z+Bt80Hq8DBQBHwgVa5to9/STMvc4FOv6VVeO2bXHBgyDeCVVz527ppzFToPp5Lf7Vvn2mua7CYADWAs45MwYhBKjsf5d3TG6vcVzxzTvld/QZRMnjXj6/vNVWWDgELEwpnyRNzf6UwIfElFYcNx2epB8fZhJamTAT5VMQZZxKC2KfH98/Pk1qiwVX9GJCUXiSW4xlQmJmyqchYiacSowtxlIwrfo4xM0cnuQy8ReifDbiX639OCjwNLeKlC+G1u6vzOFpDiVTvhNCMViiTnyr+lM0WKQfNu+Di8AyGpDvNACawzJujelOA8BhIa33GQL9FLCUW7hNABxFYTGVQnSTAKrDcm413SIA4mYKL3Brd0iA0iQOLzGZbjAJGIM5vMYb8g32gA4L3G4/yEXgdS6Fh58ADmsEpNFXAIcV1BoPPgEUVlEZ+GaAMgqsZYJE4x4CzWEta8jj34KsYTHxmA2wCGxBZczdAE/VYRMqhcffAayhFelmDXD5yXi4AJoobMatjdUIKRVx2NJYCVAuAttyGSgB4iIOG1NpiYapvypsTiUOciqgqSrswEc5F6WqsAsb4aKcKInBPhzk8scC4qmaw160JzB8/1tBr70aUt65fvA5gXxZac0N2PjfFxFFcdifBeQrRsCpCRzCarleAsQYxOEQ6hITX6/9m8JRVCISXWr3U0QdjqPWMF9IiuJwLKsT03Wmv8HhTFq6RATMUQyO52qhMNP5j7+JO5xB4fReSJxKMIWzuLUpnRgBpcfjP5FLzOfpZ7+TmdXCTGc1f4OzuZsEPD4CZmxi7nA+V6vt2AiIGWM1dbiGviIe94IZEWFp8ij/UhGkTEfU318pVIersVqIjtn5mMEF+WNBYNp38pcgBhelJrVNPYP9Wl9v/VflqlZbRGai7V8jTaUFUXW4NFeVVhAzbZcBfUlYmpg6jMC9timllLeSEsZq7uAwCjPZphtQn/liZjAUdzORUBK/ngIR94lfpTe+4bi6SQ0tIs+IFpU+w9JCFQFVGJSrqklosUyY5qJo9u/drteecCpxrl5VHcbmrupSewiIc2ukf5RTSoi9+Crei78NB4ceQ8H0q/yQfoHYSze4K/uZ1BpCay3GWGKMrbVQq4hYBzfmD2Az+Y3NwDv4P/BerM7m/Line truncated
|
||||
}
|
||||
],
|
||||
"samplers": [
|
||||
{
|
||||
"magFilter": 9729,
|
||||
"minFilter": 9986,
|
||||
"wrapS": 10497,
|
||||
"wrapT": 10497
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 768,
|
||||
"byteLength": 72,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 576,
|
||||
"byteStride": 12,
|
||||
"target": 34962
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 576,
|
||||
"byteLength": 192,
|
||||
"byteStride": 8,
|
||||
"target": 34962
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 840,
|
||||
"uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAA/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAPwAAAD8AAAC/AADAQAAAAAAAAKBAAAAAAAAAwED+/38/AACgQP7/fz8AAIBAAAAAAAAAoEAAAAAAAACAQAAAgD8AAKBAAACAPwAAAEAAAAAAAACAPwAAAAAAAABAAACAPwAAgD8AAIA/AABAQAAAAAAAAIBAAAAAAAAAQEAAAIA/AACAQAAAgD8AAEBAAAAAAAAAAEAAAAAAAABAQAAAgD8AAABAAACAPwAAAAAAAAAAAAAAAP7/fz8AAIA/AAAAAAAAgD/+/38/AAABAAIAAwACAAEABAAFAAYABwAGAAUACAAJAAoACwAKAAkADAANAA4ADwAOAA0AEAARABIAEwASABEAFAAVABYAFwAWABUA"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
{
|
||||
"asset": {
|
||||
"generator": "COLLADA2GLTF",
|
||||
"version": "2.0"
|
||||
},
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"children": [
|
||||
1
|
||||
],
|
||||
"matrix": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"mesh": 0
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"NORMAL": 1,
|
||||
"POSITION": 2,
|
||||
"TEXCOORD_0": 3
|
||||
},
|
||||
"indices": 0,
|
||||
"mode": 4,
|
||||
"material": 0
|
||||
}
|
||||
],
|
||||
"name": "Mesh"
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5123,
|
||||
"count": 36,
|
||||
"max": [
|
||||
23
|
||||
],
|
||||
"min": [
|
||||
0
|
||||
],
|
||||
"type": "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"min": [
|
||||
-1.0,
|
||||
-1.0,
|
||||
-1.0
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 288,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"min": [
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 2,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"max": [
|
||||
6.0,
|
||||
1.0
|
||||
],
|
||||
"min": [
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"type": "VEC2"
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorTexture": {
|
||||
"index": 0
|
||||
},
|
||||
"metallicFactor": 0.0
|
||||
},
|
||||
"name": "Texture"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"sampler": 0,
|
||||
"source": 0
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"uri": "CesiumLogoFlat.png"
|
||||
}
|
||||
],
|
||||
"samplers": [
|
||||
{
|
||||
"magFilter": 9729,
|
||||
"minFilter": 9986,
|
||||
"wrapS": 10497,
|
||||
"wrapT": 10497
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 768,
|
||||
"byteLength": 72,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 576,
|
||||
"byteStride": 12,
|
||||
"target": 34962
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 576,
|
||||
"byteLength": 192,
|
||||
"byteStride": 8,
|
||||
"target": 34962
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 840,
|
||||
"uri": "BoxTextured0.bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Box Vertex Colors
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Cameras
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
|
After Width: | Height: | Size: 60 B |
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"scene" : 0,
|
||||
"scenes" : [
|
||||
{
|
||||
"nodes" : [ 0, 1, 2 ]
|
||||
}
|
||||
],
|
||||
"nodes" : [
|
||||
{
|
||||
"rotation" : [ -0.383, 0.0, 0.0, 0.92375 ],
|
||||
"mesh" : 0
|
||||
},
|
||||
{
|
||||
"translation" : [ 0.5, 0.5, 3.0 ],
|
||||
"camera" : 0
|
||||
},
|
||||
{
|
||||
"translation" : [ 0.5, 0.5, 3.0 ],
|
||||
"camera" : 1
|
||||
}
|
||||
],
|
||||
|
||||
"cameras" : [
|
||||
{
|
||||
"type": "perspective",
|
||||
"perspective": {
|
||||
"aspectRatio": 1.0,
|
||||
"yfov": 0.7,
|
||||
"zfar": 100,
|
||||
"znear": 0.01
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "orthographic",
|
||||
"orthographic": {
|
||||
"xmag": 1.0,
|
||||
"ymag": 1.0,
|
||||
"zfar": 100,
|
||||
"znear": 0.01
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
"meshes" : [
|
||||
{
|
||||
"primitives" : [ {
|
||||
"attributes" : {
|
||||
"POSITION" : 1
|
||||
},
|
||||
"indices" : 0
|
||||
} ]
|
||||
}
|
||||
],
|
||||
|
||||
"buffers" : [
|
||||
{
|
||||
"uri" : "Cameras.bin",
|
||||
"byteLength" : 60
|
||||
}
|
||||
],
|
||||
"bufferViews" : [
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 0,
|
||||
"byteLength" : 12,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 12,
|
||||
"byteLength" : 48,
|
||||
"target" : 34962
|
||||
}
|
||||
],
|
||||
"accessors" : [
|
||||
{
|
||||
"bufferView" : 0,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5123,
|
||||
"count" : 6,
|
||||
"type" : "SCALAR",
|
||||
"max" : [ 3 ],
|
||||
"min" : [ 0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 1,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 4,
|
||||
"type" : "VEC3",
|
||||
"max" : [ 1.0, 1.0, 0.0 ],
|
||||
"min" : [ 0.0, 0.0, 0.0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"asset" : {
|
||||
"version" : "2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Clear Coat Car Paint
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Emissive Strength Test
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Interpolation Test
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: LightVisibility
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Mesh Primitive Modes
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,233 @@
|
||||
{
|
||||
"asset": {
|
||||
"version": "2.0"
|
||||
},
|
||||
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [0, 1, 2, 3, 4, 5, 6]
|
||||
}
|
||||
],
|
||||
|
||||
"nodes": [
|
||||
{
|
||||
"translation": [-0, 3, 0],
|
||||
"mesh": 0
|
||||
},
|
||||
{
|
||||
"translation": [-2, 0, 0],
|
||||
"mesh": 1
|
||||
},
|
||||
{
|
||||
"translation": [0, 0, 0],
|
||||
"mesh": 2
|
||||
},
|
||||
{
|
||||
"translation": [2, 0, 0],
|
||||
"mesh": 3
|
||||
},
|
||||
{
|
||||
"translation": [-2, -3, 0],
|
||||
"mesh": 4
|
||||
},
|
||||
{
|
||||
"translation": [0, -3, 0],
|
||||
"mesh": 5
|
||||
},
|
||||
{
|
||||
"translation": [2, -3, 0],
|
||||
"mesh": 6
|
||||
}
|
||||
],
|
||||
|
||||
"meshes": [
|
||||
{
|
||||
"name": "mesh with POINTS",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 7
|
||||
},
|
||||
"indices": 0,
|
||||
"mode": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mesh with LINES",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 7
|
||||
},
|
||||
"indices": 1,
|
||||
"mode": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mesh with LINE_LOOP",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 7
|
||||
},
|
||||
"indices": 2,
|
||||
"mode": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mesh with LINE_STRIP",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 7
|
||||
},
|
||||
"indices": 3,
|
||||
"mode": 3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mesh with TRIANGLES",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 7
|
||||
},
|
||||
"indices": 4,
|
||||
"mode": 4
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mesh with GL_TRIANGLE_STRIP",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 7
|
||||
},
|
||||
"indices": 5,
|
||||
"mode": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mesh with GL_TRIANGLE_FAN",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 7
|
||||
},
|
||||
"indices": 6,
|
||||
"mode": 6
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
"buffers": [
|
||||
{
|
||||
"uri": "buffer.bin",
|
||||
"byteLength": 216
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 130,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 132,
|
||||
"byteLength": 84,
|
||||
"target": 34962
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"name": "indices for POINTS",
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5123,
|
||||
"count": 7,
|
||||
"type": "SCALAR",
|
||||
"max": [6],
|
||||
"min": [0]
|
||||
},
|
||||
{
|
||||
"name": "indices for LINES",
|
||||
"bufferView": 0,
|
||||
"byteOffset": 14,
|
||||
"componentType": 5123,
|
||||
"count": 12,
|
||||
"type": "SCALAR",
|
||||
"max": [6],
|
||||
"min": [0]
|
||||
},
|
||||
{
|
||||
"name": "indices for LINE_LOOP",
|
||||
"bufferView": 0,
|
||||
"byteOffset": 38,
|
||||
"componentType": 5123,
|
||||
"count": 7,
|
||||
"type": "SCALAR",
|
||||
"max": [6],
|
||||
"min": [0]
|
||||
},
|
||||
{
|
||||
"name": "indices for LINE_STRIP",
|
||||
"bufferView": 0,
|
||||
"byteOffset": 52,
|
||||
"componentType": 5123,
|
||||
"count": 7,
|
||||
"type": "SCALAR",
|
||||
"max": [6],
|
||||
"min": [0]
|
||||
},
|
||||
{
|
||||
"name": "indices for TRIANGLES",
|
||||
"bufferView": 0,
|
||||
"byteOffset": 66,
|
||||
"componentType": 5123,
|
||||
"count": 18,
|
||||
"type": "SCALAR",
|
||||
"max": [6],
|
||||
"min": [0]
|
||||
},
|
||||
{
|
||||
"name": "indices for TRIANGLE_STRIP",
|
||||
"bufferView": 0,
|
||||
"byteOffset": 102,
|
||||
"componentType": 5123,
|
||||
"count": 6,
|
||||
"type": "SCALAR",
|
||||
"max": [6],
|
||||
"min": [1]
|
||||
},
|
||||
{
|
||||
"name": "indices for TRIANGLE_FAN",
|
||||
"bufferView": 0,
|
||||
"byteOffset": 114,
|
||||
"componentType": 5123,
|
||||
"count": 8,
|
||||
"type": "SCALAR",
|
||||
"max": [6],
|
||||
"min": [0]
|
||||
},
|
||||
{
|
||||
"name": "positions",
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 7,
|
||||
"type": "VEC3",
|
||||
"max": [0.866, 1.0, 0.0],
|
||||
"min": [-0.866, -1.0, 0.0]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 216 B |
@@ -0,0 +1,19 @@
|
||||
# LICENSE file for the model: MultiUV Test
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* [Khronos Trademark or Logo](../../LICENSES/LicenseRef-LegalMark-Khronos.txt)
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Multiple Scenes
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,118 @@
|
||||
{
|
||||
"scene" : 1,
|
||||
"scenes" : [
|
||||
{
|
||||
"nodes" : [ 0 ]
|
||||
},
|
||||
{
|
||||
"nodes" : [ 1 ]
|
||||
}
|
||||
],
|
||||
|
||||
"nodes" : [
|
||||
{
|
||||
"mesh" : 0
|
||||
},
|
||||
{
|
||||
"mesh" : 1
|
||||
}
|
||||
],
|
||||
|
||||
"meshes" : [
|
||||
{
|
||||
"primitives" : [ {
|
||||
"attributes" : {
|
||||
"POSITION" : 1
|
||||
},
|
||||
"indices" : 0
|
||||
} ]
|
||||
},
|
||||
{
|
||||
"primitives" : [ {
|
||||
"attributes" : {
|
||||
"POSITION" : 3
|
||||
},
|
||||
"indices" : 2
|
||||
} ]
|
||||
}
|
||||
],
|
||||
|
||||
"buffers" : [
|
||||
{
|
||||
"uri" : "MultipleScenes_triangle.bin",
|
||||
"byteLength" : 44
|
||||
},
|
||||
{
|
||||
"uri" : "MultipleScenes_square.bin",
|
||||
"byteLength" : 60
|
||||
}
|
||||
],
|
||||
"bufferViews" : [
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 0,
|
||||
"byteLength" : 6,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 8,
|
||||
"byteLength" : 36,
|
||||
"target" : 34962
|
||||
},
|
||||
{
|
||||
"buffer" : 1,
|
||||
"byteOffset" : 0,
|
||||
"byteLength" : 12,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 1,
|
||||
"byteOffset" : 12,
|
||||
"byteLength" : 48,
|
||||
"target" : 34962
|
||||
}
|
||||
],
|
||||
"accessors" : [
|
||||
{
|
||||
"bufferView" : 0,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5123,
|
||||
"count" : 3,
|
||||
"type" : "SCALAR",
|
||||
"max" : [ 2 ],
|
||||
"min" : [ 0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 1,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 3,
|
||||
"type" : "VEC3",
|
||||
"max" : [ 1.0, 1.0, 0.0 ],
|
||||
"min" : [ 0.0, 0.0, 0.0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 2,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5123,
|
||||
"count" : 6,
|
||||
"type" : "SCALAR",
|
||||
"max" : [ 3 ],
|
||||
"min" : [ 0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 3,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 4,
|
||||
"type" : "VEC3",
|
||||
"max" : [ 1.0, 1.0, 0.0 ],
|
||||
"min" : [ 0.0, 0.0, 0.0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"asset" : {
|
||||
"version" : "2.0"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 60 B |
|
After Width: | Height: | Size: 44 B |
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Negative Scale Test
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Point Light Intensity Test
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Rigged Simple
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Simple Meshes
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
|
After Width: | Height: | Size: 80 B |
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"scene" : 0,
|
||||
"scenes" : [
|
||||
{
|
||||
"nodes" : [ 0, 1]
|
||||
}
|
||||
],
|
||||
"nodes" : [
|
||||
{
|
||||
"mesh" : 0
|
||||
},
|
||||
{
|
||||
"mesh" : 0,
|
||||
"translation" : [ 1.0, 0.0, 0.0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"meshes" : [
|
||||
{
|
||||
"primitives" : [ {
|
||||
"attributes" : {
|
||||
"POSITION" : 1,
|
||||
"NORMAL" : 2
|
||||
},
|
||||
"indices" : 0
|
||||
} ]
|
||||
}
|
||||
],
|
||||
|
||||
"buffers" : [
|
||||
{
|
||||
"uri" : "SimpleMeshes.bin",
|
||||
"byteLength" : 80
|
||||
}
|
||||
],
|
||||
"bufferViews" : [
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 0,
|
||||
"byteLength" : 6,
|
||||
"target" : 34963
|
||||
},
|
||||
{
|
||||
"buffer" : 0,
|
||||
"byteOffset" : 8,
|
||||
"byteLength" : 72,
|
||||
"byteStride" : 12,
|
||||
"target" : 34962
|
||||
}
|
||||
],
|
||||
"accessors" : [
|
||||
{
|
||||
"bufferView" : 0,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5123,
|
||||
"count" : 3,
|
||||
"type" : "SCALAR",
|
||||
"max" : [ 2 ],
|
||||
"min" : [ 0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 1,
|
||||
"byteOffset" : 0,
|
||||
"componentType" : 5126,
|
||||
"count" : 3,
|
||||
"type" : "VEC3",
|
||||
"max" : [ 1.0, 1.0, 0.0 ],
|
||||
"min" : [ 0.0, 0.0, 0.0 ]
|
||||
},
|
||||
{
|
||||
"bufferView" : 1,
|
||||
"byteOffset" : 36,
|
||||
"componentType" : 5126,
|
||||
"count" : 3,
|
||||
"type" : "VEC3",
|
||||
"max" : [ 0.0, 0.0, 1.0 ],
|
||||
"min" : [ 0.0, 0.0, 1.0 ]
|
||||
}
|
||||
],
|
||||
|
||||
"asset" : {
|
||||
"version" : "2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# LICENSE file for the model: Simple Morph
|
||||
|
||||
All files in this directory tree are licensed as indicated below.
|
||||
|
||||
* All files directly associated with the model including all text, image and binary files:
|
||||
|
||||
* [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"]
|
||||
|
||||
* This file and all other metadocumentation files including "metadata.json":
|
||||
|
||||
* [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"]
|
||||
|
||||
Full license text of these licenses are available at the links above.
|
||||
|
||||
This license excludes logos and associated trademarks.
|
||||
|
||||
<!-- This file is auto-generated by modelmetadata. Do not edit by hand. -->
|
||||
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"scene" : 0,
|
||||
"scenes":[
|
||||
{
|
||||
"nodes":[
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes":[
|
||||
{
|
||||
"mesh":0
|
||||
}
|
||||
],
|
||||
"meshes":[
|
||||
{
|
||||
"primitives":[
|
||||
{
|
||||
"attributes":{
|
||||
"POSITION":1
|
||||
},
|
||||
"targets":[
|
||||
{
|
||||
"POSITION":2
|
||||
},
|
||||
{
|
||||
"POSITION":3
|
||||
}
|
||||
],
|
||||
"indices":0
|
||||
}
|
||||
],
|
||||
"weights":[
|
||||
0.5,
|
||||
0.5
|
||||
]
|
||||
}
|
||||
],
|
||||
"animations":[
|
||||
{
|
||||
"samplers":[
|
||||
{
|
||||
"input":4,
|
||||
"interpolation":"LINEAR",
|
||||
"output":5
|
||||
}
|
||||
],
|
||||
"channels":[
|
||||
{
|
||||
"sampler":0,
|
||||
"target":{
|
||||
"node":0,
|
||||
"path":"weights"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"buffers":[
|
||||
{
|
||||
"uri" : "SimpleMorph_geometry.bin",
|
||||
"byteLength":116
|
||||
},
|
||||
{
|
||||
"uri" : "SimpleMorph_animation.bin",
|
||||
"byteLength":60
|
||||
}
|
||||
],
|
||||
"bufferViews":[
|
||||
{
|
||||
"buffer":0,
|
||||
"byteOffset":0,
|
||||
"byteLength":6,
|
||||
"target":34963
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteOffset":8,
|
||||
"byteLength":108,
|
||||
"byteStride":12,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":1,
|
||||
"byteOffset":0,
|
||||
"byteLength":20
|
||||
},
|
||||
{
|
||||
"buffer":1,
|
||||
"byteOffset":20,
|
||||
"byteLength":40
|
||||
}
|
||||
],
|
||||
"accessors":[
|
||||
{
|
||||
"bufferView":0,
|
||||
"byteOffset":0,
|
||||
"componentType":5123,
|
||||
"count":3,
|
||||
"type":"SCALAR",
|
||||
"max":[
|
||||
2
|
||||
],
|
||||
"min":[
|
||||
0
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"byteOffset":0,
|
||||
"componentType":5126,
|
||||
"count":3,
|
||||
"type":"VEC3",
|
||||
"max":[
|
||||
1.0,
|
||||
0.5,
|
||||
0.0
|
||||
],
|
||||
"min":[
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"byteOffset":36,
|
||||
"componentType":5126,
|
||||
"count":3,
|
||||
"type":"VEC3",
|
||||
"max":[
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min":[
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"byteOffset":72,
|
||||
"componentType":5126,
|
||||
"count":3,
|
||||
"type":"VEC3",
|
||||
"max":[
|
||||
1.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"min":[
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":2,
|
||||
"byteOffset":0,
|
||||
"componentType":5126,
|
||||
"count":5,
|
||||
"type":"SCALAR",
|
||||
"max":[
|
||||
4.0
|
||||
],
|
||||
"min":[
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"bufferView":3,
|
||||
"byteOffset":0,
|
||||
"componentType":5126,
|
||||
"count":10,
|
||||
"type":"SCALAR",
|
||||
"max":[
|
||||
1.0
|
||||
],
|
||||
"min":[
|
||||
0.0
|
||||
]
|
||||
}
|
||||
],
|
||||
"asset":{
|
||||
"version":"2.0"
|
||||
}
|
||||
}
|
||||