Skip to content

Commit

Permalink
[nodejs] Add and update test cases.
Browse files Browse the repository at this point in the history
Impacted tests(approved): new 70, update 8, delete 4
Unit test platform: Ubuntu 16.04
Unit test result summary: pass 69, fail 7, block 2
  • Loading branch information
haoyunfeix committed Dec 25, 2017
1 parent 90fc463 commit 1de4bc4
Show file tree
Hide file tree
Showing 11 changed files with 732 additions and 151 deletions.
34 changes: 13 additions & 21 deletions wrappers/nodejs/test/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
});
});
87 changes: 32 additions & 55 deletions wrappers/nodejs/test/test-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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);
});
Expand Down
190 changes: 190 additions & 0 deletions wrappers/nodejs/test/test-depthframe.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
15 changes: 8 additions & 7 deletions wrappers/nodejs/test/test-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 1de4bc4

Please sign in to comment.