root/branches/boomer/t/09-image.t @ 1100

Revision 1100, 2.5 kB (checked in by hachi, 2 years ago)

Merging release-20 to boomer branch: svn merge -r62323:63659 http://svn.sixapart.com/repos/eng/movabletype/branches/release-20 .

  • 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 Test::More;
11use File::Spec;
12
13use MT::Image;
14use MT::ConfigMgr;
15use MT;
16
17use vars qw( $BASE @Img @drivers );
18
19require 't/test-common.pl';
20
21BEGIN {
22    @Img = (
23        [ 'test.gif', 233, 68 ],
24        [ 'test.jpg', 640, 480 ],
25    );
26    @drivers = qw( ImageMagick NetPBM );
27    plan tests => scalar @Img + scalar @Img * scalar @drivers * 17;
28}
29
30MT->set_language('en-us');
31
32my $File = "test.file";
33my $String = "testing";
34my $netpbm = '/usr/local/netpbm/bin';
35
36my $cfg = MT::ConfigMgr->instance;
37$cfg->NetPBMPath($netpbm) if -x $netpbm;
38
39for my $rec (@Img) {
40    my $img_file = File::Spec->catfile($BASE, 't', 'images', $rec->[0]);
41    ok(-B $img_file, "$img_file looks like a binary file");
42
43    for my $driver (@drivers) {
44        $cfg->ImageDriver($driver);
45        my $img = MT::Image->new( Filename => $img_file );
46SKIP : {
47        skip("no $driver image", 17) unless $img;
48        isa_ok($img, 'MT::Image::' . $driver);
49#        diag( MT::Image->errstr ) if MT::Image->errstr;
50
51        is($img->{width}, $rec->[1], "width is $rec->[1]");
52        is($img->{height}, $rec->[2], "height is $rec->[2]");
53        my($w, $h) = $img->get_dimensions;
54        is($w, $rec->[1], "width is $rec->[1]");
55        is($h, $rec->[2], "height is $rec->[2]");
56
57        ($w, $h) = $img->get_dimensions(Scale => 50);
58        my($x, $y) = (int($img->{width} / 2), int($img->{height} / 2));
59        is($w, $x, "width is $x");
60        is($h, $y, "height is $y");
61
62        ($w, $h) = $img->get_dimensions(Width => 50);
63        is($w, 50, 'width is 50');
64
65        ($w, $h) = $img->get_dimensions(Width => 50, Height => 100);
66        is($w, 50, 'width is 50');
67        is($h, 100, 'height is 100');
68
69        (my($blob), $w, $h) = $img->scale(Scale => 50);
70        ($x, $y) = (int($img->{width} / 2), int($img->{height} / 2));
71        is($w, $x, "width is $x");
72        is($h, $y, "height is $y");
73
74        open FH, $img_file or die $!;
75        binmode FH;
76        my $data = do { local $/; <FH> };
77        close FH;
78        (my $type = $img_file) =~ s/.*\.//;
79        $img = MT::Image->new( Data => $data, Type => $type );
80        isa_ok($img, 'MT::Image::' . $driver);
81#            diag( MT::Image->errstr ) if MT::Image->errstr;
82        is($img->{width}, $rec->[1], "width is $rec->[1]");
83        is($img->{height}, $rec->[2], "height is $rec->[2]");
84        ($w, $h) = $img->get_dimensions;
85        is($w, $rec->[1], "width is $rec->[1]");
86        is($h, $rec->[2], "height is $rec->[2]");
87} # END SKIP
88    }
89}
Note: See TracBrowser for help on using the browser.