"Fossies" - the Fresh Open Source Software Archive

Member "Image-Size-3.300/t/all.t" (28 Feb 2015, 4063 Bytes) of package /linux/privat/Image-Size-3.300.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "all.t": 3.232_vs_3.300.

    1 #!/usr/bin/perl -w
    2 
    3 use IO::File;
    4 use Image::Size qw(:all);
    5 use Test::More tests => 23;
    6 
    7 # We now only test the CWS branch if the user already has Compress::Zlib
    8 # available. We no longer require it for installation.
    9 eval 'require Compress::Zlib;';
   10 $do_cws_test = $@ ? 0 : 1;
   11 
   12 ($dir = $0) =~ s/\w+\.t$//o;
   13 
   14 #
   15 # Phase one: basic types tested on files.
   16 #
   17 ($x, $y) = imgsize("${dir}test.gif");
   18 ok(($x == 60 && $y == 40), 'Basic GIF format test');
   19 
   20 $html = html_imgsize("${dir}letter_T.jpg");
   21 ok(($html =~ /width="52"\s+height="54"/oi),
   22    'Test html_imgsize and basic JPG format');
   23 
   24 @attrs = attr_imgsize("${dir}xterm.xpm");
   25 ok(($attrs[1] == 64 && $attrs[3] == 38),
   26    'Test attr_imgsize and basic XPM format');
   27 
   28 ($x, $y) = imgsize("${dir}spacer50.xbm");
   29 ok(($x == 50 && $y == 10), 'Basic XBM format test');
   30 
   31 ($x, $y, $err) = imgsize("some non-existant file");
   32 ok(($err =~ /can\'t open/oi), 'Test non-existent file error catching');
   33 
   34 # The Pak-38 is actually a valid GIF, but this should work:
   35 ($x, $y) = imgsize("${dir}pak38.jpg");
   36 ok(($x == 333 && $y == 194), 'Test format/file-extension mis-match');
   37 
   38 # Test PNG image supplied by Tom Metro:
   39 ($x, $y) = imgsize("${dir}pass-1_s.png");
   40 ok(($x == 90 && $y == 60), 'Basic PNG format test');
   41 
   42 # Test PPM image code supplied by Carsten Dominik:
   43 ($x, $y, $id) = imgsize("${dir}letter_N.ppm");
   44 ok(($x == 66 && $y == 57 && $id eq 'PPM'), 'Basic PPM format test');
   45 
   46 # Test TIFF image code supplied by Cloyce Spradling
   47 ($x, $y, $id) = imgsize("${dir}lexjdic.tif");
   48 ok(($x == 35 && $y == 32 && $id eq 'TIF'), 'Basic TIFF format test (1)');
   49 ($x, $y, $id) = imgsize("${dir}bexjdic.tif");
   50 ok(($x == 35 && $y == 32 && $id eq 'TIF'), 'Basic TIFF format test (2)');
   51 
   52 # Test BMP code from Aldo Calpini
   53 ($x, $y, $id) = imgsize("${dir}xterm.bmp");
   54 ok(($x == 64 && $y == 38 && $id eq 'BMP'), 'Basic BMP format test');
   55 ($x, $y, $id) = imgsize("${dir}old-os2.bmp");
   56 ok(($x == 1500 && $y == 1000 && $id eq 'BMP'), 'Basic BMP OS/2 format test');
   57 
   58 # Test SWF code from Dmitry Dorofeev <dima@yasp.com>
   59 ($x, $y, $id) = imgsize("${dir}yasp.swf");
   60 ok(($x == 85 && $y == 36 && $id eq 'SWF'), 'Basic SWF format test');
   61 
   62 # Test EMF code
   63 ($x, $y, $id) = imgsize("${dir}Test_emf_small.emf");
   64 ok(($x == 638 && $y == 949 && $id eq 'EMF'), 'Basic EMF format test');
   65 
   66 # Test WEBP code from Baldur Kristinsson
   67 ($x, $y, $id) = imgsize("${dir}1.sm.webp");
   68 ok(($x == 320 && $y == 214 && $id eq 'WEBP'), 'Basic WEBP format test');
   69 
   70 # Test ICO code from Baldur Kristinsson
   71 ($x, $y, $id) = imgsize("${dir}tux.ico");
   72 ok(($x == 16 && $y == 16 && $id eq 'ICO'), 'Basic ICO format test');
   73 
   74 # Test CUR code from Baldur Kristinsson
   75 ($x, $y, $id) = imgsize("${dir}move.cur");
   76 ok(($x == 32 && $y == 32 && $id eq 'CUR'), 'Basic CUR format test');
   77 
   78 SKIP: {
   79     skip 'Compress::Zlib not installed', 1 unless $do_cws_test;
   80 
   81     # Test CWS patch from mrj@mrj.spb.ru
   82     ($x, $y, $id) = imgsize("${dir}8.swf");
   83     ok(($x == 280 && $y == 140 && $id eq 'CWS'), 'Basic CWS format test');
   84 }
   85 
   86 # Test the PSD code (orig. contributer unknown)
   87 ($x, $y, $id) = imgsize("${dir}468x60.psd");
   88 ok(($x == 468 && $y == 60 && $id eq 'PSD'), 'Basic PSD format test');
   89 
   90 # Phase two: tests on in-memory strings.
   91 $fh = new IO::File "< ${dir}test.gif";
   92 $data = '';
   93 read $fh, $data, (stat "${dir}test.gif")[7];
   94 $fh->close;
   95 ($x, $y, $id) = imgsize(\$data);
   96 ok(($x == 60 && $y == 40 && $id eq 'GIF'), 'Test in-memory image data');
   97 
   98 # Phase three: tests on open IO::File objects.
   99 $fh = new IO::File "< ${dir}test.gif";
  100 ($x, $y, $id) = imgsize($fh);
  101 ok(($x == 60 && $y == 40 && $id eq 'GIF'), 'Test open IO::File object');
  102 
  103 # Reset to head
  104 $fh->seek(0, 0);
  105 # Move somewhere
  106 $fh->seek(128, 0);
  107 # Do it again. This time when we check results, $fh->tell should be 128
  108 ($x, $y, $id) = imgsize($fh);
  109 ok(($x == 60 && $y == 40 && $id eq 'GIF' && ($fh->tell == 128)),
  110    'Test that it leaves open IO::File object in the same position');
  111 
  112 $fh->close;
  113 
  114 # Phase <whatever>: tests for specific bugs
  115 ($x, $y, $id) = imgsize("${dir}kazeburo-bar.jpg");
  116 ok(($x == 480 && $y == 640), 'JPG tag-offset bugfix');
  117 
  118 exit;