22
33var mapnik = require ( '../' ) ;
44var assert = require ( 'assert' ) ;
5+ var fs = require ( 'fs' ) ;
56
67describe ( '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