This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
forked from hMatoba/piexifjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodetest.js
123 lines (111 loc) · 3.65 KB
/
nodetest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var phestum = {
_isEqual : function (a, b) {
if (typeof(a) !== typeof(b)) {
return false;
} else if (a === undefined && b === undefined){
return true;
} else if (a instanceof Array && b instanceof Array) {
if (a.length !== b.length) {
return false;
}
for (var p=0; p<a.length; p++) {
if (!phestum._isEqual(a[p], b[p])){
return false;
}
}
return true;
} else if (typeof(a) === "object" && typeof(b) === "object") {
if (a === null && b === null) {
return true;
}
var propA = Object.getOwnPropertyNames(a);
var propB = Object.getOwnPropertyNames(b);
propA.sort();
propB.sort();
// check property names equality
if (propA.length !== propB.length) {
return false;
} else {
for (var p=0; p<propA.length; p++) {
if (!phestum._isEqual(propA[p], propB[p])){
return false;
}
}
}
// check object value equality
for (var p=0; p<propA.length; p++) {
var prop = propA[p];
if (!phestum._isEqual(a[prop], b[prop])){
return false;
}
}
return true;
} else if (typeof(a) === "string" || typeof(a) === "number") {
if (a === b) {
return true;
} else {
return false;
}
} else {
throw("Got variable that cannot compare.");
}
},
assertEqual : function (a, b) {
if (!phestum._isEqual(a, b)) {
throw("! " + JSON.stringify(a) + " != " + JSON.stringify(b));
}
},
assertNotEqual : function (a, b) {
if (phestum._isEqual(a, b)) {
throw("! " + JSON.stringify(a) + " == " + JSON.stringify(b));
}
},
assertFail : function (func) {
var failed = false;
try {
func();
} catch (e) {
failed = true;
}
if (!failed) {
throw("'phestum.assertFail' error. Given function didn't failed.");
}
},
};
var fs = require("fs");
var piexif = require("./piexif.js");
var jpeg = fs.readFileSync("tests/files/noexif.jpg");
var data = jpeg.toString("binary");
var zeroth = {};
var exif = {};
var gps = {};
zeroth[piexif.ImageIFD.Make] = "Make";
zeroth[piexif.ImageIFD.XResolution] = [777, 1];
zeroth[piexif.ImageIFD.YResolution] = [777, 1];
zeroth[piexif.ImageIFD.Software] = "Piexifjs";
exif[piexif.ExifIFD.DateTimeOriginal] = "2010:10:10 10:10:10";
exif[piexif.ExifIFD.LensMake] = "LensMake";
exif[piexif.ExifIFD.Sharpness] = 777;
exif[piexif.ExifIFD.LensSpecification] = [[1, 1], [1, 1], [1, 1], [1, 1]];
gps[piexif.GPSIFD.GPSVersionID] = [7, 7, 7, 7];
gps[piexif.GPSIFD.GPSDateStamp] = "1999:99:99 99:99:99";
var exifObj = {"0th":zeroth, "Exif":exif, "GPS":gps};
var exifbytes = piexif.dump(exifObj);
var newData = piexif.insert(exifbytes, data);
//var newJpeg = new Buffer(newData, "binary");
//fs.writeFileSync("out.jpg", newJpeg);
var exifObj2 = piexif.load(newData);
try {
delete exifObj2["0th"][34665];
delete exifObj2["0th"][34853];
delete exifObj2["Interop"];
delete exifObj2["1st"];
delete exifObj2["thumbnail"];
phestum.assertEqual(exifObj, exifObj2);
console.log("Successed Nodejs test.");
process.exit();
} catch (e){
console.log(e);
console.log("Failed Nodejs test.");
process.exit(1);
}