Skip to content

Commit

Permalink
js: Add tests for decodeGltfBuffer*
Browse files Browse the repository at this point in the history
These previously required end-to-end testing via Three.JS. Note that we
can't test Web Worker implementation via node.js.
  • Loading branch information
zeux committed Oct 5, 2023
1 parent b50b4ab commit c4e0e1b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions js/meshopt_decoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,50 @@ var tests = {

assert.deepStrictEqual(result, expected);
},

decodeGltfBuffer: function() {
var encoded = new Uint8Array([
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01,
0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00,
0x00, 0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);

var expected = new Uint8Array([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0,
0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1,
44, 1, 44, 1, 0, 0, 0, 0, 244, 1, 244, 1
]);

var result = new Uint8Array(expected.length);
decoder.decodeGltfBuffer(result, 4, 12, encoded, /* mode= */ "ATTRIBUTES");
assert.deepStrictEqual(result, expected);
},

decodeGltfBufferAsync: function() {
var encoded = new Uint8Array([
0xa0, 0x01, 0x3f, 0x00, 0x00, 0x00, 0x58, 0x57, 0x58, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01,
0x0c, 0x00, 0x00, 0x00, 0x58, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x3f, 0x00, 0x00, 0x00, 0x17, 0x18, 0x17, 0x01, 0x26, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00,
0x00, 0x00, 0x17, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);

var expected = new Uint8Array([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44, 1, 0, 0, 0, 0, 0, 0, 244, 1, 0, 0,
0, 0, 44, 1, 0, 0, 0, 0, 0, 0, 244, 1,
44, 1, 44, 1, 0, 0, 0, 0, 244, 1, 244, 1
]);

decoder.decodeGltfBufferAsync(4, 12, encoded, /* mode= */ "ATTRIBUTES").then(function (result) {
assert.deepStrictEqual(result, expected);
});
},
};

decoder.ready.then(() => {
Expand Down

0 comments on commit c4e0e1b

Please sign in to comment.