forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-frameset.js
130 lines (113 loc) · 3.29 KB
/
test-frameset.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
// Copyright (c) 2018 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 frameset;
let pipeline;
describe('FrameSet test', function() {
before(function() {
pipeline = new rs2.Pipeline();
pipeline.start();
while (frameset === undefined) {
const f = pipeline.waitForFrames();
if (f.size > 1) {
frameset = f;
}
}
});
after(function() {
pipeline.destroy();
rs2.cleanup();
});
it('Testing constructor', () => {
assert.doesNotThrow(() => {
new rs2.FrameSet();
});
});
it('Testing member size', () => {
assert.equal(typeof frameset.size, 'number');
});
it('Testing member depthFrame', () => {
assert(frameset.depthFrame instanceof rs2.DepthFrame);
});
it('Testing member colorFrame', () => {
assert(frameset.colorFrame instanceof rs2.VideoFrame);
});
it('Testing method at - 0 argument', () => {
assert.throws(() => {
frameset.at();
});
});
it('Testing method at - invalid argument', () => {
const len = frameset.size;
let f;
assert.throws(() => {
f = frameset.at(len + 1);
});
assert.equal(f, undefined);
});
it('Testing method at - valid argument', () => {
const len = frameset.size;
for (let i = 0; i < len; i++) {
let f;
assert.doesNotThrow(() => { // jshint ignore:line
f = frameset.at(i);
});
assert(f instanceof rs2.DepthFrame || f instanceof rs2.VideoFrame);
}
});
it('Testing method getFrame - 0 argument', () => {
assert.throws(() => {
frameset.getFrame();
});
});
it('Testing method getFrame - invalid argument', () => {
assert.throws(() => {
frameset.getFrame('dummy');
});
});
it('Testing method getFrame - valid argument', () => {
for (let i in rs2.stream) {
if (rs2.stream[i] &&
i.toUpperCase() !== 'STREAM_COUNT' && // skip counter
i !== 'streamToString' // skip method
) {
assert.doesNotThrow(() => { // jshint ignore:line
frameset.getFrame(rs2.stream[i]);
});
assert.doesNotThrow(() => { // jshint ignore:line
frameset.getFrame(rs2.stream[i]);
});
}
}
});
it('Testing method getFrame - stream_depth', () => {
let d = frameset.getFrame(rs2.stream['stream_depth']); // jshint ignore:line
assert(d instanceof rs2.DepthFrame);
let D = frameset.getFrame(rs2.stream['STREAM_DEPTH']); // jshint ignore:line
assert(D instanceof rs2.DepthFrame);
});
it('Testing method getFrame - stream_color', () => {
let d = frameset.getFrame(rs2.stream['stream_color']); // jshint ignore:line
assert(d instanceof rs2.VideoFrame);
let D = frameset.getFrame(rs2.stream['STREAM_COLOR']); // jshint ignore:line
assert(D instanceof rs2.VideoFrame);
});
it('Testing method forEach', () => {
let counter = 0;
function callback(frame) {
counter++;
assert.equal(frame instanceof rs2.Frame, true);
}
frameset.forEach(callback);
assert.equal(counter, frameset.size);
});
});