Skip to content

Commit

Permalink
[nodejs] Add test case for points
Browse files Browse the repository at this point in the history
Impacted tests(approved): new 7, update 0, delete 0
Unit test platform: Ubuntu 16.04
Unit test result summary: pass 6, fail 1, block 0
  • Loading branch information
zhaoming0 committed Apr 20, 2018
1 parent 1751d03 commit 7e14526
Showing 1 changed file with 110 additions and 18 deletions.
128 changes: 110 additions & 18 deletions wrappers/nodejs/test/test-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

'use strict';

/* global describe, it, before, after */
/* global describe, it, beforeEach, afterEach */
const assert = require('assert');
const fs = require('fs');
let rs2;
try {
rs2 = require('node-librealsense');
Expand All @@ -14,21 +15,29 @@ try {
}

let ctx;
let pipeline;
let pointcloud;
let frameSet;
let points;
let files = 'points.ply';
describe('Points test', function() {
before(function() {
beforeEach(function() {
ctx = new rs2.Context();
const devices = ctx.queryDevices().devices;
assert(devices.length > 0); // Device must be connected
});

after(function() {
afterEach(function() {
pipeline.destroy();
pipeline.stop();
rs2.cleanup();
frameSet.destroy();
if (fs.existsSync(files)) {
fs.unlinkSync(files);
}
});

it('Testing member textureCoordinates', () => {
let pipeline;
let frameSet;
let pointcloud;
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
Expand Down Expand Up @@ -57,14 +66,9 @@ describe('Points test', function() {
assert(false, 'could not get colorFrame or depthFrame, try to reset camera');
}
}
frameSet.destroy();
pipeline.destroy();
});

it('Testing member vertices', () => {
let pipeline;
let frameSet;
let pointcloud;
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
Expand Down Expand Up @@ -93,14 +97,9 @@ describe('Points test', function() {
assert(false, 'could not get colorFrame or depthFrame, try to reset camera');
}
}
frameSet.destroy();
pipeline.destroy();
});

it('Testing member size', () => {
let pipeline;
let frameSet;
let pointcloud;
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
Expand Down Expand Up @@ -129,7 +128,100 @@ describe('Points test', function() {
assert(false, 'could not get colorFrame or depthFrame, try to reset camera');
}
}
frameSet.destroy();
pipeline.destroy();
});

it('Testing method exportToPly without argument', () => {
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
frameSet = pipeline.waitForFrames();
points = pointcloud.calculate(frameSet.depthFrame);
});
assert.throws(() => {
points.exportToPly();
});
});

it('Testing method exportToPly with three arguments', () => {
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
frameSet = pipeline.waitForFrames();
points = pointcloud.calculate(frameSet.depthFrame);
});
assert.throws(() => {
points.exportToPly(files, files, files);
});
});

it('Testing method exportToPly first argument with number', () => {
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
frameSet = pipeline.waitForFrames();
points = pointcloud.calculate(frameSet.depthFrame);
});
assert.throws(() => {
points.exportToPly(1, 1);
});
});

it('Testing method exportToPly second argument with number', () => {
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
frameSet = pipeline.waitForFrames();
points = pointcloud.calculate(frameSet.depthFrame);
});
assert.throws(() => {
points.exportToPly(files, 1);
});
});

it('Testing method exportToPly with depthFrame', () => {
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
frameSet = pipeline.waitForFrames();
});
assert.throws(() => {
points = pointcloud.calculate(frameSet.depthFrame);
points.exportToPly(files, frameSet.depthFrame);
assert.equal(fs.existsSync(files), true);
});
});

it('Testing method exportToPly with colorFrame', () => {
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
frameSet = pipeline.waitForFrames();
});
assert.doesNotThrow(() => {
points = pointcloud.calculate(frameSet.depthFrame);
points.exportToPly(files, frameSet.colorFrame);
assert.equal(fs.existsSync(files), true);
});
});

it('Testing method exportToPly with videoFrame', () => {
assert.doesNotThrow(() => {
pipeline = new rs2.Pipeline();
pointcloud = new rs2.PointCloud();
pipeline.start();
frameSet = pipeline.waitForFrames();
points = pointcloud.calculate(frameSet.depthFrame);
});
assert.doesNotThrow(() => {
let videoFrame = frameSet.at(1);
points.exportToPly(files, videoFrame);
assert.equal(fs.existsSync(files), true);
});
});
});

0 comments on commit 7e14526

Please sign in to comment.