-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #888 from haoyunfeix/nodejs-cases-for-devicehub
Added test cases for deviceHub and deviceList
- Loading branch information
Showing
2 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.skip('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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// 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 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 method destroy', () => { | ||
assert.notEqual(devl.cxxList, undefined); | ||
assert.doesNotThrow(() => { | ||
devl.destroy(); | ||
}); | ||
assert.equal(devl.cxxList, undefined); | ||
}); | ||
|
||
it('Testing method getDevice - without argument', () => { | ||
let dev = devl.getDevice(); | ||
assert(dev instanceof rs2.Device); | ||
}); | ||
|
||
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', () => { | ||
let dev = devl.getDevice('dummy'); | ||
assert(dev instanceof rs2.Device); | ||
}); | ||
|
||
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'); | ||
}); | ||
}); | ||
}); |