merge ws/cm-tests

This commit is contained in:
4DBug committed 2026-11-01 01:27:35 -06:00
commit ac1d232852
278 files changed
+492 -2150

No files matched your search

+1 -3
View File
@@ -1,5 +1,4 @@
-- examples/archive.luau: builds a zip, lists and reads it, edits it, converts it to a .tar.gz and back, and gzips a
-- single file. Run from the repository root: luau examples/archive.luau (docs/guide/archive.md explains the API).
-- examples/archive.luau: build, read and edit a zip, convert to .tar.gz and back, gzip a file (docs/guide/archive.md).
local F = require("@rosetta")
-- a new zip: a directory, a text file, an incompressible file stored as is
@@ -16,7 +15,6 @@ zip:add("game/noise.bin", noise, { method = "store" })
local zipBytes = assert(F.save(zip, nil, { format = "zip", comment = "example" }))
print(string.format("zip: %d bytes", buffer.len(zipBytes)))
-- list and read
local loaded = assert(F.archive.load(zipBytes))
for _, e in loaded:list() do
print(string.format(" %-18s %6d -> %6s %s", e.name, e.size, tostring(e.compressedSize), e.method or (if e.dir then "dir" else "")))
+1 -2
View File
@@ -1,5 +1,4 @@
-- Audio example (rosetta): build a sound, edit it with F.ops.audio, encode it to several formats, then stream it
-- back with a Decoder. Run from the repository root: luau examples/audio.luau (docs/guide/audio.md explains the API).
-- examples/audio.luau: build a sound, edit it, encode it to several formats, stream it back (docs/guide/audio.md).
local F = require("@rosetta")
local A = F.ops.audio
+2 -4
View File
@@ -1,6 +1,5 @@
-- examples/cad.luau: reads a small STEP file, walks its entity graph (references, complex instances), adds an entity
-- and writes it back under another schema. Run from the repository root: luau examples/cad.luau
-- Solid geometry (B-rep bodies, meshes) needs a kernel plug-in, F.plugins.brep: see docs/guide/cad.md.
-- examples/cad.luau: read a STEP file, walk its entity graph, add an entity, write it as AP242 (docs/guide/cad.md).
-- Solid geometry (B-rep bodies, meshes) needs a kernel plug-in, F.plugins.brep.
local F = require("@rosetta")
local STEP = [[
@@ -54,7 +53,6 @@ local si = assert(step.part(cad.entities[20], "SI_UNIT"))
print("length unit:", si[1].enum, si[2].enum) -- MILLI METRE
assert(si[1].enum == "MILLI")
-- the product name
local product = cad.entities[step.byType(cad, "PRODUCT")[1]]
print("product:", product.args[1], product.args[2])
+1 -2
View File
@@ -1,5 +1,4 @@
-- examples/data.luau: one record through JSON, YAML, TOML, MessagePack and CBOR, plus CSV rows, an INI file and an
-- XML document. Run from the repository root: luau examples/data.luau (docs/guide/data.md explains the values).
-- examples/data.luau: one record through JSON, YAML, TOML, MessagePack and CBOR; CSV, INI and XML (docs/guide/data.md).
local F = require("@rosetta")
local Types = F.Types
+2 -4
View File
@@ -1,7 +1,5 @@
-- examples/font.luau: loads a TrueType font, prints its metrics, renders a line of text into a PNG and bakes the font
-- into a BMFont (descriptor + page images). Run from the repository root: luau examples/font.luau
-- It needs a .ttf: from the repo it uses the docs test font (generate it first with python3 -I tools/fixtures.py docs),
-- elsewhere set TTF_BYTES below to the bytes of any font (the luau CLI cannot read files). docs/guide/font.md explains.
-- examples/font.luau: load a TrueType font, render text into a PNG, bake a BMFont (docs/guide/font.md).
-- Needs a .ttf: in the repo, the docs test font (python3 -I tools/fixtures.py docs); elsewhere set TTF_BYTES below.
local F = require("@rosetta")
local TTF_BYTES: buffer? = nil
+2 -3
View File
@@ -1,6 +1,5 @@
-- examples/image.luau: build an image, edit it with F.ops.image, save it in several formats, make an animated GIF and
-- read it back. Run from the repository root: luau examples/image.luau (the .luaurc alias @rosetta points at src/).
-- On LuaJIT / LÖVE, the same calls work with local F = require("rosetta") (docs/guide/image.md).
-- examples/image.luau: build an image, edit it, save it in several formats, make an animated GIF (docs/guide/image.md).
-- On LuaJIT / LÖVE: local F = require("rosetta").
local F = require("@rosetta")
local I = F.ops.image
+1 -3
View File
@@ -1,6 +1,4 @@
-- examples/layered.luau: build a layered document (a group, a clipping layer, a blend mode), flatten it, save it as
-- PSD and Aseprite, and make a small Aseprite animation exported as a GIF. Run from the repository root:
-- luau examples/layered.luau (docs/guide/layered.md explains the type).
-- examples/layered.luau: build a layered document, flatten it, save PSD and Aseprite, a GIF (docs/guide/layered.md).
local F = require("@rosetta")
local I, L = F.ops.image, F.Types.Layered
+1 -3
View File
@@ -1,6 +1,4 @@
-- Music example (rosetta): write a MIDI file from scratch, read it back, and render it to audio with the built-in
-- waveforms (pass a SoundFont as { soundfont = sf2Bytes } for real instruments). Run from the repository root:
-- luau examples/music.luau (docs/guide/music.md explains the API).
-- examples/music.luau: write a MIDI file, read it back, render it to audio (docs/guide/music.md).
local F = require("@rosetta")
-- 1. a Midi: 480 ticks per quarter note, absolute ticks, a tempo, a track name and a little melody
+1 -2
View File
@@ -1,5 +1,4 @@
-- examples/playlist.luau: reads an M3U with a base URL, inspects an HLS master playlist, and converts a playlist to
-- PLS and XSPF. Run from the repository root: luau examples/playlist.luau (docs/guide/playlist.md explains the type).
-- examples/playlist.luau: read an M3U, inspect an HLS master playlist, convert to PLS, XSPF (docs/guide/playlist.md).
local F = require("@rosetta")
local M3U = "#EXTM3U\n#PLAYLIST:Road Trip\n#EXTINF:215,Ada - First Song\nmusic/first.mp3\n"
+1 -3
View File
@@ -1,6 +1,4 @@
-- examples/scene.luau: builds a 3D scene from scratch (a cube with a material, plus a voxel grid), edits it with
-- F.ops.mesh and saves it as GLB, OBJ + MTL and STL. Run from the repository root: luau examples/scene.luau
-- (docs/guide/scene.md explains the Scene type).
-- examples/scene.luau: build a 3D scene and a voxel grid, edit it, save as GLB, OBJ and STL (docs/guide/scene.md).
local F = require("@rosetta")
local S = F.Types.Scene
+1 -2
View File
@@ -1,5 +1,4 @@
-- examples/tilemap.luau: read a Tiled map (TMX), walk its tile layer with the flip flags, find an object, edit the map
-- and convert it to TMJ. Run from the repository root: luau examples/tilemap.luau (docs/guide/tilemap.md).
-- examples/tilemap.luau: read a TMX map, walk a tile layer, find an object, edit, write TMJ (docs/guide/tilemap.md).
local F = require("@rosetta")
local tmx = [[<?xml version="1.0" encoding="UTF-8"?>
+1 -2
View File
@@ -1,5 +1,4 @@
-- examples/vector.luau: parse an SVG, inspect its paths, rasterize it at two sizes, build a Vector from scratch and
-- write it as SVG. Run from the repository root: luau examples/vector.luau (docs/guide/vector.md explains the type).
-- examples/vector.luau: parse an SVG, rasterize it, build a Vector and write it as SVG (docs/guide/vector.md).
local F = require("@rosetta")
local svg = [[<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24">
+1 -3
View File
@@ -1,6 +1,4 @@
-- Video example (rosetta): make frames with F.ops.image, write them as an AVI (Motion-JPEG), then open the
-- video, walk its packets and frames, seek, and turn it into an animated GIF. Run from the repository root:
-- luau examples/video.luau (docs/guide/video.md explains the API).
-- examples/video.luau: write an MJPEG AVI, open it, walk packets and frames, seek, make a GIF (docs/guide/video.md).
local F = require("@rosetta")
local I = F.ops.image
+2 -17
View File
@@ -1,18 +1,9 @@
--!strict
-- tests/T: the test helper every tests/**/*.luau uses, under both runtimes (luau --codegen -O2 and LuaJIT through the
-- build). A failed check throws, so the runner (tools/test.sh) sees a non-zero exit.
--
-- local T = require("@tests/T")
-- local t = T.suite("png")
-- t:check(cond, "label") -- truthy
-- t:eq(got, want, "label") -- ==, with both values in the message
-- t:fuzz("decode", function(b) return Png.decode(Bytes.reader(b)) end, samples) -- the no-throw pass
-- t:done() -- prints "png: 123 checks passed (luajit)"
-- tests/T: the test helper; a failed check throws, so tools/test.sh sees a non-zero exit.
local T = {}
T.runtime = if (_G :: any).jit ~= nil then "luajit" else "luau"
-- deterministic LCG (the same numbers on both runtimes): rand(n) -> 0 .. n - 1
function T.rng(seed: number): (n: number) -> number
local s = seed % 2147483648
return function(n: number): number
@@ -21,7 +12,6 @@ function T.rng(seed: number): (n: number) -> number
end
end
-- bytes({ 1, 2, 3 }) -> buffer
function T.bytes(t: { number }): buffer
local b = buffer.create(#t)
for i, v in t do
@@ -30,7 +20,6 @@ function T.bytes(t: { number }): buffer
return b
end
-- hex(buf, max?) -> "89 50 4e 47 ..."
function T.hex(b: buffer, max: number?): string
local n = math.min(buffer.len(b), max or 64)
local out = table.create(n)
@@ -40,7 +29,6 @@ function T.hex(b: buffer, max: number?): string
return table.concat(out, " ") .. (if buffer.len(b) > n then " ..." else "")
end
-- clock() -> seconds (os.clock on both runtimes)
function T.clock(): number
return os.clock()
end
@@ -68,14 +56,11 @@ function Suite.eq(self: Suite, got: any, want: any, label: string)
self.passed += 1
end
-- note(fmt, ...): an indented progress line
function Suite.note(_self: Suite, fmt: string, ...: any)
print(" " .. string.format(fmt, ...))
end
-- fuzz(label, decode, samples, opts?): the no-throw pass every format test runs. For each sample (buffer or string):
-- truncations at several cuts, opts.mutations (default 8) copies with 1..4 random bytes changed, plus
-- opts.garbage (default 200) random buffers. decode(buf) may return anything except throw. Returns the counts.
-- the no-throw pass: truncations, opts.mutations (default 8) mutated copies, opts.garbage (default 200) random buffers.
function Suite.fuzz(self: Suite, label: string, decode: (buffer) -> any, samples: { any }, opts: { mutations: number?, garbage: number?, seed: number?, keepHeader: number? }?): (number, number)
local o: { mutations: number?, garbage: number?, seed: number?, keepHeader: number? } = opts or {}
local rand = T.rng(o.seed or 1234)
+1 -7
View File
@@ -1,6 +1,4 @@
-- API tests (src/Rosetta/init.luau): load / save / saveString / convert / open / detect / formats / format, the
-- category facades, sniff-then-extension detection, errors as Err values (never a throw), and file paths on hosts with
-- a file system (LuaJIT: a temporary file; the luau CLI has none).
-- API tests: load / save / convert / open / detect, the category facades, errors as values, file paths.
local T = require("@tests/T")
local F = require("@rosetta")
local Err = require("@rosetta/core/Err")
@@ -15,10 +13,8 @@ local function image(w: number, h: number): any
return img
end
-- host
t:eq(F.host.name, if T.runtime == "luajit" then "luajit" else "luau", "host detected")
-- formats()
do
local all = F.formats()
t:check(#all >= 1, "formats() lists the registry")
@@ -57,7 +53,6 @@ do
t:eq(F.detect(buf), "png", "detect")
local conv = F.convert(s, "png", { level = 1 })
t:check(conv and F.load(conv).width == 7, "convert")
-- format options reach the encoder
local stored = F.save(img, nil, { format = "png", level = 0 }) :: buffer
t:check(buffer.len(stored) > buffer.len(buf :: buffer), "opts.level reaches the encoder")
end
@@ -116,7 +111,6 @@ else
t:check(e2 and e2.code == Err.IO, "no file system: load of a path is Err.IO")
end
-- Types constructors
do
local T2 = F.Types
t:eq(buffer.len(T2.Image.new(3, 2, "rgb8").pixels), 18, "Image.new rgb8")
+1 -7
View File
@@ -1,8 +1,4 @@
-- 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.
-- archive/7z tests against 7-Zip's archives (tools/fixtures/7z.py).
local T = require("@tests/T")
local SevenZip = require("@rosetta/archive/7z")
local F = require("@rosetta")
@@ -83,7 +79,6 @@ do
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)
@@ -93,7 +88,6 @@ do
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
+1 -4
View File
@@ -1,6 +1,4 @@
-- shared by the archive tests: check(t, archive, want, label) compares an Archive's entries with the reference listing
-- want = { { name, size?, crc?, mode?, mtime?, dir?, link? } } (only the fields present are compared; every wanted
-- entry must exist; crc is the CRC-32 of the data read back), and the files written by _arch2_ours.luau.
-- shared by the archive tests: entry listings compared with a reference tool's, and the standard file set.
local Crc32 = require("@rosetta/core/Crc32")
local E = {}
@@ -51,7 +49,6 @@ E.FILES = {
{ name = "empty.txt", data = buffer.create(0) },
}
-- roundTrip(t, mod, opts, label): add the standard files to mod.new(), write with opts, decode, compare
function E.roundTrip(t: any, mod: any, opts: any?, label: string): buffer?
local Bytes = require("@rosetta/core/Bytes")
local a = mod.new()
+1 -4
View File
@@ -1,6 +1,4 @@
-- shared by tests/archive/{binhex,macbinary,applesingle}.luau: run(name, module) checks the format's cases of
-- tools/fixtures/mac.py against The Unarchiver's listings (fork names, sizes, data CRCs, type / creator), our writer's
-- output read by unar (fixture step), round trips with a resource fork and Finder info, and the fuzz pass.
-- shared by the binhex / macbinary / applesingle tests: tools/fixtures/mac.py cases against The Unarchiver's listings.
local T = require("@tests/T")
local F = require("@rosetta")
local Bytes = require("@rosetta/core/Bytes")
@@ -42,7 +40,6 @@ return function(name: string, mod: any, encodeVariants: { any }): (any, { string
t:check(o.ok, "unar reads our output (" .. o.variant .. "): " .. o.detail)
end
end
-- round trips: Finder info, dates, a resource fork
for _, opts in encodeVariants do
local a = mod.new()
a:add("Caf\u{e9}", "data fork", { mtime = 1700000000 })
+1 -5
View File
@@ -1,7 +1,4 @@
-- archive/adf tests: DD / HD images formatted OFS, FFS, FFS international, OFS / FFS with directory cache by amitools'
-- xdftool, holding nested directories, an empty file, a file with extension blocks and an ISO-8859-1 name, list the
-- files xdftool reads back (names, sizes, data CRCs, directories, a set date), volume name and file system; errors
-- (root block checksum, bad hash chains); the fuzz pass. Fixtures: tools/fixtures/adf.py (images gzip-compressed).
-- archive/adf tests against amitools' xdftool (tools/fixtures/adf.py, images gzip-compressed).
local T = require("@tests/T")
local F = require("@rosetta")
local Adf = require("@rosetta/archive/adf")
@@ -30,7 +27,6 @@ for _, c in Fx.cases do
t:eq(F.detect(data), "adf", c.name .. ": detect")
end
-- errors
local img = first :: buffer
local function code(b: buffer): string?
local _, e = Adf.decode(Bytes.reader(b))
+2 -2
View File
@@ -1,5 +1,5 @@
-- archive/applesingle tests: the applesingle cases of tools/fixtures/mac.py against The Unarchiver's listings, our output read by unar,
-- round trips with a resource fork and Finder info (tests/archive/_mac.luau), errors, the fuzz pass.
-- archive/applesingle tests (cases in tests/archive/_mac.luau).
-- Fixtures: tools/fixtures/mac.py.
local Mod = require("@rosetta/archive/applesingle")
local Bytes = require("@rosetta/core/Bytes")
local Err = require("@rosetta/core/Err")
+1 -9
View File
@@ -1,8 +1,4 @@
-- archive/ar tests: GNU ar (deterministic and with times, a library with its "/" symbol table), llvm-ar BSD (#1/ names,
-- __.SYMDEF) and bsdtar arbsd archives list the input files (names, sizes, mtimes, data CRCs) and symbols; the GNU writer
-- gives GNU ar rcSD's bytes for the same files; bsdtar and dpkg-deb archives re-encode to their own bytes; .deb packages
-- from dpkg-deb (xz / gzip / zstd / none) and older bzip2 / lzma members give meta.control and load through the api as
-- their data tar; errors; the fuzz pass. Fixtures: tools/fixtures/ar.py.
-- archive/ar tests against GNU ar, llvm-ar, bsdtar and dpkg-deb (tools/fixtures/ar.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Ar = require("@rosetta/archive/ar")
@@ -47,7 +43,6 @@ local function sortedSymbols(list: { any }): string
return table.concat(s, ",")
end
-- 1. reading
for _, c in Fx.archives do
local a, err = decode(c.data)
t:check(a, c.name .. ": " .. tostring(err))
@@ -65,7 +60,6 @@ for _, c in Fx.archives do
end
end
-- 2. writing: GNU ar rcSD's bytes; BSD names read back; any Archive to ar
do
local a = Ar.new()
for _, f in Fx.files do
@@ -89,7 +83,6 @@ do
t:eq(conv:list()[1].mtime, 5, "tar -> ar: mtime")
end
-- 3. Debian packages
for _, d in Fx.debs do
local a, err = decode(d.data)
t:check(a, d.name .. ": " .. tostring(err))
@@ -112,7 +105,6 @@ for _, d in Fx.debs do
t:eq(outer.format, "ar", d.name .. ": unwrap = false keeps the ar")
end
-- 4. errors
do
local _, e1 = decode("!<thin>\n")
t:check(e1 and e1.code == Err.UNSUPPORTED, "thin archive: " .. tostring(e1))
+1 -4
View File
@@ -1,6 +1,4 @@
-- archive/arj tests: archives by ARJ 3.10 with methods 0 .. 4 (stored, the LHA-style Huffman methods 1 .. 3, method
-- 4) give the files `arj x` extracts (names, sizes, data CRCs); header and data CRC errors, truncation; the fuzz
-- pass. Fixtures: tools/fixtures/arj.py.
-- archive/arj tests against ARJ 3.10 (tools/fixtures/arj.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Arj = require("@rosetta/archive/arj")
@@ -23,7 +21,6 @@ for _, c in Fx.cases do
table.insert(samples, string.sub(c.data, 1, 3000))
end
-- errors
local data = Fx.cases[2].data -- -m1
local function code(s: string): string?
local _, e = Arj.decode(Bytes.reader(buffer.fromstring(s)))
+2 -2
View File
@@ -1,5 +1,5 @@
-- archive/binhex tests: the binhex cases of tools/fixtures/mac.py against The Unarchiver's listings, our output read by unar,
-- round trips with a resource fork and Finder info (tests/archive/_mac.luau), errors, the fuzz pass.
-- archive/binhex tests (cases in tests/archive/_mac.luau).
-- Fixtures: tools/fixtures/mac.py.
local Mod = require("@rosetta/archive/binhex")
local Bytes = require("@rosetta/core/Bytes")
local Err = require("@rosetta/core/Err")
+1 -9
View File
@@ -1,6 +1,4 @@
-- 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.
-- archive/br tests (tools/fixtures/brotli.py).
local T = require("@tests/T")
local Br = require("@rosetta/archive/br")
local F = require("@rosetta")
@@ -10,12 +8,10 @@ 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
@@ -34,13 +30,11 @@ for i, c in Fx.cases do
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" })
@@ -55,7 +49,6 @@ do
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
@@ -78,7 +71,6 @@ do
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
+1 -4
View File
@@ -1,6 +1,4 @@
-- 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.
-- archive/bz2 tests (tools/fixtures/bzip2.py).
local T = require("@tests/T")
local Bz2 = require("@rosetta/archive/bz2")
local Bytes = require("@rosetta/core/Bytes")
@@ -44,7 +42,6 @@ do
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")
+1 -14
View File
@@ -1,11 +1,4 @@
-- archive/cab tests: cabinets by gcab (stored / MSZIP), lcab, a builder of MSZIP blocks that use the previous block as
-- their dictionary (several folders, reserve areas, attributes, UTF-8 names) and libmspack's test cabinets give the
-- files cabextract extracts (names, sizes, data CRCs, DOS times read as UTC); cabextract / gcab / 7z extract our
-- writer's output (fixture step) and it round-trips; spanned files are UNSUPPORTED; checksum, truncation and
-- signature errors, libmspack's broken cabinets; LZX (codecs/compress/Lzx) from a fixture compressor whose cabinets
-- cabextract extracts (windows 2^15 .. 2^21, verbatim / aligned / uncompressed blocks, E8); Quantum
-- (codecs/compress/Quantum) the same way (windows 2^10 .. 2^21, model rescaling); Deflate's preset
-- dictionary; the fuzz pass. Fixtures: tools/fixtures/cab.py.
-- archive/cab tests against cabextract, gcab, lcab, 7z and libmspack's test cabinets (tools/fixtures/cab.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Cab = require("@rosetta/archive/cab")
@@ -38,7 +31,6 @@ for _, c in Fx.cases do
end
t:check(methods.store and methods.mszip and methods.lzx and methods.quantum, "covers store, mszip, lzx and quantum")
-- attributes, UTF-8 names, reserve areas (the builder's two-folder cabinet)
local two = assert(load(Fx.cases[5].data))
local naive = two._byName["na\u{ef}ve \u{2603}.txt"]
t:check(naive and naive.utf8 and naive.attributes == 0x20, "utf-8 name and attributes")
@@ -47,7 +39,6 @@ t:eq(buffer.tostring(two.meta.reserve), "HEADER-RESERVE", "header reserve")
t:eq(#two.meta.folders, 2, "two folders")
t:check(assert(load(Fx.cases[4].data))._byName["b.bin"].readonly, "read-only attribute")
-- our writer
t:check(Fx.ours.ok, "reference tools extract our cabinets: " .. Fx.ours.log)
E.roundTrip(t, Cab, nil, "round trip mszip")
E.roundTrip(t, Cab, { compression = "none" }, "round trip store")
@@ -93,19 +84,16 @@ for _, c in Fx.bad do
table.insert(samples, c.data)
end
-- LZX directly
local Lzx = require("@rosetta/codecs/compress/Lzx")
t:check(not Lzx.decode(buffer.create(10), 0, 10, 100, 14), "LZX window 2^14 unsupported")
t:check(not Lzx.decode(buffer.create(10), 0, 10, 100, 16), "LZX of zeros")
t:check(not Lzx.decode(buffer.create(10), 4, 10, 100, 16), "LZX range past the end")
-- Quantum directly
local Quantum = require("@rosetta/codecs/compress/Quantum")
t:check(not Quantum.decode(buffer.create(10), {}, 0, 9), "Quantum window 2^9 unsupported")
t:check(not Quantum.decode(buffer.create(10), { { at = 0, len = 10, size = 5 } }, 6, 16), "Quantum sizes must add up")
t:check(not Quantum.decode(buffer.create(10), { { at = 4, len = 10, size = 5 } }, 5, 16), "Quantum range past the end")
-- Deflate's preset dictionary and MSZIP blocks
local block1 = assert(Deflate.compress(string.rep("ab", 50)))
local mszip = buffer.create(buffer.len(block1) + 2)
buffer.writestring(mszip, 0, "CK")
@@ -117,7 +105,6 @@ local z = assert(Deflate.compress(dictText .. dictText))
local plain = assert(Deflate.inflate(z, nil, nil, 1600, buffer.fromstring("unused prefix")))
t:eq(buffer.tostring(plain), dictText .. dictText, "inflate with an unused dictionary")
-- errors
local data = Fx.cases[2].data -- gcab -z
local function code(s: string): string?
local a, e = load(s)
+1 -11
View File
@@ -1,8 +1,4 @@
-- archive/cpio tests (and containers/Cpio): GNU cpio archives of one tree in newc / crc / odc / bin (and the bin one
-- byte-swapped to big endian) and bsdtar newc / odc archives list the entries os.lstat sees (names, types, modes, sizes,
-- mtimes, link counts, symlink targets, data CRCs, hard links reading the shared data); re-encoding the GNU newc / crc /
-- odc archives gives GNU's bytes; devices (rdev fields), crc sums, a .cpio.gz through the api, conversions to and from
-- tar (hard links share an inode), errors, the fuzz pass. Fixtures: tools/fixtures/cpio.py.
-- archive/cpio tests (and containers/Cpio) against GNU cpio and bsdtar (tools/fixtures/cpio.py).
local T = require("@tests/T")
local F = require("@rosetta")
local CpioF = require("@rosetta/archive/cpio")
@@ -42,7 +38,6 @@ local function check(a: any, want: any, label: string)
end
end
-- 1. reading
for _, c in Fx.archives do
local a, err = CpioF.decode(Bytes.reader(buffer.fromstring(c.data)))
t:check(a, c.name .. ": " .. tostring(err))
@@ -61,7 +56,6 @@ for _, c in Fx.archives do
end
end
-- 2. writing: GNU's bytes back from the decoded archive (newc / crc / odc)
for _, c in Fx.archives do
if c.gnu and c.format ~= "bin" then
local a = CpioF.decode(Bytes.reader(buffer.fromstring(c.data)))
@@ -71,7 +65,6 @@ for _, c in Fx.archives do
end
end
-- 3. devices, sums, the container directly
do
local list, info = Cpio.read(buffer.fromstring(Fx.devices))
t:check(list and info.format == "newc", "devices: read")
@@ -84,7 +77,6 @@ do
local _, e1 = Cpio.read(buffer.fromstring(Fx.badcrc))
t:check(e1 and e1.code == Err.CHECKSUM, "crc: bad sum: " .. tostring(e1))
t:check(Cpio.read(buffer.fromstring(Fx.badcrc), 0, nil, { verify = false }), "crc: verify = false")
-- devices survive a newc and an odc write
for _, fmt in { "newc", "odc" } do
local a = CpioF.decode(Bytes.reader(buffer.fromstring(Fx.devices)))
local back = CpioF.decode(Bytes.reader(assert(a:write({ format = fmt }))))
@@ -93,7 +85,6 @@ do
end
end
-- 4. the api: .cpio.gz unwraps, Archive values, conversions
do
local a, err = F.load(Fx.gz, { name = "tree.cpio.gz" })
t:check(a and a.format == "cpio" and a.meta.compression == "gzip", "cpio.gz unwraps: " .. tostring(err))
@@ -125,7 +116,6 @@ do
t:eq(cp:list()[1].nlink, 2, "tar hard link -> cpio: nlink")
end
-- 5. errors
do
local good = Fx.archives[1].data
local _, e1 = CpioF.decode(Bytes.reader(buffer.fromstring(string.sub(good, 1, 300))))
+1 -6
View File
@@ -1,7 +1,4 @@
-- archive/d64 tests: D64 / D71 / D81 images made by VICE's c1541 (PRG / SEQ / USR, multi-sector, a deleted file, an
-- error-info block, 30 files over several directory sectors) list the files c1541 reads back (names, sizes, types,
-- data CRCs), disk name and id; our D64 / D71 / D81 output is read by c1541 (fixture step) and round-trips; PETSCII
-- names; errors; the fuzz pass. Fixtures: tools/fixtures/d64.py.
-- archive/d64 tests against VICE's c1541 (tools/fixtures/d64.py).
local T = require("@tests/T")
local F = require("@rosetta")
local D64 = require("@rosetta/archive/d64")
@@ -43,14 +40,12 @@ for _, v in { "d64", "d71", "d81" } do
t:eq(a.meta.disk, "round trip", v .. ": disk name")
end
end
-- PETSCII names: lower / upper case and other bytes survive a round trip
local a = D64.new()
a:add("Mixed Case 1", "x")
a:add("\u{E0D3}hift", "y")
local back = D64.decode(Bytes.reader(a:write() :: buffer)) :: any
t:check(back._byName["Mixed Case 1"] and back._byName["\u{E0D3}hift"] == nil and back._byName["Shift"], "petscii names")
-- errors
local function code(b: buffer): string?
local _, e = D64.decode(Bytes.reader(b))
return e and e.code
+1 -7
View File
@@ -1,8 +1,4 @@
-- archive/fat tests (and containers/Fat): FAT12 (1.44 MB, 720 KB) / FAT16 / FAT32 images by mkfs.fat filled by mtools
-- (long names over several entries, lower-case 8.3, non-ASCII names, nested directories, empty and many-cluster files)
-- and a hard-disk image with an MBR partition list what mtools extracts (names, sizes, data CRCs, dates as UTC,
-- directories), FAT width and label; our floppies pass fsck.fat -n and extract with mtools (fixture step) and
-- round-trip; errors; the fuzz pass. Fixtures: tools/fixtures/fat.py (images gzip-compressed).
-- archive/fat tests (and containers/Fat) against mtools and fsck.fat (tools/fixtures/fat.py, images gzip-compressed).
local T = require("@tests/T")
local F = require("@rosetta")
local FatF = require("@rosetta/archive/fat")
@@ -38,7 +34,6 @@ end
for _, size in { 1440, 720, 360, 2880 } do
E.roundTrip(t, FatF, { size = size }, "round trip " .. size)
end
-- long and short names, directories, dates
local a = FatF.new()
a:add("Some Long Name.html", "a", { mtime = 1700000000 })
a:add("dir/UPPER.TXT", "b", { mtime = 1700000002 })
@@ -55,7 +50,6 @@ t:eq(back._byName["dir/UPPER.TXT"].mtime, 1700000002, "dos time")
t:eq(back._byName["dir/Same Prefix 2.txt"].shortName, "SAMEPR~2.TXT", "numeric tail")
t:eq(back.meta.label, "TEST", "label")
-- errors
local function code(b: buffer): string?
local _, e = FatF.decode(Bytes.reader(b))
return e and e.code
+1 -3
View File
@@ -1,6 +1,4 @@
-- archive/grp tests: Build GRP archives written by tools/fixtures/grp.py list the entries an independent Python
-- reader sees (names, sizes, data CRCs); our writer produces the same bytes as the Python writer and round-trips;
-- conversion from a zip; errors; the fuzz pass. Fixtures: tools/fixtures/grp.py.
-- archive/grp tests against an independent Python reader and writer (tools/fixtures/grp.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Grp = require("@rosetta/archive/grp")
+1 -7
View File
@@ -1,6 +1,4 @@
-- 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.
-- archive/gzip tests against Python's gzip and the gzip CLI (tools/fixtures/tar.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Gzip = require("@rosetta/archive/gzip")
@@ -34,7 +32,6 @@ do
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
@@ -48,7 +45,6 @@ do
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")
@@ -61,7 +57,6 @@ do
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")
@@ -71,7 +66,6 @@ do
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))))
+1 -10
View File
@@ -1,9 +1,4 @@
-- archive/iso tests (and containers/Iso9660): xorriso images (plain names, Joliet, Rock Ridge, Joliet + Rock Ridge with
-- deep directories / a 200-byte name / a long symlink target) and a genisoimage -J -R image (rr_moved relocation, CE
-- areas) list what the source tree holds (Rock Ridge: names, modes, symlink targets, mtimes, data CRCs) or what pycdlib
-- reads (plain and Joliet names, sizes, data CRCs); prefer = "joliet" on a -J -R image; an El Torito boot catalog as
-- xorriso reports it; a crafted multi-extent file reads whole; an interleaved file is UNSUPPORTED; errors; the fuzz pass.
-- Fixtures: tools/fixtures/iso.py.
-- archive/iso tests (and containers/Iso9660) against xorriso, genisoimage and pycdlib (tools/fixtures/iso.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Iso = require("@rosetta/archive/iso")
@@ -65,12 +60,10 @@ do
t:eq(p.format, "iso", "F.load")
t:eq(p.meta.iso.tree, "iso9660", "plain")
t:check(p.meta.iso.blockSize == 2048 and p.meta.iso.blocks > 0, "volume facts")
-- any Archive converts: iso -> tar
local tar = F.load(assert(F.save(jr, nil, { format = "tar" })))
t:eq(buffer.tostring(tar:read("hello.txt")), "hello, iso\n", "iso -> tar")
end
-- El Torito
do
local a = Iso.decode(Bytes.reader(buffer.fromstring(Fx.boot.data)))
local bt = a.meta.boot
@@ -83,7 +76,6 @@ do
t:check(bt.valid, "boot: validation entry checksum")
end
-- multi-extent and interleaved records
do
local a = Iso.decode(Bytes.reader(buffer.fromstring(Fx.multi.data)))
local n = 0
@@ -100,7 +92,6 @@ do
t:check(e and e.code == Err.UNSUPPORTED, "interleaved: " .. tostring(e))
end
-- errors
do
local good = Fx.images[1].data
local _, e1 = Iso.decode(Bytes.reader(buffer.fromstring(string.sub(good, 1, 20000))))
+1 -5
View File
@@ -1,8 +1,4 @@
-- archive/lha tests (and codecs/compress/Lzh): lhasa's test archives (LHarc lh1, LArc lzs / lz5 / lz4, LHA lh0 / lh5 /
-- lh6 / lh7 by many DOS / Amiga / OS-9 / Unix / Windows tools, header levels 0 / 1 / 2, subdirectories, symlinks, lh1 and
-- lz5 length tests up to 2 MB) and LHa for UNIX archives (-o5 / -o6 / -o7 / -z at levels 0 / 1 / 2) give the files lhasa
-- extracts (names, sizes, data CRCs) and its symlinks; our level-2 lh0 output extracts with lhasa (fixture step) and
-- round-trips; CRC and truncation errors; the fuzz pass. Fixtures: tools/fixtures/lha.py.
-- archive/lha tests (and codecs/compress/Lzh) against lhasa and LHa for UNIX (tools/fixtures/lha.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Lha = require("@rosetta/archive/lha")
+1 -7
View File
@@ -1,8 +1,4 @@
-- archive/lz4 tests (and codecs/compress/Xxh32): frames from the lz4 tool (default, linked blocks, 64 KB blocks, block
-- checksums, content size, no content checksum, HC, legacy), concatenated and skippable frames decode to their corpora;
-- our frames (every option set) decode with `lz4 -d` (verdicts from the fixture step) and round-trip; XXH32 test
-- vectors; checksum / size / truncation errors; the api (.tar.lz4 unwrap, naming); the fuzz pass.
-- Fixtures: tools/fixtures/lz4frame.py.
-- archive/lz4 tests (and codecs/compress/Xxh32) against the lz4 tool (tools/fixtures/lz4frame.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Lz4F = require("@rosetta/archive/lz4")
@@ -51,7 +47,6 @@ for name, data in C do
end
end
-- the api
do
local a = assert(F.load(Fx.cases[1].data, { name = "notes.txt.lz4" }))
t:check(a.meta.stream and a.format == "lz4", "single stream")
@@ -68,7 +63,6 @@ do
t:eq(buffer.tostring(F.load(s):read("data")), "some text", "a string")
end
-- errors
do
local good
for _, c in Fx.cases do
+2 -2
View File
@@ -1,5 +1,5 @@
-- archive/macbinary tests: the macbinary cases of tools/fixtures/mac.py against The Unarchiver's listings, our output read by unar,
-- round trips with a resource fork and Finder info (tests/archive/_mac.luau), errors, the fuzz pass.
-- archive/macbinary tests (cases in tests/archive/_mac.luau).
-- Fixtures: tools/fixtures/mac.py.
local Mod = require("@rosetta/archive/macbinary")
local Bytes = require("@rosetta/core/Bytes")
local Err = require("@rosetta/core/Err")
+1 -6
View File
@@ -1,7 +1,4 @@
-- archive/mpq tests: archives written by StormLib (tools/fixtures/mpq.py; header versions 1-4) list every file and
-- read back its exact bytes: zlib, PKWARE implode, bzip2, LZMA and sparse sectors, imploded files, single-unit,
-- stored, encrypted (plain and fix-key) and sector-CRC files; a prefixed archive; an archive without a listfile
-- (names by block index, opts.names); Huffman sectors are UNSUPPORTED; the hash helper; errors; the fuzz pass.
-- archive/mpq tests against StormLib (tools/fixtures/mpq.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Mpq = require("@rosetta/archive/mpq")
@@ -72,7 +69,6 @@ for _, c in Fx.archives do
t:note("%-9s v%d, %2d entries, %2d files checked", c.name, a.meta.source.version, #a:list(), ok)
end
-- errors
do
local c = Fx.archives[1]
local _, e1 = Mpq.decode(Bytes.reader(buffer.fromstring(string.sub(c.data, 1, 200))))
@@ -100,7 +96,6 @@ t:fuzz("decode", function(b: buffer)
return a
end, samples, { mutations = 60 })
do
-- mutations inside the file data (the tables intact)
local c = Fx.archives[1]
local rand = T.rng(5)
local threw = 0
+1 -5
View File
@@ -1,6 +1,4 @@
-- archive/pak tests: Quake ("PACK") and SiN ("SPAK") archives written by tools/fixtures/pak.py list the entries an
-- independent Python reader sees (names, sizes, data CRCs); our writer produces the same bytes as the Python writer
-- for the same files and round-trips; conversion from a tar; errors; the fuzz pass. Fixtures: tools/fixtures/pak.py.
-- archive/pak tests against an independent Python reader and writer (tools/fixtures/pak.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Pak = require("@rosetta/archive/pak")
@@ -38,12 +36,10 @@ for _, c in Fx do
end
local back = Pak.decode(Bytes.reader(out))
t:eq(#back:list(), #c.files, c.name .. ": round trip count")
-- rewriting a decoded archive keeps its variant
local again = F.save(a) :: buffer
t:eq(buffer.readstring(again, 0, 4), if c.variant == "sin" then "SPAK" else "PACK", c.name .. ": F.save keeps the variant")
end
-- a sub-range reader, conversion from another archive, errors
do
local c = Fx[1]
local big = buffer.create(#c.data + 7)
+1 -6
View File
@@ -1,7 +1,4 @@
-- archive/rpm tests: one package from rpmbuild with each payload compressor (gzip, bzip2, xz, lzma, zstd, none) gives
-- the header fields `rpm -qp --qf` prints, its file list (names, sizes, modes, mtimes, symlink targets; %ghost files
-- skipped), the file data rpm2cpio's stream holds (CRCs, hard links), and Rpm.cpio = rpm2cpio's bytes; errors; the
-- fuzz pass. Fixtures: tools/fixtures/rpm.py.
-- archive/rpm tests against rpm -qp and rpm2cpio (tools/fixtures/rpm.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Rpm = require("@rosetta/archive/rpm")
@@ -48,7 +45,6 @@ for _, c in Fx.rpms do
end
end
t:eq(#a:list(), n, c.name .. ": entry count")
-- hard links: both read the same bytes
t:eq(buffer.tostring(a:read("usr/bin/hello")), "#!/bin/sh\necho hello\n", c.name .. ": hard link (first)")
t:eq(buffer.tostring(a:read("usr/bin/hello2")), "#!/bin/sh\necho hello\n", c.name .. ": hard link (second)")
local raw = Rpm.cpio(Bytes.reader(buffer.fromstring(c.data)))
@@ -67,7 +63,6 @@ do
t:check(e, "rpm is read-only")
end
-- errors
do
local good = Fx.rpms[1].data
local _, e1 = Rpm.decode(Bytes.reader(buffer.fromstring(string.sub(good, 1, 50))))
+2 -11
View File
@@ -1,8 +1,4 @@
-- 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.
-- archive/tar tests against Python's tarfile and GNU tar (tools/fixtures/tar.py).
local T = require("@tests/T")
local F = require("@rosetta")
local TarF = require("@rosetta/archive/tar")
@@ -38,7 +34,6 @@ local function check(a: any, want: any, label: string)
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))
@@ -47,7 +42,7 @@ for _, c in Fx.tars do
t:note("%-18s %2d entries", c.name, #c.entries)
end
-- 2. writing: byte-identical to Python's tarfile (which pads to 10240-byte records)
-- 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
@@ -83,7 +78,6 @@ for _, w in Fx.writes do
end
end
-- 3. Archive values: add / read / write, other archives to tar
do
local a = TarF.new()
a:add("a.txt", "alpha", { mtime = 5 })
@@ -98,7 +92,6 @@ do
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)
@@ -106,7 +99,6 @@ do
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))
@@ -118,7 +110,6 @@ for _, w in Fx.wrapped do
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)
+1 -5
View File
@@ -1,7 +1,4 @@
-- archive/uu tests: blocks by GNU uuencode (classic / -m) and uuenview (-u / -x) decode to the right names, sizes,
-- modes and data; several blocks in a mail; CRLF lines; our uu / xx / base64 output decodes with uudecode / uudeview
-- (fixture step) and is byte-identical to GNU uuencode for one file; round trips; errors; the fuzz pass.
-- Fixtures: tools/fixtures/uu.py.
-- archive/uu tests against GNU uuencode, uuenview and uudeview (tools/fixtures/uu.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Uu = require("@rosetta/archive/uu")
@@ -53,7 +50,6 @@ local outer = Uu.encode(inner, { name = "x.uu" }) :: buffer
local v = F.load(outer) :: any
t:check(v and v.format == "uu" and v.meta.compression == "uu" and buffer.tostring((v:read("x.uu"))) == "abc", "api unwraps a single block")
-- errors
local function code(s: string): string?
local _, e = Uu.decode(Bytes.reader(buffer.fromstring(s)))
return e and e.code
+1 -9
View File
@@ -1,7 +1,4 @@
-- archive/vpk tests: version 1 and 2 directory files written by Python's vpk package list the entries it reads back
-- (names, sizes, CRC-32s); a multi-part archive (part files through opts.files and opts.resolve, preload bytes, an
-- embedded entry); our writer's version 1 / 2 output read back by the vpk package (MD5 verify for version 2) and by
-- us; CRC checks; errors; the fuzz pass. Fixtures: tools/fixtures/vpk.py.
-- archive/vpk tests against Python's vpk package (tools/fixtures/vpk.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Vpk = require("@rosetta/archive/vpk")
@@ -32,7 +29,6 @@ local function check(a: any, want: { any }, label: string)
end
end
-- 1. Python's vpk package
for _, c in Fx.cases do
local a, err = Vpk.decode(Bytes.reader(buffer.fromstring(c.data)))
t:check(a, c.name .. ": " .. tostring(err))
@@ -44,7 +40,6 @@ for _, c in Fx.cases do
end
end
-- 2. multi-part
do
local m = Fx.multi
local a = Vpk.decode(Bytes.reader(buffer.fromstring(m.dir)), { files = m.parts, name = "maps/pak01_dir.vpk" })
@@ -63,12 +58,10 @@ do
local _, e = c:read("materials/a.vmt")
t:check(e and e.code == Err.UNSUPPORTED, "missing part: " .. tostring(e))
t:eq(buffer.tostring((c:read("root.txt"))), "embedded", "embedded entry without the parts")
-- multi-part -> single file
local one = F.load(F.save(b) :: buffer)
check(one, m.entries, "multi -> one directory file")
end
-- 3. our writer, read back by the vpk package and by us
for k, v in Fx.ours do
t:check(v.ok, k .. ": the vpk package verifies our MD5s")
t:eq(#v.entries, #Fx.want, k .. ": the vpk package lists every entry")
@@ -83,7 +76,6 @@ for k, v in Fx.ours do
check(Vpk.decode(Bytes.reader(a:write() :: buffer)), Fx.want, k .. ": round trip")
end
-- 4. errors
do
local c = Fx.cases[2]
local bad = buffer.fromstring(c.data)
+2 -14
View File
@@ -1,9 +1,5 @@
-- archive/wad tests: a cut-down Freedoom IWAD (tools/fixtures/wad.py) lists its lumps (names, sizes, data CRCs,
-- namespaces, map lumps as "MAP01/THINGS"); every flat, patch, sprite and graphic decodes to the pixels DeuTex
-- extracts (RGBA CRC, offsets); composed wall textures; MAP01 parses to the counts of an independent parse and its
-- Scene's floor area matches Green's theorem over the sectors' sides; a hand-made room with a pillar (exact areas,
-- walls, things on floors), a UDMF stub, duplicate names, a tall patch; the writer round-trips byte for byte;
-- errors; the fuzz pass. Fixtures: tools/fixtures/wad.py.
-- archive/wad tests: a cut-down Freedoom IWAD against DeuTex, map floor areas by Green's theorem.
-- Fixtures: tools/fixtures/wad.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Wad = require("@rosetta/archive/wad")
@@ -22,7 +18,6 @@ t:check(a, "freedoom: " .. tostring(err))
t:eq(F.detect(fd.data), "wad", "F.detect")
t:eq(a.meta.source.type, "IWAD", "IWAD")
-- 1. lumps
do
local lumps = Wad.lumps(a) :: { Wad.Lump }
t:eq(#lumps, #fd.lumps, "lump count")
@@ -46,7 +41,6 @@ do
t:eq(#Wad.maps(a), 1, "one map")
end
-- 2. images against DeuTex
do
local n = 0
for _, w in fd.images do
@@ -74,7 +68,6 @@ do
end
end
-- 3. MAP01
do
local m = Wad.mapData(a, "MAP01") :: any
local r = fd.map
@@ -116,7 +109,6 @@ do
t:check(lean.textures[1].image == nil and lean.textures[1].uri ~= nil, "textures = false")
end
-- 4. the hand-made room
do
local rm = Wad.decode(Bytes.reader(buffer.fromstring(Fx.room.data)))
t:check(rm, "room decodes")
@@ -170,7 +162,6 @@ do
t:check(buffer.tostring(F.save(rm) :: buffer) == Fx.room.data, "room: decode + save is byte-identical")
end
-- 5. writer
do
t:check(buffer.tostring(F.save(a) :: buffer) == fd.data, "freedoom: decode + save is byte-identical")
local p = Wad.new()
@@ -188,7 +179,6 @@ do
t:eq(Wad.lumps(F.load(F.save(zip, nil, { format = "wad" }) :: buffer))[1].name, "X.LMP", "zip -> wad")
end
-- 6. errors
do
local _, e1 = Wad.decode(Bytes.reader(buffer.fromstring(string.sub(fd.data, 1, 100))))
t:check(e1 and e1.code == Err.TRUNCATED, "truncated: " .. tostring(e1))
@@ -200,7 +190,6 @@ do
t:check(e4 and e4.code == Err.ARG, "missing map")
end
-- 7. fuzz: the directory, then the lumps of the room (maps, pictures)
t:fuzz("decode", function(b: buffer)
local w = Wad.decode(Bytes.reader(b))
if w then
@@ -217,7 +206,6 @@ t:fuzz("decode", function(b: buffer)
return w
end, { Fx.room.data }, { mutations = 300 })
do
-- mutate inside the lumps of the real map and pictures (the directory kept intact)
local rand = T.rng(9)
local threw = 0
for i = 1, 60 do
+1 -6
View File
@@ -1,6 +1,4 @@
-- 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.
-- archive/xz tests (tools/fixtures/lzma.py).
local T = require("@tests/T")
local Xz = require("@rosetta/archive/xz")
local F = require("@rosetta")
@@ -37,12 +35,10 @@ for _, c in Fx.cases do
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
@@ -62,7 +58,6 @@ do
t:check(e3 and e3.code == Err.TRUNCATED, "truncated: " .. tostring(e3))
end
-- fuzz
do
local samples = {}
for i, c in Fx.cases do
+1 -5
View File
@@ -1,7 +1,4 @@
-- archive/yenc tests: single-part files by uuenview -y (including every byte value and the critical characters), a
-- multi-part posting in order and reversed, two files in one text; part / file CRC and size checks; an incomplete
-- posting; our output decodes with uudeview (fixture step) and round-trips; errors; the fuzz pass.
-- Fixtures: tools/fixtures/yenc.py.
-- archive/yenc tests against uuenview and uudeview (tools/fixtures/yenc.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Yenc = require("@rosetta/archive/yenc")
@@ -34,7 +31,6 @@ E.roundTrip(t, Yenc, { line = 7 }, "round trip, 7-character lines")
local p = Yenc.decode(Bytes.reader(buffer.fromstring(Fx.partial))) :: any
t:check(p and p.meta.incomplete and p.meta.incomplete[1] == "big.bin" and p:list()[1].complete == false, "incomplete posting")
-- errors
local good = buffer.tostring(Yenc.encode("hello", { name = "h" }) :: buffer)
local function code(s: string): string?
local _, e = Yenc.decode(Bytes.reader(buffer.fromstring(s)))
+1 -5
View File
@@ -1,6 +1,4 @@
-- archive/z tests: .Z files from ncompress load as single-stream archives (entry names from the file name, .taz -> .tar),
-- a .tar.Z unwraps to the tar through the api, writing gives ncompress's bytes (a buffer, a one-entry Archive) and a
-- tar inside for several entries, conversions, errors, the fuzz pass. Fixtures: tools/fixtures/z.py.
-- archive/z tests against ncompress (tools/fixtures/z.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Z = require("@rosetta/archive/z")
@@ -37,7 +35,6 @@ do
t:eq(outer:list()[1].name, "src.tar", "unwrap = false")
end
-- writing
do
local out = assert(F.save(text.input, nil, { format = "z" }))
t:check(buffer.tostring(out) == text.z, "a string: ncompress's bytes")
@@ -54,7 +51,6 @@ do
t:check(buffer.tostring(b10) == Fx.cases[6].z, "maxBits option")
end
-- errors
do
local _, e1 = Z.decode(Bytes.reader(buffer.fromstring("\31\157")))
t:check(e1 and e1.code == Err.TRUNCATED, "short")
+2 -20
View File
@@ -1,10 +1,5 @@
-- archive/zip + containers/Zip tests: generated archives (comment with a fake end record, data descriptors,
-- force_zip64, an all-ZIP64 archive, 66000 entries, a prefix stub, a wrong local header, unicode, empty) read entry by
-- entry against Python's zipfile listing (and every Webamp demo skin when SKINS_DIR is set); lookup rules; bad CRC,
-- encrypted and unsupported entries; the writer (stored / deflated, levels, UTF-8 names, DOS times, comments, ZIP64,
-- raw copies) read back; the Archive API (list / read / add / remove / write, create, encode of a table) and the api;
-- corrupt input never throws. The writer's output was also checked by hand: `unzip -t`, Python zipfile and 7z read it.
-- Ported from zip-luau tests/zip.luau. Fixtures: tools/fixtures/zip.py.
-- archive/zip + containers/Zip tests against Python's zipfile; SKINS_DIR adds the Webamp demo skins.
-- Fixtures: tools/fixtures/zip.py.
local T = require("@tests/T")
local Zip = require("@rosetta/containers/Zip")
local ZipF = require("@rosetta/archive/zip")
@@ -24,7 +19,6 @@ local function dataOf(a: any): string
return buffer.tostring(Deflate.zlib(buffer.fromstring(a.dataZ)) :: buffer)
end
-- open an archive and compare it with zipfile's listing; read every entry
local function verify(a: any, label: string): (any, number)
local z, err = Zip.open(dataOf(a))
t:check(z, label .. ": open: " .. tostring(err))
@@ -61,7 +55,6 @@ else
t:note("(no skins: set SKINS_DIR to the Webamp demo skins)")
end
-- lookup and specifics
do
local z = byName.basic.zip
t:eq(z:find("readme.txt").name, "readme.txt", "find exact")
@@ -88,7 +81,6 @@ do
t:eq(byName.many.zip:readString("d/65999.txt"), "65999", "last of 66000 entries")
t:eq(#byName.empty.zip:list(), 0, "empty archive")
t:check(Zip.isZip(byName.basic.data) and Zip.isZip(byName.empty.data) and not Zip.isZip("GIF89a"), "isZip")
-- a sub-range reader
local s = byName.basic.data
local big = buffer.create(#s + 10)
buffer.writestring(big, 4, s)
@@ -96,7 +88,6 @@ do
t:check(zs and zs:readString("readme.txt") ~= nil, "open a sub-range Reader")
end
-- a bad CRC, encrypted and unsupported entries
do
local data = buffer.fromstring(byName.basic.data)
local z = Zip.open(byName.basic.data)
@@ -118,7 +109,6 @@ do
t:check(oe and oe.code == Err.ARG, "a non-buffer argument")
end
-- the writer
do
local rand = T.rng(5)
local w = Zip.writer()
@@ -162,7 +152,6 @@ do
t:check(list[2].modified.year == 1980 and list[2].modified.month == 1 and list[2].modified.day == 1, "default time 1980-01-01")
t:eq(z.comment, "archive comment", "archive comment written")
t:check(not z.zip64, "small archive is not ZIP64")
-- forced ZIP64
local w64 = Zip.writer()
w64:add("a.txt", text)
w64:add("b.txt", "bee", { method = "store" })
@@ -175,19 +164,16 @@ do
end
local zm = Zip.open(wm:finish() :: buffer)
t:check(zm and zm.zip64 and #zm:list() == 66000 and zm:readString("d/65999.txt") == "65999", "66000 entries")
-- dates
for _, s in { 315532800, 946684799, 1700000000, 4354819198 } do
local tm, dt = Zip.dosTime(s)
t:eq(Zip.unixTime(tm, dt), s - s % 2, "dos time of " .. s)
end
t:check(select(2, Zip.dosTime(0)) == 0x21, "before 1980 clamps")
-- bad arguments
t:check(not w:add("", "x"), "empty name")
t:check(not w:add("x", 5 :: any), "bad data")
t:check(not w:add("x", "y", { method = "lzma" } :: any), "bad method")
end
-- the Archive (archive/zip)
do
t:eq(ZipF.name, "zip", "name")
t:eq(ZipF.category, "archive", "category")
@@ -216,7 +202,6 @@ do
table.insert(names, e.name)
end
t:eq(table.concat(names, ","), "readme.txt,Skin/Main.BMP,Skin/,Skin/sub/deep.txt,empty.txt,__MACOSX/Skin/._Main.BMP,Sk\u{ef}n/\u{fc}nicode.txt,new/one.txt", "order kept")
-- create, encode of a table, encode of another Archive
local c = ZipF.create()
c:add("hello.txt", "hi")
local cz = ZipF.decode(Bytes.reader(ZipF.encode(c) :: buffer)) :: any
@@ -225,10 +210,8 @@ do
t:check(tz:list()[1].name == "a.txt" and buffer.tostring(tz:read("b.txt")) == "bee", "encode a { name = data } table")
local _, ee = ZipF.encode(5 :: any)
t:check(ee and ee.code == Err.ARG, "encode a number")
-- comments survive a rewrite
local cm = ZipF.decode(Bytes.reader(buffer.fromstring(byName.comment.data))) :: any
t:eq(string.sub(Zip.open(cm:write()).comment, 1, 14), "a comment with", "comment kept on write")
-- the api
local la = F.archive.load(byName.basic.data)
t:check(la and la.kind == "archive" and #la:list() == byName.basic.count, "F.archive.load")
t:eq(F.detect(byName.basic.data), "zip", "F.detect")
@@ -238,7 +221,6 @@ do
t:check(saved2 ~= nil, "F.save without a format uses the source format")
end
-- corrupt archives never throw
local samples = {}
for _, a in Fx.archives do
if a.data then
+1 -3
View File
@@ -1,6 +1,4 @@
-- archive/zoo tests: zoo archives assembled by tools/fixtures/zoo.py (type 1 / type 2 entries, long and directory
-- names, a deleted entry, methods stored / LZW / lzh, an LZW stream with table resets) give the files The Unarchiver
-- extracts (names, sizes, data CRCs); CRC errors; the fuzz pass. Fixtures: tools/fixtures/zoo.py.
-- archive/zoo tests against The Unarchiver (tools/fixtures/zoo.py).
local T = require("@tests/T")
local F = require("@rosetta")
local Zoo = require("@rosetta/archive/zoo")
+1 -9
View File
@@ -1,6 +1,4 @@
-- 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).
-- archive/zst tests (tools/fixtures/zstd.py, shared with tests/codecs/zstd.luau).
local T = require("@tests/T")
local F = require("@rosetta")
local Zst = require("@rosetta/archive/zst")
@@ -10,7 +8,6 @@ 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")
@@ -24,13 +21,11 @@ local function case(name: string): any
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" })
@@ -54,14 +49,12 @@ do
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" })
@@ -74,7 +67,6 @@ do
t:check(se and se.code == Err.UNSUPPORTED, "no encoder")
end
-- fuzz
do
local samples = {}
for i, c in Fx.cases do
+1 -5
View File
@@ -1,11 +1,8 @@
-- tests/audio/_adpcm: shared checks of the ADPCM game-audio formats (adx, vag, brstm): a file against the reference
-- decoder's s16le output, bit-exact, through decode() and through open() with seeks (forward into unvisited packets,
-- back, the end), loop points; the SNR of an encoder's round trip.
-- tests/audio/_adpcm: shared checks of adx, vag, brstm: bit-exact against the reference decoder's s16le output.
local Bytes = require("@rosetta/core/Bytes")
local H = {}
-- same(f32 buffer, s16le reference buffer, first reference sample, count) -> true when every sample is equal
function H.same(out: buffer, ref: buffer, from: number, count: number): boolean
for i = 0, count - 1 do
if buffer.readf32(out, i * 4) * 32768 ~= buffer.readi16(ref, (from + i) * 2) then
@@ -26,7 +23,6 @@ function H.snr(x: buffer, y: buffer, count: number): number
return if err == 0 then 200 else 10 * math.log10(sig / err)
end
-- check(t, Fmt, c, opts?): c = { name, data, rate, ch, frames?, ref, loopStart?, loopEnd? }
function H.check(t: any, Fmt: any, c: any, opts: any?)
local ref = buffer.fromstring(c.ref)
local frames = buffer.len(ref) // (2 * c.ch)
+1 -2
View File
@@ -1,5 +1,4 @@
-- 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).
-- tests/audio/_encode_cases: the ALAC / CAF writer inputs of the reference check (tools/fixtures/m4a.py).
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 = "rosetta", 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 },
+3 -9
View File
@@ -1,8 +1,5 @@
-- Shared checks of the lossless audio format tests (wavpack, ape, tta): every fixture opened, decoded bit-exact
-- against the reference decoder's samples (readInt for integer streams, the f32 bytes for float ones), f32 scaling
-- and output reuse, seeking to sample-accurate positions, reading past the end, tags, sniff. A fixture is a table
-- { name, data, rate, channels, bits, float, frames, crc, tags?, partial? } (partial: a cut file whose decode stops
-- with an error; the reference decoded its first `frames` frames).
-- Shared checks of the lossless audio format tests (wavpack, ape, tta): bit-exact against the reference decoder.
-- partial: a cut file whose decode stops with an error; the reference decoded its first `frames` frames.
local T = require("@tests/T")
local Bytes = require("@rosetta/core/Bytes")
local Crc32 = require("@rosetta/core/Crc32")
@@ -20,7 +17,6 @@ local function open(mod: any, b: any, opts: any?): (any, any)
end
L.open = open
-- all(dec, fx) -> crc of every sample read (i32 for integer streams, f32 bytes for floats), frames, the values
function L.all(dec: any, fx: any): (number, number, { number })
local ch = dec.channels
local vals = table.create(fx.frames * ch, 0)
@@ -52,7 +48,6 @@ function L.all(dec: any, fx: any): (number, number, { number })
return crc, n, vals
end
-- cases(t, mod, cases, optsOf?) -> seeks checked: the per-fixture checks; optsOf(fx) gives the open options
function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): number
local seekChecks = 0
for _, fx in cases do
@@ -73,7 +68,6 @@ function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): num
end
t:eq(n, fx.frames, name .. ": decoded frames")
t:eq(crc, fx.crc, name .. ": samples identical to the reference decoder")
-- f32 scaling, output reuse
local ch = dec.channels
dec:seek(0)
local reuse = buffer.create(100 * ch * 4)
@@ -120,7 +114,7 @@ function L.cases(t: any, mod: any, cases: { any }, optsOf: ((any) -> any)?): num
return seekChecks
end
-- subrange(t, mod, fx, depth) : decode() from a Reader over a sub-range equals read(); meta.source
-- decode() from a Reader over a sub-range equals read()
function L.subrange(t: any, mod: any, fx: any, format: string)
local name = fx.name
local big = buffer.create(#fx.data + 13)
+1 -3
View File
@@ -1,6 +1,4 @@
-- 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.
-- tests/audio/_opus_cases: the CELT encoder reference check inputs (tools/fixtures/opus_celt.py).
local Types = require("@rosetta/Types")
local Cases = {}
+1 -3
View File
@@ -1,6 +1,4 @@
-- 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).
-- tests/audio/_signal: the deterministic integer test signal of tools/fixtures/_m4a_signal.py (the same numbers).
local Types = require("@rosetta/Types")
local Signal = {}
+1 -8
View File
@@ -1,6 +1,4 @@
-- 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.
-- audio/aac tests: ADTS streams from ffmpeg and fdkaac against ffmpeg's float decode (SNR, length).
-- Fixtures: tools/fixtures/m4a.py.
local T = require("@tests/T")
local AacF = require("@rosetta/audio/aac")
@@ -49,7 +47,6 @@ for _, c in Fx do
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))
@@ -57,7 +54,6 @@ for _, c in He do
end
end
-- ID3v2 in front + garbage, truncated tail
do
local function frame(id: string, text: string): string
local body = "\3" .. text
@@ -77,7 +73,6 @@ do
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
@@ -94,14 +89,12 @@ do
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
+4 -10
View File
@@ -1,9 +1,6 @@
-- audio/ac3 tests: AC-3 streams from ffmpeg (every acmod with and without LFE, coupling incl. cplbegf 0, rematrixing,
-- 32 / 44.1 / 48 kHz) and aften (block switching, 1+1 dual mono, dynamic range profiles, the alternate BSI) against
-- ffmpeg's float decode, or liba52's for block-switched streams (SNR, max difference; dithflags cleared in the
-- fixture step so both sides decode the same numbers); dynamic range on; the encoders' dithered originals; AC-3 tracks
-- of MKV / MP4 / MPEG-TS / AVI through the api's audio hook; exact seeking; resync and truncation; error codes (E-AC-3,
-- CRC); the fuzz no-throw pass. Fixtures: tools/fixtures/ac3.py.
-- audio/ac3 tests: AC-3 streams from ffmpeg and aften against ffmpeg's float decode, or liba52's for block-switched
-- streams (dithflags cleared in the fixture step so both sides decode the same numbers).
-- Fixtures: tools/fixtures/ac3.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Ac3F = require("@rosetta/audio/ac3")
@@ -19,7 +16,6 @@ local function reader(s: string): Bytes.Reader
return Bytes.reader(buffer.fromstring(s))
end
-- SNR (dB) and the largest difference of interleaved f32 `got` against the f32le reference `ref`
local function compare(got: buffer, ref: string, count: number): (number, number)
local rb = buffer.fromstring(ref)
local n = math.min(count, #ref // 4, buffer.len(got) // 4)
@@ -104,7 +100,6 @@ do
end
end
-- resync over garbage, a truncated last frame, the raw codec API
do
local c = byName.stereo_44k
local a = Ac3F.decode(reader("\0\11\119garbage" .. c.data)) :: any
@@ -118,7 +113,6 @@ do
t:check(n == 1536 and d.channels == 2 and #d.pcm == 1536 * 2, "decoder: one syncframe")
end
-- errors
do
local c = byName.stereo_44k.data
t:eq(Ac3F.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV")
@@ -138,7 +132,7 @@ do
t:check(e and e.code == Err.LIMIT, "maxFrames: " .. tostring(e))
end
-- fuzz (without the CRC check, so mutations reach the decoder)
-- fuzz without the CRC check, so mutations reach the decoder
do
local samples = {}
for _, c in Fx do
+2 -7
View File
@@ -1,7 +1,5 @@
-- audio/adpcm tests: headerless streams (IMA nibbles, IMA WAV / MS blocks, Apple ima4, PS-ADPCM) decoded with the
-- layout in the options, bit-exact against ffmpeg / vgmstream (tools/fixtures/adpcm.py), with seeking; our encoder's
-- streams (ima, ms, ima_wav) as ffmpeg decodes them (wrapped in KVAG / WAV in the fixture step) against our decode of
-- the same bytes, and their quality; options and errors; the api by format name; the fuzz pass.
-- audio/adpcm tests: headerless ADPCM streams bit-exact against ffmpeg / vgmstream; our encoder's via ffmpeg.
-- Fixtures: tools/fixtures/adpcm.py.
local T = require("@tests/T")
local Raw = require("@rosetta/audio/adpcm")
local Bytes = require("@rosetta/core/Bytes")
@@ -47,7 +45,6 @@ for _, c in Cases do
end
t:note("%d raw streams bit-exact with ffmpeg / vgmstream", #Cases)
-- ------------------------------------------------------------------------------------------------ encoder
local function snr(x: buffer, y: buffer, count: number): number
local sig, err = 0, 0
for i = 0, count - 1 do
@@ -100,7 +97,6 @@ do
t:check(lo.frames == 6 and buffer.tostring(lo.samples) == buffer.tostring(hi.samples), "nibble order")
end
-- ------------------------------------------------------------------------------------------------ api
do
local c = Cases[1]
local a, err = F.audio.load(c.data, { format = "adpcm", codec = c.codec, sampleRate = c.rate, channels = c.ch })
@@ -110,7 +106,6 @@ do
t:check(out ~= nil and buffer.len(out) % 256 == 0, "F.save adpcm")
end
-- ------------------------------------------------------------------------------------------------ fuzz
local kinds = { "ima", "ima_wav", "ms", "ima_qt", "psx" }
local k = 0
t:fuzz("open + read + seek", function(b: buffer)
+2 -5
View File
@@ -1,6 +1,5 @@
-- audio/adx tests: ffmpeg's ADX files (version 3) and a version 4 file with history and loop points, bit-exact with
-- vgmstream (tools/fixtures/adx.py) through decode and open with seeks; our encoder's files as vgmstream decodes them
-- (equal to our decode, loops reported) and their quality; header errors; the api; the fuzz pass.
-- audio/adx tests: ffmpeg's ADX files and a version 4 file with loop points, bit-exact with vgmstream.
-- Fixtures: tools/fixtures/adx.py.
local T = require("@tests/T")
local Adx = require("@rosetta/audio/adx")
local Bytes = require("@rosetta/core/Bytes")
@@ -24,7 +23,6 @@ for _, c in Cases do
end
t:note("%d files bit-exact with vgmstream", #Cases)
-- ------------------------------------------------------------------------------------------------ encoder
local audio = Types.Audio.new(Sig.rate, Sig.channels, Sig.frames)
buffer.writestring(audio.samples, 0, Sig.data)
for _, c in Ours do
@@ -49,7 +47,6 @@ do
t:check(e3 and e3.code == Err.ARG, "bad cutoff")
end
-- ------------------------------------------------------------------------------------------------ errors
do
local base = Cases[1].data
local function patch(at: number, bytes: string): buffer
+1 -11
View File
@@ -1,6 +1,4 @@
-- audio/aiff tests: files written by ffmpeg and sox in every sample format (AIFF 8 / 12 / 16 / 24 / 32-bit, AIFF-C
-- sowt / fl32 / fl64 / ulaw / alaw / ima4, 6 channels, text chunks) against ffmpeg's decode; streaming reads and seeks;
-- our encoder's output for every sample format decoded by ffmpeg (fixture step) and by us; errors; fuzz.
-- audio/aiff tests: AIFF / AIFF-C files written by ffmpeg and sox against ffmpeg's decode; our encoder's via ffmpeg.
-- Fixtures: tools/fixtures/aiff.py.
local T = require("@tests/T")
local Aiff = require("@rosetta/audio/aiff")
@@ -16,7 +14,6 @@ local t = T.suite("aiff")
local function reader(s: string): Bytes.Reader
return Bytes.reader(buffer.fromstring(s))
end
-- max |a - b| over n f32 samples (a at byte ao, b at byte bo)
local function maxDiff(a: buffer, ao: number, b: buffer, bo: number, n: number): number
local m = 0
for i = 0, n - 1 do
@@ -28,12 +25,10 @@ local function maxDiff(a: buffer, ao: number, b: buffer, bo: number, n: number):
return m
end
-- the contract
t:eq(Aiff.name, "aiff", "name")
t:eq(Aiff.category, "audio", "category")
t:check(Aiff.caps.decode and Aiff.caps.encode and table.find(Aiff.extensions, "aif") ~= nil, "caps / extensions")
-- reference files: decode, stream, seek
for _, c in Cases do
local a, err = Aiff.decode(reader(c.data))
t:check(a, c.name .. ": " .. tostring(err))
@@ -63,7 +58,6 @@ for _, c in Cases do
end
t:note("%d reference files match ffmpeg", #Cases)
-- details of particular files
local function case(name: string): any
for _, c in Cases do
if c.name == name then
@@ -86,7 +80,6 @@ do
t:check(s12.meta.source.bitDepth == 12 and maxDiff(s12.samples, 0, buffer.fromstring(s16.ref), 0, s16.frames * 2) < 1e-6, "12-bit sample size")
local sw = Aiff.info(reader(case("ffmpeg-sowt").data))
t:check(sw and sw.compression == "sowt" and sw.format == "s16le", "info: sowt")
-- inside a bigger buffer
local c = case("ffmpeg-s16be")
local big = buffer.create(#c.data + 9)
buffer.writestring(big, 5, c.data)
@@ -114,7 +107,6 @@ for _, e in Enc do
end
t:note("%d encoder outputs read back by ffmpeg and by us", #Enc)
-- encoder: tags, odd sizes, errors
do
local a = Types.Audio.new(44100, 1, 3)
buffer.writef32(a.samples, 0, 0.5)
@@ -143,7 +135,6 @@ do
t:eq(Aiff.sniff(reader("")), 0, "sniff nothing")
end
-- errors
do
local _, e = Aiff.decode(reader("FORM\0\0\0\4WAVE"))
t:check(e and e.code == Err.CORRUPT, "wrong FORM type: " .. tostring(e))
@@ -160,7 +151,6 @@ do
t:check(e4 and e4.code == Err.LIMIT, "maxFrames: LIMIT")
end
-- fuzz
do
local samples = {}
for i, c in Cases do
+2 -8
View File
@@ -1,8 +1,5 @@
-- audio/ape tests: every fixture from tools/fixtures/ape.py (mac -c1000 .. -c5000, 8 - 32-bit int and 32-bit float,
-- 1 - 8 channels, special frames (silence, pseudo stereo), odd rates and lengths, a second frame, APEv2 tags, the FATE
-- sample of an older 3.99 encoder cut mid-frame) decoded bit-exact against `mac -d`; seeking; f32 scaling and output
-- reuse; decode() from a sub-range Reader; an ID3v2 tag in front; the header facts; sniff; the api; a damaged frame
-- (CRC); the fuzz pass. Fixtures: tools/fixtures/ape.py.
-- audio/ape tests: tools/fixtures/ape.py's files (mac -c1000 .. -c5000, a FATE 3.99 sample) bit-exact against `mac -d`.
-- Fixtures: tools/fixtures/ape.py.
local T = require("@tests/T")
local Ape = require("@rosetta/audio/ape")
local Bytes = require("@rosetta/core/Bytes")
@@ -30,7 +27,6 @@ for _, name in { "s16_c2000", "tags", "f32", "ch6" } do
L.subrange(t, Ape, byName[name], "ape")
end
-- header facts
do
local d = open(byName.s16_c5000.data)
t:eq(d.level, "insane", "level")
@@ -50,7 +46,6 @@ do
t:check(dec and (L.all(dec, fx)) == fx.crc, "ID3v2 in front")
end
-- the api
do
local fx = byName.s16_c2000
local _ = fx
@@ -79,7 +74,6 @@ do
t:eq(Ape.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF")
end
-- the fuzz pass
local samples = {}
for _, name in { "s16_c2000", "s16_c4000", "mono", "s24", "s32", "f32", "ch6", "silence", "pseudo_stereo" } do
table.insert(samples, buffer.fromstring(byName[name].data))
+2 -3
View File
@@ -1,6 +1,5 @@
-- audio/au tests: files written by ffmpeg and sox in every encoding (8 / 16 / 24 / 32-bit, float, double, mu-law,
-- A-law, an annotation) against ffmpeg's decode; streaming reads and seeks; our encoder's output for every encoding
-- decoded by ffmpeg (fixture step) and by us; an unknown data size; errors; fuzz. Fixtures: tools/fixtures/au.py.
-- audio/au tests: files written by ffmpeg and sox against ffmpeg's decode; our encoder's output via ffmpeg.
-- Fixtures: tools/fixtures/au.py.
local T = require("@tests/T")
local Au = require("@rosetta/audio/au")
local Bytes = require("@rosetta/core/Bytes")
+2 -3
View File
@@ -1,6 +1,5 @@
-- audio/brstm tests: BRSTM / BCSTM / BFSTM files (DSP ADPCM, PCM16, PCM8; big- and little-endian; loops) from our
-- Python writer, bit-exact with vgmstream (tools/fixtures/brstm.py) through decode and open with seeks (forward seeks
-- start from the ADPC / SEEK history table); errors; the api; the fuzz pass.
-- audio/brstm tests: BRSTM / BCSTM / BFSTM files from our Python writer, bit-exact with vgmstream (forward seeks
-- start from the ADPC / SEEK history table). Fixtures: tools/fixtures/brstm.py.
local T = require("@tests/T")
local Brstm = require("@rosetta/audio/brstm")
local Bytes = require("@rosetta/core/Bytes")
+2 -7
View File
@@ -1,7 +1,5 @@
-- 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.
-- audio/caf tests: ALAC CAF from ffmpeg bit-exact; AAC CAF against ffmpeg's float decode; our writer's bytes.
-- Fixtures: tools/fixtures/m4a.py.
local T = require("@tests/T")
local Caf = require("@rosetta/audio/caf")
local Bytes = require("@rosetta/core/Bytes")
@@ -128,7 +126,6 @@ do
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
@@ -145,7 +142,6 @@ do
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"))
@@ -154,7 +150,6 @@ do
t:check(e2 and e2.code == Err.ARG, "bad codec: " .. tostring(e2))
end
-- fuzz
do
local samples = {}
for _, c in Alac do
+4 -13
View File
@@ -1,8 +1,5 @@
-- audio/flac tests: every fixture from tools/fixtures/flac.py (flac 0-8, 4-32 bits, 1-6 channels, odd rates and block
-- sizes, LPC order 32, wasted bits, every stereo mode, ffmpeg's encoder, Ogg FLAC, ID3v2 in front) decoded bit-exact
-- against `flac -d`; sample-accurate seeking; f32 scaling and output reuse; decode() to an Audio from a sub-range
-- Reader; tags and pictures; the length from the last frame; sniff; the api; damaged frames skipped; the fuzz pass.
-- Ported from flac-luau tests/flac.luau. Fixtures: tools/fixtures/flac.py.
-- audio/flac tests: tools/fixtures/flac.py's files (flac 0-8, ffmpeg's encoder, Ogg FLAC) bit-exact against `flac -d`.
-- Fixtures: tools/fixtures/flac.py.
local T = require("@tests/T")
local VorbisComment = require("@rosetta/codecs/audio/VorbisComment")
local Flac = require("@rosetta/audio/flac")
@@ -23,7 +20,7 @@ for _, c in Cases do
end
t:eq(Flac.name, "flac", "name")
t:check(Flac.caps.decode and Flac.caps.encode, "caps") -- encode: ws-audio (tests/audio/flac_encode.luau)
t:check(Flac.caps.decode and Flac.caps.encode, "caps")
local seekChecks = 0
for _, fx in Cases do
@@ -53,7 +50,6 @@ for _, fx in Cases do
t:eq(n, fx.frames, name .. ": decoded frames")
t:eq(crc, fx.crc, name .. ": samples identical to flac -d")
t:eq(select(2, dec:position()), fx.frames, name .. ": position at end")
-- f32 scaling, output reuse
dec:seekSample(0)
local reuse = buffer.create(100 * ch * 4)
local f, gotf = dec:read(100, reuse)
@@ -66,7 +62,6 @@ for _, fx in Cases do
end
end
t:eq(bad, 0, name .. ": f32 samples")
-- seeking
local rand = T.rng(99)
local targets = { 0, 1, fx.frames - 1, fx.frames // 2, 4096, 4095, 4097, 1152, 1151 }
for _ = 1, 12 do
@@ -100,7 +95,6 @@ for _, fx in Cases do
end
t:note("%d fixtures bit-exact against flac -d, %d seeks", #Cases, seekChecks)
-- decode() from a sub-range Reader
for _, name in { "s16_l5", "ogg_s16", "id3", "s24_96k" } do
local fx = byName[name]
local big = buffer.create(#fx.data + 13)
@@ -113,7 +107,6 @@ for _, name in { "s16_l5", "ogg_s16", "id3", "s24_96k" } do
t:eq(a.meta.source.bitDepth, fx.bps, name .. ": meta.source")
end
-- tags and pictures
do
local dec = open(byName.s16_noseek.data)
t:check(#dec.pictures == 1 and dec.pictures[1].mime == "image/png" and dec.pictures[1].width == 1, "picture")
@@ -142,7 +135,6 @@ for _, name in { "s16_l5", "varblock", "bs17" } do
t:check(n == fx.frames and crc == fx.crc, name .. ": decode without total length")
end
-- sniff, errors, the api
do
t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xxfLaC"))), 1, "sniff ID3 + fLaC")
t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xx\255\251"))), 0, "sniff ID3 + mp3")
@@ -157,7 +149,7 @@ do
t:check(a and a.frames == fx.frames, "F.audio.load")
local d = F.audio.open(byName.s16_l3.data)
t:check(d and d.frames == byName.s16_l3.frames, "F.audio.open")
local saved, se = F.save(a, nil, { format = "flac" }) -- the encoder (ws-audio)
local saved, se = F.save(a, nil, { format = "flac" })
t:check(saved and F.audio.load(saved).frames == fx.frames, "F.save flac: " .. tostring(se))
end
@@ -178,7 +170,6 @@ do
t:check(total < d.frames and total >= d.frames - 2 * 4096, "one damaged frame dropped: " .. total)
end
-- fuzz
local samples = {}
for _, name in { "s16_l5", "ogg_s16", "id3", "varblock", "s32_rice2", "u8_mono", "bits4" } do
table.insert(samples, byName[name].data)
+2 -5
View File
@@ -1,7 +1,5 @@
-- audio/flac encoder tests: every fixture-step encode (levels 0-8, 1 / 2 / 6 channels, 8 / 12 / 16 / 20 / 24 bits,
-- odd lengths and block sizes, odd rates, seek tables, padding) passed `flac -t` and carries the MD5 of the quantized
-- input; sizes within 10% of libFLAC at the same level; each decodes bit-exactly through our own decoder; streaming
-- from a Decoder gives the same bytes; tags; option errors. Fixtures: tools/fixtures/flac_enc.py.
-- audio/flac encoder tests: each fixture-step encode passed `flac -t`, has the input's MD5, is within 10% of libFLAC.
-- Fixtures: tools/fixtures/flac_enc.py.
local T = require("@tests/T")
local Flac = require("@rosetta/audio/flac")
local Bytes = require("@rosetta/core/Bytes")
@@ -88,7 +86,6 @@ do
t:check(e0 and e0.frames == 0, "empty audio")
end
-- errors
do
local a = Types.Audio.new(44100, 2, 10)
local function code(v: any, o: any): string?
+2 -14
View File
@@ -1,8 +1,5 @@
-- 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.
-- audio/m4a tests: ALAC from ffmpeg bit-exact; AAC from ffmpeg and fdkaac against ffmpeg's float decode (gapless).
-- our ALAC writer's bytes as ffmpeg decoded them bit-exactly and MP4Box accepted in the fixture step.
-- Fixtures: tools/fixtures/m4a.py.
local T = require("@tests/T")
local M4a = require("@rosetta/audio/m4a")
@@ -22,7 +19,6 @@ 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)
@@ -49,12 +45,10 @@ local function snr(a: any, ref: string): (number, number)
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
@@ -70,7 +64,6 @@ for _, c in Alac do
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
@@ -102,7 +95,6 @@ for _, c in He do
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
@@ -141,7 +133,6 @@ do
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") } }
@@ -164,7 +155,6 @@ 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)
@@ -188,7 +178,6 @@ for _, c in { Aac[1], Alac[1] } do
end
end
-- errors
do
local _, e = M4a.decode(reader("\0\0\0\8ftypM4A "))
t:check(e ~= nil, "a lone ftyp: " .. tostring(e))
@@ -197,7 +186,6 @@ do
t:eq(M4a.sniff(reader("hello")), 0, "sniff junk")
end
-- fuzz
do
local samples = {}
for i, c in Alac do
+4 -17
View File
@@ -1,8 +1,5 @@
-- audio/mp3 tests: every fixture against its minimp3 reference decode (exact length, SNR > 90 dB on windows, block
-- energies) and against ffmpeg (length, SNR > 75 dB), lame-written streams against ffmpeg; chunked reads, reads into
-- a caller buffer, sample-accurate seeking; robustness (garbage, corruption, truncation, mono / stereo switches, API
-- misuse); ID3v1 / v2.2 / 2.3 / 2.4 and APE tags; the contract, sniff, decode to Audio, the fuzz no-throw pass.
-- Ported from mp3-luau tests/decode.luau, robust.luau, tags.luau. Fixtures: tools/fixtures/mp3.py.
-- audio/mp3 tests: every fixture against its minimp3 reference decode (SNR > 90 dB) and ffmpeg (SNR > 75 dB).
-- Fixtures: tools/fixtures/mp3.py.
local T = require("@tests/T")
local Mp3 = require("@rosetta/audio/mp3")
local Bytes = require("@rosetta/core/Bytes")
@@ -78,13 +75,11 @@ end
local rand = T.rng(12345)
-- ------------------------------------------------------------------------------------------------ contract
t:eq(Mp3.name, "mp3", "name")
t:eq(Mp3.category, "audio", "category")
t:check(table.find(Mp3.extensions, "mp3") ~= nil and table.find(Mp3.extensions, "mp2") ~= nil, "extensions")
t:check(Mp3.caps.decode and Mp3.caps.encode and Mp3.open ~= nil, "caps") -- encode: ws-audio (tests/audio/mp3_encode.luau)
t:check(Mp3.caps.decode and Mp3.caps.encode and Mp3.open ~= nil, "caps")
-- ------------------------------------------------------------------------------------------------ decode vs references
for _, c in Cases do
local name = c.name
local buf = buffer.fromstring(c.data)
@@ -105,7 +100,6 @@ for _, c in Cases do
t:eq(dec.frames, c.ffFrames, name .. ": frames vs ffmpeg")
t:check(dec.bitrate > 0, name .. ": bitrate")
-- whole decode in chunks of varied sizes
local all = buffer.create(dec.frames * ch * 4)
local total = 0
while true do
@@ -184,7 +178,6 @@ for _, c in Cases do
local pcm0, n3 = dec:read(256)
t:check(n3 == 256 and maxDiff(pcm0, 0, all, 0, 256 * ch) == 0, name .. ": seek back to the start")
-- decode to Audio, also from a sub-range of a bigger buffer
local big = buffer.create(buffer.len(buf) + 17)
buffer.copy(big, 9, buf)
local a, aerr = Mp3.decode(Bytes.reader(big, 9, buffer.len(buf)))
@@ -196,7 +189,6 @@ for _, c in Cases do
t:note("%-20s L%d MPEG-%s %5d Hz %d ch %6d frames %3d kbps SNR minimp3 %s, ffmpeg %.1f dB", name, dec.layer, tostring(dec.version), dec.sampleRate, ch, dec.frames, dec.bitrate // 1000, if ref then string.format("%.1f", worst) else "-", worstFF)
end
-- ------------------------------------------------------------------------------------------------ robustness
local function concat(...: buffer): buffer
local n = 0
for _, b in { ... } do
@@ -215,7 +207,6 @@ local function slice(b: buffer, i: number, j: number): buffer
buffer.copy(out, 0, b, i, j - i)
return out
end
-- decodes everything; checks every sample is finite; returns pcm, frames, decoder
local function decodeAll(b: buffer, label: string): (buffer?, number, any)
local ok, dec, err = pcall(open, b)
t:check(ok, label .. ": open does not throw (" .. tostring(dec) .. ")")
@@ -303,7 +294,6 @@ do
end
t:check(same, "switch: mono part duplicated")
end
-- bad input and API misuse
do
local d, err = open(buffer.create(0))
t:check(d == nil and Err.is(err) and err.code == Err.CORRUPT, "empty buffer")
@@ -333,7 +323,6 @@ do
t:eq(Mp3.sniff(Bytes.reader(buffer.create(0))), 0, "sniff nothing")
end
-- ------------------------------------------------------------------------------------------------ tags
local function eq(a: any, b: any, label: string)
t:eq(a, b, label)
end
@@ -478,7 +467,6 @@ do
t:check(dec == nil or dec.frames <= plain.frames, "truncated tag")
end
-- ------------------------------------------------------------------------------------------------ through the api
do
local F = require("@rosetta")
local data = byName.l3_tags.data
@@ -487,11 +475,10 @@ do
t:check(a and a.kind == "audio" and a.frames == 22050 and a.tags.title == "Test Title", "F.audio.load: " .. tostring(err))
local dec = F.audio.open(data)
t:check(dec and dec.sampleRate == 44100 and dec.frames == 22050, "F.audio.open")
local saved, serr = F.save(a, nil, { format = "mp3" }) -- the layer III encoder (ws-audio)
local saved, serr = F.save(a, nil, { format = "mp3" })
t:check(saved and F.audio.load(saved).sampleRate == 44100, "F.save mp3: " .. tostring(serr))
end
-- ------------------------------------------------------------------------------------------------ fuzz
do
local samples = {}
for _, name in { "l3_cbr32_mono", "l3_mpeg2_22k", "l3_mpeg25_8k", "l2_64_mono", "l2_mpeg2_24k", "l3_tags", "lame_cbr64_mono_22k" } do
+3 -10
View File
@@ -1,7 +1,5 @@
-- audio/mp3 encoder tests (layer III and layer II): every fixture-step encode (sample rates of MPEG-1 / 2 / 2.5,
-- bit rates 24 .. 384 kbps, stereo / joint / mono) decodes in ffmpeg without errors and in LAME, with the expected
-- length and an SNR over a per-bit-rate floor after aligning the decoder delay; our own decoder (the minimp3 port)
-- agrees; streaming from a Decoder gives the same bytes; the ID3v2 tag round-trips; option errors.
-- audio/mp3 encoder tests (layer III and II): fixture-step encodes decode in ffmpeg and LAME, SNR over a per-bit-rate
-- floor after aligning the decoder delay.
-- Fixtures: tools/fixtures/mp3_enc.py.
local T = require("@tests/T")
local Mp3 = require("@rosetta/audio/mp3")
@@ -21,7 +19,6 @@ local function audio(name: string): Types.Audio
return a
end
-- SNR of y (delayed by lag frames) against x over frames [from, to)
local function snr(x: Types.Audio, y: Types.Audio, lag: number, from: number, to: number): number
local ch = x.channels
local sig, er = 0, 0
@@ -85,7 +82,6 @@ for _, e in Enc do
if f > -math.huge then
minByLayer[e.layer] = math.min(minByLayer[e.layer], e.ffSnr)
end
-- our decoder agrees with ffmpeg
local x = audio(e.sig)
local y, err = Mp3.decode(Bytes.reader(buffer.fromstring(e.data)))
t:check(y, e.name .. ": our decoder: " .. tostring(err))
@@ -96,7 +92,6 @@ for _, e in Enc do
end
t:note("%d encodes: ffmpeg + LAME decode them; lowest SNR layer III %.1f dB, layer II %.1f dB", #Enc, minByLayer[3], minByLayer[2])
-- streaming, tags, defaults
do
local a = audio("music_2_44100")
local f1 = Mp3.encode(a, { bitrate = 128 }) :: buffer
@@ -128,8 +123,7 @@ do
t:check(empty and buffer.len(empty) > 0, "empty input: one flush frame")
end
-- other input rates are resampled (codecs/audio/Resample) to the next rate up: 44 kHz -> 44.1 kHz, 46 kHz -> 48 kHz,
-- layer II 8 kHz -> 16 kHz, opts.sampleRate
-- other input rates are resampled to the next rate up (codecs/audio/Resample)
do
local function tone(rate: number, f: number): any
local n = rate
@@ -166,7 +160,6 @@ do
end
end
-- errors
do
local function code(v: any, o: any): string?
local _, e = Mp3.encode(v, o)
+3 -10
View File
@@ -1,7 +1,5 @@
-- audio/mpc tests: Musepack SV8 (mpcenc 1.30: stereo / mono, 32 / 44.1 / 48 kHz, quality 1 .. 9, 1 / 4 / 16 / 64
-- frames per packet) and SV7 (mppenc 1.16, quality 2 / 5 / 8) against libmpcdec's float output (mpcf32: gapless
-- length, near bit-exact) and ffmpeg's decode (SNR); APEv2 tags; seeking (SV8 exact, SV7 like libmpcdec); a leading
-- ID3v2 tag; truncated files; error codes; the fuzz no-throw pass. Fixtures: tools/fixtures/mpc.py.
-- audio/mpc tests: Musepack SV8 (mpcenc 1.30) and SV7 (mppenc 1.16) against libmpcdec's float output and ffmpeg.
-- Fixtures: tools/fixtures/mpc.py.
local T = require("@tests/T")
local Mpc = require("@rosetta/audio/mpc")
local Bytes = require("@rosetta/core/Bytes")
@@ -15,7 +13,6 @@ local function reader(s: string): Bytes.Reader
return Bytes.reader(buffer.fromstring(s))
end
-- SNR (dB) and the largest difference of frames [from, to) of got against a f32le reference (frames from 0)
local function compare(got: buffer, gotFrom: number, ref: string, ch: number, frames: number): (number, number)
local rb = buffer.fromstring(ref)
local n = math.min(frames * ch, #ref // 4)
@@ -64,8 +61,7 @@ for _, c in Fx do
end
end
-- seeking: SV8 is exact (one packet of pre-roll); SV7 decodes like libmpcdec's seek (32 frames of pre-roll from reset
-- scalefactors)
-- SV8 seeks exactly; SV7 like libmpcdec's seek (32 frames of pre-roll from reset scalefactors)
for _, sk in Seek do
local c = byName[sk.name]
local whole = Mpc.decode(reader(c.data)) :: any
@@ -94,7 +90,6 @@ for _, sk in Seek do
t:check(n0 == 1000 and d0 < 1e-5, sk.name .. ": seek back to 0")
end
-- an ID3v2 tag in front; truncated files
do
local c = byName.sv8_q5_stereo
local id3 = "ID3\3\0\0\0\0\0\20" .. string.rep("\0", 20)
@@ -112,7 +107,6 @@ do
end
end
-- errors
do
local c8, c7 = byName.sv8_q5_stereo.data, byName.sv7_q5_stereo.data
t:eq(Mpc.sniff(reader("RIFF....WAVE")), 0, "sniff a WAV")
@@ -131,7 +125,6 @@ do
t:check(e and e.code == Err.LIMIT, "maxFrames: " .. tostring(e))
end
-- fuzz
do
local samples = {}
for _, c in Fx do
+3 -18
View File
@@ -1,9 +1,5 @@
-- audio/opus tests: every fixture (opusenc / ffmpeg libopus: CELT frame sizes and bitrates, SILK NB / MB / WB, hybrid,
-- mode transitions, 5.1 multistream, a long tagged file) through open / read against opusdec --float (frame counts,
-- SNR per fixture), CELT-only and SILK-only decoding with the private decoders alone, SILK packet loss concealment,
-- tags, seeking, the stereo downmix, decode() to an Audio, the contract, sniff, error codes, random / bit-flipped
-- packets through the packet decoder, and the fuzz no-throw pass over whole files.
-- Ported from opus-luau tests/opus.luau, celt.luau, silk.luau, fuzz.luau. Fixtures: tools/fixtures/opus.py.
-- audio/opus tests: every fixture (opusenc / ffmpeg libopus) against opusdec --float (frame counts, SNR per fixture).
-- Fixtures: tools/fixtures/opus.py.
local T = require("@tests/T")
local Opus = require("@rosetta/audio/opus")
local Packet = require("@rosetta/codecs/audio/Opus/Packet")
@@ -58,7 +54,6 @@ do
Pcm.reorder(fx.ref, 0, buffer.len(fx.ref) // 24, 6, Pcm.WAVE_FROM_VORBIS[6])
end
-- SNR in dB of f32 samples against a reference over n samples; returns snr, max abs error
local function snr(out: buffer, ref: buffer, n: number, outOff: number?, refOff: number?): (number, number)
local oo, ro = outOff or 0, refOff or 0
local sig, err, maxe = 0, 0, 0
@@ -77,7 +72,6 @@ local function snr(out: buffer, ref: buffer, n: number, outOff: number?, refOff:
return 10 * math.log10(sig / err), maxe
end
-- the packets of the first stream: { data, offset, size }
local function packets(buf: buffer): { any }
local d = Ogg.open(buf)
local out = {}
@@ -87,7 +81,6 @@ local function packets(buf: buffer): { any }
return out
end
-- ------------------------------------------------------------------------------------------------ contract
t:eq(Opus.name, "opus", "name")
t:eq(Opus.category, "audio", "category")
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)")
@@ -95,7 +88,6 @@ 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")
-- ------------------------------------------------------------------------------------------------ open / read vs opusdec
-- name, minimum SNR (dB). CELT is float-exact (> 130 dB in practice), SILK bit-exact; hybrid / transitions mix both.
local cases = {
{ "celt_st_128", 100 }, { "celt_st_32", 100 }, { "celt_st_64", 100 }, { "celt_st_256", 100 },
@@ -134,7 +126,6 @@ for _, case in cases do
t:check(math.abs(dec:position() - dec.duration) < 1e-9, name .. ": position at end")
end
-- read into a caller buffer, decode() to an Audio, a sub-range Reader
do
local fx = FX.hybrid_st
local dec = Opus.open(Bytes.reader(fx.data))
@@ -151,7 +142,6 @@ do
t:eq(a.meta.source.format, "opus", "decode: meta.source")
end
-- ------------------------------------------------------------------------------------------------ tags, seeking
do
local dec = Opus.open(Bytes.reader(FX.long_128.data))
t:eq(dec.tags.title, "Long Test", "tags: title")
@@ -203,7 +193,6 @@ do
t:check(db > 100, string.format("downmix SNR %.1f", db))
end
-- ------------------------------------------------------------------------------------------------ CELT alone
do
local endbands = { [Packet.BW_NB] = 13, [Packet.BW_MB] = 17, [Packet.BW_WB] = 17, [Packet.BW_SWB] = 19, [Packet.BW_FB] = 21 }
for _, name in { "celt_st_128", "celt_st_32", "celt_st_64", "celt_st_256", "celt_mono_64", "celt_fs2_5", "celt_fs5", "celt_fs10", "celt_fs40", "celt_fs60", "ff_cbr", "ff_lowdelay" } do
@@ -243,7 +232,6 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ SILK alone
do
local rates = { [Packet.BW_NB] = 8000, [Packet.BW_MB] = 12000, [Packet.BW_WB] = 16000 }
local function decodeSilk(name: string, hybridOk: boolean?, lose: boolean?): ({ number }, number, number, number)
@@ -323,7 +311,6 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ errors
do
local d, err = Opus.open(Bytes.reader(buffer.fromstring("not an ogg file at all")))
t:check(d == nil and err and err.code == Err.CORRUPT, "garbage is CORRUPT: " .. tostring(err))
@@ -371,8 +358,7 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ packet fuzz
-- random packets (every TOC config, random payloads) and bit-flipped real packets: never throw, output finite
-- random packets (every TOC config) and bit-flipped real packets: never throw, output finite
do
local rand = T.rng(987654321)
local pcm = table.create(5760 * 2, 0)
@@ -431,7 +417,6 @@ do
t:note("packet fuzz: %d packets decoded, %d rejected", decoded, rejected)
end
-- ------------------------------------------------------------------------------------------------ fuzz (whole files)
do
local samples = {}
for _, name in { "hybrid_fb", "silk_nb", "celt_fs5" } do
+1 -9
View File
@@ -1,7 +1,4 @@
-- 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.
-- audio/opus encoder tests (CELT-only): our Ogg Opus decodes in opusdec to the input's exact length, opusinfo-clean.
-- Fixtures: tools/fixtures/opus_celt.py.
local T = require("@tests/T")
local Opus = require("@rosetta/audio/opus")
@@ -46,7 +43,6 @@ for _, c in Cases.list do
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)
@@ -66,7 +62,6 @@ for _, c in Cases.list do
end
end
-- silence frames decode to silence
do
local c = Cases.list[1]
local ref = buffer.fromstring(byName[c.name].opusdec)
@@ -77,7 +72,6 @@ do
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
@@ -90,7 +84,6 @@ do
t:check(kb ~= nil and buffer.tostring(kb :: buffer) == buffer.tostring(again :: buffer), "bitrate 64 = 64000 bit/s")
end
-- errors
do
local three = Cases.signal({ rate = 48000, channels = 3, seconds = 0.05 })
local _, e = Opus.encode(three)
@@ -101,7 +94,6 @@ do
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
+2 -6
View File
@@ -1,7 +1,5 @@
-- audio/qoa tests: files written by qoa.h (tools/fixtures/qoa.py; 1, 2 and 6 channels, a frame boundary, a partial
-- last slice, clipping signals) decoded bit-exact against ffmpeg and qoa.h; our encoder byte-for-byte equal to
-- qoa.h's qoa_encode, from an Audio and from a streaming Decoder; seeking; streaming files (total 0); a cut file; errors;
-- the api; the fuzz pass.
-- audio/qoa tests: qoa.h's files bit-exact against ffmpeg and qoa.h; our encoder byte-for-byte equal to qoa_encode.
-- Fixtures: tools/fixtures/qoa.py.
local T = require("@tests/T")
local Qoa = require("@rosetta/audio/qoa")
local Bytes = require("@rosetta/core/Bytes")
@@ -51,7 +49,6 @@ for _, c in Cases do
end
t:note("%d qoa.h files decoded bit-exact (ffmpeg, qoa.h) and re-encoded byte-for-byte", #Cases)
-- ------------------------------------------------------------------------------------------------ variants
do
local c = Cases[1]
local ref = buffer.fromstring(c.ref)
@@ -64,7 +61,6 @@ do
-- a cut file keeps its whole frames
local cut = Qoa.decode(Bytes.reader(buffer.fromstring(string.sub(c.data, 1, #c.data - 100)))) :: any
t:check(cut and cut.frames == 5120 * 2 and H.same(cut.samples, ref, 0, cut.frames * c.ch), "cut file: the whole frames")
-- errors
local _, e1 = Qoa.open(Bytes.reader(buffer.fromstring("qoaf\0\0\0\1")))
t:check(e1 and e1.code == Err.TRUNCATED, "no frames: " .. tostring(e1))
local bad = buffer.fromstring(c.data)
+3 -7
View File
@@ -1,8 +1,5 @@
-- audio/tta tests: every fixture from tools/fixtures/tta.py (ttaenc 3.4.1: 8 / 16 / 24 bits, 1 - 6 channels, odd
-- rates and lengths, several frames, silence, noise; the FATE sample inside.tta cut mid-file) decoded bit-exact
-- against `ttaenc -d`; seeking; f32 scaling and output reuse; decode() from a sub-range Reader; an ID3v2 tag in front
-- and an APEv2 tag at the end; password-protected files (UNSUPPORTED); header / seek table / frame CRCs; sniff; the
-- api; the fuzz pass. Fixtures: tools/fixtures/tta.py.
-- audio/tta tests: tools/fixtures/tta.py's files (ttaenc 3.4.1, FATE's inside.tta) bit-exact against `ttaenc -d`.
-- Fixtures: tools/fixtures/tta.py.
local T = require("@tests/T")
local Tta = require("@rosetta/audio/tta")
local Bytes = require("@rosetta/core/Bytes")
@@ -72,7 +69,6 @@ do
t:eq(Tta.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF")
end
-- the api
do
local fx = byName.s16
t:eq(F.detect(buffer.fromstring(fx.data)), "tta", "detect")
@@ -80,7 +76,7 @@ do
t:check(a and a.frames == fx.frames and a.meta.source.format == "tta", "F.audio.load")
end
-- the fuzz pass (the frame CRC rejects most mutations; the second set skips it to reach the decoder)
-- the frame CRC rejects most mutations; the second fuzz set skips it to reach the decoder
local samples = {}
for _, name in { "s16", "mono", "s24", "u8", "ch6" } do
table.insert(samples, buffer.fromstring(byName[name].data))
+2 -5
View File
@@ -1,6 +1,5 @@
-- audio/vag tests: VAGp (with and without loop flags), VAGi and KVAG files from our Python encoders, bit-exact with
-- vgmstream / ffmpeg (tools/fixtures/vag.py) through decode and open with seeks; our encoder's files as vgmstream
-- decodes them (loops reported where vgmstream reads them), their quality; errors; the api; the fuzz pass.
-- audio/vag tests: VAGp, VAGi and KVAG files from our Python encoders, bit-exact with vgmstream / ffmpeg.
-- Fixtures: tools/fixtures/vag.py.
local T = require("@tests/T")
local Vag = require("@rosetta/audio/vag")
local Bytes = require("@rosetta/core/Bytes")
@@ -27,7 +26,6 @@ for _, c in Cases do
end
t:note("%d files bit-exact with vgmstream / ffmpeg", #Cases)
-- ------------------------------------------------------------------------------------------------ encoder
local function audioOf(S: any): any
local a = Types.Audio.new(S.rate, S.channels, S.frames)
buffer.writestring(a.samples, 0, S.data)
@@ -57,7 +55,6 @@ do
t:check(e3 and e3.code == Err.ARG, "bad interleave")
end
-- ------------------------------------------------------------------------------------------------ errors
do
local base = Cases[1].data
local hevag = buffer.fromstring(base)
+1 -4
View File
@@ -1,6 +1,4 @@
-- audio/voc tests: files written by ffmpeg (type 1 + 8 blocks for 8-bit, type 9 otherwise) and sox against ffmpeg's
-- decode; silence / text / continuation blocks and repeat markers built here; streaming reads and seeks; our
-- encoder's output for every sample format decoded by ffmpeg (fixture step) and by us; errors; fuzz.
-- audio/voc tests: files written by ffmpeg and sox against ffmpeg's decode; our encoder's output via ffmpeg.
-- Fixtures: tools/fixtures/voc.py.
local T = require("@tests/T")
local Voc = require("@rosetta/audio/voc")
@@ -45,7 +43,6 @@ for _, c in Cases do
end
t:note("%d reference files match ffmpeg", #Cases)
-- hand-built blocks: text, type 1 u8, silence, continuation, repeat markers, terminator
do
local hdr = "Creative Voice File\26\26\0\10\1\41\17"
local function blk(typ: number, payload: string): string
+2 -8
View File
@@ -1,7 +1,5 @@
-- audio/vorbis tests: oggenc / ffmpeg streams (qualities -1 .. 10, managed bitrate, 8 .. 96 kHz, mono / stereo / 5.1,
-- transients, silence, tags, sub-block lengths) against oggdec (libvorbisfile: sample counts and 16-bit samples, so
-- start / end trimming is exact) and ffmpeg's f32 decode (SNR); streaming reads; seeking (sample-exact against the
-- reference at the target); the packet-level decoder; errors; fuzz. Fixtures: tools/fixtures/vorbis.py.
-- audio/vorbis tests: oggenc / ffmpeg streams against oggdec (16-bit, exact trimming) and ffmpeg's f32 decode (SNR).
-- Fixtures: tools/fixtures/vorbis.py.
local T = require("@tests/T")
local Vorbis = require("@rosetta/audio/vorbis")
local Bytes = require("@rosetta/core/Bytes")
@@ -20,7 +18,6 @@ local function s16(x: number): number
local v = math.floor(x * 32768 + 0.5)
return math.clamp(v, -32768, 32767)
end
-- the largest |our sample as s16 - oggdec's| over n samples of ours at byte a0 against ref16 from sample r0
local function maxDiff16(a: buffer, a0: number, ref: buffer, r0: number, n: number): number
local m = 0
for i = 0, n - 1 do
@@ -76,7 +73,6 @@ for _, c in Cases do
minSnr = math.min(minSnr, s)
t:check(s > 100, string.format("%s: SNR vs ffmpeg %.1f dB", c.name, s))
end
-- streaming in odd chunks gives the same samples
local dec = Vorbis.open(reader(c.data)) :: Types.Decoder
t:eq(dec.frames, c.frames, c.name .. ": Decoder.frames")
local got, ok = 0, true
@@ -117,7 +113,6 @@ local function case(name: string): any
error("no case " .. name)
end
-- tags, meta, sniff, sub-range
do
local c = case("q2-stereo-32k-tags")
local dec = Vorbis.open(reader(c.data)) :: any
@@ -164,7 +159,6 @@ do
t:check(e and e.code == Err.CORRUPT, "packetDecoder with headers swapped")
end
-- errors
do
local _, e1 = Vorbis.decode(reader("OggS but not really"))
t:check(e1 and Err.is(e1), "junk: " .. tostring(e1))
+2 -6
View File
@@ -1,7 +1,5 @@
-- audio/vorbis encoder tests: every fixture-step encode (qualities -1 .. 10, mono / stereo / 5.1, 8 .. 96 kHz, odd
-- lengths, silence) passes ogginfo, decodes in oggdec (libvorbisfile) with the exact input length and an SNR over a
-- per-quality floor, and in ffmpeg; our own decoder gives the same; the codebooks are valid prefix codes; streaming
-- from a Decoder gives the same bytes; tags round-trip; option errors. Fixtures: tools/fixtures/vorbis_enc.py.
-- audio/vorbis encoder tests: each fixture-step encode passes ogginfo, decodes in oggdec with the exact length and
-- an SNR over a per-quality floor, and in ffmpeg. Fixtures: tools/fixtures/vorbis_enc.py.
local T = require("@tests/T")
local Vorbis = require("@rosetta/audio/vorbis")
local VEnc = require("@rosetta/audio/vorbis/Encode")
@@ -75,7 +73,6 @@ for _, e in Enc do
end
t:note("%d encodes pass ogginfo / oggdec / ffmpeg; lowest SNR %.1f dB", #Enc, minSnr)
-- streaming, tags
do
local a = audio("music_2_3000_44100")
local f1 = Vorbis.encode(a) :: buffer
@@ -92,7 +89,6 @@ do
t:check(e0 and e0.frames == 0, "empty input")
end
-- errors
do
local a = Types.Audio.new(44100, 2, 10)
local function code(v: any, o: any): string?
+5 -19
View File
@@ -1,9 +1,5 @@
-- audio/wav tests: every format / container / damaged variant from tools/fixtures/wav.py decoded in reads of mixed
-- sizes against ffmpeg's (or sox's) f32 decode, with tags, seeking and output-buffer reuse; hand-built files (header
-- parsing, errors, argument clamping, EXTENSIBLE with valid bits, the truncated flag); the encoder byte-exact against
-- ffmpeg -bitexact (u8 / s16 / s24 / s32 / f32, 1-8 channels, > 48 kHz, RF64), round trips from an Audio and from a
-- streaming Decoder, tags, encodeParts, the RF64 switch; the api (F.audio.load / open / save); the fuzz pass.
-- Ported from wav-luau tests/core.luau + tests/decode.luau. Fixtures: tools/fixtures/wav.py.
-- audio/wav tests: tools/fixtures/wav.py's files against ffmpeg's (or sox's) f32 decode; encoder vs ffmpeg -bitexact.
-- Fixtures: tools/fixtures/wav.py.
local T = require("@tests/T")
local Wav = require("@rosetta/audio/wav")
local Bytes = require("@rosetta/core/Bytes")
@@ -63,12 +59,10 @@ local function riff(...: string): string
return "RIFF" .. u32(#body) .. body
end
-- the contract
t:eq(Wav.name, "wav", "name")
t:eq(Wav.category, "audio", "category")
t:check(Wav.caps.decode and Wav.caps.encode and Wav.open ~= nil, "caps / open")
-- ------------------------------------------------------------------------------------------------ fixtures
local function readAll(dec: any, sizes: { number }): (buffer, number)
local out = buffer.create(dec.frames * dec.channels * 4)
local got, i = 0, 0
@@ -138,7 +132,6 @@ for _, fx in Cases do
end
t:note("%d fixture files match ffmpeg / sox", #Cases)
-- ------------------------------------------------------------------------------------------------ hand-built files
do
local dec = open(riff(fmt(1, 2, 8000, 16), chunk("data", i16s(16384, -16384, 32767, -32768))))
t:check(dec, "open minimal")
@@ -179,13 +172,13 @@ do -- EXTENSIBLE: 24 valid bits in a 32-bit container
local _, e = open(riff(fmt(0xFFFE, 1, 8000, 16), chunk("data", "\0\0")))
t:check(e and e.code == Err.CORRUPT, "extensible without extension")
end
do -- tags
do
local info = "INFO" .. "INAM" .. u32(3) .. "abc\0" .. "IART" .. u32(6) .. "xy\0\0\0\0" .. "IXYZ" .. u32(2) .. "zz" .. "ITRK" .. u32(2) .. "7\0"
local dec = open(riff(fmt(1, 1, 8000, 8), chunk("LIST", info), chunk("data", "\128\128\128")))
t:check(dec and dec.tags.title == "abc" and dec.tags.artist == "xy" and dec.tags.ixyz == "zz" and dec.tags.track == "7", "tags")
t:check(dec and dec.frames == 3, "8-bit odd data")
end
do -- 8-bit, A-law and mu-law values
do
local o = open(riff(fmt(1, 1, 8000, 8), chunk("data", "\0\128\255"))):read(3)
t:check(buffer.readf32(o, 0) == -1 and buffer.readf32(o, 4) == 0 and buffer.readf32(o, 8) == 127 / 128, "u8 values")
local m = open(riff(fmt(7, 1, 8000, 8), chunk("data", "\255\127\0\128"))):read(4)
@@ -195,7 +188,7 @@ do -- 8-bit, A-law and mu-law values
t:check(buffer.readf32(a, 0) == 8 / 32768 and buffer.readf32(a, 4) == -8 / 32768, "A-law smallest")
t:check(buffer.readf32(a, 8) == -32256 / 32768 and buffer.readf32(a, 12) == 32256 / 32768, "A-law extremes")
end
do -- errors: nil, Err
do
local function fails(s: any, code: string, pattern: string, label: string)
local ok, dec, err = pcall(open, s)
t:check(ok, label .. ": threw " .. tostring(dec))
@@ -216,7 +209,6 @@ do -- errors: nil, Err
t:eq(Wav.sniff(Bytes.reader(buffer.fromstring("RIFF\0\0\0\0AVI "))), 0, "sniff AVI")
end
-- ------------------------------------------------------------------------------------------------ encoder
do
for _, c in Enc do
local a = Types.Audio.new(c.rate, c.channels, c.frames)
@@ -229,7 +221,6 @@ do
t:note("%s: ffmpeg %s", c.name, T.hex(buffer.fromstring(c.file), 80))
end
t:check(same, c.name .. ": identical to ffmpeg -bitexact")
-- and back
local back = Wav.decode(Bytes.reader(out :: buffer))
t:check(back and back.frames == c.frames and buffer.tostring(back.samples) == c.samples, c.name .. ": round trip")
-- from a streaming Decoder (our own, over ffmpeg's file)
@@ -238,7 +229,6 @@ do
t:check(out2 and buffer.tostring(out2) == c.file, c.name .. ": encode from a Decoder")
end
t:note("encoder: %d files identical to ffmpeg -bitexact", #Enc)
-- clamping and rounding
local a = Types.Audio.new(8000, 1, 6)
for i, v in { 2, -2, 0.5 / 32768, -0.5 / 32768, 1.5 / 32768, 0 / 0 } do
buffer.writef32(a.samples, (i - 1) * 4, v)
@@ -248,7 +238,6 @@ do
for i, w in want do
t:eq(math.floor(buffer.readf32(d.samples, (i - 1) * 4) * 32768 + 0.5), w, "s16 rounding / clamping " .. i)
end
-- tags
a.tags = { title = "Hello", artist = "Someone", IXYZ = "kept", comment = "" }
local tg = Wav.decode(Bytes.reader(Wav.encode(a, { sampleFormat = "u8" }) :: buffer)) :: any
t:check(tg.tags.title == "Hello" and tg.tags.artist == "Someone" and tg.tags.ixyz == "kept" and tg.tags.comment == nil, "tag round trip")
@@ -269,7 +258,6 @@ do
t:check(rd.container == "RF64" and rd.frames == 3000, "RF64 reads back")
t:check(buffer.tostring(rd:read(3000)) == buffer.tostring(Wav.decode(Bytes.reader(Wav.encode(big) :: buffer)).samples), "RF64 samples")
t:eq(buffer.readstring(Wav.encode(big) :: buffer, 0, 4), "RIFF", "plain RIFF below the threshold")
-- bad arguments
local _, e1 = Wav.encode({} :: any)
t:check(e1 and e1.code == Err.ARG, "encode {}: " .. tostring(e1))
local _, e2 = Wav.encode(a, { sampleFormat = "s12" } :: any)
@@ -280,7 +268,6 @@ do
t:check(e3 and e3.code == Err.ARG, "short samples buffer")
end
-- ------------------------------------------------------------------------------------------------ api
do
local c = Enc[1]
local a, err = F.audio.load(c.file)
@@ -292,7 +279,6 @@ do
t:eq(F.detect(c.file), "wav", "F.detect")
end
-- ------------------------------------------------------------------------------------------------ fuzz
t:fuzz("open + read + seek", function(b: buffer)
local dec = Wav.open(Bytes.reader(b))
if dec then
+2 -9
View File
@@ -1,8 +1,5 @@
-- audio/wavpack tests: every fixture from tools/fixtures/wavpack.py (wavpack -f / -g / -h / -hh / -x1..6, joint stereo
-- on / off, 8 - 32-bit int and 32-bit float, 1 - 8 channels, odd rates and lengths, hybrid lossy and hybrid lossless
-- with the .wvc, noise shaping, ffmpeg's encoder) decoded bit-exact against wvunpack; seeking; f32 scaling and output
-- reuse; decode() from a sub-range Reader; APEv2 tags and the MD5; the correction file through opts.resolve; sniff;
-- the api; damaged blocks; the fuzz pass. Fixtures: tools/fixtures/wavpack.py.
-- audio/wavpack tests: tools/fixtures/wavpack.py's files (every mode, hybrid + .wvc) bit-exact against wvunpack.
-- Fixtures: tools/fixtures/wavpack.py.
local T = require("@tests/T")
local WavPack = require("@rosetta/audio/wavpack")
local Bytes = require("@rosetta/core/Bytes")
@@ -39,12 +36,10 @@ for _, fx in Cases do
end
t:note("%d fixtures bit-exact against wvunpack, %d seeks", #Cases, seekChecks)
-- decode() from a sub-range Reader
for _, name in { "s16_g", "md5_tags", "f32", "ch6" } do
L.subrange(t, WavPack, byName[name], "wavpack")
end
-- tags, md5, the source facts
do
local dec = open(byName.md5_tags.data)
t:eq(#dec.md5, 32, "md5")
@@ -72,7 +67,6 @@ do
t:check(dec2 and not dec2.lossless, "resolve: no wvc -> lossy")
end
-- the api
do
local fx = byName.s16_g
t:eq(F.detect(buffer.fromstring(fx.data)), "wavpack", "detect")
@@ -101,7 +95,6 @@ do
t:eq(WavPack.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF")
end
-- the fuzz pass
local samples = {}
for _, name in { "s16_g", "f32", "hyb_b3", "s32_hh", "ch6", "u8" } do
table.insert(samples, buffer.fromstring(byName[name].data))
+3 -17
View File
@@ -1,9 +1,5 @@
-- cad/step tests: STEP files written by OCCT (solids modelled in gmsh's OpenCASCADE kernel) and public sample files,
-- against an independent Python Part 21 census (instances, count per type); our writer's output read back by OCCT
-- (solids, volume, faces, area, bounding box equal to the originals); parse -> write -> parse equality; every
-- parameter kind and string escape, complex instances, edition 3 sections, comments; the api (F.load / F.save /
-- F.cad.*); the B-rep plug-in path through brep-luau (luau CLI only: the alias in tests/gen/.luaurc) against OCCT's
-- volumes and bounds, and a custom plug-in table; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/step.py.
-- cad/step tests: OCCT-written and public STEP files against a Python Part 21 census, OCCT and brep-luau.
-- Fixtures: tools/fixtures/step.py.
local T = require("@tests/T")
local F = require("@rosetta")
local Step = require("@rosetta/cad/step")
@@ -25,12 +21,10 @@ local function near(a: number, b: number, rel: number): boolean
return math.abs(a - b) <= rel * math.max(1, math.abs(a), math.abs(b))
end
-- 1. contract
t:eq(Step.name, "step", "name")
t:eq(Step.category, "cad", "category")
t:check(Step.caps.decode and Step.caps.encode and table.find(Step.extensions, "stp"), "contract")
-- deep equality of two decoded values (buffers, the real marks of lists included)
local function same(a: any, b: any, path: string, depth: number?): (boolean, string)
local d = depth or 0
if type(a) ~= "table" or type(b) ~= "table" then
@@ -69,7 +63,6 @@ local function same(a: any, b: any, path: string, depth: number?): (boolean, str
return true, path
end
-- 2. fixtures: census, round trips; OCCT read our output like the original
local decoded = {}
local samples = {}
local t0 = T.clock()
@@ -111,7 +104,6 @@ end
local dt = T.clock() - t0
t:note("%d files (%.1f MB): census, OCCT read-back, round trips (%.2f s)", #Cases, bytes / 1e6, dt)
-- 3. every parameter kind, escapes, complex instances, sections, comments
local CRAFT = [[
ISO-10303-21; /* a comment */
HEADER;
@@ -212,7 +204,6 @@ t:check(string.find(e3text, "ANCHOR;\n<http://example.org/a> = #1;\nENDSEC;", 1,
local e3b = decode(e3text)
t:check(e3b and same(e3.entities, e3b.entities, "e"), "ed3: round trip")
-- 4. building a file
local new = Step.new("AP242")
local pt = Step.add(new, "cartesian_point", { "origin", Step.real({ 0, 0, 1.25 }, 1) })
Step.add(new, "VERTEX_POINT", { "", { ref = pt } })
@@ -231,7 +222,6 @@ t:eq(bad3 and bad3.code, Err.ARG, "encode: cycle -> ARG")
local _, bad4 = Step.encode({ kind = "image" } :: any)
t:eq(bad4 and bad4.code, Err.ARG, "encode: not a Cad")
-- 5. errors and sniff
local function code(s: string, opts: any?): string?
local v, e = decode(s, opts)
return if v then nil else e.code
@@ -249,7 +239,6 @@ t:eq(Step.sniff(Bytes.reader(buffer.fromstring(CRAFT))), 1, "sniff")
t:eq(Step.sniff(Bytes.reader(buffer.fromstring("\239\187\191/* x */ ISO-10303-21;"))), 1, "sniff: BOM + comment")
t:eq(Step.sniff(Bytes.reader(buffer.fromstring("ISO-10303-28"))), 0, "sniff: other")
-- 6. the api
local loaded, lerr = F.load(CRAFT)
t:check(loaded and loaded.kind == "cad", "F.load: " .. tostring(lerr))
t:eq(F.detect(CRAFT), "step", "F.detect")
@@ -260,7 +249,6 @@ t:eq(nop and nop.code, Err.UNSUPPORTED, "toBodies without a plug-in")
local _, nop2 = F.cad.tessellate(loaded)
t:eq(nop2 and nop2.code, Err.UNSUPPORTED, "F.cad.tessellate without a plug-in")
-- 7. the plug-in: a custom interface table
local calls = {}
local fake = {
read = function(text: string, _opts: any): any
@@ -296,7 +284,7 @@ local fapi = F.cad.tessellate(loaded)
t:check(fapi and fapi.kind == "scene", "F.cad.tessellate through F.plugins")
F.plugins.brep = nil
-- 8. brep-luau (luau CLI: tests/gen/.luaurc aliases it; LuaJIT has no `vector` type: skipped)
-- brep-luau: luau CLI only (tests/gen/.luaurc aliases it); LuaJIT has no `vector` type
local function volume(scene: any): (number, { number })
local v = 0
local lo, hi = { math.huge, math.huge, math.huge }, { -math.huge, -math.huge, -math.huge }
@@ -364,7 +352,6 @@ if brepOk then
end
end
end
-- kernel bodies -> our Cad -> our text -> bodies again
local M = brep.M
local part = brep.Boolean.subtract(brep.Build.box(M.v(0, 0, 0), M.v(40, 30, 5)), brep.Build.cylinder(M.v(20, 15, -1), 6, 7))[1]
part.color = { r = 0.2, g = 0.5, b = 0.9 }
@@ -383,7 +370,6 @@ else
t:note("brep-luau plug-in part skipped (%s)", if T.runtime ~= "luau" then "LuaJIT: no vector type" else "no ~/dev/luau/brep-luau")
end
-- 9. fuzz
table.insert(samples, buffer.fromstring(CRAFT))
table.insert(samples, buffer.fromstring(ED3))
t:fuzz("decode", function(b: buffer): any
+2 -10
View File
@@ -1,7 +1,5 @@
-- codecs/audio/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.
-- codecs/audio/Aac tests: AudioSpecificConfig parsing, ADTS headers, raw frames against ffmpeg's float decode, errors.
-- Fixtures: tools/fixtures/m4a.py.
local T = require("@tests/T")
local Aac = require("@rosetta/codecs/audio/Aac")
local IsoBmff = require("@rosetta/containers/IsoBmff")
@@ -13,7 +11,6 @@ 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
@@ -28,7 +25,6 @@ local function frames(data: buffer): ({ { number } }, Aac.Adts?)
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))
@@ -49,7 +45,6 @@ for _, c in He do
end
end
-- crafted configs
do
local asc = Aac.asc(2, 4, 2)
local cfg = Aac.config(asc) :: Aac.Config
@@ -90,7 +85,6 @@ do
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
@@ -148,7 +142,6 @@ for _, c in He do
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"))
@@ -158,7 +151,6 @@ do
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
+1 -4
View File
@@ -1,6 +1,4 @@
-- codecs/audio/Ac3 tests: the codec API under audio/ac3 and the container hook: header fields of every fixture layout,
-- the CRC (a syncframe checks to 0), one-frame decodes against the reference (frame by frame, as a container feeds
-- them), the block offsets, reset, argument / data errors, and a fuzz pass over single frames (CRC off).
-- codecs/audio/Ac3 tests: header fields, the CRC (a syncframe checks to 0), one-frame decodes against the reference.
-- Fixtures: tools/fixtures/ac3.py.
local T = require("@tests/T")
local Ac3 = require("@rosetta/codecs/audio/Ac3")
@@ -38,7 +36,6 @@ for _, c in Fx do
table.insert(frames, buffer.readstring(b, 0, h.frameSize))
end
-- errors
do
local d = Ac3.decoder()
local _, e = d:decode(buffer.create(10), 20)
+2 -13
View File
@@ -1,9 +1,5 @@
-- codecs/adpcm tests: every decoder kernel of codecs/audio/Adpcm against a reference decoder, bit-exact as s16
-- (tools/fixtures/adpcm.py: ADX from ffmpeg and PS-ADPCM / DSP from our Python encoders decoded by vgmstream, Apple
-- ima4 from ffmpeg, IMA nibble streams decoded by ffmpeg); ADX coefficients; the encoders (IMA nibbles, IMA WAV
-- blocks, MS blocks) decoded back with a signal-to-noise floor; the Decoder layouts (seeking matches a straight
-- read); Flash ADPCM by hand; a fuzz pass of random bytes through every kernel (ranges valid, contents random) and
-- the layouts.
-- codecs/adpcm tests: every kernel of codecs/audio/Adpcm bit-exact as s16 against a reference decoder, the encoders.
-- Fixtures: tools/fixtures/adpcm.py (ADX and ima4 from ffmpeg; PS-ADPCM / DSP decoded by vgmstream).
local T = require("@tests/T")
local Adpcm = require("@rosetta/codecs/audio/Adpcm")
local Decoder = require("@rosetta/codecs/audio/Adpcm/Decoder")
@@ -12,7 +8,6 @@ local Sig = require("@tests/gen/adpcm_sig")
local t = T.suite("adpcm codec")
-- s16le reference vs interleaved f32: the count of differing samples and the first one
local function compare(out: buffer, ref: string, count: number): (number, number)
local r = buffer.fromstring(ref)
local bad, first = 0, -1
@@ -27,7 +22,6 @@ local function compare(out: buffer, ref: string, count: number): (number, number
return bad, first
end
-- ------------------------------------------------------------------------------------------------ kernels
for _, c in Cases do
local src = buffer.fromstring(c.data)
local ch, frames = c.ch, c.frames
@@ -108,7 +102,6 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ encoders
local function snr(x: buffer, y: buffer, count: number): number
local sig, err = 0, 0
for i = 0, count - 1 do
@@ -123,7 +116,6 @@ end
do
local x = buffer.fromstring(Sig.data)
local ch, n = Sig.channels, Sig.frames
-- IMA nibbles, both nibble orders
for _, hi in { true, false } do
local raw = buffer.create((n * ch + 1) // 2)
local st = buffer.create(8 * ch)
@@ -139,7 +131,6 @@ do
t:check(s > 20, string.format("ima encode (hi %s): %.1f dB", tostring(hi), s))
t:check(buffer.readi32(st, 0) == buffer.readi32(ds, 0), "ima encoder and decoder end in the same state")
end
-- IMA WAV and MS blocks
for _, kind in { "ima_wav", "ms" } do
local ba = 512
local spb = Decoder.blockFrames(kind, ba, ch) :: number
@@ -174,7 +165,6 @@ do
end
end
-- ------------------------------------------------------------------------------------------------ Decoder layouts
local function readAll(dec: any, step: number): buffer
local out = buffer.create(dec.frames * dec.channels * 4)
local got = 0
@@ -224,7 +214,6 @@ do
t:eq(dec.frames, 3 * 4 * 28 + 28, "cut interleaved: the whole frames both channels have")
end
-- ------------------------------------------------------------------------------------------------ fuzz
local samples = {}
for _, c in Cases do
table.insert(samples, c.data)
+2 -7
View File
@@ -1,7 +1,5 @@
-- codecs/audio/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.
-- codecs/audio/Alac tests: encoder -> decoder round trips, ffmpeg's ALAC packets, the magic cookie, errors.
-- Fixtures: tools/fixtures/m4a.py.
local T = require("@tests/T")
local Alac = require("@rosetta/codecs/audio/Alac")
local IsoBmff = require("@rosetta/containers/IsoBmff")
@@ -97,7 +95,6 @@ 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))
@@ -120,7 +117,6 @@ for _, c in Fx do
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)
@@ -149,7 +145,6 @@ do
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)
+1 -6
View File
@@ -1,6 +1,4 @@
-- codecs/audio/ApeTag tests: APEv2 tags with and without a header, APEv1, multi-value items, binary items, an ID3v1
-- tag after the APE tag, a tag inside a sub-range, malformed sizes / counts; the fuzz no-throw pass. The real files
-- (wavpack -w, mac -t, ...) are covered by tests/audio/wavpack.luau and tests/audio/ape.luau.
-- codecs/audio/ApeTag tests: hand-made APEv1 / APEv2 tags. The real files are in tests/audio/wavpack.luau and ape.luau.
local T = require("@tests/T")
local ApeTag = require("@rosetta/codecs/audio/ApeTag")
@@ -9,7 +7,6 @@ local t = T.suite("apetag")
local function u32(v: number): string
return string.char(v % 256, (v // 256) % 256, (v // 65536) % 256, (v // 16777216) % 256)
end
-- tag(items, version, header) -> the tag bytes; items = { { key, value, flags? } }
local function tag(items: { any }, version: number, header: boolean): string
local body = {}
for _, it in items do
@@ -41,11 +38,9 @@ do
t:eq(#info.items, 6, "items")
t:eq(info.items[5].kind, "binary", "binary kind")
t:eq(info.items[5].value, "f.png\0PNG", "binary value")
-- ID3v1 after it
local s2 = s .. "TAG" .. string.rep("x", 125)
local tags2, info2 = ApeTag.find(buffer.fromstring(s2), 0, #s2)
t:check(tags2 and tags2.title == "Hello" and info2.stop == #s, "before ID3v1")
-- inside a sub-range
local s3 = "zz" .. s .. "yyy"
local tags3, info3 = ApeTag.find(buffer.fromstring(s3), 2, 2 + #s)
t:check(tags3 and tags3.title == "Hello" and info3.start == 12, "sub-range")
+2 -10
View File
@@ -1,6 +1,5 @@
-- codecs/image/Bcn tests: random BC1..BC7 blocks (every BC7 and BC6H mode, the BC1 3-colour mode, odd sizes) against
-- Pillow's and Godot's (bcdec) decodes; BC6H floats against Godot; the encoders (BC1 / BC3 / BC4 / BC5) within reach
-- of Pillow's encoder PSNR, exact on flat blocks; argument errors; the fuzz no-throw pass. Fixtures: tools/fixtures/bcn.py.
-- codecs/image/Bcn tests: random BC1..BC7 blocks against Pillow's and Godot's (bcdec) decodes, the encoders.
-- Fixtures: tools/fixtures/bcn.py.
local T = require("@tests/T")
local Bcn = require("@rosetta/codecs/image/Bcn")
local Half = require("@rosetta/codecs/image/Half")
@@ -8,7 +7,6 @@ local Fx = require("@tests/gen/bcn")
local t = T.suite("bcn")
-- the largest per-byte difference between two rgba8 buffers (channels: which of r, g, b, a count)
local function maxDiff(a: buffer, b: buffer, n: number, channels: { number }): (number, number)
local worst, at = 0, -1
for i = 0, n - 1 do
@@ -23,7 +21,6 @@ local function maxDiff(a: buffer, b: buffer, n: number, channels: { number }): (
end
local RGBA, RGB, RG, R = { 0, 1, 2, 3 }, { 0, 1, 2 }, { 0, 1 }, { 0 }
-- which channels each reference defines, and the allowed difference to it
local PILLOW: { [string]: { any } } = {
bc1 = { RGBA, 0 },
bc2 = { RGBA, 0 },
@@ -82,7 +79,6 @@ for _, c in Fx.cases do
stats.godot += 1
end
end
-- into a bigger buffer at an offset, from an offset
local big = buffer.create(buffer.len(src) + 5)
buffer.copy(big, 5, src)
local bpp = if Bcn.FLOAT[c.kind] then 16 else 4
@@ -113,7 +109,6 @@ do
end
end
-- encoders
local function psnr(a: buffer, b: buffer, n: number, channels: { number }): number
local se = 0
for i = 0, n - 1 do
@@ -194,7 +189,6 @@ do
end
end
-- Half
do
t:eq(Half.fromFloat(1), 0x3C00, "half 1")
t:eq(Half.fromFloat(-2), 0xC000, "half -2")
@@ -212,7 +206,6 @@ do
t:check(ok, "half round trip of every pattern")
end
-- errors
do
local _, e1 = Bcn.decode("bc9", buffer.create(8), 0, 4, 4)
t:check(e1 and string.find(e1, "unsupported") ~= nil, "unknown kind")
@@ -224,7 +217,6 @@ do
t:check(e4 ~= nil, "short pixels")
end
-- fuzz: random block data of every kind and size
local samples = {}
for _, c in Fx.cases do
table.insert(samples, buffer.fromstring(c.data))
+2 -3
View File
@@ -1,6 +1,5 @@
-- codecs/font/Bitmap tests: 1-bit row pack / unpack round trips (MSB- and LSB-first, padded strides), the Font over a
-- strike (glyphIndex / advance / rasterize / default glyph), Bitmap.strike of a bitmap font and of the first outline
-- font from tools/fixtures/fonts.py (thresholded rasterization), and argument errors.
-- codecs/font/Bitmap tests: 1-bit row pack / unpack, the Font over a strike, Bitmap.strike, argument errors.
-- Fixtures: tools/fixtures/fonts.py.
local T = require("@tests/T")
local Bitmap = require("@rosetta/codecs/font/Bitmap")
local Ttf = require("@rosetta/font/ttf")
+2 -10
View File
@@ -1,7 +1,5 @@
-- codecs/compress/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.
-- codecs/compress/Brotli tests: reference encoder streams (qualities 0..11, windows 10..24), hand-made streams.
-- Fixtures: tools/fixtures/brotli.py.
local T = require("@tests/T")
local Brotli = require("@rosetta/codecs/compress/Brotli")
local Err = require("@rosetta/core/Err")
@@ -10,14 +8,12 @@ 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]
@@ -31,7 +27,6 @@ for _, c in Fx.cases do
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)
@@ -41,7 +36,6 @@ do
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
@@ -72,7 +66,6 @@ do
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
@@ -110,7 +103,6 @@ do
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
+1 -7
View File
@@ -1,6 +1,4 @@
-- codecs/compress/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.
-- codecs/compress/Bzip2 tests: Python bz2 (libbzip2) streams decode exactly, CRC mismatches, truncations.
-- Fixtures: tools/fixtures/bzip2.py.
local T = require("@tests/T")
local Bzip2 = require("@rosetta/codecs/compress/Bzip2")
@@ -33,7 +31,6 @@ local function case(name: string): any
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)
@@ -44,7 +41,6 @@ do
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 })
@@ -53,7 +49,6 @@ do
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)
@@ -84,7 +79,6 @@ do
t:check(e3 and e3.code == Err.ARG, "bad offset")
end
-- fuzz
do
local samples = {}
for i, c in Fx.cases do
+2 -6
View File
@@ -1,7 +1,5 @@
-- codecs/image/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.
-- codecs/image/Dct tests: the islow IDCT against a double-precision reference, the forward DCT + quantiser.
-- The bit-exact djpeg / cjpeg checks are in tests/image/jpeg.luau.
local T = require("@tests/T")
local Dct = require("@rosetta/codecs/image/Dct")
@@ -62,7 +60,6 @@ do
t:note("idct: worst error %d over 300 random blocks", worst)
end
-- forward + quantiser
do
local worst = 0
for _ = 1, 200 do
@@ -91,7 +88,6 @@ do
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)
+2 -10
View File
@@ -1,7 +1,5 @@
-- codecs/compress/Deflate tests: every fixture case (Python zlib, levels 0-9, every strategy, small windows, flushes, gzip
-- headers, multi-member gzip) decodes; exact-size mode; checksum vectors; the compressor round-trips every corpus at
-- every level (and its zlib / gzip framing); truncated / corrupted / random input returns nil, Err and never throws.
-- Ported from deflate-luau tests/inflate.luau. Fixtures: tools/fixtures/deflate.py.
-- codecs/compress/Deflate tests: Python zlib streams (levels 0-9, every strategy, gzip), the compressor round trips.
-- Fixtures: tools/fixtures/deflate.py.
local T = require("@tests/T")
local Deflate = require("@rosetta/codecs/compress/Deflate")
local Err = require("@rosetta/core/Err")
@@ -19,7 +17,6 @@ local function decode(kind: string, b: buffer, ...: any): (buffer?, any)
end
end
-- checksum vectors
t:eq(Deflate.crc32("123456789"), 0xCBF43926, "crc32 check value")
t:eq(Deflate.crc32(""), 0, "crc32 empty")
t:eq(Deflate.adler32("Wikipedia"), 0x11E60398, "adler32 Wikipedia")
@@ -35,7 +32,6 @@ do
t:eq(Deflate.crc32(b, 3, 17), Deflate.crc32(string.sub(s, 4, 20)), "crc32 range")
end
-- every case decodes to its corpus
local nbytes = 0
for _, c in Fx.cases do
local want = Fx.corpora[c.corpus]
@@ -65,10 +61,8 @@ for _, c in Fx.cases do
end
t:note("%d fixture streams, %.1f MB decoded", #Fx.cases, nbytes / 1e6)
-- strings are accepted
t:check(buffer.tostring((Deflate.zlib(Fx.cases[25].data))) == Fx.corpora[Fx.cases[25].corpus], "string input")
-- corrupted checksums
do
local z
for _, c in Fx.cases do
@@ -93,7 +87,6 @@ do
end
end
-- hand-made streams
do
local bytes = T.bytes
-- stored block "hi" then a fixed block with only end-of-block
@@ -148,7 +141,6 @@ do
t:check(e and e.code == Err.ARG, "bad level returns Err.ARG")
end
-- truncation, corruption and garbage never throw
do
local samples = {}
local kinds = {}
+2 -7
View File
@@ -1,8 +1,5 @@
-- codecs/model/Draco tests: Google's Draco test data (bitstreams 0.9 - 2.2) and files encoded by draco_encoder 1.5.7
-- at every compression level, quantization and as point clouds, decoded and compared byte for byte (points, faces,
-- every attribute's values per point, as CRCs) with libdraco's own decoder (tools/fixtures/_draco_dump.cc), kd-tree
-- point clouds included; argument errors; the fuzz no-throw pass (which also fails on any internal error the
-- decoder's safety net caught). Fixtures: tools/fixtures/draco.py.
-- codecs/model/Draco tests: Google's test data and draco_encoder 1.5.7 files against libdraco's decoder.
-- Fixtures: tools/fixtures/draco.py (dumps from tools/fixtures/_draco_dump.cc).
local T = require("@tests/T")
local Draco = require("@rosetta/codecs/model/Draco")
local Err = require("@rosetta/core/Err")
@@ -50,14 +47,12 @@ for _, c in Cases do
end
t:note("%d files decoded exactly like libdraco (%d kd-tree point clouds), %d rejected by both", counts.exact, counts.kd, counts.rejected)
-- the attribute lookup and the header
local first = Cases[1]
local info = Draco.info(first.data)
t:check(info and (info.kind == "mesh" or info.kind == "points"), "info")
t:check(Draco.sniff(buffer.fromstring(first.data)), "sniff")
t:check(not Draco.sniff(buffer.fromstring("DRAC")), "sniff short")
-- errors
local _, e1 = Draco.decode(buffer.fromstring("NOTDRACO......"))
t:check(e1 and e1.code == Err.CORRUPT, "not Draco data: " .. tostring(e1))
local _, e2 = Draco.decode(buffer.fromstring("DRACO\9\0\1\1\0\0"))
+2 -4
View File
@@ -1,6 +1,5 @@
-- codecs/image/Etc tests: random ETC1 / ETC2 (every mode: individual, differential, T, H, planar; RGB A1 opaque and
-- transparent; RGBA with EAC alpha) and EAC R11 / RG11 (unsigned, signed, multiplier 0) blocks against Godot 4's
-- decode (etcpak); odd sizes; the 16-bit EAC output; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/etc.py.
-- codecs/image/Etc tests: random ETC1 / ETC2 / EAC blocks against Godot 4's decode (etcpak), the 16-bit EAC output.
-- Fixtures: tools/fixtures/etc.py.
local T = require("@tests/T")
local Etc = require("@rosetta/codecs/image/Etc")
local Fx = require("@tests/gen/etc")
@@ -99,7 +98,6 @@ for _, c in Fx do
end
t:check(ok, c.name .. ": rgba16 ~ rgba8")
end
-- from / into offsets
local big = buffer.create(buffer.len(src) + 3)
buffer.copy(big, 3, src)
local out = buffer.create(n * 4 + 4)
+2 -3
View File
@@ -1,6 +1,5 @@
-- codecs/compress/Explode tests: PKWARE DCL streams written by StormLib's SCompImplode (tools/fixtures/mpq.py:
-- text, noise, a short repeat, zeros) decompress to the source bytes; maxOut stops early; hand-made streams with
-- coded literals; bad headers and truncations; the fuzz pass.
-- codecs/compress/Explode tests: PKWARE DCL streams from StormLib's SCompImplode, hand-made streams, bad headers.
-- Fixtures: tools/fixtures/mpq.py.
local T = require("@tests/T")
local Explode = require("@rosetta/codecs/compress/Explode")
local Crc32 = require("@rosetta/core/Crc32")
+2 -13
View File
@@ -1,9 +1,5 @@
-- codecs/video/H263 tests. Against `ffmpeg -idct int` (tools/fixtures/h263.py): H.263 streams (sub-QCIF .. 4CIF, GOB
-- headers, DQUANT, q 1 .. high quantisers), H.263+ PLUSPTYPE streams (custom sizes, sizes that are not a multiple of
-- 16, the rounding type, unrestricted vectors with reversible codes, slice structure) and Sorenson Spark streams (standard, 8-bit and
-- 16-bit custom sizes, 11-bit escapes, high motion, disposable inter pictures) decode one picture at a time to exactly
-- ffmpeg's planes, every frame; header info; frameImage; the registry's decoders (h263, flv1); unsupported options are
-- UNSUPPORTED; truncated and corrupted pictures never throw; the fuzz no-throw pass.
-- codecs/video/H263 tests: H.263, H.263+ and Sorenson Spark streams bit-exact against `ffmpeg -idct int`.
-- Fixtures: tools/fixtures/h263.py.
local T = require("@tests/T")
local H263 = require("@rosetta/codecs/video/H263")
local Video = require("@rosetta/codecs/video/Video")
@@ -55,7 +51,6 @@ local function crcs(f: any): (number, number, number)
return planeCrc(f.y, f.stride, w, h), planeCrc(f.cb, f.stride // 2, cw, ch), planeCrc(f.cr, f.stride // 2, cw, ch)
end
-- differing luma samples against a reference frame (detail on a mismatch)
local function lumaDiff(f: any, ref: buffer): (number, number)
local n, first = 0, -1
for y = 0, f.height - 1 do
@@ -71,7 +66,6 @@ local function lumaDiff(f: any, ref: buffer): (number, number)
return n, first
end
-- 1. every stream against ffmpeg, bit-exact
local total = 0
local disposables = 0
for _, fx in STREAMS do
@@ -117,7 +111,6 @@ for _, fx in STREAMS do
end
t:check(disposables > 0, "disposable Sorenson pictures decoded (" .. disposables .. ")")
-- 2. header info
do
local fx = STREAMS[8] -- plus_custom
local file = b64(fx.file)
@@ -136,14 +129,12 @@ do
t:check(e ~= nil and e.code == Err.CORRUPT, "no start code: CORRUPT")
end
-- 3. unsupported H.263+ options
for name, data in BAD do
local dec = H263.new()
local f, e = dec:decode(b64(data))
t:check(f == nil and e ~= nil and e.code == Err.UNSUPPORTED, name .. ": UNSUPPORTED (" .. tostring(e) .. ")")
end
-- 4. frameImage
do
local fx = STREAMS[14]
local dec = H263.new({ flv = true })
@@ -159,7 +150,6 @@ do
t:check(dec:decode(42 :: any) == nil, "decode of a non-buffer is nil")
end
-- 5. the registry's decoders
do
t:check(Video.fromFourcc("H263") == "h263" and Video.fromFourcc("s263") == "h263" and Video.fromFourcc("FLV1") == "flv1", "registry names")
t:check(Video.canDecode("h263") and Video.canDecode("flv1"), "registry decoders")
@@ -191,7 +181,6 @@ do
end
end
-- 6. robustness: truncated and corrupted pictures, garbage (never throws), the fuzz pass
do
local samples = {}
for _, idx in { 1, 6, 8, 10, 11, 13, 16 } do
+2 -10
View File
@@ -1,8 +1,5 @@
-- codecs/video/H264 tests: libx264 streams at many settings (Baseline / Main / High, CAVLC / CABAC, B frames, references,
-- weighted prediction, 8x8 transforms, scaling matrices, slices, odd sizes with cropping, ...) decoded and compared
-- per frame with ffmpeg's decoder (CRC-32 of the yuv420p planes, bit-exact); the AVCC (avcC + length-prefixed
-- samples) and NAL-at-a-time paths; pts propagation; UNSUPPORTED streams (interlaced, 4:2:2, 4:4:4, 10-bit); error
-- codes; and the fuzz no-throw pass. Fixtures: tools/fixtures/h264.py.
-- codecs/video/H264 tests: libx264 streams at many settings, per frame against ffmpeg (CRC-32 of yuv420p planes).
-- Fixtures: tools/fixtures/h264.py.
local T = require("@tests/T")
require("@rosetta/host") -- LuaJIT: the trace limits the api sets (host/init.luau)
local H264 = require("@rosetta/codecs/video/H264")
@@ -13,7 +10,6 @@ local Bad = require("@tests/gen/h264_bad")
local t = T.suite("h264")
-- 1. every stream, whole, against ffmpeg
local nframes = 0
for _, c in Cases do
local frames, err = H264.decodeAll(c.data)
@@ -33,7 +29,6 @@ for _, c in Cases do
end
t:note("%d streams, %d frames bit-exact with ffmpeg", #Cases, nframes)
-- 2. AVCC samples, NAL-at-a-time input, pts
local function splitAnnexB(s: string): { string }
local out = {}
local i = 1
@@ -107,13 +102,11 @@ for _, c in Cases do
end
end
-- 3. unsupported streams
for _, c in Bad do
local frames, err = H264.decodeAll(c.data)
t:check(frames == nil and err and err.code == c.code, c.name .. ": " .. tostring(err))
end
-- 4. error codes
do
local _, e1 = H264.decodeAll(123 :: any)
t:check(e1 and e1.code == Err.ARG, "decode of a number: ARG")
@@ -134,7 +127,6 @@ do
t:check(ld and #ld == #c.frames and Crc32.of(ld[#ld].image.pixels) == c.frames[#c.frames], "lowDelay on a P-only stream")
end
-- 5. fuzz: streams with damaged bytes / truncations must never throw
local samples = {}
for _, c in Cases do
if #c.data < 20000 and #samples < 14 then
+2 -5
View File
@@ -1,8 +1,5 @@
-- codecs/video/H264 conformance: a selection of the ITU-T H.264.1 (JVT) conformance bitstreams (Baseline / Main / Extended
-- without SP / High: CAVLC, CABAC, B frames, weighted prediction, multiple slices, MMCO / long-term references,
-- frame_num gaps, cropping, PCM, 8x8 transforms, scaling matrices, ...) decoded bit-exact against the reference
-- decoder's yuv (JM, shipped in each zip; ffmpeg where there is none), and interlaced / SP / 4:2:2 streams refused
-- with UNSUPPORTED. Fixtures: tools/fixtures/h264_jvt.py (downloaded from itu.int; skipped when unreachable).
-- codecs/video/H264 conformance: ITU-T H.264.1 (JVT) bitstreams bit-exact against the JM yuv (ffmpeg where none).
-- Fixtures: tools/fixtures/h264_jvt.py (downloaded from itu.int; skipped when unreachable).
local T = require("@tests/T")
require("@rosetta/host") -- LuaJIT: the trace limits the api sets (host/init.luau)
local H264 = require("@rosetta/codecs/video/H264")
+6 -14
View File
@@ -1,9 +1,5 @@
-- codecs/image/Jpeg tests (the Motion-JPEG side; tests/image/jpeg.luau covers the still-image decoder and encoder through
-- image/jpeg): ffmpeg mjpeg frames (4:2:0, 4:2:2, 4:4:4, odd sizes, stripped DHT, AVI1 + junk after EOI) decoded
-- to yuv420p bit-exact with libjpeg-turbo's IDCT planes (TurboJPEG) and to rgba8 bit-exact with djpeg, and within
-- PSNR thresholds of ffmpeg's own decode; an interlaced AVI1 frame (two fields) woven; the yuv420p encoder
-- byte-identical to TurboJPEG's tj3CompressFromYUV8, read back by djpeg (exact) and ffmpeg (PSNR); the API's
-- arguments; the fuzz no-throw pass. Fixtures: tools/fixtures/mjpeg.py.
-- codecs/image/Jpeg tests (Motion-JPEG; still images are in tests/image/jpeg.luau): ffmpeg mjpeg frames, the encoder.
-- Fixtures: tools/fixtures/mjpeg.py.
local T = require("@tests/T")
local Jpeg = require("@rosetta/codecs/image/Jpeg")
local Crc32 = require("@rosetta/core/Crc32")
@@ -37,7 +33,6 @@ for _, c in Enc do
c.want = b64(c.want)
end
-- PSNR of n bytes of a at ao against b at bo
local function psnr(a: buffer, ao: number, b: buffer, bo: number, n: number): number
local se = 0
for i = 0, n - 1 do
@@ -50,7 +45,6 @@ local function psnr(a: buffer, ao: number, b: buffer, bo: number, n: number): nu
return 10 * math.log10(255 * 255 * n / se)
end
-- PSNR of the RGB channels of two rgba8 buffers of n pixels
local function psnrRgb(a: buffer, b: buffer, n: number): number
local se = 0
for i = 0, n - 1 do
@@ -71,7 +65,7 @@ local function hasDht(s: string): boolean
return at ~= nil and sos ~= nil and at < sos
end
-- 1. ffmpeg's frames: yuv420p (TurboJPEG planes) and rgba8 (djpeg) bit-exact, PSNR against ffmpeg's decode
-- yuv420p bit-exact with TurboJPEG's planes, rgba8 bit-exact with djpeg, PSNR against ffmpeg's decode
do
local frames, worstY, worstC, worstRgb = 0, 99, 99, 99
for _, s in Fx.streams do
@@ -118,7 +112,7 @@ do
t:note("%d ffmpeg mjpeg frames bit-exact (yuv420p: TurboJPEG, rgba8: djpeg); worst PSNR against ffmpeg: luma %.1f, chroma %.1f, rgba %.1f dB", frames, worstY, worstC, worstRgb)
end
-- 2. an interlaced frame: two fields (AVI1 polarity 1) woven, field 1 on the even rows
-- an interlaced frame: two fields (AVI1 polarity 1) woven, field 1 on the even rows
do
local F = Fx.fields
local b = buffer.fromstring(F.data)
@@ -140,7 +134,7 @@ do
t:check(Jpeg.info(b).avi1 == 1, "fields: info.avi1")
end
-- 3. the yuv420p encoder: byte-identical with TurboJPEG, read back by djpeg (exact) and ffmpeg (PSNR)
-- the yuv420p encoder: byte-identical with TurboJPEG's tj3CompressFromYUV8
do
local exact = 0
for _, c in Enc do
@@ -193,7 +187,6 @@ do
t:check(sd.meta.text and sd.meta.text.comment == "hello" and sd.meta.dpi and sd.meta.dpi.x == 72, "segments and density")
end
-- 4. the API: ranges, options, fallbacks, errors
do
local s = Fx.streams[1]
local data = s.frames[1].data
@@ -237,7 +230,7 @@ do
t:note("%d truncated frames, %d decoded partially", cuts, partial)
end
-- 5. speed (a note; tools/bench.luau has the real numbers)
-- speed (a note; tools/bench.luau has the real numbers)
do
local s = Fx.streams[1]
local frames = {}
@@ -254,7 +247,6 @@ do
t:note("%dx%d yuv420p decode: %.0f fps", s.width, s.height, n / (os.clock() - t0))
end
-- 6. fuzz
do
local samples = {}
for k, s in Fx.streams do
+2 -9
View File
@@ -1,6 +1,4 @@
-- codecs/text/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.
-- codecs/text/Json tests: the JSONTestSuite corpus, Python json.dumps output reproduced byte for byte, the API.
-- Fixtures: tools/fixtures/json.py.
local T = require("@tests/T")
local Json = require("@rosetta/codecs/text/Json")
@@ -47,7 +45,7 @@ local function fromEvents(s: string): (any, any)
return top, nil
end
-- 1. JSONTestSuite
-- JSONTestSuite: y_ must parse to Python's value, n_ must fail, i_ must not throw
local counts = { y = 0, n = 0, i = 0, iok = 0 }
for _, c in Suite do
local v, err = Json.decode(c.data)
@@ -71,7 +69,6 @@ for _, c in Suite do
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))
@@ -85,7 +82,6 @@ for i, c in Corpus do
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")
@@ -122,7 +118,6 @@ do
end
end
-- 4. streaming: lines, decodeAt, writer
do
local got = {}
for _, v in Json.lines('{"a":1}\n[2]\n"x"\n 3 ') do
@@ -170,7 +165,6 @@ do
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
@@ -189,7 +183,6 @@ do
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)
+1 -6
View File
@@ -1,7 +1,4 @@
-- codecs/video/Legacy tests: Cinepak (24-bit, grey, 8-bit palettised, several strips, a 92x68 size), Microsoft Video 1
-- (16-bit, 8-bit with an AVI palette), QuickTime RLE (depths 1 / 2 / 4 / 8 with colour tables, default Macintosh
-- tables and grey ramps; 16 / 24 / 32-bit and grey from ffmpeg) and QuickTime SMC, in AVI, MOV and MKV: every frame
-- equals ffmpeg's decode (CRC-32 of rgba); seeking; the registry entries; the fuzz pass on each codec's packet decoder.
-- codecs/video/Legacy tests: Cinepak, MS Video 1, QuickTime RLE and SMC: every frame equals ffmpeg's (CRC-32 of rgba).
-- Fixtures: tools/fixtures/legacy.py.
local T = require("@tests/T")
local F = require("@rosetta")
@@ -12,7 +9,6 @@ local Fx = require("@tests/gen/legacy_cases")
local t = T.suite("legacy")
-- the registry
t:eq(Video.fromFourcc("cvid"), "cinepak", "cvid")
t:eq(Video.fromFourcc("CRAM"), "msvideo1", "CRAM")
t:eq(Video.fromFourcc("msvc"), "msvideo1", "msvc")
@@ -50,7 +46,6 @@ for _, c in Fx do
v:seek(0)
local f = v:nextFrame()
t:check(f ~= nil and Crc32.of(f.image.pixels) == c.frames[1], label .. ": seek(0)")
-- packets for the fuzz pass
local dmx = v.demuxer
local tr = dmx:track("video")
if not samples[c.codec] then
+2 -5
View File
@@ -1,7 +1,5 @@
-- codecs/compress/Lz4 tests: every reference block (python-lz4 fast at accelerations 1 / 4 / 16, HC 4 / 9 / 12)
-- decodes to its corpus, with and without the size; our encoder's blocks decode with the reference (fixture verdicts)
-- and round trip here; linked blocks through decodeInto's history; error codes; truncated / mutated / random blocks
-- never throw. Fixtures: tools/fixtures/lz4.py.
-- codecs/compress/Lz4 tests: python-lz4 blocks (fast 1 / 4 / 16, HC 4 / 9 / 12), our encoder, linked blocks.
-- Fixtures: tools/fixtures/lz4.py.
local T = require("@tests/T")
local Lz4 = require("@rosetta/codecs/compress/Lz4")
local Err = require("@rosetta/core/Err")
@@ -63,7 +61,6 @@ do
t:check(b2 ~= nil, "second half")
end
-- errors
do
local _, e1 = Lz4.decompress("")
t:check(e1 and e1.code == Err.TRUNCATED, "empty: " .. tostring(e1))
Loaded 100 of 278 files, more files were not shown because too many files have changed in this diff. Show more