forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-frame.js
182 lines (156 loc) · 4.86 KB
/
test-frame.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright (c) 2017 Intel Corporation. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license
// that can be found in the LICENSE file.
'use strict';
/* global describe, it, before, after */
const assert = require('assert');
let rs2;
try {
rs2 = require('node-librealsense');
} catch (e) {
rs2 = require('../index.js');
}
let frame;
let pipeline;
describe('Frame test', function() {
before(function() {
pipeline = new rs2.Pipeline();
pipeline.start();
while (!frame) {
const frameset = pipeline.waitForFrames();
frame = frameset.at(0);
}
});
after(function() {
pipeline.destroy();
rs2.cleanup();
});
it('Testing constructor', () => {
assert.doesNotThrow(() => {
new rs2.Frame();
});
});
it('Testing property isValid', () => {
assert.equal(typeof frame.isValid, 'boolean');
});
it('Testing property data', () => {
assert(Object.prototype.toString.call(frame.data), '[object Uint16Array]' ||
Object.prototype.toString.call(frame.data), '[object Uint8Array]'
);
});
it('Testing property width', () => {
assert.equal(typeof frame.width, 'number');
});
it('Testing property height', () => {
assert.equal(typeof frame.height, 'number');
});
it('Testing property frameNumber', () => {
assert.equal(typeof frame.frameNumber, 'number');
});
it('Testing property timestamp', () => {
assert.equal(typeof frame.timestamp, 'number');
});
it('Testing property streamType', () => {
assert.equal(typeof frame.streamType, 'number');
});
it('Testing property dataByteLength', () => {
assert.equal(typeof frame.dataByteLength, 'number');
});
it('Testing property strideInBytes', () => {
assert.equal(typeof frame.strideInBytes, 'number');
});
it('Testing property bitsPerPixel', () => {
assert.equal(typeof frame.bitsPerPixel, 'number');
});
it('Testing property timestampDomain', () => {
assert.equal(typeof frame.timestampDomain, 'number');
});
it('Testing method frameMetadata - 0 argument', () => {
assert.throws(() => {
frame.frameMetadata();
});
});
it('Testing method frameMetadata - invalid argument', () => {
assert.throws(() => {
frame.frameMetadata('dummy');
});
});
it('Testing method frameMetadata - valid argument', () => {
for (let i in rs2.frame_metadata) {
if (rs2.frame_metadata[i] &&
i.toUpperCase() !== 'FRAME_METADATA_COUNT' && // skip counter
i !== 'frameMetadataToString' // skip method
) {
if (frame.supportsFrameMetadata(rs2.frame_metadata[i])) {
assert.doesNotThrow(() => { // jshint ignore:line
frame.frameMetadata(rs2.frame_metadata[i]);
});
assert.equal(Object.prototype.toString.call(
frame.frameMetadata(rs2.frame_metadata[i])
), '[object Uint8Array]');
} else {
assert.throws(() => { // jshint ignore:line
frame.frameMetadata(rs2.frame_metadata[i]);
});
}
}
}
});
it('Testing method getData - 0 argument', () => {
assert.doesNotThrow(() => {
frame.getData();
});
assert(
Object.prototype.toString.call(frame.getData()), '[object Uint16Array]' ||
Object.prototype.toString.call(frame.getData()), '[object Uint8Array]' ||
Object.prototype.toString.call(frame.getData()), '[object Buffer]'
);
});
it('Testing method getData - buffer argument', () => {
const len = frame.dataByteLength;
let buf = new ArrayBuffer(len);
assert.doesNotThrow(() => {
frame.getData(buf);
});
assert(
Object.prototype.toString.call(buf), '[object Uint16Array]' ||
Object.prototype.toString.call(buf), '[object Uint8Array]' ||
Object.prototype.toString.call(buf), '[object Buffer]'
);
});
it('Testing method getData - 2 argument', () => {
assert.throws(() => {
frame.getData(1, 2);
});
});
it('Testing method getData - invalid argument', () => {
assert.throws(() => {
frame.getData('dummy');
});
});
it('Testing method supportsFrameMetadata - invalid argument', () => {
assert.throws(() => {
frame.supportsFrameMetadata('dummy');
});
});
it('Testing method supportsFrameMetadata - valid argument', () => {
for (let i in rs2.frame_metadata) {
if (rs2.frame_metadata[i] &&
i.toUpperCase() !== 'FRAME_METADATA_COUNT' && // skip counter
i !== 'frameMetadataToString' // skip method
) {
assert.doesNotThrow(() => { // jshint ignore:line
frame.supportsFrameMetadata(rs2.frame_metadata[i]);
});
assert.equal(Object.prototype.toString.call(
frame.supportsFrameMetadata(rs2.frame_metadata[i])
), '[object Boolean]');
}
}
});
it('Testing method destroy', () => {
assert.doesNotThrow(() => {
frame.destroy();
});
});
});