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

Revision 2562, 3.8 kB (checked in by bchoate, 18 months ago)

Test suite cleanup. Use MT::Test to force t/ based configuration file for all tests. Fixed several tests that had incorrect expected values.

  • 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( $BASE @Img @drivers );
19
20require 't/test-common.pl';
21
22BEGIN {
23    @Img = (
24        [ 'test.gif', 233, 68 ],
25        [ 'test.jpg', 640, 480 ],
26    );
27    @drivers = qw( ImageMagick NetPBM );
28    plan tests => scalar @Img                           # file exists
29                + (scalar @Img * scalar @drivers * 18)  # 18 tests each for every image and driver
30                ;
31}
32
33MT->set_language('en-us');
34
35my $File = "test.file";
36my $String = "testing";
37my $netpbm = '/usr/local/netpbm/bin';
38
39my $cfg = MT::ConfigMgr->instance;
40$cfg->NetPBMPath($netpbm) if -x $netpbm;
41
42for my $rec (@Img) {
43    my ($img_filename, $img_width, $img_height) = @$rec;
44    my $img_file = File::Spec->catfile($BASE, '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", 18) 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.