Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better error testing of invalid image encoding formats

  • Loading branch information...
commit bb201db1354514f284fad803e520e6eb0cc71238 1 parent 064c9d2
@springmeyer springmeyer authored
View
2  src/mapnik_image.cpp
@@ -600,7 +600,7 @@ Handle<Value> Image::save(const Arguments& args)
Image* im = ObjectWrap::Unwrap<Image>(args.This());
try
{
- mapnik::save_to_file<mapnik::image_data_32>(im->get()->data(),filename);
+ mapnik::save_to_file<mapnik::image_data_32>(im->get()->data(),filename, format);
}
catch (std::exception const& ex)
{
View
2  src/mapnik_image_view.cpp
@@ -447,7 +447,7 @@ void ImageView::EIO_AfterEncode(uv_work_t* req)
}
else
{
- node::Buffer *retbuf = Buffer::New((char*)closure->result.data(),closure->result.size());
+ node::Buffer *retbuf = node::Buffer::New((char*)closure->result.data(),closure->result.size());
Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(retbuf->handle_) };
closure->cb->Call(Context::GetCurrent()->Global(), 2, argv);
}
View
23 test/image.test.js
@@ -15,6 +15,29 @@ describe('mapnik.Image ', function() {
assert.throws(function() { new mapnik.Image('a', 'b', 'c'); });
});
+ it('should throw with filename lacking an extension', function() {
+ var im = new mapnik.Image(256, 256);
+ assert.throws(function() { im.save('foo'); });
+ });
+
+ it('should throw with invalid encoding format 1', function() {
+ var im = new mapnik.Image(256, 256);
+ assert.throws(function() { im.encodeSync('foo'); });
+ });
+
+ it('should throw with invalid encoding format 2', function() {
+ var im = new mapnik.Image(256, 256);
+ assert.throws(function() { im.save('foo','foo'); });
+ });
+
+ it('should throw with invalid encoding format 3', function(done) {
+ var im = new mapnik.Image(256, 256);
+ im.encode('foo',function(err) {
+ assert.ok(err);
+ done();
+ })
+ });
+
it('should be initialized properly', function() {
var im = new mapnik.Image(256, 256);
assert.ok(im instanceof mapnik.Image);
Please sign in to comment.
Something went wrong with that request. Please try again.