Browse files

better error testing of invalid image encoding formats

  • Loading branch information...
1 parent 064c9d2 commit bb201db1354514f284fad803e520e6eb0cc71238 @springmeyer springmeyer committed Dec 5, 2012
Showing with 25 additions and 2 deletions.
  1. +1 −1 src/mapnik_image.cpp
  2. +1 −1 src/mapnik_image_view.cpp
  3. +23 −0 test/image.test.js
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);

0 comments on commit bb201db

Please sign in to comment.