forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-pipelineprofile.js
144 lines (126 loc) · 3.73 KB
/
test-pipelineprofile.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
// 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, beforeEach, afterEach */
const assert = require('assert');
let rs2;
try {
rs2 = require('node-librealsense');
} catch (e) {
rs2 = require('../index.js');
}
let ctx;
let pipeline;
let pipelineProfile;
let devices;
describe('PipelineProfile test', function() {
beforeEach(function() {
ctx = new rs2.Context();
devices = ctx.queryDevices().devices;
assert(devices.length > 0); // Device must be connected
pipeline = new rs2.Pipeline(ctx);
pipeline.start();
pipelineProfile = pipeline.getActiveProfile();
});
afterEach(function() {
pipeline.stop();
pipeline.destroy();
rs2.cleanup();
});
it('Testing constructor - valid', () => {
assert.doesNotThrow(() => {
new rs2.PipelineProfile();
});
});
it('Testing member isValid', () => {
let res;
assert.doesNotThrow(() => {
res = pipelineProfile.isValid;
});
assert.equal(typeof res, 'boolean');
assert(typeof res !== undefined);
});
it('Testing method destroy', () => {
assert.doesNotThrow(() => {
let res = pipelineProfile.destroy();
assert.equal(typeof res, 'undefined');
});
assert.equal(pipelineProfile.cxxPipelineProfile, undefined);
});
it('Testing method getDevice', () => {
assert.doesNotThrow(() => {
let res = pipelineProfile.getDevice();
assert(res instanceof rs2.Device);
assert.equal(res.isValid, true);
});
});
it('Testing method getDevice before pipeline.start', () => {
pipeline.destroy();
let pipe = new rs2.Pipeline(ctx);
let pipeProfile = pipe.getActiveProfile();
assert.throws(() => {
pipeProfile.getDevice();
});
assert.doesNotThrow(() => {
pipe.start();
pipeProfile = pipe.getActiveProfile();
let res = pipeProfile.getDevice();
assert(res instanceof rs2.Device);
assert.equal(res.isValid, true);
});
});
it('Testing method getStream w/o args', () => {
assert.throws(() => {
pipelineProfile.getStream();
});
});
it('Testing method getStream w/ invalid args', () => {
assert.throws(() => {
pipelineProfile.getStream('dummy');
});
});
it('Testing method getStream w/ invalid number', () => {
assert.throws(() => {
pipelineProfile.getStream(999);
});
});
it('Testing method getStream, w/ three args', () => {
assert.throws(() => {
pipelineProfile.getStream(1, 1, 1);
});
});
it('Testing method getStream, w/ invalid streamIndex', () => {
assert.doesNotThrow(() => {
let res = pipelineProfile.getStream(1, 999);
assert.equal(res, undefined);
});
});
it('Testing method getStream, w/ one args', () => {
let res = pipelineProfile.getStreams();
let valueArray = [];
res.forEach((s) => {
if (valueArray.indexOf(s.streamIndex) === -1) valueArray.push(s.streamIndex);
});
valueArray.forEach((value) => {
assert.doesNotThrow(() => {
pipelineProfile.getStream(value);
});
});
});
it('Testing method getStreams', () => {
assert.doesNotThrow(() => {
let res = pipelineProfile.getStreams();
assert.equal(Object.prototype.toString.call(res), '[object Array]');
assert.notEqual(res, undefined);
res.forEach((s) => {
assert.equal(typeof s.format, 'number');
assert.equal(typeof s.fps, 'number');
assert.equal(typeof s.isDefault, 'boolean');
assert.equal(typeof s.streamIndex, 'number');
assert.equal(typeof s.streamType, 'number');
assert.equal(typeof s.uniqueID, 'number');
});
});
});
});