From 748dbd47b6ddd9f2599777bfe6528b5c6f1553c0 Mon Sep 17 00:00:00 2001 From: zobalogh Date: Tue, 4 Nov 2014 15:07:32 +0000 Subject: [PATCH] Adding exif node tests --- test/utility/exif/94-exif_spec.js | 76 ++++++++++++++++++++++++++ test/utility/exif/Gruntfile.js | 57 +++++++++++++++++++ test/utility/exif/exif_test_image.jpg | Bin 0 -> 1732 bytes 3 files changed, 133 insertions(+) create mode 100644 test/utility/exif/94-exif_spec.js create mode 100644 test/utility/exif/Gruntfile.js create mode 100644 test/utility/exif/exif_test_image.jpg diff --git a/test/utility/exif/94-exif_spec.js b/test/utility/exif/94-exif_spec.js new file mode 100644 index 00000000..30087415 --- /dev/null +++ b/test/utility/exif/94-exif_spec.js @@ -0,0 +1,76 @@ +/** + * Copyright 2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var should = require("should"); +var sinon = require('sinon'); +var fs = require("fs"); + +var exifNode = require("../../../utility/exif/94-exif.js"); + +var helper = require('../../../../node-red/test/nodes/helper.js'); + +describe('exif node', function() { + + beforeEach(function(done) { + helper.startServer(done); + }); + + afterEach(function(done) { + helper.unload(); + helper.stopServer(done); + }); + + it('extracts location data from Exif data of JPEG', function(done) { + + var exif = require('exif'); + var ExifImage = exif.ExifImage; + + // the jpg file is a single black dot but it was originally a photo taken at IBM Hursley + var data = fs.readFileSync("./exif_test_image.jpg", null); // extracting genuine exif data to be fed back as the result of the stubbed ExifImage constructor + + var eD; + + new ExifImage({ image : data }, function (error, exifData) { + if(error) { + done(error); + } else { + eD = exifData; + } + + var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]}, + {id:"helperNode1", type:"helper"}]; + + helper.load(exifNode, flow, function() { + var exifNode1 = helper.getNode("exifNode1"); + var helperNode1 = helper.getNode("helperNode1"); + + helperNode1.on("input", function(msg) { + msg.location.lat.should.equal(50.95624); // this data is stored in the jpg file + msg.location.lon.should.equal(-1.36701); + done(); + }); + + var stub = sinon.stub(ExifImage.prototype, 'loadImage', function(error, callback) { + stub.restore(); + callback(null, eD); + }); + + exifNode1.receive({payload:data}); + }); + }); + + }); +}); diff --git a/test/utility/exif/Gruntfile.js b/test/utility/exif/Gruntfile.js new file mode 100644 index 00000000..80a4296e --- /dev/null +++ b/test/utility/exif/Gruntfile.js @@ -0,0 +1,57 @@ +/** + * Copyright 2013, 2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + simplemocha: { + options: { + globals: ['expect'], + timeout: 3000, + ignoreLeaks: false, + ui: 'bdd', + reporter: 'spec' + }, + all: { src: ['./*_spec.js'] }, + }, + jshint: { + options: { + // http://www.jshint.com/docs/options/ + "asi": true, // allow missing semicolons + "curly": true, // require braces + "eqnull": true, // ignore ==null + "forin": true, // require property filtering in "for in" loops + "immed": true, // require immediate functions to be wrapped in ( ) + "nonbsp": true, // warn on unexpected whitespace breaking chars + //"strict": true, // commented out for now as it causes 100s of warnings, but want to get there eventually + "loopfunc": true, // allow functions to be defined in loops + "sub": true // don't warn that foo['bar'] should be written as foo.bar + }, + all: { + src: ['../../../utility/exif/*.js'] + }, + } + }); + + grunt.loadNpmTasks('grunt-simple-mocha'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-lint-inline'); + + grunt.registerTask('default', + ['jshint:all', 'simplemocha:all']); + +}; diff --git a/test/utility/exif/exif_test_image.jpg b/test/utility/exif/exif_test_image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4ce96b3c4917c1e799f251cdfffc831b5047770f GIT binary patch literal 1732 zcmd5-SxggA6uocWOk0W(MivoctO$aBO$#FQ#{d>65h9?1ehC%?6OEuC8a1JAl|)nO zh9o4#1<@~2ar-bXxbb1)4j2=0MZa)gVlv)0GaW$uF#6+bUf!8I=bgFd-FH*DM}7*S zIhoE(AcR0R{y^>*+8lM2!v|Ie>&J*o4n3Ni+z!5}dVUqK-F_ z1fWVBcX44FM%MO9;5Gg>Ph0?#+sNw9E32znZJCL$Sr&?>x{B`RfHEm|x9E6@Ctg!_ z0eAt7xQmx;Hpxqs48u{R!prM;LnBc+grndiU{=3Eygp9XZ1VAX-0ut0^pWT@>zsCf z;9FKn@{=KVelFk$h@TF_LI9H!D8&Yz1>b_}AWoM}vL@N3WV=|oOVC^lJ#~xMBSS79)9kA+hMJ&!M zK3RMfB34;8*;lkma~{-Xm~p(I-Ucq0aYUWd4igp4vB)_AlN20`_#&g>u;FC7sme-M zoJVh=T8zabRV&n%l78@gOs64!jSU#AM{1`Go{?~yb2BZ zOjWq8zOmIbHNE3ImcaS-9eAI;KxM}eT(`O{jOrDjJYR{PC$jr)i<`m9f zu&}6j(c-19vhrmWmCIMJsi|FCw{HFBEnBy3_v~o!?cTF@-~Ofp%?A%1KGJry{n+u7 zr%rdCIeYH>g)3LPu3f)z^H%rWd-oqaeALt1*Z=JKi