BlueGit

timfa raytracer

Files

raytracer / test / ppdaLoader.test.js

ppdaLoader.test.js

ppdaLoader.test.js 2.1 KiB Download Raw
1"use strict";
2const { describe, it } = require("node:test");
3const assert = require("node:assert/strict");
4const fs = require("fs");
5const path = require("path");
6const DepthDecode = require("../src/ppda/depthDecode.js");
7global.DepthDecode = DepthDecode;
8const PpdaLoader = require("../src/ppda/loadPpda.js");
9
10describe("PpdaLoader", () =>
11{
12 it("loads vendored male-body atlas", () =>
13 {
14 const text = fs.readFileSync(path.join(__dirname, "../build/paperdolls/male-body/male-body-atlas.ppda"), "utf8");
15 const ppda = PpdaLoader.parse(text);
16 assert.equal(ppda.sex, "male");
17 assert.equal(ppda.settype, "body");
18 assert.equal(ppda.depth_format.encoding, "gray");
19 assert.equal(ppda.depth_format.bits, 16);
20 assert.ok(ppda.yaws.length === 12);
21 assert.ok(ppda.clips.length >= 1);
22 });
23
24 it("body and sword are compatible", () =>
25 {
26 const body = PpdaLoader.parse(fs.readFileSync(path.join(__dirname, "../build/paperdolls/male-body/male-body-atlas.ppda"), "utf8"));
27 const sword = PpdaLoader.parse(fs.readFileSync(path.join(__dirname, "../build/paperdolls/male-sword/male-sword-atlas.ppda"), "utf8"));
28 assert.doesNotThrow(() => PpdaLoader.assertCompatible(body, sword));
29 });
30
31 it("rejects path traversal in map files", () =>
32 {
33 const bad = {
34 format_version: 1,
35 sex: "male",
36 settype: "body",
37 fps: 4,
38 cell_width: 32,
39 cell_height: 48,
40 pitches: [0],
41 yaws: [0],
42 maps: { diffuse: { file: "../x.png" }, depth: { file: "d.u16" } },
43 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 }] }] }],
44 identity: { near: 0, far: 1 }
45 };
46 assert.throws(() => PpdaLoader.parse(bad));
47 });
48
49 it("rejects unknown format_version", () =>
50 {
51 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 } }));
52 });
53});