| 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 |
my $gif_version = Image::Scale->gif_versionscip-perl cpan Image-Scale 0.14 Image/Scale/gif_version().(); |
| 12 |
my $png_version = Image::Scale->png_versionscip-perl cpan Image-Scale 0.14 Image/Scale/png_version().(); |
| 13 |
|
| 14 |
if ($gif_version) { |
| •15 |
planscip-perl cpan Image-Scale 0.14 main/plan(). tests => 3; |
| 16 |
} |
| 17 |
else { |
| 18 |
planscip-perl cpan Image-Scale 0.14 main/plan(). skip_all => 'Image::Scale not built with giflib support'; |
| 19 |
} |
| 20 |
|
| 21 |
my $tmpdir = catdirscip-perl cpan Image-Scale 0.14 main/catdir().( $FindBin::Binscip-perl cpan Image-Scale 0.14 FindBin/$Bin., 'tmp' ); |
| 22 |
if ( -d $tmpdir ) { |
| 23 |
File::Path::rmtreescip-perl cpan Image-Scale 0.14 File/Path/rmtree().($tmpdir); |
| 24 |
} |
| 25 |
mkdirscip-perl cpan Image-Scale 0.14 main/mkdir(). $tmpdir; |
| 26 |
|
| 27 |
# corrupt file |
| 28 |
{ |
| 29 |
no strict 'subs'; |
| 30 |
no warnings; |
| 31 |
|
| 32 |
Test::NoWarnings::clear_warningsscip-perl cpan Image-Scale 0.14 Test/NoWarnings/clear_warnings().(); |
| 33 |
|
| 34 |
my $im = Image::Scale->newscip-perl cpan Image-Scale 0.14 Image/Scale/new().( _fscip-perl cpan Image-Scale 0.14 main/_f().("corrupt.gif") ); |
| 35 |
|
| 36 |
# Hide stderr |
| 37 |
openscip-perl cpan Image-Scale 0.14 main/open(). OLD_STDERR, '>&', STDERR; |
| 38 |
close STDERR; |
| 39 |
|
| 40 |
my $ok = $im->resize_gd_fixed_pointscip-perl cpan Image-Scale 0.14 Image/Scale/resize_gd_fixed_point().( { width => 50 } ); |
| 41 |
|
| 42 |
# Restore stderr |
| 43 |
openscip-perl cpan Image-Scale 0.14 main/open(). STDERR, '>&', OLD_STDERR; |
| 44 |
|
| 45 |
isscip-perl cpan Image-Scale 0.14 main/is().( $ok, 0, 'GIF corrupt failed resize ok' ); |
| 46 |
|
| 47 |
# Test that the correct warning was output |
| 48 |
likescip-perl cpan Image-Scale 0.14 main/like().( (Test::NoWarnings::warningsscip-perl cpan Image-Scale 0.14 Test/NoWarnings/warnings().())[0]->getMessagescip-perl cpan Image-Scale 0.14 main/getMessage()., qr/Image::Scale unable to read GIF file/i, 'GIF corrupt error output ok' ); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
# Bug 17573, very thin gif could cause divide by 0 errors |
| 53 |
SKIP: |
| 54 |
{ |
| 55 |
skipscip-perl cpan Image-Scale 0.14 main/skip(). "PNG support not built, skipping file comparison tests", 1 if !$png_version; |
| 56 |
|
| 57 |
my $outfile = _tmpscip-perl cpan Image-Scale 0.14 main/_tmp().("bug17573-thin_gd_fixed_point_w40.png"); |
| 58 |
my $im = Image::Scale->newscip-perl cpan Image-Scale 0.14 Image/Scale/new().( _fscip-perl cpan Image-Scale 0.14 main/_f().('bug17573-thin.gif') ); |
| 59 |
|
| 60 |
$im->resize_gd_fixed_pointscip-perl cpan Image-Scale 0.14 Image/Scale/resize_gd_fixed_point().( { width => 40 } ); |
| 61 |
$im->save_pngscip-perl cpan Image-Scale 0.14 Image/Scale/save_png().($outfile); |
| 62 |
|
| 63 |
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), "bug17573-thin_gd_fixed_point_w40.png" ), 1, "GIF resize_gd_fixed_point from thin image ok" ); |
| 64 |
} |
| 65 |
|
| 66 |
diagscip-perl cpan Image-Scale 0.14 main/diag().("giflib version: $gif_version"); |
| 67 |
|
| 68 |
END { |
| 69 |
File::Path::rmtreescip-perl cpan Image-Scale 0.14 File/Path/rmtree().($tmpdir); |
| 70 |
} |
| 71 |
|
| 72 |
sub _fscip-perl cpan Image-Scale 0.14 main/_f(). { |
| 73 |
return catfilescip-perl cpan Image-Scale 0.14 main/catfile().( $FindBin::Binscip-perl cpan Image-Scale 0.14 FindBin/$Bin., 'images', 'gif', shiftscip-perl cpan Image-Scale 0.14 main/shift(). ); |
| 74 |
} |
| 75 |
|
| 76 |
sub _tmpscip-perl cpan Image-Scale 0.14 main/_tmp(). { |
| 77 |
return catfilescip-perl cpan Image-Scale 0.14 main/catfile().( $tmpdir, shiftscip-perl cpan Image-Scale 0.14 main/shift(). ); |
| 78 |
} |
| 79 |
|
| 80 |
sub _loadscip-perl cpan Image-Scale 0.14 main/_load(). { |
| 81 |
my $path = shiftscip-perl cpan Image-Scale 0.14 main/shift().; |
| 82 |
|
| 83 |
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"; |
| 84 |
binmodescip-perl cpan Image-Scale 0.14 main/binmode(). $fh; |
| 85 |
my $data = do { local $/scip-perl cpan Image-Scale 0.14 main/`$/`.; <$fh> }; |
| 86 |
closescip-perl cpan Image-Scale 0.14 main/close(). $fh; |
| 87 |
|
| 88 |
return \$data; |
| 89 |
} |
| 90 |
|
| 91 |
sub _comparescip-perl cpan Image-Scale 0.14 main/_compare(). { |
| 92 |
my ( $test, $path ) = @_scip-perl cpan Image-Scale 0.14 main/`@_`.; |
| 93 |
|
| 94 |
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', 'gif', $path ) ); |
| 95 |
|
| 96 |
return $$ref eq $$test; |
| 97 |
} |