mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-08-20 22:39:00 +00:00
more bundle tests
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
const { deepEqual, equal } = require('assert');
|
const { deepEqual, equal, throws } = require('assert');
|
||||||
const { describe, it } = require('node:test');
|
const { describe, it } = require('node:test');
|
||||||
const osc = require('../dist/index');
|
const osc = require('../dist/index');
|
||||||
|
|
||||||
const tests = [
|
const goodTests = [
|
||||||
{
|
{
|
||||||
description: 'simple contents single message',
|
description: 'simple contents single message',
|
||||||
bytes: new Uint8Array([
|
bytes: new Uint8Array([
|
||||||
@@ -20,6 +20,34 @@ const tests = [
|
|||||||
contents: [{ address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }],
|
contents: [{ address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: 'simple contents single bundle',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
...new TextEncoder().encode('#bundle'),
|
||||||
|
...new Uint8Array([0x00]),
|
||||||
|
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||||
|
...new Uint8Array([0x00, 0x00, 0x00, 0x34]),
|
||||||
|
...new Uint8Array([
|
||||||
|
...new TextEncoder().encode('#bundle'),
|
||||||
|
...new Uint8Array([0x00]),
|
||||||
|
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||||
|
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||||
|
...new Uint8Array([
|
||||||
|
0x2f, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x34, 0x2f, 0x66, 0x72, 0x65, 0x71,
|
||||||
|
0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x43, 0xdc, 0x00, 0x00,
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
expected: {
|
||||||
|
timeTag: [32, 0],
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
timeTag: [32, 0],
|
||||||
|
contents: [{ address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: 'resolume bundle example',
|
description: 'resolume bundle example',
|
||||||
bytes: new Uint8Array([
|
bytes: new Uint8Array([
|
||||||
@@ -88,8 +116,71 @@ const tests = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('OSC Bundle Decoding', () => {
|
const badTests = [
|
||||||
tests.forEach((bundleTest) => {
|
{
|
||||||
|
description: 'bad bundle header',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
...new TextEncoder().encode('bundle'),
|
||||||
|
...new Uint8Array([0x00]),
|
||||||
|
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||||
|
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||||
|
...new Uint8Array([
|
||||||
|
0x2f, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x34, 0x2f, 0x66, 0x72, 0x65, 0x71,
|
||||||
|
0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x43, 0xdc, 0x00, 0x00,
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
throwsMessage: {
|
||||||
|
name: /^Error$/,
|
||||||
|
message: 'bundle must start with #bundle',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: 'incomplete bundle',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
...new TextEncoder().encode('#bundle'),
|
||||||
|
...new Uint8Array([0x00]),
|
||||||
|
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||||
|
]),
|
||||||
|
throwsMessage: {
|
||||||
|
name: /^Error$/,
|
||||||
|
message: 'bundle has to be at least 20 bytes',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: 'bundle not enough bytes',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
...new TextEncoder().encode('#bundle'),
|
||||||
|
...new Uint8Array([0x00]),
|
||||||
|
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||||
|
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||||
|
...new Uint8Array([0x2f, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61]),
|
||||||
|
]),
|
||||||
|
throwsMessage: {
|
||||||
|
name: /^Error$/,
|
||||||
|
message: 'bundle does not contain enough data',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: 'bad bundle contents',
|
||||||
|
bytes: new Uint8Array([
|
||||||
|
...new TextEncoder().encode('#bundle'),
|
||||||
|
...new Uint8Array([0x00]),
|
||||||
|
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||||
|
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||||
|
...new Uint8Array([
|
||||||
|
0x2a, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x34, 0x2f, 0x66, 0x72, 0x65, 0x71,
|
||||||
|
0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x43, 0xdc, 0x00, 0x00,
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
throwsMessage: {
|
||||||
|
name: /^Error$/,
|
||||||
|
message: 'bundle contents does not look like a OSC message or bundle',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('OSC Bundle Decoding Pass', () => {
|
||||||
|
goodTests.forEach((bundleTest) => {
|
||||||
it(bundleTest.description, () => {
|
it(bundleTest.description, () => {
|
||||||
const [encoded, remainingBytes] = osc.bundleFromBuffer(bundleTest.bytes);
|
const [encoded, remainingBytes] = osc.bundleFromBuffer(bundleTest.bytes);
|
||||||
equal(remainingBytes.length, 0);
|
equal(remainingBytes.length, 0);
|
||||||
@@ -97,3 +188,13 @@ describe('OSC Bundle Decoding', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('OSC Bundle Decoding Throws', () => {
|
||||||
|
badTests.forEach((bundleTest) => {
|
||||||
|
it(bundleTest.description, () => {
|
||||||
|
throws(() => {
|
||||||
|
osc.bundleFromBuffer(bundleTest.bytes);
|
||||||
|
}, bundleTest.throwsMessage);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user