| 1 |
use strictscip-perl cpan Image-Scale 0.14 strict/; |
| 2 |
|
| 3 |
use File::Pathscip-perl cpan Image-Scale 0.14 File/Path/ (); |
| 4 |
use File::Spec::Functionsscip-perl cpan Image-Scale 0.14 File/Spec/Functions/; |
| 5 |
use FindBinscip-perl cpan Image-Scale 0.14 FindBin/ (); |
| 6 |
use Test::Morescip-perl cpan Image-Scale 0.14 Test/More/; |
| 7 |
requirescip-perl cpan Image-Scale 0.14 main/require(). Test::NoWarnings; |
| 8 |
|
| 9 |
use Image::Scalescip-perl cpan Image-Scale 0.14 Image/Scale/; |
| 10 |
|
| 11 |
### PNG tests pass with both 1.4.3 and 1.2.44, don't need to skip any |
| 12 |
|
| 13 |
my $png_version = Image::Scale->png_versionscip-perl cpan Image-Scale 0.14 Image/Scale/png_version().(); |
| 14 |
|
| 15 |
if ($png_version) { |
| •16 |
planscip-perl cpan Image-Scale 0.14 main/plan(). tests => 4; |
| 17 |
} |
| 18 |
else { |
| 19 |
planscip-perl cpan Image-Scale 0.14 main/plan(). skip_all => 'Image::Scale not built with libpng support'; |
| 20 |
} |
| 21 |
|
| 22 |
my $tmpdir = catdirscip-perl cpan Image-Scale 0.14 main/catdir().( $FindBin::Binscip-perl cpan Image-Scale 0.14 FindBin/$Bin., 'tmp' ); |
| 23 |
if ( -d $tmpdir ) { |
| 24 |
File::Path::rmtreescip-perl cpan Image-Scale 0.14 File/Path/rmtree().($tmpdir); |
| 25 |
} |
| 26 |
mkdirscip-perl cpan Image-Scale 0.14 main/mkdir(). $tmpdir; |
| 27 |
|
| 28 |
# XXX palette_bkgd |
| 29 |
|
| 30 |
# corrupt files from PNG test suite |
| 31 |
# x00n0g01 - empty 0x0 grayscale file |
| 32 |
# xcrn0g04 - added cr bytes |
| 33 |
{ |
| 34 |
Test::NoWarnings::clear_warningsscip-perl cpan Image-Scale 0.14 Test/NoWarnings/clear_warnings().(); |
| 35 |
|
| 36 |
my $im = Image::Scale->newscip-perl cpan Image-Scale 0.14 Image/Scale/new().( _fscip-perl cpan Image-Scale 0.14 main/_f().("x00n0g01.png") ); |
| 37 |
|
| 38 |
# Test that $im is undef when new fails |
| 39 |
okscip-perl cpan Image-Scale 0.14 main/ok().( !definedscip-perl cpan Image-Scale 0.14 main/defined(). $im, 'new() returns undef on error ok' ); |
| 40 |
|
| 41 |
# Test that the correct warning was output |
| 42 |
my @warnings = Test::NoWarnings::warningsscip-perl cpan Image-Scale 0.14 Test/NoWarnings/warnings().(); |
| 43 |
likescip-perl cpan Image-Scale 0.14 main/like().( $warnings[0]->getMessagescip-perl cpan Image-Scale 0.14 main/getMessage()., qr/zero in IHDR/, 'PNG corrupt warning 1 output ok' ); |
| 44 |
} |
| 45 |
|
| 46 |
{ |
| 47 |
Test::NoWarnings::clear_warningsscip-perl cpan Image-Scale 0.14 Test/NoWarnings/clear_warnings().(); |
| 48 |
|
| 49 |
my $im = Image::Scale->newscip-perl cpan Image-Scale 0.14 Image/Scale/new().( _fscip-perl cpan Image-Scale 0.14 main/_f().("xcrn0g04.png") ); |
| 50 |
|
| 51 |
# This file won't be seen as PNG, so generates a generic unknown warning |
| 52 |
my @warnings = Test::NoWarnings::warningsscip-perl cpan Image-Scale 0.14 Test/NoWarnings/warnings().(); |
| 53 |
likescip-perl cpan Image-Scale 0.14 main/like().( $warnings[0]->getMessagescip-perl cpan Image-Scale 0.14 main/getMessage()., qr/Image::Scale unknown file type/, 'PNG corrupt header ok' ); |
| 54 |
} |
| 55 |
|
| 56 |
# XXX test for valid header but error during image_png_load() |
| 57 |
|
| 58 |
# 1-height image that would previously try to resize to 0-height |
| 59 |
{ |
| 60 |
my $dataref = _loadscip-perl cpan Image-Scale 0.14 main/_load().( _fscip-perl cpan Image-Scale 0.14 main/_f().("height1.png") ); |
| 61 |
|
| 62 |
my $outfile = _tmpscip-perl cpan Image-Scale 0.14 main/_tmp().("height1_resize_gd_fixed_point_w100.png"); |
| 63 |
my $im = Image::Scale->newscip-perl cpan Image-Scale 0.14 Image/Scale/new().($dataref); |
| 64 |
$im->resize_gd_fixed_pointscip-perl cpan Image-Scale 0.14 Image/Scale/resize_gd_fixed_point().( { width => 100 } ); |
| 65 |
$im->save_pngscip-perl cpan Image-Scale 0.14 Image/Scale/save_png().($outfile); |
| 66 |
|
| 67 |
isscip-perl cpan Image-Scale 0.14 main/is().( _comparescip-perl cpan Image-Scale 0.14 main/_compare().( _loadscip-perl cpan Image-Scale 0.14 main/_load().($outfile), "height1_resize_gd_fixed_point_w100.png" ), 1, "PNG 1-height resize ok" ); |
| 68 |
} |
| 69 |
|
| 70 |
diagscip-perl cpan Image-Scale 0.14 main/diag().("libpng version: $png_version"); |
| 71 |
|
| 72 |
END { |
| 73 |
File::Path::rmtreescip-perl cpan Image-Scale 0.14 File/Path/rmtree().($tmpdir); |
| 74 |
} |
| 75 |
|
| 76 |
sub _fscip-perl cpan Image-Scale 0.14 main/_f(). { |
| 77 |
return catfilescip-perl cpan Image-Scale 0.14 main/catfile().( $FindBin::Binscip-perl cpan Image-Scale 0.14 FindBin/$Bin., 'images', 'png', shiftscip-perl cpan Image-Scale 0.14 main/shift(). ); |
| 78 |
} |
| 79 |
|
| 80 |
sub _tmpscip-perl cpan Image-Scale 0.14 main/_tmp(). { |
| 81 |
return catfilescip-perl cpan Image-Scale 0.14 main/catfile().( $tmpdir, shiftscip-perl cpan Image-Scale 0.14 main/shift(). ); |
| 82 |
} |
| 83 |
|
| 84 |
sub _loadscip-perl cpan Image-Scale 0.14 main/_load(). { |
| 85 |
my $path = shiftscip-perl cpan Image-Scale 0.14 main/shift().; |
| 86 |
|
| 87 |
openscip-perl cpan Image-Scale 0.14 main/open(). my $fh, '<', $path or diescip-perl cpan Image-Scale 0.14 main/die(). "Cannot open $path"; |
| 88 |
binmodescip-perl cpan Image-Scale 0.14 main/binmode(). $fh; |
| 89 |
my $data = do { local $/scip-perl cpan Image-Scale 0.14 main/`$/`.; <$fh> }; |
| 90 |
closescip-perl cpan Image-Scale 0.14 main/close(). $fh; |
| 91 |
|
| 92 |
return \$data; |
| 93 |
} |
| 94 |
|
| 95 |
sub _comparescip-perl cpan Image-Scale 0.14 main/_compare(). { |
| 96 |
my ( $test, $path ) = @_scip-perl cpan Image-Scale 0.14 main/`@_`.; |
| 97 |
|
| 98 |
my $ref = _loadscip-perl cpan Image-Scale 0.14 main/_load().( catfilescip-perl cpan Image-Scale 0.14 main/catfile().( $FindBin::Binscip-perl cpan Image-Scale 0.14 FindBin/$Bin., 'ref', 'png', $path ) ); |
| 99 |
|
| 100 |
return $$ref eq $$test; |
| 101 |
} |