Skip to content

Commit 477c259

Browse files
author
Dane Springmeyer
committed
improve test coverage for ImageView.save - refs #509 #527 #528
1 parent 40fb7a7 commit 477c259

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/mapnik_image_view.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ NAN_METHOD(ImageView::save)
585585
catch (std::exception const& ex)
586586
{
587587
Nan::ThrowError(ex.what());
588-
return;
589588
}
590589
return;
591590
}

test/image_view.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var mapnik = require('../');
44
var assert = require('assert');
5+
var fs = require('fs');
56

67
describe('mapnik.ImageView ', function() {
78
it('should throw with invalid usage', function() {
@@ -213,6 +214,16 @@ describe('mapnik.ImageView ', function() {
213214
done();
214215
});
215216
});
217+
218+
it('should be able to save an ImageView', function(done) {
219+
var im = new mapnik.Image(256, 256);
220+
var view = im.view(0,0,256,256);
221+
var pal = new mapnik.Palette(new Buffer('\xff\x09\x93\xFF\x01\x02\x03\x04','ascii'));
222+
var expected = '/tmp/mapnik-image-view-saved.png';
223+
view.save(expected);
224+
assert.ok(fs.existsSync(expected));
225+
done();
226+
});
216227

217228
it('should throw with invalid formats', function() {
218229
var im = new mapnik.Image(256, 256);
@@ -221,6 +232,17 @@ describe('mapnik.ImageView ', function() {
221232
assert.throws(function() { view.save(); });
222233
assert.throws(function() { view.save('file.png', null); });
223234
assert.throws(function() { view.save('foo'); });
235+
assert.throws(function() { view.save('foo','foo'); });
236+
assert.throws(function() { view.save(); });
237+
assert.throws(function() { view.save('file.png', null); });
238+
assert.throws(function() { view.save('foo'); });
239+
assert.throws(function() { view.saveSync(); });
240+
assert.throws(function() { view.saveSync('foo','foo'); });
241+
assert.throws(function() { view.saveSync('file.png', null); });
242+
assert.throws(function() { view.saveSync('foo'); });
243+
assert.throws(function() { view.save(function(err) {}); });
244+
assert.throws(function() { view.save('file.png', null, function(err) {}); });
245+
assert.throws(function() { view.save('foo', function(err) {}); });
224246
});
225247

226248
if (mapnik.supports.webp) {

0 commit comments

Comments
 (0)