Skip to content

Commit

Permalink
fix #67
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalAr committed Nov 25, 2014
1 parent 828e5db commit 84ed584
Show file tree
Hide file tree
Showing 3 changed files with 434 additions and 44 deletions.
10 changes: 6 additions & 4 deletions lib/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
throw err;
}
);
}
};

Image.prototype.darken = function() {
this.__lock();
Expand Down Expand Up @@ -494,9 +494,11 @@
params.interlaced = params.interlaced || defs.defaults.PNG_DEF_INTERLACED;
if (typeof params.interlaced !== 'boolean') throw Error('PNG \'interlaced\' must be boolean');
params.transparency = params.transparency || defs.defaults.PNG_DEF_TRANSPARENT;
if (typeof params.transparency !== 'boolean' && params.transparency.toLowerCase() !== 'auto')
throw Error('PNG \'transparency\' must be boolean or \'auto\'');
if (params.transparency.toLowerCase() !== 'auto') params.transparency = that.__trans;
if (typeof params.transparency !== 'boolean'){
if (typeof params.transparency === 'string' && params.transparency.toLowerCase() === 'auto')
params.transparency = that.__trans;
else throw Error('PNG \'transparency\' must be boolean or \'auto\'');
}
return encoder.png(
that.__lwip.buffer(),
that.__lwip.width(),
Expand Down
228 changes: 211 additions & 17 deletions tests/00.argsValidation/104.image.toBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var should = require("should"),
describe('image.toBuffer arguments validation', function() {

var image;
before(function(done) {
beforeEach(function(done) {
lwip.open(imgs.jpg.rgb, function(err, img) {
image = img;
done(err);
Expand All @@ -34,28 +34,222 @@ describe('image.toBuffer arguments validation', function() {

describe('PNG params', function() {

describe('invalid compression', function() {
it('should throw an error', function() {
image.toBuffer.bind(image, 'png', {
compression: 'foo'
}, function() {}).should.throwError();
describe("valid params", function(){

describe('defaults', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', done).should.not.throwError();
});
});
});

describe('invalid interlaced', function() {
it('should throw an error', function() {
image.toBuffer.bind(image, 'png', {
interlaced: 'foo'
}, function() {}).should.throwError();
describe('none, false, true', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'none',
interlaced: false,
transparency: true
}, done).should.not.throwError();
});
});

describe('fast, false, true', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'fast',
interlaced: false,
transparency: true
}, done).should.not.throwError();
});
});

describe('high, false, true', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'high',
interlaced: false,
transparency: true
}, done).should.not.throwError();
});
});

describe('none, true, true', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'none',
interlaced: true,
transparency: true
}, done).should.not.throwError();
});
});

describe('fast, true, true', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'fast',
interlaced: true,
transparency: true
}, done).should.not.throwError();
});
});

describe('high, true, true', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'high',
interlaced: true,
transparency: true
}, done).should.not.throwError();
});
});

describe('none, false, false', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'none',
interlaced: false,
transparency: false
}, done).should.not.throwError();
});
});

describe('fast, false, false', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'fast',
interlaced: false,
transparency: false
}, done).should.not.throwError();
});
});

describe('high, false, false', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'high',
interlaced: false,
transparency: false
}, done).should.not.throwError();
});
});

describe('none, true, false', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'none',
interlaced: true,
transparency: false
}, done).should.not.throwError();
});
});

describe('fast, true, false', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'fast',
interlaced: true,
transparency: false
}, done).should.not.throwError();
});
});

describe('high, true, false', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'high',
interlaced: true,
transparency: false
}, done).should.not.throwError();
});
});

describe('none, false, auto', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'none',
interlaced: false,
transparency: 'auto'
}, done).should.not.throwError();
});
});

describe('fast, false, auto', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'fast',
interlaced: false,
transparency: 'auto'
}, done).should.not.throwError();
});
});

describe('high, false, auto', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'high',
interlaced: false,
transparency: 'auto'
}, done).should.not.throwError();
});
});

describe('none, true, auto', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'none',
interlaced: true,
transparency: 'auto'
}, done).should.not.throwError();
});
});

describe('fast, true, auto', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'fast',
interlaced: true,
transparency: 'auto'
}, done).should.not.throwError();
});
});

describe('high, true, auto', function() {
it('should succeed', function(done) {
image.toBuffer.bind(image, 'png', {
compression: 'high',
interlaced: true,
transparency: 'auto'
}, done).should.not.throwError();
});
});

});

describe('invalid transparency', function() {
it('should throw an error', function() {
image.toBuffer.bind(image, 'png', {
transparency: 'foo'
}, function() {}).should.throwError();
describe("invalid params", function(){

describe('invalid compression', function() {
it('should throw an error', function() {
image.toBuffer.bind(image, 'png', {
compression: 'foo'
}, function() {}).should.throwError();
});
});

describe('invalid interlaced', function() {
it('should throw an error', function() {
image.toBuffer.bind(image, 'png', {
interlaced: 'foo'
}, function() {}).should.throwError();
});
});

describe('invalid transparency', function() {
it('should throw an error', function() {
image.toBuffer.bind(image, 'png', {
transparency: 'foo'
}, function() {}).should.throwError();
});
});

});

});
Expand Down
Loading

0 comments on commit 84ed584

Please sign in to comment.