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 interlace files
* Support for reading transparent colours
* Support for reading `tTRNS` transparent colours
* Sync interface as well as async
* API compatible with pngjs and node-pngjs
@ -14,13 +14,39 @@ Known lack of support for:
* Animation
* 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
=====
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 tests in chrome

View file

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

View file

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

View file

@ -16,11 +16,21 @@ setInterval(function() {
if (results) {
var success = true;
var successes = [],
failures = [];
for(var i = 0; i < results.length; 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;
}
console.log("Success:", successes.join(", "));
if (failures.length) {
console.log("Failure:", failures.join(", "));
}
phantom.exit(success ? 0 : 1);
return;