tidy up tests

This commit is contained in:
Luke Page 2015-08-03 16:18:01 +01:00
parent 233925190c
commit b89ef0384f
4 changed files with 80 additions and 29 deletions

View file

@ -6,7 +6,7 @@ Based on [pngjs](https://github.com/niegowski/node-pngjs) with the follow enhanc
* Support for reading 1,2,4 & 16 bit files * Support for reading 1,2,4 & 16 bit files
* Support for reading interlace files * Support for reading interlace files
* Support for reading transparent colours * Support for reading `tTRNS` transparent colours
* Sync interface as well as async * Sync interface as well as async
* API compatible with pngjs and node-pngjs * API compatible with pngjs and node-pngjs
@ -14,13 +14,39 @@ Known lack of support for:
* Animation * Animation
* Gamma correction in 16 bit files * Gamma correction in 16 bit files
Comparison Table
================
Name | Forked From | Sync | Async | 16 Bit | 1/2/4 Bit | Interlace | Gamma | Encodes | Tested
---------|--------------|------|-------|--------|-----------|-----------|-------|---------|--------
pngjs2 | pngjs | Read | Yes | Yes | Yes | Yes | Yes | Yes | Yes
node-png | pngjs | No | Yes | No | No | No | Hidden| Yes | Manual
pngjs | | No | Yes | No | No | No | Hidden| Yes | Manual
png-coder| pngjs | No | Yes | Yes | No | No | Hidden| Yes | Manual
pngparse | | No | Yes | No | Yes | No | No | No | Yes
pngparse-sync | pngparse| Yes | No | No | Yes | No | No | No | Yes
png-async| | No | Yes | No | No | No | No | Yes | Yes
png-js | | No | Yes | No | No | No | No | No | No
Native C++ node decoders:
* png
* png-sync (sync version of above)
* pixel-png
* png-img
Tests Tests
===== =====
Tested using [PNG Suite](http://www.schaik.com/pngsuite/). Tested using [PNG Suite](http://www.schaik.com/pngsuite/). We read every file into pngjs2, output it in standard 8bit colour, synchronously and asynchronously, then compare the original
with the newly saved images.
To run the tests, run `node test`.
The only thing not converted is gamma correction - this is because multiple vendors will do gamma correction differently, so the tests will have different results on different browsers.
To run the tests in phantomjs, run `node test`. In addition we use a tolerance of 3 for 16 bit images in PhantomJS because PhantomJS seems to have non-compliant rules for downscaling 16 bit images.
TODO: How to run the gamma tests TODO: How to run the gamma tests
TODO: How to run the tests in chrome TODO: How to run the tests in chrome

View file

@ -13,7 +13,16 @@
], ],
"homepage": "https://github.com/lukeapage/pngjs2", "homepage": "https://github.com/lukeapage/pngjs2",
"keywords": [ "keywords": [
"png" "png",
"PNG",
"parser",
"encoder",
"decoder",
"pngjs",
"node-png",
"png-parse",
"png-js",
"js-png"
], ],
"engines": { "engines": {
"node": "0.10.x" "node": "0.10.x"

View file

@ -13,18 +13,23 @@ module.exports = function(done) {
console.log("Converting images"); console.log("Converting images");
var asyncSaved = 0; var completed = 0;
var expected = files.length * 2;
function complete() {
completed++;
if (expected === completed) {
done();
}
}
files.forEach(function (file) { files.forEach(function (file) {
var expectedError = false; var expectedError = false;
if (file.match(/^x/)) { if (file.match(/^x/)) {
expectedError = true; expectedError = true;
} }
var syncError = true; var syncError = false;
var data = fs.readFileSync(__dirname + '/in/' + file); var data = fs.readFileSync(__dirname + '/in/' + file);
try { try {
var png = PNG.sync.read(data); var png = PNG.sync.read(data);
@ -33,22 +38,28 @@ module.exports = function(done) {
console.log("Unexpected error parsing.." + file); console.log("Unexpected error parsing.." + file);
console.log(e); console.log(e);
console.log(e.stack); console.log(e.stack);
syncError = true;
} }
syncError = true;
complete();
} }
if (!syncError) { if (!syncError) {
if (expectedError) { if (expectedError) {
console.log("Error expected, parsed fine ..", file); console.log("Error expected, parsed fine ..", file);
} complete();
} else {
var outpng = new PNG(); var outpng = new PNG();
//PNG.adjustGamma(png); //PNG.adjustGamma(png);
outpng.data = png.data; outpng.data = png.data;
outpng.width = png.width; outpng.width = png.width;
outpng.height = png.height; outpng.height = png.height;
outpng.pack() outpng.pack()
.pipe(fs.createWriteStream(__dirname + '/outsync/' + file)); .pipe(fs.createWriteStream(__dirname + '/outsync/' + file)
.on("finish", function () {
complete();
}));
}
} }
fs.createReadStream(__dirname + '/in/' + file) fs.createReadStream(__dirname + '/in/' + file)
@ -57,10 +68,7 @@ module.exports = function(done) {
if (!expectedError) { if (!expectedError) {
console.log("Error reading " + file, err); console.log("Error reading " + file, err);
} }
asyncSaved++; complete();
if (asyncSaved === files.length) {
done();
}
}) })
.on('parsed', function () { .on('parsed', function () {
@ -70,13 +78,11 @@ module.exports = function(done) {
//this.adjustGamma(); //this.adjustGamma();
this.pack() this.pack()
.on("end", function() { .pipe(
asyncSaved++; fs.createWriteStream(__dirname + '/out/' + file)
if (asyncSaved === files.length) { .on("finish", function() {
done(); complete();
} }));
})
.pipe(fs.createWriteStream(__dirname + '/out/' + file))
}); });

View file

@ -16,11 +16,21 @@ setInterval(function() {
if (results) { if (results) {
var success = true; var success = true;
var successes = [],
failures = [];
for(var i = 0; i < results.length; i++) { for(var i = 0; i < results.length; i++) {
var result = results[i]; var result = results[i];
console.log(result.name, result.success); if (result.success) {
successes.push(result.name);
} else {
failures.push(result.name);
}
success = success && result.success; success = success && result.success;
} }
console.log("Success:", successes.join(", "));
if (failures.length) {
console.log("Failure:", failures.join(", "));
}
phantom.exit(success ? 0 : 1); phantom.exit(success ? 0 : 1);
return; return;