Skip to content

Commit

Permalink
Merge pull request #888 from haoyunfeix/nodejs-cases-for-devicehub
Browse files Browse the repository at this point in the history
Added test cases for deviceHub and deviceList
  • Loading branch information
Halton Huo authored Dec 8, 2017
2 parents f2534eb + 2fe62cd commit c6106fd
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 0 deletions.
96 changes: 96 additions & 0 deletions wrappers/nodejs/test/test-devicehub.js
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);
}
});
});
112 changes: 112 additions & 0 deletions wrappers/nodejs/test/test-devicelist.js
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');
});
});
});

0 comments on commit c6106fd

Please sign in to comment.