-- 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") local Crc32 = require("@rosetta/core/Crc32") local Cases = require("@tests/gen/draco_cases") local t = T.suite("draco") local counts = { exact = 0, rejected = 0, kd = 0 } local samples = {} for _, c in Cases do local g, err = Draco.decode(c.data) if c.error then t:check(g == nil and err ~= nil, c.name .. ": libdraco rejects it, so do we") counts.rejected += 1 else t:check(g, c.name .. ": decode: " .. tostring(err)) if g then t:eq(g.numPoints, c.points, c.name .. ": points") if c.faces then t:eq(g.numFaces, c.faces, c.name .. ": faces") t:eq(Crc32.of(g.indices :: buffer), c.indices, c.name .. ": indices") end t:eq(#g.attributes, #c.attrs, c.name .. ": attribute count") for i, want in c.attrs do local a = g.attributes[i] if a then t:eq(a.typeId, want.type, c.name .. ": attribute " .. i .. " type") t:eq(a.type, Draco.DATA_TYPES[want.dataType], c.name .. ": attribute " .. i .. " data type") t:eq(a.components, want.components, c.name .. ": attribute " .. i .. " components") t:eq(a.normalized, want.normalized, c.name .. ": attribute " .. i .. " normalized") t:eq(a.uniqueId, want.uniqueId, c.name .. ": attribute " .. i .. " unique id") t:eq(Crc32.of(a.data), want.crc, c.name .. ": attribute " .. i .. " (" .. a.name .. ") values") end end counts.exact += 1 if g.method == "kdtree" then counts.kd += 1 end if #c.data < 4000 then table.insert(samples, c.data) end end end end t:note("%d files decoded exactly like libdraco (%d kd-tree point clouds), %d rejected by both", counts.exact, counts.kd, counts.rejected) 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") 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")) t:check(e2 and e2.code == Err.UNSUPPORTED, "future version: " .. tostring(e2)) local _, e3 = Draco.decode(42 :: any) t:check(e3 and e3.code == Err.ARG, "bad argument") -- fuzz: never throws, and the internal safety net never fires local internal = 0 t:fuzz("decode", function(b: buffer) local g, err = Draco.decode(b) if not g and err and string.find(err.message, "internal error", 1, true) then internal += 1 if internal <= 5 then print(" internal error: " .. err.message) end end return g end, samples, { mutations = 12, keepHeader = 11 }) t:eq(internal, 0, "fuzz: internal errors") t:done()