diff --git a/package.json b/package.json index 6ce6992..cafe120 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "url": "https://github.com/lukeapage/pngjs2/issues" }, "devDependencies": { + "buffer-equal": "0.0.1", "connect": "^3.4.0", "coveralls": "^2.11.3", "eslint": "^1.0.0", diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..f540178 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +bg.png diff --git a/test/bg-ref.png b/test/bg-ref.png new file mode 100644 index 0000000..e4361e0 Binary files /dev/null and b/test/bg-ref.png differ diff --git a/test/bg-spec.js b/test/bg-spec.js new file mode 100644 index 0000000..dd71096 --- /dev/null +++ b/test/bg-spec.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node + +var fs = require('fs'); +var PNG = require('../lib/png').PNG; +var test = require('tape'); +var bufferEqual = require('buffer-equal'); + +test('outputs background, created from scratch', function (t) { + var png = new PNG({ + width: 10, + height: 10, + filterType: -1 + }); + + + for (var y = 0; y < png.height; y++) { + for (var x = 0; x < png.width; x++) { + var idx = (png.width * y + x) << 2; + + var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff; + + png.data[idx] = col; + png.data[idx + 1] = col; + png.data[idx + 2] = col; + png.data[idx + 3] = 0xff; + } + } + + png.pack().pipe(fs.createWriteStream(__dirname + '/bg.png')) + .on("finish", function () { + + var out = fs.readFileSync(__dirname + '/bg.png'); + var ref = fs.readFileSync(__dirname + '/bg-ref.png'); + + t.ok(bufferEqual(out, ref), "compares with working file ok"); + + t.end(); + }); +}); diff --git a/test/bg.js b/test/bg.js deleted file mode 100644 index ad39243..0000000 --- a/test/bg.js +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env node - -var fs = require('fs'), - PNG = require('pngjs').PNG; - - -var png = new PNG({ - width: 10, - height: 10, - filterType: -1 -}); - - -for (var y = 0; y < png.height; y++) { - for (var x = 0; x < png.width; x++) { - var idx = (png.width * y + x) << 2; - - var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff; - - png.data[idx] = col; - png.data[idx + 1] = col; - png.data[idx + 2] = col; - png.data[idx + 3] = 0xff; - } -} - -png.pack().pipe(fs.createWriteStream(__dirname + '/bg.png')); diff --git a/test/bg.png b/test/bg.png index b030229..e4361e0 100644 Binary files a/test/bg.png and b/test/bg.png differ diff --git a/test/run-compare.js b/test/run-compare.js index b9a98de..fe4ef23 100644 --- a/test/run-compare.js +++ b/test/run-compare.js @@ -13,7 +13,7 @@ try { console.log("Comparing in PhantomJS"); childProcess.execFile(binPath, childArgs, function (err, stdout, stderr) { - + // handle results console.log("Comparison Test Results:"); console.log(stdout);