Skip to content

Commit

Permalink
eliminate t/testtools.pl
Browse files Browse the repository at this point in the history
have t/t35ttfont.pl check the font is created, this may have been the
cause of the failure at
http://www.nntp.perl.org/group/perl.cpan.testers/1313902
  • Loading branch information
Tony Cook committed Apr 29, 2008
1 parent 6912d85 commit 8927ff8
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 226 deletions.
54 changes: 37 additions & 17 deletions lib/Imager/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ use Test::Builder;
require Exporter;
use vars qw(@ISA @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(diff_text_with_nul
test_image_raw test_image_16 test_image test_image_double
is_color3 is_color1 is_color4 is_color_close3
is_fcolor4
is_image is_image_similar
image_bounds_checks mask_tests
test_colorf_gpix test_color_gpix test_colorf_glin);
@EXPORT_OK =
qw(
diff_text_with_nul
test_image_raw
test_image_16
test_image
test_image_double
is_color1
is_color3
is_color4
is_color_close3
is_fcolor4
color_cmp
is_image
is_image_similar
image_bounds_checks
mask_tests
test_colorf_gpix
test_color_gpix
test_colorf_glin);

sub diff_text_with_nul {
my ($desc, $text1, $text2, @params) = @_;
Expand Down Expand Up @@ -363,11 +376,14 @@ sub test_colorf_gpix {
$builder->ok(0, "$comment - retrieve color at ($x,$y)");
return;
}
unless ($builder->ok(_colorf_cmp($c, $expected, $epsilon) == 0,
unless ($builder->ok(colorf_cmp($c, $expected, $epsilon) == 0,
"$comment - got right color ($x, $y)")) {
print "# got: (", join(",", ($c->rgba)[0,1,2]), ")\n";
print "# expected: (", join(",", ($expected->rgba)[0,1,2]), ")\n";
return;
my @c = $c->rgba;
my @exp = $expected->rgba;
$builder->diag(<<EOS);
# got: ($c[0], $c[1], $c[2])
# expected: ($exp[0], $exp[1], $exp[2])
EOS
}
1;
}
Expand All @@ -383,10 +399,14 @@ sub test_color_gpix {
$builder->ok(0, "$comment - retrieve color at ($x,$y)");
return;
}
unless ($builder->ok(_color_cmp($c, $expected) == 0,
unless ($builder->ok(color_cmp($c, $expected) == 0,
"got right color ($x, $y)")) {
print "# got: (", join(",", ($c->rgba)[0,1,2]), ")\n";
print "# expected: (", join(",", ($expected->rgba)[0,1,2]), ")\n";
my @c = $c->rgba;
my @exp = $expected->rgba;
$builder->diag(<<EOS);
# got: ($c[0], $c[1], $c[2])
# expected: ($exp[0], $exp[1], $exp[2])
EOS
return;
}

Expand All @@ -402,11 +422,11 @@ sub test_colorf_glin {
@got == @$pels
or return $builder->is_num(scalar(@got), scalar(@$pels), "$comment - pixels retrieved");

return $builder->ok(!grep(_colorf_cmp($pels->[$_], $got[$_], 0.005), 0..$#got),
return $builder->ok(!grep(colorf_cmp($pels->[$_], $got[$_], 0.005), 0..$#got),
"$comment - check colors ($x, $y)");
}

sub _colorf_cmp {
sub colorf_cmp {
my ($c1, $c2, $epsilon) = @_;

defined $epsilon or $epsilon = 0;
Expand All @@ -420,7 +440,7 @@ sub _colorf_cmp {
|| abs($s1[2]-$s2[2]) >= $epsilon && $s1[2] <=> $s2[2];
}

sub _color_cmp {
sub color_cmp {
my ($c1, $c2) = @_;

my @s1 = $c1->rgba;
Expand Down
18 changes: 8 additions & 10 deletions t/t01introvert.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
# to make sure we get expected values

use strict;
use Test::More tests => 228;
use Test::More tests => 220;

BEGIN { use_ok(Imager => qw(:handy :all)) }

require "t/testtools.pl";

use Imager::Test qw(image_bounds_checks is_color4 is_fcolor4);
use Imager::Test qw(image_bounds_checks is_color3 is_color4 is_fcolor4 color_cmp mask_tests);

init_log("testout/t01introvert.log",1);

Expand Down Expand Up @@ -82,10 +80,10 @@ is($samp, "\xFF\0\0" x 50 . "\0\0\xFF" x 50, "gsamp scalar bytes");
# reading indicies as colors
my $c_red = Imager::i_get_pixel($im_pal, 0, 0);
ok($c_red, "got the red pixel");
ok(color_cmp($red, $c_red) == 0, "and it's red");
is_color3($c_red, 255, 0, 0, "and it's red");
my $c_blue = Imager::i_get_pixel($im_pal, 50, 0);
ok($c_blue, "got the blue pixel");
ok(color_cmp($blue, $c_blue) == 0, "and it's blue");
is_color3($c_blue, 0, 0, 255, "and it's blue");

# drawing with colors
ok(Imager::i_ppix($im_pal, 0, 0, $green) == 0, "draw with color in palette");
Expand All @@ -94,7 +92,7 @@ is(Imager::i_img_type($im_pal), 1, "image still paletted");

my $c_green = Imager::i_get_pixel($im_pal, 0, 0);
ok($c_green, "got green pixel");
ok(color_cmp($green, $c_green) == 0, "and it's green");
is_color3($c_green, 0, 255, 0, "and it's green");

is(Imager::i_colorcount($im_pal), 3, "still 3 colors in palette");
is(Imager::i_findcolor($im_pal, $green), 1, "and green is the second");
Expand Down Expand Up @@ -132,7 +130,7 @@ is($impal2->type, 'paletted', "check type");
is($blue_idx, 1, "and it's expected index for blue");
my $green_idx = $blue_idx + 1;
my $c = $impal2->getcolors(start=>$green_idx);
ok(color_cmp($green, $c) == 0, "found green where expected");
is_color3($c, 0, 255, 0, "found green where expected");
my @cols = $impal2->getcolors;
is(@cols, 3, "got 3 colors");
my @exp = ( $red, $blue, $green );
Expand Down Expand Up @@ -267,8 +265,8 @@ cmp_ok(Imager->errstr, '=~', qr/channels must be between 1 and 4/,

my @row = Imager::i_glin($im->{IMG}, 0, 2, 0);
is(@row, 2, "got 2 pixels from i_glin");
ok(color_cmp($row[0], $red) == 0, "red first");
ok(color_cmp($row[1], $blue) == 0, "then blue");
is_color3($row[0], 255, 0, 0, "red first");
is_color3($row[1], 0, 0, 255, "then blue");
}

{ # general tag tests
Expand Down
12 changes: 6 additions & 6 deletions t/t022double.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!perl -w
use strict;
use Test::More tests => 98;
use Test::More tests => 83;

BEGIN { use_ok(Imager => qw(:all :handy)) }
require "t/testtools.pl";

init_log("testout/t022double.log", 1);

use Imager::Test qw(image_bounds_checks);
use Imager::Test qw(image_bounds_checks test_colorf_gpix test_colorf_glin mask_tests);

use Imager::Color::Float;

Expand Down Expand Up @@ -53,12 +52,13 @@ test_colorf_gpix($im_rgb, 0, 0, $redf);
test_colorf_gpix($im_rgb, 99, 0, $redf);
test_colorf_gpix($im_rgb, 0, 100, $redf);
test_colorf_gpix($im_rgb, 99, 100, $redf);
test_colorf_glin($im_rgb, 0, 0, ($redf) x 100);
test_colorf_glin($im_rgb, 0, 100, ($redf) x 100);
test_colorf_glin($im_rgb, 0, 0, [ ($redf) x 100 ], 'sanity glin @0');
test_colorf_glin($im_rgb, 0, 100, [ ($redf) x 100 ], 'sanity glin @100');

Imager::i_plinf($im_rgb, 20, 1, ($greenf) x 60);
test_colorf_glin($im_rgb, 0, 1,
($redf) x 20, ($greenf) x 60, ($redf) x 20);
[ ($redf) x 20, ($greenf) x 60, ($redf) x 20 ],
'check after write');

# basic OO tests
my $ooimg = Imager->new(xsize=>200, ysize=>201, bits=>'double');
Expand Down
1 change: 0 additions & 1 deletion t/t102png.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use Test::More tests => 34;
# (It may become useful if the test is moved to ./t subdirectory.)
use lib qw(blib/lib blib/arch);

BEGIN { require 't/testtools.pl'; }
BEGIN { use_ok('Imager', ':all') }
init_log("testout/t102png.log",1);

Expand Down
8 changes: 4 additions & 4 deletions t/t105gif.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $|=1;
use Test::More tests => 132;
use Imager qw(:all);
use Imager::Test qw(is_color3);
BEGIN { require "t/testtools.pl"; }

use Carp 'confess';
$SIG{__DIE__} = sub { confess @_ };

Expand Down Expand Up @@ -186,9 +186,9 @@ SKIP:
skip("giflib3 doesn't support callbacks", 1) unless $gifver >= 4.0;
++$can_write_callback;
my $good = ext_test(14, <<'ENDOFCODE');
use Imager;
require "t/testtools.pl";
my $timg = test_img();
use Imager qw(:all);
use Imager::Test qw(test_image_raw);
my $timg = test_image_raw();
my @gif_delays = (50) x 5;
my @gif_disposal = (2) x 5;
my @imgs = ($timg) x 5;
Expand Down
12 changes: 7 additions & 5 deletions t/t35ttfont.t
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!perl -w
use strict;
use Test::More tests => 91;
use Test::More tests => 92;

$|=1;

BEGIN { use_ok(Imager => ':all') }
require "t/testtools.pl";
use Imager::Test qw(diff_text_with_nul is_color3);

init_log("testout/t35ttfont.log",2);

SKIP:
{
skip("freetype 1.x unavailable or disabled", 90)
skip("freetype 1.x unavailable or disabled", 91)
unless i_has_format("tt");
print "# has tt\n";

Expand Down Expand Up @@ -276,16 +275,19 @@ SKIP:

# UTF8 encoded \x{2010}
my $dash = pack("C*", 0xE2, 0x80, 0x90);
diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
diff_text_with_nul("utf8 dash\\0dash vs dash", "$dash\0$dash", $dash,
font => $font, color => '#FFFFFF', utf8 => 1);
diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
diff_text_with_nul("utf8 dash\\0dash vs dash", "$dash\0$dash", $dash,
font => $font, channel => 1, utf8 => 1);
}

SKIP:
{ # RT 11972
# when rendering to a transparent image the coverage should be
# expressed in terms of the alpha channel rather than the color
my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'tt');
ok($font, "loaded fontfiles/ImUgly.ttf")
or skip("Could not load test font: ".Imager->errstr, 4);
my $im = Imager->new(xsize => 40, ysize => 20, channels => 4);
ok($im->string(string => "AB", size => 20, aa => 1, color => '#F00',
x => 0, y => 15, font => $font),
Expand Down
2 changes: 0 additions & 2 deletions t/t40scale.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use Test::More tests => 230;
BEGIN { use_ok(Imager=>':all') }
use Imager::Test qw(is_image is_color4);

#require "t/testtools.pl";

Imager::init('log'=>'testout/t40scale.log');
my $img=Imager->new();

Expand Down
8 changes: 4 additions & 4 deletions t/t65crop.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!perl -w
use strict;
use Test::More tests => 64;
require "t/testtools.pl";
use Imager;
use Imager::Test qw(test_image);

#$Imager::DEBUG=1;

Expand Down Expand Up @@ -46,7 +46,7 @@ SKIP:
# the left of the image, even if left/top are provided, despite the
# sample in the docs
# Let's make sure that things happen as documented
my $src = test_oo_img();
my $src = test_image();
# make sure we get what we want
is($src->getwidth, 150, "src width");
is($src->getheight, 150, "src height");
Expand Down Expand Up @@ -146,7 +146,7 @@ SKIP:
{ # https://rt.cpan.org/Ticket/Display.html?id=7581
# previously we didn't check that the result had some pixels
# make sure we do
my $src = test_oo_img();
my $src = test_image();
ok(!$src->crop(left=>50, right=>50), "nothing across");
cmp_ok($src->errstr, '=~', qr/resulting image would have no content/,
"and message");
Expand All @@ -172,7 +172,7 @@ SKIP:
}

{
my $src = test_oo_img();
my $src = test_image();
ok(!$src->crop( top=>1000, bottom=>1500, left=>0, right=>100 ),
"outside of image" );
cmp_ok($src->errstr, '=~', qr/outside of the image/, "and message");
Expand Down
Loading

0 comments on commit 8927ff8

Please sign in to comment.