diff --git a/wrappers/nodejs/test/test-config.js b/wrappers/nodejs/test/test-config.js index 963e7b4382..0d8e47b0d3 100644 --- a/wrappers/nodejs/test/test-config.js +++ b/wrappers/nodejs/test/test-config.js @@ -14,19 +14,11 @@ try { } let config; -let frameset; let pipeline; let serial; describe('Config test', function() { before(function() { pipeline = new rs2.Pipeline(); - pipeline.start(); - while (frameset === undefined) { - const f = pipeline.waitForFrames(); - if (f.size > 1) { - frameset = f; - } - } config = new rs2.Config(); const ctx = new rs2.Context(); const devices = ctx.queryDevices().devices; @@ -103,18 +95,6 @@ describe('Config test', function() { } }); - it('Testing method enableAllStreams - 0 argument', () => { - assert.doesNotThrow(() => { - config.enableAllStreams(); - }); - }); - - it('Testing method enableAllStreams - 1 argument', () => { - assert.doesNotThrow(() => { - config.enableAllStreams(1); - }); - }); - it('Testing method enableDevice - 0 argument', () => { assert.doesNotThrow(() => { config.enableDevice(); @@ -176,11 +156,23 @@ describe('Config test', function() { }); }); - it.skip('Testing method resolve - valid argument', () => { + it('Testing method resolve - valid argument', () => { let pp; assert.doesNotThrow(() => { pp = config.resolve(pipeline); }); assert(pp instanceof rs2.PipelineProfile); }); + + it('Testing method enableAllStreams - 0 argument', () => { + assert.doesNotThrow(() => { + config.enableAllStreams(); + }); + }); + + it('Testing method enableAllStreams - 1 argument', () => { + assert.doesNotThrow(() => { + config.enableAllStreams(1); + }); + }); }); diff --git a/wrappers/nodejs/test/test-context.js b/wrappers/nodejs/test/test-context.js index 3ef9b85fb2..832741a546 100644 --- a/wrappers/nodejs/test/test-context.js +++ b/wrappers/nodejs/test/test-context.js @@ -24,6 +24,36 @@ describe('Context test', function() { after(function() { librealsense2.cleanup(); }); + + function createRrdFile() { + const ctx = new librealsense2.Context(); + let dev = ctx.queryDevices().devices[0]; + // record to file record.bag + let recorder = new librealsense2.RecorderDevice('record.bag', dev); + let sensors = recorder.querySensors(); + let sensor = sensors[0]; + let profiles = sensor.getStreamProfiles(); + for (let i =0; i < profiles.length; i++) { + if (profiles[i].streamType === librealsense2.stream.STREAM_DEPTH && + profiles[i].fps === 30 && + profiles[i].width === 640 && + profiles[i].height === 480 && + profiles[i].format === librealsense2.format.FORMAT_Z16) { + sensor.open(profiles[i]); + } + } + // record 10 frames + let cnt = 0; + sensor.start((frame) => { + cnt++; + if (cnt === 10) { + // stop recording + recorder.reset(); + librealsense2.cleanup(); + } + }); + } + it('testing constructor', () => { assert.doesNotThrow(() => { new librealsense2.Context(); @@ -76,25 +106,6 @@ describe('Context test', function() { }); }); - // getTime is removed - it.skip('testing method - getTime, should get number value', () => { - const context = new librealsense2.Context(); - assert.doesNotThrow(() => { - context.getTime(); - }); - assert.equal(typeof context.getTime(), 'number'); - }); - - it.skip('testing method - getTime, should get current system time', () => { - const context = new librealsense2.Context(); - assert.doesNotThrow(() => { - context.getTime(); - }); - const currentTime = new Date(); - assert(context.getTime() - currentTime > 0 && - context.getTime() - currentTime < 5); - }); - it('testing method - queryDevices, should get array', () => { const context = new librealsense2.Context(); assert.doesNotThrow(() => { @@ -140,46 +151,12 @@ describe('Context test', function() { }); }); - // isDeviceConnected is no more a method of Context - it.skip('testing method - isDeviceConnected', () => { - const context = new librealsense2.Context(); - const devs = context.queryDevices().devices; - assert(devs[0]); - const dev = devs[0]; - assert.doesNotThrow(() => { - context.isDeviceConnected(dev); - }); - }); - - // isDeviceConnected is no more a method of Context - it.skip('testing method - isDeviceConnected, return value', () => { - const context = new librealsense2.Context(); - const devs = context.queryDevices().devices; - assert(devs[0]); - const dev = devs[0]; - assert.equal(typeof context.isDeviceConnected(dev), 'boolean'); - assert.equal(context.isDeviceConnected(dev), true); - }); - - it('testing method - isDeviceConnected, with invalid options', () => { - const context = new librealsense2.Context(); - let opt; - assert.throws(() => { - context.isDeviceConnected(); - }); - assert.throws(() => { - context.isDeviceConnected(opt); - }); - assert.throws(() => { - context.isDeviceConnected(null); - }); - }); - it('testing method - loadDevice, return playbackDevice', () => { + createRrdFile(); const context = new librealsense2.Context(); let pbd; assert.doesNotThrow(() => { - pbd = context.loadDevice(); + pbd = context.loadDevice('record.bag'); }); assert(pbd instanceof librealsense2.Device); }); diff --git a/wrappers/nodejs/test/test-depthframe.js b/wrappers/nodejs/test/test-depthframe.js new file mode 100644 index 0000000000..aa01fc41c1 --- /dev/null +++ b/wrappers/nodejs/test/test-depthframe.js @@ -0,0 +1,190 @@ +// 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, before, after */ +const assert = require('assert'); +let rs2; +try { + rs2 = require('node-librealsense'); +} catch (e) { + rs2 = require('../index.js'); +} + +let frame; +let pipeline; +describe('DepthFrame test', function() { + before(function() { + pipeline = new rs2.Pipeline(); + pipeline.start(); + while (!frame) { + const frameset = pipeline.waitForFrames(); + frame = frameset.at(0); + } + }); + + after(function() { + pipeline.destroy(); + rs2.cleanup(); + }); + + it('Testing constructor', () => { + assert.doesNotThrow(() => { + new rs2.DepthFrame(); + }); + }); + + it('Testing property isValid', () => { + assert.equal(typeof frame.isValid, 'boolean'); + }); + + it('Testing property data', () => { + assert(Object.prototype.toString.call(frame.data), '[object Uint16Array]' || + Object.prototype.toString.call(frame.data), '[object Uint8Array]' + ); + }); + + it('Testing property width', () => { + assert.equal(typeof frame.width, 'number'); + }); + + it('Testing property height', () => { + assert.equal(typeof frame.height, 'number'); + }); + + it('Testing property frameNumber', () => { + assert.equal(typeof frame.frameNumber, 'number'); + }); + + it('Testing property timestamp', () => { + assert.equal(typeof frame.timestamp, 'number'); + }); + + it('Testing property streamType', () => { + assert.equal(typeof frame.streamType, 'number'); + }); + + it('Testing property dataByteLength', () => { + assert.equal(typeof frame.dataByteLength, 'number'); + }); + + it('Testing property strideInBytes', () => { + assert.equal(typeof frame.strideInBytes, 'number'); + }); + + it('Testing property bitsPerPixel', () => { + assert.equal(typeof frame.bitsPerPixel, 'number'); + }); + + it('Testing property bytesPerPixel', () => { + assert.equal(typeof frame.bytesPerPixel, 'number'); + assert.equal(frame.bytesPerPixel, frame.bitsPerPixel/8); + }); + + it('Testing property timestampDomain', () => { + assert.equal(typeof frame.timestampDomain, 'string'); + }); + + it('Testing method frameMetadata - 0 argument', () => { + assert.throws(() => { + frame.frameMetadata(); + }); + }); + + it('Testing method frameMetadata - invalid argument', () => { + assert.throws(() => { + frame.frameMetadata('dummy'); + }); + }); + + it('Testing method frameMetadata - valid argument', () => { + for (let i in rs2.frame_metadata) { + if (rs2.frame_metadata[i] && + i.toUpperCase() !== 'FRAME_METADATA_COUNT' && // skip counter + i !== 'frameMetadataToString' // skip method + ) { + assert.doesNotThrow(() => { // jshint ignore:line + frame.frameMetadata(rs2.frame_metadata[i]); + }); + assert.equal(Object.prototype.toString.call( + frame.frameMetadata(rs2.frame_metadata[i]) + ), '[object Uint8Array]'); + } + } + }); + + it('Testing method getData - 0 argument', () => { + assert.doesNotThrow(() => { + frame.getData(); + }); + assert( + Object.prototype.toString.call(frame.getData()), '[object Uint16Array]' || + Object.prototype.toString.call(frame.getData()), '[object Uint8Array]' || + Object.prototype.toString.call(frame.getData()), '[object Buffer]' + ); + }); + + it('Testing method getData - buffer argument', () => { + const len = frame.dataByteLength; + let buf = new ArrayBuffer(len); + console.log(typeof buf); + assert.doesNotThrow(() => { + frame.getData(buf); + }); + assert( + Object.prototype.toString.call(buf), '[object Uint16Array]' || + Object.prototype.toString.call(buf), '[object Uint8Array]' || + Object.prototype.toString.call(buf), '[object Buffer]' + ); + }); + + it('Testing method getData - 2 argument', () => { + assert.throws(() => { + frame.getData(1, 2); + }); + }); + + it('Testing method getData - invalid argument', () => { + assert.throws(() => { + frame.getData('dummy'); + }); + }); + + it('Testing method supportsFrameMetadata - invalid argument', () => { + assert.throws(() => { + frame.supportsFrameMetadata('dummy'); + }); + }); + + it('Testing method supportsFrameMetadata - valid argument', () => { + for (let i in rs2.frame_metadata) { + if (rs2.frame_metadata[i] && + i.toUpperCase() !== 'FRAME_METADATA_COUNT' && // skip counter + i !== 'frameMetadataToString' // skip method + ) { + assert.doesNotThrow(() => { // jshint ignore:line + frame.supportsFrameMetadata(rs2.frame_metadata[i]); + }); + assert.equal(Object.prototype.toString.call( + frame.supportsFrameMetadata(rs2.frame_metadata[i]) + ), '[object Boolean]'); + } + } + }); + + it('Testing method getDistance - valid argument', () => { + let d; + assert.doesNotThrow(() => { + d = frame.getDistance(1, 2); + }); + assert.equal(typeof d, 'number'); + }); + + it('Testing method destroy', () => { + assert.doesNotThrow(() => { + frame.destroy(); + }); + }); +}); diff --git a/wrappers/nodejs/test/test-device.js b/wrappers/nodejs/test/test-device.js index 00ce3f3cb6..15920d5550 100644 --- a/wrappers/nodejs/test/test-device.js +++ b/wrappers/nodejs/test/test-device.js @@ -33,6 +33,14 @@ describe('Device test', function() { }); }); + it('Testing member - first', () => { + assert(dev.first instanceof rs2.Sensor); + }); + + it('Testing member - isValid', () => { + assert.equal(typeof dev.isValid, 'boolean'); + }); + it('Testing method destroy', () => { assert.doesNotThrow(() => { dev.destroy(); @@ -78,13 +86,6 @@ describe('Device test', function() { }); }); - it('Testing method isValid', () => { - assert.doesNotThrow(() => { - dev.isValid(); - }); - assert.equal(typeof dev.isValid(), 'boolean'); - }); - it('Testing method querySensors - return value', () => { assert.doesNotThrow(() => { dev.querySensors(); diff --git a/wrappers/nodejs/test/test-frame.js b/wrappers/nodejs/test/test-frame.js index 496e8513b9..41adc8ba4c 100644 --- a/wrappers/nodejs/test/test-frame.js +++ b/wrappers/nodejs/test/test-frame.js @@ -62,7 +62,7 @@ describe('Frame test', function() { assert.equal(typeof frame.timestamp, 'number'); }); - it.skip('Testing property streamType', () => { + it('Testing property streamType', () => { assert.equal(typeof frame.streamType, 'number'); }); @@ -121,10 +121,9 @@ describe('Frame test', function() { ); }); - it.skip('Testing method getData - buffer argument', () => { + it('Testing method getData - buffer argument', () => { const len = frame.dataByteLength; let buf = new ArrayBuffer(len); - console.log(typeof buf); assert.doesNotThrow(() => { frame.getData(buf); }); diff --git a/wrappers/nodejs/test/test-pipeline.js b/wrappers/nodejs/test/test-pipeline.js index b25f515ad6..213c80a0d4 100644 --- a/wrappers/nodejs/test/test-pipeline.js +++ b/wrappers/nodejs/test/test-pipeline.js @@ -14,13 +14,11 @@ try { } let ctx; -let dev; describe('Pipeline test', function() { before(function() { ctx = new rs2.Context(); const devices = ctx.queryDevices().devices; assert(devices.length > 0); // Device must be connected - dev = devices[0]; }); after(function() { @@ -51,13 +49,6 @@ describe('Pipeline test', function() { }); }); - // Not supported - it.skip('Testing constructor - 1 device option', () => { - assert.doesNotThrow(() => { - new rs2.Pipeline(dev); - }); - }); - it('Testing method destroy', () => { let pipeline; assert.doesNotThrow(() => { diff --git a/wrappers/nodejs/test/test-points.js b/wrappers/nodejs/test/test-points.js index e38ea51a1f..cfe1141387 100644 --- a/wrappers/nodejs/test/test-points.js +++ b/wrappers/nodejs/test/test-points.js @@ -96,4 +96,40 @@ describe('Points test', function() { frameSet.destroy(); pipeline.destroy(); }); + + it('Testing member size', () => { + let pipeline; + let frameSet; + let pointcloud; + assert.doesNotThrow(() => { + pipeline = new rs2.Pipeline(); + pointcloud = new rs2.PointCloud(); + pipeline.start(); + }); + let endTest = false; + let n = 0; + while (!endTest) { + frameSet = pipeline.waitForFrames(); + n++; + console.log(`retring left ...${10 - n} times`); + if (frameSet !== undefined && frameSet.colorFrame !== undefined && + frameSet.depthFrame !== undefined) { + let points; + let arr; + assert.doesNotThrow(() => { // jshint ignore:line + points = pointcloud.calculate(frameSet.depthFrame); + arr = points.size; + }); + assert.equal(typeof arr, 'number'); + assert.equal(Object.prototype.toString.call(arr), '[object Number]'); + pointcloud.destroy(); + endTest = true; + } + if (n >= 10) { + assert(false, 'could not get colorFrame or depthFrame, try to reset camera'); + } + } + frameSet.destroy(); + pipeline.destroy(); + }); }); diff --git a/wrappers/nodejs/test/test-sensor.js b/wrappers/nodejs/test/test-sensor.js index 0f1e51f50a..0d58244711 100644 --- a/wrappers/nodejs/test/test-sensor.js +++ b/wrappers/nodejs/test/test-sensor.js @@ -32,17 +32,22 @@ describe('Sensor test', function() { rs2.option.OPTION_ENABLE_AUTO_WHITE_BALANCE, ]; - it.skip('Testing method getMotionIntrinsics', () => { + it('Testing member - isValid', () => { + sensors.forEach((sensor) => { + assert.equal(typeof sensor.isValid, 'boolean'); + }); + }); + it('Testing method getMotionIntrinsics', () => { sensors.forEach((sensor) => { Object.keys(rs2.stream).forEach((o) => { if (o === 'STREAM_COUNT' || o === 'streamToString') return; const m = sensor.getMotionIntrinsics(rs2.stream[o]); assert.equal(typeof m, 'object'); - assert.equal(Object.prototype.toString.call(m.data), '[object Float32Array]'); + assert.equal(Object.prototype.toString.call(m.data), '[object Array]'); assert.equal(m.data.length, 12); - assert.equal(Object.prototype.toString.call(m.noiseVariances), '[object Float32Array]'); + assert.equal(Object.prototype.toString.call(m.noiseVariances), '[object Array]'); assert.equal(m.noiseVariances.length, 3); - assert.equal(Object.prototype.toString.call(m.biasVariances), '[object Float32Array]'); + assert.equal(Object.prototype.toString.call(m.biasVariances), '[object Array]'); assert.equal(m.biasVariances.length, 3); }); }); @@ -190,62 +195,45 @@ describe('Sensor test', function() { if (o === 'OPTION_COUNT' || o === 'optionToString') return; // retrun if sensor does not support option if (!sensor.supportsOption(rs2.option[o])) return; - if (rs2.option[o] === 'visual-preset' || - rs2.option[o] === 'error-polling-enabled' || - rs2.option[o] === 'output-trigger-enabled' || - rs2.option[o] === 'depth-units' || - rs2.option[o] === 12 || - rs2.option[o] === 24 || - rs2.option[o] === 26 || - rs2.option[o] === 28 || - rs2.option[o] === 'backlight-compensation' || - rs2.option[o] === 'white-balance' || - rs2.option[o] === 'enable-auto-white-balance' || - rs2.option[o] === 'power-line-frequency' || - rs2.option[o] === 0 || - rs2.option[o] === 9 || - rs2.option[o] === 11 || - rs2.option[o] === 22 || - rs2.option[o] === 19 - ) return; const v = sensor.getOption(rs2.option[o]); - sensor.setOption(rs2.option[o], v + 1); + let vSet; + const r = sensor.getOptionRange(rs2.option[o]); + if ((v - r.step) < r.minValue) { + vSet = v + r.step; + } else { + vSet = v - r.step; + } + sensor.setOption(rs2.option[o], vSet); const vNew = sensor.getOption(rs2.option[o]); - assert.equal(vNew, v + 1); + if (o.toUpperCase() === 'OPTION_DEPTH_UNITS') { + assert.equal(Math.round(vNew * 100000)/100000, Math.round(vSet * 100000)/100000); + } else { + assert.equal(vNew, vSet); + } }); }); }).timeout(20 * 1000); - it.skip('Testing method getOptionDescription', () => { + it('Testing method getOptionDescription', () => { sensors.forEach((sensor) => { optionsTestArray.forEach((o) => { - assert.equal(typeof sensor.getOptionDescription(o), 'string'); + assert(typeof sensor.getOptionDescription(o) === 'string' || + typeof sensor.getOptionDescription(o) === 'undefined' + ); }); }); }); - it.skip('Testing method getOptionValueDescription', () => { + it('Testing method getOptionValueDescription', () => { sensors.forEach((sensor) => { optionsTestArray.forEach((o) => { - assert.equal(typeof sensor.getOptionValueDescription(o), 'string'); + assert(typeof sensor.getOptionValueDescription(o) === 'string' || + typeof sensor.getOptionValueDescription(o) === 'undefined' + ); }); }); }); - it('Testing method isValid', () => { - sensors.forEach((sensor) => { - assert.doesNotThrow(() => { - sensor.isValid(); - }); - }); - }); - - it('Testing method isValid, return boolean', () => { - sensors.forEach((sensor) => { - assert.equal(typeof sensor.isValid(), 'boolean'); - }); - }); - it('Testing method getStreamProfiles', () => { sensors.forEach((sensor) => { let profiles; @@ -275,27 +263,16 @@ describe('Sensor test', function() { }); }); - it.skip('Testing method open, profileArray', () => { + it('Testing method open, profileArray', () => { sensors.forEach((sensor) => { const profiles = sensor.getStreamProfiles(); - for (let i in profiles) { - const format = profiles[i].format; - const fps = profiles[i].fps; - const isDefault = profiles[i].isDefault; - const streamIndex = profiles[i].streamIndex; - const streamType = profiles[i].streamType; - const uniqueID = profiles[i].uniqueID; - console.log(profiles[i]); - console.log(format, fps, isDefault, streamIndex, streamType, uniqueID); assert.doesNotThrow(() => { // jshint ignore:line - sensor.open([format, fps, isDefault, streamIndex, - streamType, uniqueID]); + sensor.open(profiles); }); - } }); }); - it.skip('Testing method start, with callback', () => { + it('Testing method start, with callback', () => { sensors.forEach((sensor) => { const profiles = sensor.getStreamProfiles(); for (let i in profiles) { diff --git a/wrappers/nodejs/test/test-streamprofile.js b/wrappers/nodejs/test/test-streamprofile.js new file mode 100644 index 0000000000..1394bd3be1 --- /dev/null +++ b/wrappers/nodejs/test/test-streamprofile.js @@ -0,0 +1,101 @@ +// 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, before, after */ +const assert = require('assert'); +let rs2; +try { + rs2 = require('node-librealsense'); +} catch (e) { + rs2 = require('../index.js'); +} + +let ctx; +let pipeline; +let pipelineProfile; +let streamProfiles; + +describe('StreamProfile test', function() { + before(function() { + ctx = new rs2.Context(); + const devices = ctx.queryDevices().devices; + assert(devices.length > 0); // Device must be connected + pipeline = new rs2.Pipeline(ctx); + pipeline.start(); + pipelineProfile = pipeline.getActiveProfile(); + streamProfiles = pipelineProfile.getStreams(); + }); + + after(function() { + pipeline.stop(); + pipeline.destroy(); + rs2.cleanup(); + }); + + it('Testing constructor - 0 option', () => { + assert.throws(() => { + new rs2.StreamProfile(); + }); + }); + + it('Testing member - streamIndex', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.streamIndex, 'number'); + }); + }); + + it('Testing member - streamType', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.streamType, 'number'); + }); + }); + + it('Testing member - format', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.format, 'number'); + }); + }); + + it('Testing member - fps', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.fps, 'number'); + }); + }); + + it('Testing member - uniqueID', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.uniqueID, 'number'); + }); + }); + + it('Testing member - isDefault', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.isDefault, 'boolean'); + }); + }); + + it('Testing mothod getExtrinsicsTo - 0 argument', () => { + streamProfiles.forEach( (stream) => { + assert.throws(() => { + stream.getExtrinsicsTo(); + }); + }); + }); + + it('Testing mothod getExtrinsicsTo - valid argument', () => { + let ExtrinsicsObject; + assert.doesNotThrow(() => { + ExtrinsicsObject = streamProfiles[0].getExtrinsicsTo(streamProfiles[1]); + }); + assert.equal(Object.prototype.toString.call(ExtrinsicsObject.rotation), '[object Array]'); + }); + + it.skip('Testing mothod getExtrinsicsTo - invalid argument', () => { + assert.throws(() => { + streamProfiles[0].getExtrinsicsTo('dummy'); + }); + }); +}); diff --git a/wrappers/nodejs/test/test-videoframe.js b/wrappers/nodejs/test/test-videoframe.js new file mode 100644 index 0000000000..394f4f3790 --- /dev/null +++ b/wrappers/nodejs/test/test-videoframe.js @@ -0,0 +1,181 @@ +// 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, before, after */ +const assert = require('assert'); +let rs2; +try { + rs2 = require('node-librealsense'); +} catch (e) { + rs2 = require('../index.js'); +} + +let frame; +let pipeline; +describe('VideoFrame test', function() { + before(function() { + pipeline = new rs2.Pipeline(); + pipeline.start(); + while (!frame) { + const frameset = pipeline.waitForFrames(); + frame = frameset.at(1); + } + }); + + after(function() { + pipeline.destroy(); + rs2.cleanup(); + }); + + it('Testing constructor', () => { + assert.doesNotThrow(() => { + new rs2.VideoFrame(); + }); + }); + + it('Testing property isValid', () => { + assert.equal(typeof frame.isValid, 'boolean'); + }); + + it('Testing property data', () => { + assert(Object.prototype.toString.call(frame.data), '[object Uint16Array]' || + Object.prototype.toString.call(frame.data), '[object Uint8Array]' + ); + }); + + it('Testing property width', () => { + assert.equal(typeof frame.width, 'number'); + }); + + it('Testing property height', () => { + assert.equal(typeof frame.height, 'number'); + }); + + it('Testing property frameNumber', () => { + assert.equal(typeof frame.frameNumber, 'number'); + }); + + it('Testing property timestamp', () => { + assert.equal(typeof frame.timestamp, 'number'); + }); + + it('Testing property streamType', () => { + assert.equal(typeof frame.streamType, 'number'); + }); + + it('Testing property dataByteLength', () => { + assert.equal(typeof frame.dataByteLength, 'number'); + }); + + it('Testing property strideInBytes', () => { + assert.equal(typeof frame.strideInBytes, 'number'); + }); + + it('Testing property bitsPerPixel', () => { + assert.equal(typeof frame.bitsPerPixel, 'number'); + }); + + it('Testing property bytesPerPixel', () => { + assert.equal(typeof frame.bytesPerPixel, 'number'); + assert.equal(frame.bytesPerPixel, frame.bitsPerPixel/8); + }); + + it('Testing property timestampDomain', () => { + assert.equal(typeof frame.timestampDomain, 'string'); + }); + + it('Testing method frameMetadata - 0 argument', () => { + assert.throws(() => { + frame.frameMetadata(); + }); + }); + + it('Testing method frameMetadata - invalid argument', () => { + assert.throws(() => { + frame.frameMetadata('dummy'); + }); + }); + + it('Testing method frameMetadata - valid argument', () => { + for (let i in rs2.frame_metadata) { + if (rs2.frame_metadata[i] && + i.toUpperCase() !== 'FRAME_METADATA_COUNT' && // skip counter + i !== 'frameMetadataToString' // skip method + ) { + assert.doesNotThrow(() => { // jshint ignore:line + frame.frameMetadata(rs2.frame_metadata[i]); + }); + assert.equal(Object.prototype.toString.call( + frame.frameMetadata(rs2.frame_metadata[i]) + ), '[object Uint8Array]'); + } + } + }); + + it('Testing method getData - 0 argument', () => { + assert.doesNotThrow(() => { + frame.getData(); + }); + assert( + Object.prototype.toString.call(frame.getData()), '[object Uint16Array]' || + Object.prototype.toString.call(frame.getData()), '[object Uint8Array]' || + Object.prototype.toString.call(frame.getData()), '[object Buffer]' + ); + }); + + it('Testing method getData - buffer argument', () => { + const len = frame.dataByteLength; + let buf = new ArrayBuffer(len); + assert.doesNotThrow(() => { + frame.getData(buf); + }); + assert( + Object.prototype.toString.call(buf), '[object Uint16Array]' || + Object.prototype.toString.call(buf), '[object Uint8Array]' || + Object.prototype.toString.call(buf), '[object Buffer]' + ); + }); + + it('Testing method getData - 2 argument', () => { + assert.throws(() => { + frame.getData(1, 2); + }); + }); + + it('Testing method getData - invalid argument', () => { + assert.throws(() => { + frame.getData('dummy'); + }); + }); + + it('Testing method supportsFrameMetadata - invalid argument', () => { + assert.throws(() => { + frame.supportsFrameMetadata('dummy'); + }); + }); + + it('Testing method supportsFrameMetadata - valid argument', () => { + for (let i in rs2.frame_metadata) { + if (rs2.frame_metadata[i] && + i.toUpperCase() !== 'FRAME_METADATA_COUNT' && // skip counter + i !== 'frameMetadataToString' // skip method + ) { + assert.doesNotThrow(() => { // jshint ignore:line + frame.supportsFrameMetadata(rs2.frame_metadata[i]); + }); + assert.equal(Object.prototype.toString.call( + frame.supportsFrameMetadata(rs2.frame_metadata[i]) + ), '[object Boolean]'); + } + } + }); + + it('Testing method destroy', () => { + assert.doesNotThrow(() => { + frame.destroy(); + }); + }); +}); diff --git a/wrappers/nodejs/test/test-videostreamprofile.js b/wrappers/nodejs/test/test-videostreamprofile.js new file mode 100644 index 0000000000..c6ffa97081 --- /dev/null +++ b/wrappers/nodejs/test/test-videostreamprofile.js @@ -0,0 +1,136 @@ +// 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, before, after */ +const assert = require('assert'); +let rs2; +try { + rs2 = require('node-librealsense'); +} catch (e) { + rs2 = require('../index.js'); +} + +let ctx; +let pipeline; +let pipelineProfile; +let streamProfiles; + +describe('VideoStreamProfile test', function() { + before(function() { + ctx = new rs2.Context(); + const devices = ctx.queryDevices().devices; + assert(devices.length > 0); // Device must be connected + pipeline = new rs2.Pipeline(ctx); + pipeline.start(); + pipelineProfile = pipeline.getActiveProfile(); + streamProfiles = pipelineProfile.getStreams(); + }); + + after(function() { + pipeline.stop(); + pipeline.destroy(); + rs2.cleanup(); + }); + + it('Testing constructor - 0 option', () => { + assert.throws(() => { + new rs2.StreamProfile(); + }); + }); + + it('Testing member - width', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.width, 'number'); + }); + }); + + it('Testing member - height', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.height, 'number'); + }); + }); + + it('Testing member - streamIndex', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.streamIndex, 'number'); + }); + }); + + it('Testing member - streamType', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.streamType, 'number'); + }); + }); + + it('Testing member - format', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.format, 'number'); + }); + }); + + it('Testing member - fps', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.fps, 'number'); + }); + }); + + it('Testing member - uniqueID', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.uniqueID, 'number'); + }); + }); + + it('Testing member - isDefault', () => { + streamProfiles.forEach( (stream) => { + assert.equal(typeof stream.isDefault, 'boolean'); + }); + }); + + it('Testing mothod getExtrinsicsTo - 0 argument', () => { + streamProfiles.forEach( (stream) => { + assert.throws(() => { + stream.getExtrinsicsTo(); + }); + }); + }); + + it('Testing method getExtrinsicsTo - valid argument', () => { + let ExtrinsicsObject; + assert.doesNotThrow(() => { + ExtrinsicsObject = streamProfiles[0].getExtrinsicsTo(streamProfiles[1]); + }); + assert.equal(Object.prototype.toString.call(ExtrinsicsObject.rotation), '[object Array]'); + }); + + it.skip('Testing method getExtrinsicsTo - invalid argument', () => { + assert.throws(() => { + streamProfiles[0].getExtrinsicsTo('dummy'); + }); + }); + + it('Testing method getIntrinsics - valid argument', () => { + streamProfiles.forEach((stream) => { + let intrinsics = stream.getIntrinsics(); + assert.equal(typeof intrinsics.width, 'number'); + assert.equal(typeof intrinsics.height, 'number'); + assert.equal(typeof intrinsics.ppx, 'number'); + assert.equal(typeof intrinsics.ppy, 'number'); + assert.equal(typeof intrinsics.fx, 'number'); + assert.equal(typeof intrinsics.fy, 'number'); + assert.equal(typeof intrinsics.model, 'number'); + assert.equal(Object.prototype.toString.call(intrinsics.coeffs), '[object Array]'); + assert.equal(intrinsics.coeffs.length, 5); + }); + }); + + it('Testing method getIntrinsics - invalid argument', () => { + streamProfiles.forEach((stream) => { + assert.doesNotThrow(() => { + stream.getIntrinsics('dummy'); + }); + }); + }); +});