"use strict"; const { describe, it } = require("node:test"); const assert = require("node:assert/strict"); const fs = require("fs"); const path = require("path"); const DepthDecode = require("../src/ppda/depthDecode.js"); global.DepthDecode = DepthDecode; const PpdaLoader = require("../src/ppda/loadPpda.js"); describe("PpdaLoader", () => { it("loads vendored male-body atlas", () => { const text = fs.readFileSync(path.join(__dirname, "../build/paperdolls/male-body/male-body-atlas.ppda"), "utf8"); const ppda = PpdaLoader.parse(text); assert.equal(ppda.sex, "male"); assert.equal(ppda.settype, "body"); assert.equal(ppda.depth_format.encoding, "gray"); assert.equal(ppda.depth_format.bits, 16); assert.ok(ppda.yaws.length === 12); assert.ok(ppda.clips.length >= 1); }); it("body and sword are compatible", () => { const body = PpdaLoader.parse(fs.readFileSync(path.join(__dirname, "../build/paperdolls/male-body/male-body-atlas.ppda"), "utf8")); const sword = PpdaLoader.parse(fs.readFileSync(path.join(__dirname, "../build/paperdolls/male-sword/male-sword-atlas.ppda"), "utf8")); assert.doesNotThrow(() => PpdaLoader.assertCompatible(body, sword)); }); it("rejects path traversal in map files", () => { const bad = { format_version: 1, sex: "male", settype: "body", fps: 4, cell_width: 32, cell_height: 48, pitches: [0], yaws: [0], maps: { diffuse: { file: "../x.png" }, depth: { file: "d.u16" } }, clips: [{ name: "a", token: "a", frame_count: 1, duration: 1, frames: [{ index: 0, views: [{ pitch: 0, yaw: 0, x: 0, y: 0, w: 1, h: 1 }] }] }], identity: { near: 0, far: 1 } }; assert.throws(() => PpdaLoader.parse(bad)); }); it("rejects unknown format_version", () => { assert.throws(() => PpdaLoader.parse({ format_version: 99, sex: "m", settype: "b", fps: 1, cell_width: 1, cell_height: 1, pitches: [0], yaws: [0], maps: { diffuse: { file: "a.png" }, depth: { file: "d.u16" } }, clips: [{ name: "a", token: "a", frame_count: 1, duration: 1, frames: [{ index: 0, views: [{ pitch: 0, yaw: 0, x: 0, y: 0, w: 1, h: 1 }] }] }], identity: { near: 0, far: 1 } })); }); });