Skip to content
Permalink
Browse files

image error checking, enable msIO_getAndStripStdoutBufferMimeHeaders,…

… new tests
  • Loading branch information...
andy
andy committed Apr 16, 2019
1 parent 37815bb commit bfcce38bc1dc1d505aa30170340cda33814eaa36
Showing with 101 additions and 50 deletions.
  1. +1 −21 mapscript/perl/tests/0-load.t
  2. +61 −0 mapscript/perl/tests/maps.t
  3. +39 −27 mapscript/swiginc/image.i
  4. +0 −2 mapscript/swiginc/msio.i
@@ -2,8 +2,8 @@
use strict;
use warnings;
use Test::More tests => 11;
use File::Spec;

# check the mapserver version for keywords
sub msHas
{
my ($mod) = @_;
@@ -38,23 +38,3 @@ SKIP: {
}
};

=pod
my $map = new mapscript::mapObj( "../mspython/test_mapio.map" );
mapscript::msIO_installStdoutToBuffer();
my $owreq = new mapscript::OWSRequest();
$owreq->loadParamsFromURL('service=WMS&version=1.1.1&request=GetMap&layers=grey&srs=EPSG:4326&bbox=-180,-90,180,90&format=image/png&width=80&height=40')
my $err = $map->OWSDispatch( $owreq );
ok($err == 0, 'OWSDispatch');
# warn(mapscript::msGetErrorString("\n"));
my $content_type = mapscript::msIO_stripStdoutBufferContentType();
$x = mapscript::msIO_getStdoutBufferBytes();
mapscript::msIO_resetHandlers();
$res->status(200);
$res->content_type($content_type);
$res->body($$x);
=cut

@@ -0,0 +1,61 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 10;
use mapscript;

sub msHas
{
my ($mod) = @_;
my $ver = mapscript::msGetVersion();
if (index($ver, $mod) > -1) {
return 1;
} else {
return 0;
}
}

# we need to search up directories for the test folder
my $mapfile = '../../../msautotest/mspython/test_mapio.map';
if (! -e $mapfile)
{
$mapfile = '../../../../msautotest/mspython/test_mapio.map';
}
ok(-e $mapfile, 'mapfile exists');

my $map = new mapscript::mapObj($mapfile);
ok($map, 'create mapObj');

mapscript::msIO_installStdoutToBuffer();
my $owreq = new mapscript::OWSRequest();
ok($owreq, 'create OWSRequest');
$owreq->loadParamsFromURL('service=WMS&version=1.1.1&request=GetMap&layers=grey&srs=EPSG:4326&bbox=-180,-90,180,90&format=image/png&width=80&height=40');
ok($owreq->getName(0) eq 'service');
ok($owreq->getValue(0) eq 'WMS');
ok($owreq->getValueByName('request') eq 'GetMap');

my $err = $map->OWSDispatch( $owreq );
ok($err == 0, 'OWSDispatch');

# warn(mapscript::msGetErrorString("\n"));

my $h = mapscript::msIO_getAndStripStdoutBufferMimeHeaders();
#my $k = $h->nextKey();
#while ($k)
#{
# diag("$k == " . $h->get($k));
# $k = $h->nextKey($k);
#}

ok($h->get('Cache-Control') eq 'max-age=86400');
ok($h->get('Content-Type') eq 'image/png');


my $x = mapscript::msIO_getStdoutBufferBytes();
#open(F, '>', 'x.png');
#print F $$x;
#close(F);

ok(substr($$x, 1, 3) eq 'PNG');


@@ -1,24 +1,24 @@
/* ===========================================================================
$Id$

Project: MapServer
Purpose: SWIG interface file for mapscript imageObj extensions
Author: Steve Lime
Author: Steve Lime
Sean Gillies, sgillies@frii.com

===========================================================================
Copyright (c) 1996-2001 Regents of the University of Minnesota.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
@@ -29,7 +29,7 @@
=========================================================================*/

%extend imageObj {

/* imageObj constructor now takes filename as an optional argument. */
imageObj(int width, int height, outputFormatObj *input_format=NULL,
const char *file=NULL,
@@ -55,19 +55,30 @@
}

if (file) {

renderer = format->vtable;
rb = (rasterBufferObj*) malloc(sizeof(rasterBufferObj));
if (!rb) {
msSetError(MS_MEMERR, NULL, "imageObj()");
return NULL;
}
if ( (renderer->loadImageFromFile((char *)file, rb)) == MS_FAILURE)
if ( (renderer->loadImageFromFile((char *)file, rb)) == MS_FAILURE) {
msFreeRasterBuffer(rb);
free(rb);
return NULL;

image = msImageCreate(rb->width, rb->height, format, NULL, NULL,
}
image = msImageCreate(rb->width, rb->height, format, NULL, NULL,
resolution, defresolution, NULL);
renderer->mergeRasterBuffer(image, rb, 1.0, 0, 0, 0, 0, rb->width, rb->height);
if (! image) {
msFreeRasterBuffer(rb);
free(rb);
return NULL;
}

if(renderer->mergeRasterBuffer(image, rb, 1.0, 0, 0, 0, 0, rb->width, rb->height) != MS_SUCCESS) {
msFreeImage(image);
image = NULL;
}

msFreeRasterBuffer(rb);
free(rb);
@@ -79,13 +90,13 @@
return image;
}

~imageObj()
~imageObj()
{
msFreeImage(self);
msFreeImage(self);
}

/* saveGeo - see Bugzilla issue 549 */
void save(char *filename, mapObj *map=NULL)
/* saveGeo - see Bugzilla issue 549 */
void save(char *filename, mapObj *map=NULL)
{
msSaveImage(map, self, filename );
}
@@ -119,7 +130,8 @@
else
{
msSetError(MS_IMGERR, "Writing of %s format not implemented",
"imageObj::write");
"imageObj::write",
self->format->name);
}

return retval;
@@ -136,15 +148,15 @@
contributed by Jerry Pisk, jerry.pisk@gmail.com
-------------------------------------------------------------------------
*/
gdBuffer getBytes()

gdBuffer getBytes()
{
gdBuffer buffer;

buffer.owns_data = MS_TRUE;

buffer.data = msSaveImageBuffer(self, &buffer.size, self->format);

if( buffer.data == NULL || buffer.size == 0 )
{
buffer.data = NULL;
@@ -157,16 +169,16 @@

int getSize() {
gdBuffer buffer;
int size=0;
int size=0;

buffer.data = msSaveImageBuffer(self, &buffer.size, self->format);
size = buffer.size;
size = buffer.size;

if( buffer.data == NULL || buffer.size == 0 ) {
buffer.data = NULL;
msSetError(MS_MISCERR, "Failed to get image buffer size", "getSize");
}
free(buffer.data);
free(buffer.data);
return size;
}
}
@@ -45,10 +45,8 @@ void msIO_stripStdoutBufferContentHeaders(void);
const char *msIO_getStdoutBufferString(void);
gdBuffer msIO_getStdoutBufferBytes(void);

#ifdef SWIGPYTHON
%newobject msIO_getAndStripStdoutBufferMimeHeaders;
hashTableObj* msIO_getAndStripStdoutBufferMimeHeaders(void);
#endif

%{

0 comments on commit bfcce38

Please sign in to comment.
You can’t perform that action at this time.