-
Notifications
You must be signed in to change notification settings - Fork 428
/
test-PaVEParser.js
114 lines (96 loc) · 3.62 KB
/
test-PaVEParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var common = require('../../common');
var assert = require('assert');
var test = require('utest');
var PaVEParser = require(common.lib + '/video/PaVEParser');
var fs = require('fs');
var sinon = require('sinon');
var fixture = fs.readFileSync(common.fixtures + '/pave.bin');
var fixture68 = fs.readFileSync(common.fixtures + '/pave-68.bin');
test('PaVEParser', {
before: function() {
this.parser = new PaVEParser();
},
'parses fixture properly': function() {
var frames = [];
this.parser.on('data', function(frame) {
frames.push(frame);
});
this.parser.write(fixture);
assert.equal(frames.length, 20);
var first = frames[0];
assert.equal(first.signature, 'PaVE');
assert.equal(first.version, 2);
assert.equal(first.video_codec, 4);
assert.equal(first.header_size, 64);
assert.equal(first.payload_size, 2632);
assert.equal(first.encoded_stream_width, 640);
assert.equal(first.encoded_stream_height, 368);
assert.equal(first.display_width, 640);
assert.equal(first.display_height, 360);
assert.equal(first.frame_number, 17368);
assert.equal(first.timestamp, 1792570814);
assert.equal(first.total_chunks, 1);
assert.equal(first.chunk_index, 0);
assert.equal(first.frame_type, 3);
assert.equal(first.control, 0);
assert.equal(first.stream_byte_position_lw, 72366960);
assert.equal(first.stream_byte_position_uw, 0);
assert.equal(first.stream_id, 5);
assert.equal(first.total_slices, 1);
assert.equal(first.slice_index, 0);
assert.equal(first.header1_size, 0);
assert.equal(first.header2_size, 0);
assert.equal(first.reserved2.length, 2);
assert.equal(first.advertised_size, 2632);
assert.equal(first.reserved3.length, 12);
assert.equal(first.payload.length, 2632);
},
'parses 68 byte frames properly': function() {
var frames = [];
this.parser.on('data', function(frame) {
frames.push(frame);
});
this.parser.write(fixture68);
assert.equal(frames.length, 5);
var first = frames[0];
assert.equal(first.signature, 'PaVE');
assert.equal(first.version, 2);
assert.equal(first.video_codec, 4);
assert.equal(first.header_size, 68);
assert.equal(first.payload_size, 10180);
assert.equal(first.encoded_stream_width, 640);
assert.equal(first.encoded_stream_height, 368);
assert.equal(first.display_width, 640);
assert.equal(first.display_height, 360);
assert.equal(first.frame_number, 245401);
assert.equal(first.timestamp, 8015353);
assert.equal(first.total_chunks, 1);
assert.equal(first.chunk_index, 0);
assert.equal(first.frame_type, 1);
assert.equal(first.control, 0);
assert.equal(first.stream_byte_position_lw, 1009151980);
assert.equal(first.stream_byte_position_uw, 0);
assert.equal(first.stream_id, 1);
assert.equal(first.total_slices, 1);
assert.equal(first.slice_index, 0);
assert.equal(first.header1_size, 14);
assert.equal(first.header2_size, 10);
assert.equal(first.reserved2.length, 2);
assert.equal(first.advertised_size, 10180);
assert.equal(first.reserved3.length, 12);
assert.equal(first.payload.length, 10180);
},
'emits error on bad signature': function() {
var buffer = new Buffer(68);
// should be PaVE, not fuck
buffer.write('fuck');
var errorStub = sinon.stub();
this.parser.on('error', errorStub);
this.parser.write(buffer);
assert.equal(errorStub.callCount, 1);
assert.equal(/signature/i.test(errorStub.getCall(0).args[0]), true);
},
'end method exists, but does nothing': function() {
this.parser.end();
},
});