Skip to content

Commit

Permalink
chore(core): Add unit test for GLB with unknown chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Jul 15, 2024
1 parent 34436f8 commit 323c859
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/core/test/io/platform-io.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import fs from 'fs';
import { BufferUtils, Document, Format, GLB_BUFFER, JSONDocument } from '@gltf-transform/core';
import { BufferUtils, Document, Format, GLB_BUFFER, GLTF, JSONDocument } from '@gltf-transform/core';
import { createPlatformIO, resolve } from '@gltf-transform/test-utils';

test('common', async (t) => {
Expand Down Expand Up @@ -153,3 +153,29 @@ test('gltf embedded', async (t) => {
t.truthy(await io.readJSON(jsonDoc), 'reads document');
t.deepEqual(jsonDoc, jsonDocCopy, 'original unchanged');
});

test('glb with unknown chunk', async (t) => {
const io = await createPlatformIO();

const jsonChunkText = JSON.stringify({
asset: { version: '2.0' },
scenes: [{ nodes: [0] }],
nodes: [{ name: 'RootNode' }],
} as GLTF.IGLTF);
const jsonChunkData = BufferUtils.pad(BufferUtils.encodeText(jsonChunkText), 0x20);
const totalByteLength = 12 + 8 + jsonChunkData.byteLength + 8 + 80;

const glb = BufferUtils.concat([
BufferUtils.toView(new Uint32Array([0x46546c67, 2, totalByteLength])),
BufferUtils.toView(new Uint32Array([jsonChunkData.byteLength, 0x4e4f534a])),
jsonChunkData,
BufferUtils.toView(new Uint32Array([80, 0x12345678])),
new Uint8Array(80).fill(0),
]);

const document = await io.readBinary(glb);
t.truthy(document, 'parses GLB with unknown chunk');

const node = document.getRoot().listNodes()[0];
t.is(node.getName(), 'RootNode', 'parses nodes');
});

0 comments on commit 323c859

Please sign in to comment.