Skip to content

Commit

Permalink
Add tests from
Browse files Browse the repository at this point in the history
  • Loading branch information
oeuillot committed Feb 2, 2016
1 parent 1a2929f commit ced3f2f
Show file tree
Hide file tree
Showing 32 changed files with 489 additions and 4 deletions.
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"name" : "exif",
"version" : "0.5.1",
"version" : "0.6.0",
"description" : "A node.js library to extract Exif metadata from images.",
"author" : "Daniel Leinich <[email protected]>",
"keywords" : ["exif", "image", "jpeg", "jpg", "tiff", "makernotes", "gps"],
"author" : [ "Daniel Leinich <[email protected]>", "Olivier Oeuillot <[email protected]>" ],
"keywords" : ["exif", "image", "jpeg", "jpg", "makernotes", "gps"],
"main" : "./lib/exif",
"repository" : {
"type" : "git",
"url" : "http://github.com/gomfunkel/node-exif.git"
},
"dependencies": {
"debug": "2.2"
"debug": "^2.2"
},
"devDependencies": {
"mocha": "^2.4"
},
"scripts": {
"test": "node_modules/.bin/mocha --reporter spec test/*-test.js"
}
}
129 changes: 129 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
var assert = require('assert');
var fs=require('fs');
var Path = require('path');

describe('node-exif API', function() {

var path=Path.join(__dirname, "evil1.jpg");
var json='{"image":{"Make":"Canon","Model":"Canon PowerShot S400","Orientation":1,"XResolution":180,"YResolution":180,"ResolutionUnit":2,"Software":"Adobe Photoshop 7.0","ModifyDate":"2003:05:25 11:11:41","YCbCrPositioning":1,"ExifOffset":217},"thumbnail":{"Compression":6,"XResolution":72,"YResolution":72,"ResolutionUnit":2,"ThumbnailOffset":1057,"ThumbnailLength":6298},"exif":{"ExposureTime":0.125,"FNumber":2.8,"ExifVersion":{"type":"Buffer","data":[48,50,50,48]},"DateTimeOriginal":"2003:05:24 16:40:33","CreateDate":"2003:05:24 16:40:33","ComponentsConfiguration":{"type":"Buffer","data":[1,2,3,0]},"CompressedBitsPerPixel":3,"ShutterSpeedValue":3,"ApertureValue":2.96875,"ExposureCompensation":0,"MaxApertureValue":2.96875,"MeteringMode":5,"Flash":16,"FocalLength":7.40625,"UserComment":{"type":"Buffer","data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"FlashpixVersion":{"type":"Buffer","data":[48,49,48,48]},"ColorSpace":1,"ExifImageWidth":400,"ExifImageHeight":300,"FocalPlaneXResolution":8114.285714285715,"FocalPlaneYResolution":8114.285714285715,"FocalPlaneResolutionUnit":2,"SensingMethod":2,"FileSource":{"type":"Buffer","data":[3]},"CustomRendered":0,"ExposureMode":0,"WhiteBalance":0,"DigitalZoomRatio":1,"SceneCaptureType":0},"gps":{},"interoperability":{},"makernote":{}}';


it('test constructor (filename)', function(done) {

var ExifImage = require('..').ExifImage;

new ExifImage({image: path }, function(error, data) {
if (error) {
throw error;
}

assert.equal(JSON.stringify(data), json, "Not same datas ?");

done();
});
});

it('test constructor (buffer)', function(done) {

var ExifImage = require('..').ExifImage;

var buffer=fs.readFileSync(path);

new ExifImage({image: buffer }, function(error, data) {
if (error) {
throw error;
}

assert.equal(JSON.stringify(data), json, "Not same datas ?");

done();
});
});

it('test loadImage (buffer)', function(done) {

var ExifImage = require('..').ExifImage;

var exif=new ExifImage();

exif.loadImage(path, function(error, data) {
if (error) {
throw error;
}

assert.equal(JSON.stringify(data), json, "Not same datas ?");

done();
});
});

it('test loadImage (filename)', function(done) {

var ExifImage = require('..').ExifImage;

var buffer=fs.readFileSync(path);

var exif=new ExifImage();

exif.loadImage(buffer , function(error, data) {
if (error) {
throw error;
}

assert.equal(JSON.stringify(data), json, "Not same datas");

done();
});
});

it('test wrapper', function(done) {

var Exif = require('..');

Exif(path, function(error, data, dataPath) {
if (error) {
throw error;
}

assert.equal(dataPath, path, "Not same path");
delete data.path;

assert.equal(JSON.stringify(data), json, "Not same datas ?");

done();
});
});
});

describe('node-exif tests', function() {
var ExifImage = require('..').ExifImage;

var files=fs.readdirSync(__dirname);

files.forEach(function(f) {
if (!/\.jpg$/.exec(f)) {
return;
}

var path=Path.join(__dirname, f);

it('test '+f, function(done) {
var expected=String(fs.readFileSync(path+".json"));

new ExifImage({image: path }, function(error, data) {
if (error) {
throw error;
}

var json=JSON.stringify(data);

//console.log(" data=", json, json.length);
// console.log("expected=", expected, expected.length);

assert.equal(json, expected, "Data are not the same");

done();
});
});
});
});
Binary file added test/down-mirrored.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/down-mirrored.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Camera make :
Camera model :
Software :
Bits per sample : 0
Image width : 0
Image height : 0
Image description :
Image orientation : 4
Image copyright :
Image date/time :
Original date/time :
Digitize date/time :
Subsecond time :
Exposure time : 1/0 s
F-stop : f/0.0
ISO speed : 0
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 0
Metering mode : 0
Lens focal length : 0.000000 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
1 change: 1 addition & 0 deletions test/down-mirrored.jpg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"image":{"Orientation":4,"XResolution":28,"YResolution":28,"ResolutionUnit":3,"YCbCrPositioning":1},"thumbnail":{},"exif":{},"gps":{},"interoperability":{},"makernote":{}}
Binary file added test/evil1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/evil1.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Camera make : Canon
Camera model : Canon PowerShot S400
Software : Adobe Photoshop 7.0
Bits per sample : 0
Image width : 400
Image height : 300
Image description :
Image orientation : 1
Image copyright :
Image date/time : 2003:05:25 11:11:41
Original date/time : 2003:05:24 16:40:33
Digitize date/time : 2003:05:24 16:40:33
Subsecond time :
Exposure time : 1/8 s
F-stop : f/2.8
ISO speed : 0
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 1
Metering mode : 5
Lens focal length : 7.406250 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 8114.285714
Focal plane YRes : 8114.285714
1 change: 1 addition & 0 deletions test/evil1.jpg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"image":{"Make":"Canon","Model":"Canon PowerShot S400","Orientation":1,"XResolution":180,"YResolution":180,"ResolutionUnit":2,"Software":"Adobe Photoshop 7.0","ModifyDate":"2003:05:25 11:11:41","YCbCrPositioning":1,"ExifOffset":217},"thumbnail":{"Compression":6,"XResolution":72,"YResolution":72,"ResolutionUnit":2,"ThumbnailOffset":1057,"ThumbnailLength":6298},"exif":{"ExposureTime":0.125,"FNumber":2.8,"ExifVersion":{"type":"Buffer","data":[48,50,50,48]},"DateTimeOriginal":"2003:05:24 16:40:33","CreateDate":"2003:05:24 16:40:33","ComponentsConfiguration":{"type":"Buffer","data":[1,2,3,0]},"CompressedBitsPerPixel":3,"ShutterSpeedValue":3,"ApertureValue":2.96875,"ExposureCompensation":0,"MaxApertureValue":2.96875,"MeteringMode":5,"Flash":16,"FocalLength":7.40625,"UserComment":{"type":"Buffer","data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"FlashpixVersion":{"type":"Buffer","data":[48,49,48,48]},"ColorSpace":1,"ExifImageWidth":400,"ExifImageHeight":300,"FocalPlaneXResolution":8114.285714285715,"FocalPlaneYResolution":8114.285714285715,"FocalPlaneResolutionUnit":2,"SensingMethod":2,"FileSource":{"type":"Buffer","data":[3]},"CustomRendered":0,"ExposureMode":0,"WhiteBalance":0,"DigitalZoomRatio":1,"SceneCaptureType":0},"gps":{},"interoperability":{},"makernote":{}}
Binary file added test/lens_info.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/lens_info.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Camera make :
Camera model :
Software :
Bits per sample : 0
Image width : 0
Image height : 0
Image description :
Image orientation : 0
Image copyright :
Image date/time :
Original date/time :
Digitize date/time :
Subsecond time :
Exposure time : 1/0 s
F-stop : f/0.0
ISO speed : 0
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 0
Metering mode : 0
Lens focal length : 0.000000 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 10.000000 mm
Lens max focal length: 400.000000 mm
Lens f-stop min : f/1.1
Lens f-stop max : f/1.2
Lens make : Lens Maker Inc.
Lens model : Lens Model mk I
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
1 change: 1 addition & 0 deletions test/lens_info.jpg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"image":{"XResolution":96,"YResolution":96,"ResolutionUnit":2,"YCbCrPositioning":1,"ExifOffset":90},"thumbnail":{},"exif":{"ExifVersion":{"type":"Buffer","data":[48,50,51,48]},"ComponentsConfiguration":{"type":"Buffer","data":[1,2,3,0]},"FlashpixVersion":{"type":"Buffer","data":[48,49,48,48]},"ColorSpace":65535,"LensInfo":[10,400,1.1,1.2],"LensMake":"Lens Maker Inc.","LensModel":"Lens Model mk I","LensSerialNumber":"123"},"gps":{},"interoperability":{},"makernote":{}}
Binary file added test/right.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/right.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Camera make :
Camera model :
Software :
Bits per sample : 0
Image width : 0
Image height : 0
Image description :
Image orientation : 8
Image copyright :
Image date/time :
Original date/time :
Digitize date/time :
Subsecond time :
Exposure time : 1/0 s
F-stop : f/0.0
ISO speed : 0
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 0
Metering mode : 0
Lens focal length : 0.000000 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
1 change: 1 addition & 0 deletions test/right.jpg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"image":{"Orientation":8,"XResolution":28,"YResolution":28,"ResolutionUnit":3,"YCbCrPositioning":1},"thumbnail":{},"exif":{},"gps":{},"interoperability":{},"makernote":{}}
Binary file added test/short-ascii-II.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/short-ascii-II.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Camera make : XIAOMI
Camera model : MI3
Software :
Bits per sample : 0
Image width : 4208
Image height : 3120
Image description :
Image orientation : 1
Image copyright :
Image date/time : 2015:02:28 17:10:49
Original date/time : 2015:02:28 17:10:49
Digitize date/time : 2015:02:28 17:10:49
Subsecond time :
Exposure time : 1/20 s
F-stop : f/2.2
ISO speed : 250
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 1
Metering mode : 2
Lens focal length : 3.510000 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 0.000000 mm
Lens max focal length: 0.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model :
Focal plane XRes : 0.000000
Focal plane YRes : 0.000000
Loading

0 comments on commit ced3f2f

Please sign in to comment.