From 2fe62cd878bbf849ad8b3ee74634e760d420603d Mon Sep 17 00:00:00 2001 From: Yunfei Hao Date: Thu, 7 Dec 2017 10:51:01 +0800 Subject: [PATCH] Added test cases for deviceHub and deviceList Impacted tests: new 21, update 0, delete 0 Unit test platform: Ubuntu 16.04 Unit test result summary: pass 20, fail 0, block 1 --- wrappers/nodejs/test/test-devicehub.js | 96 ++++++++++++++++++++ wrappers/nodejs/test/test-devicelist.js | 112 ++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 wrappers/nodejs/test/test-devicehub.js create mode 100644 wrappers/nodejs/test/test-devicelist.js diff --git a/wrappers/nodejs/test/test-devicehub.js b/wrappers/nodejs/test/test-devicehub.js new file mode 100644 index 0000000000..5fa7dc5354 --- /dev/null +++ b/wrappers/nodejs/test/test-devicehub.js @@ -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); + } + }); +}); diff --git a/wrappers/nodejs/test/test-devicelist.js b/wrappers/nodejs/test/test-devicelist.js new file mode 100644 index 0000000000..4b8980e085 --- /dev/null +++ b/wrappers/nodejs/test/test-devicelist.js @@ -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'); + }); + }); +});