forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-devicehub.js
96 lines (83 loc) · 2.14 KB
/
test-devicehub.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
// 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, beforeEach, afterEach */
const assert = require('assert');
let rs2;
try {
rs2 = require('node-librealsense');
} catch (e) {
rs2 = require('../index.js');
}
let ctx;
let devh;
describe('DeviceHub test', function() {
beforeEach(function() {
ctx = new rs2.Context();
devh = new rs2.DeviceHub(ctx);
});
afterEach(function() {
rs2.cleanup();
});
it('Testing constructor', () => {
assert.doesNotThrow(() => {
new rs2.DeviceHub(ctx);
});
});
it('Testing method destroy', () => {
assert.notEqual(devh.cxxHub, undefined);
assert.doesNotThrow(() => {
devh.destroy();
});
assert.equal(devh.cxxHub, undefined);
});
it('Testing method isConnected', () => {
let devs = ctx.queryDevices().devices;
devs.forEach((dev) => {
assert.doesNotThrow(() => {
devh.isConnected(dev);
});
assert(devh.isConnected(dev));
});
});
it('Testing method isConnected - without argument', () => {
assert.throws(() => {
devh.isConnected();
});
});
it('Testing method isConnected - with invalid argument', () => {
assert.throws(() => {
devh.isConnected('dummy');
});
});
it('Testing method waitForDevice', () => {
assert.doesNotThrow(() => {
devh.waitForDevice();
});
});
it('Testing method waitForDevice - return value', () => {
let dev = devh.waitForDevice();
if (dev) {
assert(dev instanceof rs2.Device);
} else {
assert.equal(dev, undefined);
}
});
it('Testing method waitForDevice - with invalid argument', () => {
let dev = devh.waitForDevice('dummy');
assert(dev instanceof rs2.Device);
});
it('Testing method waitForDevice - call multiple times', () => {
let dev;
assert.doesNotThrow(() => {
dev = devh.waitForDevice();
dev = devh.waitForDevice();
});
if (dev) {
assert(dev instanceof rs2.Device);
} else {
assert.equal(dev, undefined);
}
});
});