root/trunk/t/09-image.t

Revision 3886, 3.8 kB (checked in by fumiakiy, 5 months ago)

Merged fringale down to trunk. "svn merge -r 3460:3877 http://code.sixapart.com/svn/movabletype/branches/fringale ."

  • Property svn:mime-type set to text/plain
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl -w
2# $Id$
3
4use strict;
5use warnings;
6
7use lib 't/lib';
8use lib 'lib';
9use lib 'extlib';
10
11use MT::Test;
12use Test::More;
13use File::Spec;
14
15use MT::Image;
16use MT::ConfigMgr;
17use MT;
18
19use vars qw( @Img @drivers );
20
21BEGIN {
22    @Img = (
23        [ 'test.gif', 233, 68 ],
24        [ 'test.jpg', 640, 480 ],
25    );
26    @drivers = qw( ImageMagick NetPBM GD );
27    plan tests => scalar @Img                           # file exists
28                + (scalar @Img * scalar @drivers * 19)  # 19 tests each for every image and driver
29                ;
30}
31
32MT->set_language('en-us');
33
34my $File = "test.file";
35my $String = "testing";
36my $netpbm = '/usr/local/netpbm/bin';
37
38my $cfg = MT::ConfigMgr->instance;
39if (!$cfg->NetPBMPath) {
40    $cfg->NetPBMPath($netpbm) if -x $netpbm;
41}
42
43for my $rec (@Img) {
44    my ($img_filename, $img_width, $img_height) = @$rec;
45    my $img_file = File::Spec->catfile($ENV{MT_HOME}, 't', 'images', $img_filename);
46    ok(-B $img_file, "$img_file looks like a binary file");
47
48    for my $driver (@drivers) {
49        $cfg->ImageDriver($driver);
50        my $img = MT::Image->new( Filename => $img_file );
51SKIP : {
52#        skip("no $driver image", 19) unless $img;
53        isa_ok($img, 'MT::Image::' . $driver, "driver $driver with image $img_file is an MT::Image::$driver");
54#        diag( MT::Image->errstr ) if MT::Image->errstr;
55
56        is($img->{width},  $img_width,  "$driver says $img_filename is $img_width px wide");
57        is($img->{height}, $img_height, "$driver says $img_filename is $img_height px high");
58        my($w, $h) = $img->get_dimensions();
59        is($w, $img_width,  "${driver}'s get_dimensions says $img_filename is $img_width px wide");
60        is($h, $img_height, "${driver}'s get_dimensions says $img_filename is $img_height px high");
61
62        ($w, $h) = $img->get_dimensions(Scale => 50);
63        my($x, $y) = (int($img_width / 2), int($img_height / 2));
64        is($w, $x, "$driver says $img_filename at 50\% scale is $x px wide");
65        is($h, $y, "$driver says $img_filename at 50\% scale is $y px high");
66
67        ($w, $h) = $img->get_dimensions();
68        is($w, $img_width,  "${driver}'s get_dimensions says $img_filename is still $img_width px wide after theoretical scaling");
69        is($h, $img_height, "${driver}'s get_dimensions says $img_filename is still $img_height px high after theoretical scaling");
70
71        ($w, $h) = $img->get_dimensions(Width => 50);
72        is($w, 50, "$driver says $img_filename scaled to 50 px wide is 50 px wide");
73
74        ($w, $h) = $img->get_dimensions(Width => 50, Height => 100);
75        is($w, 50,  "$driver says $img_filename scaled to 50x100 is 50 px wide");
76        is($h, 100, "$driver says $img_filename scaled to 50x100 is 100 px high");
77
78        (my($blob), $w, $h) = $img->scale(Scale => 50);
79        ($x, $y) = (int($img_width / 2), int($img_height / 2));
80        is($w, $x, "result of scaling $img_filename to 50\% with $driver is $x px wide");
81        is($h, $y, "result of scaling $img_filename to 50\% with $driver is $y px high");
82
83        open FH, $img_file or die $!;
84        binmode FH;
85        my $data = do { local $/; <FH> };
86        close FH;
87        (my $type = $img_file) =~ s/.*\.//;
88        $img = MT::Image->new( Data => $data, Type => $type );
89        isa_ok($img, 'MT::Image::' . $driver);
90#            diag( MT::Image->errstr ) if MT::Image->errstr;
91        is($img->{width},  $img_width,  "$driver says $img_filename from blob is $img_width px wide");
92        is($img->{height}, $img_height, "$driver says $img_filename from blob is $img_height px high");
93        ($w, $h) = $img->get_dimensions;
94        is($w, $img_width,  "${driver}'s get_dimensions says $img_filename from blob is $img_width px wide");
95        is($h, $img_height, "${driver}'s get_dimensions says $img_filename from blob is $img_height px high");
96} # END SKIP
97    }
98}
Note: See TracBrowser for help on using the browser.