root/branches/release-40/t/09-image.t @ 2641

Revision 2641, 3.8 kB (checked in by takayama, 17 months ago)

* Added tests for MT::Image::GD
* Fixed to work

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