forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-devicelist.js
144 lines (126 loc) · 3.56 KB
/
test-devicelist.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
// 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 devl;
describe('DeviceList test', function() {
beforeEach(function() {
ctx = new rs2.Context();
devl = ctx.queryDevices();
});
afterEach(function() {
rs2.cleanup();
});
it('Testing constructor', () => {
assert.doesNotThrow(() => {
new rs2.DeviceList(devl);
});
});
it('Testing member devices', () => {
if (devl.size === 0 || devl.size === undefined) {
assert.equal(devl.devices, undefined);
}
let output = devl.devices;
for (let i=0; i < devl.size; i++) {
assert(output[i] instanceof rs2.Device);
}
});
it('Testing member size', () => {
assert.equal(typeof devl.size, 'number');
});
it('Testing member back', () => {
let dev = devl.devices;
assert(dev.length > 0); // Device must be connected
let device = devl.getDevice(dev.length -1);
let SN = device.getCameraInfo().serialNumber;
assert.doesNotThrow(() => {
if (devl.size > 0) {
let res = devl.back;
assert(devl.back instanceof rs2.Device);
assert.equal(typeof res, 'object');
assert.equal(res.getCameraInfo().serialNumber, SN);
}
});
});
it('Testing member front', () => {
let dev = devl.devices;
assert(dev.length > 0); // Device must be connected
let device = devl.getDevice(0);
let SN = device.getCameraInfo().serialNumber;
assert.doesNotThrow(() => {
if (devl.size > 0) {
let res = devl.front;
assert(devl.front instanceof rs2.Device);
assert.equal(typeof res, 'object');
assert.equal(res.getCameraInfo().serialNumber, SN);
}
});
});
it('Testing method destroy', () => {
assert.notEqual(devl.cxxList, undefined);
assert.doesNotThrow(() => {
devl.destroy();
});
assert.equal(devl.cxxList, undefined);
});
it('Testing method getDevice - without argument', () => {
assert.throws(() => {
devl.getDevice();
});
});
it('Testing method getDevice - return value', () => {
for (let i = 0; i < devl.size; i++) {
let dev = devl.getDevice(i);
if (dev) {
assert(dev instanceof rs2.Device);
} else {
assert.equal(dev, undefined);
}
}
});
it('Testing method getDevice - with argument', () => {
for (let i = 0; i < devl.size; i++) {
assert.doesNotThrow(() => { // jshint ignore:line
devl.getDevice(i);
});
}
});
it('Testing method getDevice - with invalid argument', () => {
assert.throws(() => {
devl.getDevice('dummy');
});
});
it('Testing method contains - without argument', () => {
assert.throws(() => {
devl.contains();
});
});
it('Testing method contains - return value', () => {
for (let i = 0; i < devl.size; i++) {
let dev = devl.getDevice(i);
assert.equal(typeof devl.contains(dev), 'boolean');
}
});
it('Testing method contains - with argument', () => {
for (let i = 0; i < devl.size; i++) {
assert.doesNotThrow(() => { // jshint ignore:line
let dev = devl.getDevice(i);
devl.contains(dev);
});
}
});
it('Testing method contains - with invalid argument', () => {
assert.throws(() => {
devl.contains('dummy');
});
});
});