mirror of
https://github.com/danbulant/pngjs
synced 2026-07-06 19:50:36 +00:00
Code format test code
This commit is contained in:
parent
288a696584
commit
5310b0ed5f
4 changed files with 159 additions and 159 deletions
24
test/bg.js
24
test/bg.js
|
|
@ -1,27 +1,27 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
PNG = require('pngjs').PNG;
|
PNG = require('pngjs').PNG;
|
||||||
|
|
||||||
|
|
||||||
var png = new PNG({
|
var png = new PNG({
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 10,
|
height: 10,
|
||||||
filterType: -1
|
filterType: -1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
for (var y = 0; y < png.height; y++) {
|
for (var y = 0; y < png.height; y++) {
|
||||||
for (var x = 0; x < png.width; x++) {
|
for (var x = 0; x < png.width; x++) {
|
||||||
var idx = (png.width * y + x) << 2;
|
var idx = (png.width * y + x) << 2;
|
||||||
|
|
||||||
var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff;
|
var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff;
|
||||||
|
|
||||||
png.data[idx ] = col;
|
png.data[idx] = col;
|
||||||
png.data[idx+1] = col;
|
png.data[idx + 1] = col;
|
||||||
png.data[idx+2] = col;
|
png.data[idx + 2] = col;
|
||||||
png.data[idx+3] = 0xff;
|
png.data[idx + 3] = 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
png.pack().pipe(fs.createWriteStream(__dirname + '/bg.png'));
|
png.pack().pipe(fs.createWriteStream(__dirname + '/bg.png'));
|
||||||
|
|
|
||||||
|
|
@ -1,88 +1,87 @@
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var PNG = require('../lib/png').PNG;
|
var PNG = require('../lib/png').PNG;
|
||||||
var test = require('tape');
|
var test = require('tape');
|
||||||
|
|
||||||
fs.readdir(__dirname + '/in/', function (err, files) {
|
fs.readdir(__dirname + '/in/', function (err, files) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
files = files.filter(function(file) {
|
files = files.filter(function (file) {
|
||||||
return ((process.argv[3] || "").indexOf("nolarge") < 0 || !file.match(/large/i)) && Boolean(file.match(/\.png$/i));
|
return ((process.argv[3] || "").indexOf("nolarge") < 0 || !file.match(/large/i)) && Boolean(file.match(/\.png$/i));
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Converting images");
|
console.log("Converting images");
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
test('convert sync - ' + file, function (t) {
|
||||||
|
|
||||||
|
if (file.match(/large/)) {
|
||||||
|
t.timeoutAfter(1000 * 60);
|
||||||
|
} else {
|
||||||
|
t.timeoutAfter(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
test('convert sync - ' + file, function(t) {
|
var data = fs.readFileSync(__dirname + '/in/' + file);
|
||||||
|
try {
|
||||||
if (file.match(/large/)) {
|
var png = PNG.sync.read(data);
|
||||||
t.timeoutAfter(1000 * 60);
|
} catch (e) {
|
||||||
|
if (!expectedError) {
|
||||||
|
t.fail('Unexpected error parsing..' + file + '\n' + e.message + "\n" + e.stack);
|
||||||
} else {
|
} else {
|
||||||
t.timeoutAfter(1000);
|
t.pass("completed");
|
||||||
}
|
}
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
|
||||||
var data = fs.readFileSync(__dirname + '/in/' + file);
|
if (expectedError) {
|
||||||
try {
|
t.fail("Sync: Error expected, parsed fine .. - " + file);
|
||||||
var png = PNG.sync.read(data);
|
return t.end();
|
||||||
} catch (e) {
|
}
|
||||||
if (!expectedError) {
|
|
||||||
t.fail('Unexpected error parsing..' + file + '\n' + e.message + "\n" + e.stack);
|
|
||||||
} else {
|
|
||||||
t.pass("completed");
|
|
||||||
}
|
|
||||||
return t.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expectedError) {
|
var outpng = new PNG();
|
||||||
t.fail("Sync: Error expected, parsed fine .. - " + file);
|
outpng.gamma = png.gamma;
|
||||||
return t.end();
|
outpng.data = png.data;
|
||||||
}
|
outpng.width = png.width;
|
||||||
|
outpng.height = png.height;
|
||||||
|
outpng.pack()
|
||||||
|
.pipe(fs.createWriteStream(__dirname + '/outsync/' + file)
|
||||||
|
.on("finish", function () {
|
||||||
|
t.pass("completed");
|
||||||
|
t.end();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
var outpng = new PNG();
|
test('convert async - ' + file, function (t) {
|
||||||
outpng.gamma = png.gamma;
|
fs.createReadStream(__dirname + '/in/' + file)
|
||||||
outpng.data = png.data;
|
.pipe(new PNG())
|
||||||
outpng.width = png.width;
|
.on('error', function (err) {
|
||||||
outpng.height = png.height;
|
if (!expectedError) {
|
||||||
outpng.pack()
|
t.fail("Async: Unexpected error parsing.." + file + '\n' + err.message + '\n' + err.stack);
|
||||||
.pipe(fs.createWriteStream(__dirname + '/outsync/' + file)
|
} else {
|
||||||
.on("finish", function () {
|
t.pass("completed");
|
||||||
t.pass("completed");
|
}
|
||||||
t.end();
|
t.end();
|
||||||
}));
|
})
|
||||||
});
|
.on('parsed', function () {
|
||||||
|
|
||||||
test('convert async - ' + file, function(t) {
|
if (expectedError) {
|
||||||
fs.createReadStream(__dirname + '/in/' + file)
|
t.fail("Async: Error expected, parsed fine .." + file);
|
||||||
.pipe(new PNG())
|
return t.end();
|
||||||
.on('error', function (err) {
|
}
|
||||||
if (!expectedError) {
|
|
||||||
t.fail("Async: Unexpected error parsing.." + file + '\n' + err.message + '\n' + err.stack);
|
|
||||||
} else {
|
|
||||||
t.pass("completed");
|
|
||||||
}
|
|
||||||
t.end();
|
|
||||||
})
|
|
||||||
.on('parsed', function () {
|
|
||||||
|
|
||||||
if (expectedError) {
|
this.pack()
|
||||||
t.fail("Async: Error expected, parsed fine .." + file);
|
.pipe(
|
||||||
return t.end();
|
fs.createWriteStream(__dirname + '/out/' + file)
|
||||||
}
|
.on("finish", function () {
|
||||||
|
t.pass("completed");
|
||||||
this.pack()
|
t.end();
|
||||||
.pipe(
|
}));
|
||||||
fs.createWriteStream(__dirname + '/out/' + file)
|
|
||||||
.on("finish", function() {
|
|
||||||
t.pass("completed");
|
|
||||||
t.end();
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,58 @@
|
||||||
/*global phantom:true*/
|
/*global phantom:true*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var page = require('webpage').create();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
var last = new Date();
|
var last = new Date();
|
||||||
var timeout = 10000;
|
var timeout = 10000;
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function () {
|
||||||
var results = page.evaluate(function(){
|
var results = page.evaluate(function () {
|
||||||
if (window.isFinished && window.isFinished()) {
|
if (window.isFinished && window.isFinished()) {
|
||||||
return window.results;
|
return window.results;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (results) {
|
if (results) {
|
||||||
var success = true;
|
var success = true;
|
||||||
var successes = [],
|
var successes = [],
|
||||||
failures = [];
|
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];
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
successes.push(result.name);
|
successes.push(result.name);
|
||||||
} else {
|
} else {
|
||||||
failures.push(result.name);
|
failures.push(result.name);
|
||||||
}
|
}
|
||||||
success = success && result.success;
|
success = success && result.success;
|
||||||
}
|
}
|
||||||
console.log("Success:", successes.join(", "));
|
console.log("Success:", successes.join(", "));
|
||||||
if (failures.length) {
|
if (failures.length) {
|
||||||
console.log("Failure:", failures.join(", "));
|
console.log("Failure:", failures.join(", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
phantom.exit(success ? 0 : 1);
|
phantom.exit(success ? 0 : 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new Date() - last > timeout) {
|
if (new Date() - last > timeout) {
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
page.onConsoleMessage = function(msg, lineNum, sourceId) {
|
page.onConsoleMessage = function (msg, lineNum, sourceId) {
|
||||||
//console.log('CONSOLE: ' + msg);
|
//console.log('CONSOLE: ' + msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
page.onError = function(msg, trace) {
|
page.onError = function (msg, trace) {
|
||||||
console.log('error.onError', msg, trace);
|
console.log('error.onError', msg, trace);
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
phantom.onError = function(msg, trace) {
|
phantom.onError = function (msg, trace) {
|
||||||
console.log('error.onError', msg, trace);
|
console.log('error.onError', msg, trace);
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
page.open("http://localhost:8000");
|
page.open("http://localhost:8000");
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,24 @@
|
||||||
require("./http-server");
|
require("./http-server");
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var childProcess = require('child_process');
|
var childProcess = require('child_process');
|
||||||
var phantomjs = require('phantomjs');
|
var phantomjs = require('phantomjs');
|
||||||
var binPath = phantomjs.path;
|
var binPath = phantomjs.path;
|
||||||
|
|
||||||
var childArgs = [
|
var childArgs = [
|
||||||
path.join(__dirname, 'phantom-compare.js')
|
path.join(__dirname, 'phantom-compare.js')
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("Comparing in PhantomJS");
|
console.log("Comparing in PhantomJS");
|
||||||
|
|
||||||
childProcess.execFile(binPath, childArgs, function (err, stdout, stderr) {
|
childProcess.execFile(binPath, childArgs, function (err, stdout, stderr) {
|
||||||
// handle results
|
|
||||||
console.log("Comparison Test Results:");
|
// handle results
|
||||||
console.log(stdout);
|
console.log("Comparison Test Results:");
|
||||||
process.exit(err ? 1 : 0);
|
console.log(stdout);
|
||||||
});
|
process.exit(err ? 1 : 0);
|
||||||
} catch(e) {
|
});
|
||||||
console.log("Error starting phantomjs");
|
} catch (e) {
|
||||||
|
console.log("Error starting phantomjs");
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue