-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests to test `co64` and `stsz` atoms.
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
const Atom = require('../../lib/mp4/atoms/atom-co64'); | ||
const BufferUtils = require('../../lib/buffer-utils'); | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
const Utils = require('../lib/utils'); | ||
|
||
describe('co64', function () { | ||
describe('#parse()', function () { | ||
it('should parse a well-built buffer', function () { | ||
let entries = [ | ||
Utils.randInt(111111111111, 999999999999999), | ||
Utils.randInt(111111111111, 999999999999999), | ||
Utils.randInt(111111111111, 999999999999999), | ||
]; | ||
let buffer = Buffer.alloc(8 + 8 * entries.length); | ||
buffer.writeUInt32BE(entries.length, 4); | ||
for (let i = 0; i < entries.length; i++) { | ||
BufferUtils.writeUInt64BE(buffer, entries[i], 8 + 8 * i); | ||
} | ||
|
||
let atom = new Atom(); | ||
atom.parse(buffer); | ||
|
||
expect(atom.entries).to.deep.equal(entries); | ||
}); | ||
}); | ||
|
||
describe('#build()', function () { | ||
it('should build a correct buffer', function () { | ||
let entries = [ | ||
Utils.randInt(111111111111, 999999999999999), | ||
Utils.randInt(111111111111, 999999999999999), | ||
Utils.randInt(111111111111, 999999999999999), | ||
]; | ||
|
||
let atom = new Atom(); | ||
atom.entries = entries; | ||
|
||
let buffer = Buffer.alloc(16 + 8 * entries.length); | ||
atom.build(buffer, 0); | ||
|
||
expect(buffer.readUInt32BE(0)).to.be.equal(buffer.length); | ||
expect(buffer.toString('ascii', 4, 8)).to.be.equal('co64'); | ||
|
||
atom = new Atom(); | ||
atom.parse(buffer.subarray(8)); | ||
|
||
expect(atom.entries).to.deep.equal(entries); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const Atom = require('../../lib/mp4/atoms/atom-stsz'); | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
const Utils = require('../lib/utils'); | ||
|
||
describe('stsz', function () { | ||
describe('#parse()', function () { | ||
it('should parse a well-built buffer with different entries', function () { | ||
let entries = [ | ||
Utils.randInt(), | ||
Utils.randInt(), | ||
Utils.randInt(), | ||
]; | ||
let buffer = Buffer.alloc(12 + 4 * entries.length); | ||
buffer.writeUInt32BE(0, 4); | ||
buffer.writeUInt32BE(entries.length, 8); | ||
for (let i = 0; i < entries.length; i++) { | ||
buffer.writeUInt32BE(entries[i], 12 + 4 * i); | ||
} | ||
|
||
let atom = new Atom(); | ||
atom.parse(buffer); | ||
|
||
expect(atom.entries).to.deep.equal(entries); | ||
}); | ||
|
||
it('should parse a well-built buffer with identical entries', function () { | ||
let value = Utils.randInt(); | ||
let entries = [ | ||
value, | ||
value, | ||
value, | ||
]; | ||
let buffer = Buffer.alloc(12); | ||
buffer.writeUInt32BE(value, 4); | ||
buffer.writeUInt32BE(entries.length, 8); | ||
|
||
let atom = new Atom(); | ||
atom.parse(buffer); | ||
|
||
expect(atom.entries).to.deep.equal(entries); | ||
}); | ||
}); | ||
|
||
describe('#build()', function () { | ||
it('should build a correct buffer', function () { | ||
let entries = [ | ||
Utils.randInt(), | ||
Utils.randInt(), | ||
Utils.randInt(), | ||
]; | ||
|
||
let atom = new Atom(); | ||
atom.entries = entries; | ||
|
||
let buffer = Buffer.alloc(20 + 4 * entries.length); | ||
atom.build(buffer, 0); | ||
|
||
expect(buffer.readUInt32BE(0)).to.be.equal(buffer.length); | ||
expect(buffer.toString('ascii', 4, 8)).to.be.equal('stsz'); | ||
|
||
atom = new Atom(); | ||
atom.parse(buffer.subarray(8)); | ||
|
||
expect(atom.entries).to.deep.equal(entries); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters