Pushing changes
This commit is contained in:
123
node_modules/ebml/test/decoder.js
generated
vendored
Normal file
123
node_modules/ebml/test/decoder.js
generated
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
var ebml = require('../lib/ebml/index.js'),
|
||||
assert = require('assert');
|
||||
|
||||
var STATE_TAG = 1,
|
||||
STATE_SIZE = 2,
|
||||
STATE_CONTENT = 3;
|
||||
|
||||
describe('embl', function() {
|
||||
describe('Decoder', function() {
|
||||
it('should wait for more data if a tag is longer than the buffer', function() {
|
||||
var decoder = new ebml.Decoder();
|
||||
decoder.write(new Buffer([0x1A, 0x45]));
|
||||
|
||||
assert.equal(STATE_TAG, decoder._state);
|
||||
assert.equal(2, decoder._buffer.length);
|
||||
assert.equal(0, decoder._cursor);
|
||||
});
|
||||
|
||||
it('should clear the buffer after a full tag is written in one chunk', function() {
|
||||
var decoder = new ebml.Decoder();
|
||||
decoder.write(new Buffer([0x42, 0x86, 0x81, 0x01]));
|
||||
|
||||
assert.equal(STATE_TAG, decoder._state);
|
||||
assert.equal(0, decoder._buffer.length);
|
||||
assert.equal(0, decoder._cursor);
|
||||
});
|
||||
|
||||
it('should clear the buffer after a full tag is written in multiple chunks', function() {
|
||||
var decoder = new ebml.Decoder();
|
||||
|
||||
decoder.write(new Buffer([0x42, 0x86]));
|
||||
decoder.write(new Buffer([0x81, 0x01]));
|
||||
|
||||
assert.equal(STATE_TAG, decoder._state);
|
||||
assert.equal(0, decoder._buffer.length);
|
||||
assert.equal(0, decoder._cursor);
|
||||
});
|
||||
|
||||
it('should increment the cursor on each step', function() {
|
||||
var decoder = new ebml.Decoder();
|
||||
|
||||
decoder.write(new Buffer([0x42])); // 4
|
||||
|
||||
assert.equal(STATE_TAG, decoder._state);
|
||||
assert.equal(1, decoder._buffer.length);
|
||||
assert.equal(0, decoder._cursor);
|
||||
|
||||
decoder.write(new Buffer([0x86])); // 5
|
||||
|
||||
assert.equal(STATE_SIZE, decoder._state);
|
||||
assert.equal(2, decoder._buffer.length);
|
||||
assert.equal(2, decoder._cursor);
|
||||
|
||||
decoder.write(new Buffer([0x81])); // 6 & 7
|
||||
|
||||
assert.equal(STATE_CONTENT, decoder._state);
|
||||
assert.equal(3, decoder._buffer.length);
|
||||
assert.equal(3, decoder._cursor);
|
||||
|
||||
decoder.write(new Buffer([0x01])); // 6 & 7
|
||||
|
||||
assert.equal(STATE_TAG, decoder._state);
|
||||
assert.equal(0, decoder._buffer.length);
|
||||
assert.equal(0, decoder._cursor);
|
||||
});
|
||||
|
||||
it('should emit correct tag events for simple data', function(done) {
|
||||
var decoder = new ebml.Decoder();
|
||||
decoder.on('data', function(data) {
|
||||
var state = data[0];
|
||||
data = data[1];
|
||||
assert.equal(state, 'tag');
|
||||
assert.equal(data.tag, 0x286);
|
||||
assert.equal(data.tagStr, "4286");
|
||||
assert.equal(data.dataSize, 0x01);
|
||||
assert.equal(data.type, 'u');
|
||||
assert.deepEqual(data.data, new Buffer([0x01]));
|
||||
done();
|
||||
});
|
||||
decoder.write(new Buffer([0x42, 0x86, 0x81, 0x01]));
|
||||
});
|
||||
|
||||
it('should emit correct EBML tag events for master tags', function(done) {
|
||||
var decoder = new ebml.Decoder();
|
||||
|
||||
decoder.on('data', function(data) {
|
||||
var state = data[0];
|
||||
data = data[1];
|
||||
assert.equal(state, 'start');
|
||||
assert.equal(data.tag, 0x0a45dfa3);
|
||||
assert.equal(data.tagStr, "1a45dfa3");
|
||||
assert.equal(data.dataSize, 0);
|
||||
assert.equal(data.type, 'm');
|
||||
assert.equal(data.data, undefined);
|
||||
done();
|
||||
});
|
||||
|
||||
decoder.write(new Buffer([0x1a, 0x45, 0xdf, 0xa3, 0x80]));
|
||||
});
|
||||
|
||||
it('should emit correct EBML:end events for master tags', function(done) {
|
||||
var decoder = new ebml.Decoder();
|
||||
var tags = 0;
|
||||
decoder.on('data', function(data) {
|
||||
var state = data[0];
|
||||
data = data[1];
|
||||
if(state != 'end') {
|
||||
tags++;
|
||||
} else {
|
||||
assert.equal(tags, 2); // two tags
|
||||
assert.equal(data.tag, 0x0a45dfa3);
|
||||
assert.equal(data.tagStr, "1a45dfa3");
|
||||
assert.equal(data.dataSize, 4);
|
||||
assert.equal(data.type, 'm');
|
||||
assert.equal(data.data, undefined);
|
||||
done();
|
||||
}
|
||||
});
|
||||
decoder.write(new Buffer([0x1a, 0x45, 0xdf, 0xa3]));
|
||||
decoder.write(new Buffer([0x84, 0x42, 0x86, 0x81, 0x00]));
|
||||
});
|
||||
});
|
||||
});
|
136
node_modules/ebml/test/ebml.js
generated
vendored
Normal file
136
node_modules/ebml/test/ebml.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
var ebml = require('../lib/ebml/index.js'),
|
||||
assert = require('assert');
|
||||
|
||||
describe('embl', function() {
|
||||
describe('tools', function() {
|
||||
describe('#readVint()', function() {
|
||||
function readVint(buffer, expected) {
|
||||
var vint = ebml.tools.readVint(buffer, 0);
|
||||
assert.equal(expected, vint.value);
|
||||
assert.equal(buffer.length, vint.length);
|
||||
}
|
||||
it('should read the correct value for all 1 byte ints', function() {
|
||||
for (var i = 0; i < 0x80; i++) {
|
||||
readVint(new Buffer([i | 0x80]), i);
|
||||
}
|
||||
});
|
||||
it('should read the correct value for 1 byte int with non-zero start', function() {
|
||||
var b = new Buffer([0x00, 0x81]);
|
||||
var vint = ebml.tools.readVint(b, 1);
|
||||
assert.equal(1, vint.value);
|
||||
assert.equal(1, vint.length);
|
||||
});
|
||||
it('should read the correct value for all 2 byte ints', function() {
|
||||
for (var i = 0; i < 0x40; i++)
|
||||
for (j = 0; j < 0xff; j++) {
|
||||
readVint(new Buffer([i | 0x40, j]), (i << 8) + j);
|
||||
}
|
||||
});
|
||||
it('should read the correct value for all 3 byte ints', function() {
|
||||
for (var i = 0; i < 0x20; i++)
|
||||
for (j = 0; j < 0xff; j += 2)
|
||||
for (k = 0; k < 0xff; k += 3) {
|
||||
readVint(new Buffer([i | 0x20, j, k]), (i << 16) + (j << 8) + k);
|
||||
}
|
||||
});
|
||||
// not brute forcing any more bytes, takes sooo long
|
||||
it('should read the correct value for 4 byte int min/max values', function() {
|
||||
readVint(new Buffer([0x10, 0x20, 0x00, 0x00]), Math.pow(2, 21));
|
||||
readVint(new Buffer([0x1F, 0xFF, 0xFF, 0xFF]), Math.pow(2, 28) - 1);
|
||||
});
|
||||
it('should read the correct value for 5 byte int min/max values', function() {
|
||||
readVint(new Buffer([0x08, 0x10, 0x00, 0x00, 0x00]), Math.pow(2, 28));
|
||||
readVint(new Buffer([0x0F, 0xFF, 0xFF, 0xFF, 0xFF]), Math.pow(2, 35) - 1);
|
||||
});
|
||||
it('should read the correct value for 6 byte int min/max values', function() {
|
||||
readVint(new Buffer([0x04, 0x08, 0x00, 0x00, 0x00, 0x00]), Math.pow(2, 35));
|
||||
readVint(new Buffer([0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), Math.pow(2, 42) - 1);
|
||||
});
|
||||
it('should read the correct value for 7 byte int min/max values', function() {
|
||||
readVint(new Buffer([0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]), Math.pow(2, 42));
|
||||
readVint(new Buffer([0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), Math.pow(2, 49) - 1);
|
||||
});
|
||||
it('should read the correct value for 8 byte int min value', function() {
|
||||
readVint(new Buffer([0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), Math.pow(2, 49));
|
||||
});
|
||||
it('should read the correct value for the max representable JS number (2^53)', function() {
|
||||
readVint(new Buffer([0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), Math.pow(2, 53));
|
||||
});
|
||||
// an unknown value is represented by -1
|
||||
it('should return value -1 for more than max representable JS number (2^53 + 1)', function() {
|
||||
readVint(new Buffer([0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]), -1);
|
||||
});
|
||||
it('should return value -1 for more than max representable JS number (8 byte int max value)', function() {
|
||||
readVint(new Buffer([0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), -1);
|
||||
});
|
||||
it('should throw for 9+ byte int values', function() {
|
||||
assert.throws(function() {
|
||||
ebml.tools.readVint(new Buffer([0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF]));
|
||||
}, /Unrepresentable length/);
|
||||
});
|
||||
});
|
||||
describe('#writeVint()', function() {
|
||||
function writeVint(value, expected) {
|
||||
var actual = ebml.tools.writeVint(value);
|
||||
assert.equal(expected.toString('hex'), actual.toString('hex'));
|
||||
}
|
||||
it('should throw when writing -1', function() {
|
||||
assert.throws(function() {
|
||||
ebml.tools.writeVint(-1);
|
||||
}, /Unrepresentable value/);
|
||||
});
|
||||
it('should write all 1 byte ints', function() {
|
||||
for (var i = 0; i < 0x80 - 1; i++) {
|
||||
writeVint(i, new Buffer([i | 0x80]));
|
||||
}
|
||||
});
|
||||
it('should write 2 byte int min/max values', function() {
|
||||
writeVint(Math.pow(2, 7) - 1, new Buffer([0x40, 0x7F]));
|
||||
writeVint(Math.pow(2, 14) - 2, new Buffer([0x7F, 0xFE]));
|
||||
});
|
||||
it('should write 3 byte int min/max values', function() {
|
||||
writeVint(Math.pow(2, 14) - 1, new Buffer([0x20, 0x3F, 0xFF]));
|
||||
writeVint(Math.pow(2, 21) - 2, new Buffer([0x3F, 0xFF, 0xFE]));
|
||||
});
|
||||
it('should write 4 byte int min/max values', function() {
|
||||
writeVint(Math.pow(2, 21) - 1, new Buffer([0x10, 0x1F, 0xFF, 0xFF]));
|
||||
writeVint(Math.pow(2, 28) - 2, new Buffer([0x1F, 0xFF, 0xFF, 0xFE]));
|
||||
});
|
||||
it('should write 5 byte int min/max value', function() {
|
||||
writeVint(Math.pow(2, 28) - 1, new Buffer([0x08, 0x0F, 0xFF, 0xFF, 0xFF]));
|
||||
writeVint(Math.pow(2, 35) - 2, new Buffer([0x0F, 0xFF, 0xFF, 0xFF, 0xFE]));
|
||||
});
|
||||
it('should write 6 byte int min/max value', function() {
|
||||
writeVint(Math.pow(2, 35) - 1, new Buffer([0x04, 0x07, 0xFF, 0xFF, 0xFF, 0xFF]));
|
||||
writeVint(Math.pow(2, 42) - 2, new Buffer([0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE]));
|
||||
});
|
||||
it('should write 7 byte int min/max value', function() {
|
||||
writeVint(Math.pow(2, 42) - 1, new Buffer([0x02, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]));
|
||||
writeVint(Math.pow(2, 49) - 2, new Buffer([0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE]));
|
||||
});
|
||||
it('should write the correct value for 8 byte int min value', function() {
|
||||
writeVint(Math.pow(2, 49) - 1, new Buffer([0x01, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]));
|
||||
});
|
||||
it('should write the correct value for the max representable JS number (2^53)', function() {
|
||||
writeVint(Math.pow(2, 53), new Buffer([0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]));
|
||||
});
|
||||
// Can't prevent this, 2^53 + 1 === 2^53
|
||||
// it('should throw for more than max representable JS number (2^53 + 1)', function() {
|
||||
// assert.throws(function() {
|
||||
// ebml.tools.writeVint(Math.pow(2, 53) + 1));
|
||||
// }, /Unrepresentable value/)
|
||||
// })
|
||||
it('should throw for more than max representable JS number (8 byte int max value)', function() {
|
||||
assert.throws(function() {
|
||||
ebml.tools.writeVint(Math.pow(2, 56) + 1);
|
||||
}, /Unrepresentable value/);
|
||||
});
|
||||
it('should throw for 9+ byte int values', function() {
|
||||
assert.throws(function() {
|
||||
ebml.tools.writeVint(Math.pow(2, 56) + 1);
|
||||
}, /Unrepresentable value/);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
35
node_modules/ebml/test/encoder.js
generated
vendored
Normal file
35
node_modules/ebml/test/encoder.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
var ebml = require('../lib/ebml/index.js'),
|
||||
assert = require('assert');
|
||||
|
||||
describe('embl', function() {
|
||||
describe('Encoder', function() {
|
||||
function createEncoder(expected, done) {
|
||||
var encoder = new ebml.Encoder();
|
||||
encoder.on('data', function(chunk) {
|
||||
assert.equal(chunk.toString('hex'), new Buffer(expected).toString('hex'));
|
||||
done();
|
||||
});
|
||||
return encoder;
|
||||
}
|
||||
it('should write a single tag', function(done) {
|
||||
var encoder = createEncoder([0x42, 0x86, 0x81, 0x01], done);
|
||||
encoder.write(['tag', {
|
||||
name: 'EBMLVersion',
|
||||
data: new Buffer([0x01])
|
||||
}]);
|
||||
});
|
||||
it('should write a tag with a single child', function(done) {
|
||||
var encoder = createEncoder([0x1a, 0x45, 0xdf, 0xa3, 0x84, 0x42, 0x86, 0x81, 0x00], done);
|
||||
encoder.write(['start', {
|
||||
name: 'EBML',
|
||||
}]);
|
||||
encoder.write(['tag', {
|
||||
name: 'EBMLVersion',
|
||||
data: new Buffer([0x00])
|
||||
}]);
|
||||
encoder.write(['end', {
|
||||
name: 'EBML',
|
||||
}]);
|
||||
});
|
||||
});
|
||||
});
|
1
node_modules/ebml/test/mocha.opts
generated
vendored
Normal file
1
node_modules/ebml/test/mocha.opts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
--reporter spec
|
33
node_modules/ebml/test/pipeline.js
generated
vendored
Normal file
33
node_modules/ebml/test/pipeline.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
var ebml = require('../lib/ebml/index.js'),
|
||||
assert = require('assert');
|
||||
|
||||
describe('embl', function() {
|
||||
describe('Pipeline', function() {
|
||||
it('should output input buffer', function(done) {
|
||||
var decoder = new ebml.Decoder();
|
||||
var encoder = new ebml.Encoder();
|
||||
var buffer = new Buffer([0x1a, 0x45, 0xdf, 0xa3, 0x84, 0x42, 0x86, 0x81, 0x00]);
|
||||
encoder.on('data', function(chunk) {
|
||||
assert.equal(chunk.toString('hex'), buffer.toString('hex'));
|
||||
done();
|
||||
});
|
||||
decoder.pipe(encoder);
|
||||
decoder.write(buffer);
|
||||
});
|
||||
|
||||
it('should support end === -1', function (done) {
|
||||
var decoder = new ebml.Decoder();
|
||||
var encoder = new ebml.Encoder();
|
||||
|
||||
encoder.write(['start', {name: 'Cluster', start: 0, end: -1}]);
|
||||
encoder.write(['end', {name: 'Cluster', start: 0, end: -1}]);
|
||||
|
||||
encoder.pipe(decoder).on('data', function (data) {
|
||||
assert.equal(data[1].name, 'Cluster');
|
||||
assert.equal(data[1].start, 0);
|
||||
assert.equal(data[1].end, -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user