From: Tony Cook Date: Mon, 12 Sep 2011 10:57:21 +0000 (+1000) Subject: add simple tests for the Imager::Test test_image functions X-Git-Tag: v0.85_01~3 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/a7e32bebf9b9aa9c4a0a5914d009fdd98581b218 add simple tests for the Imager::Test test_image functions --- diff --git a/Changes b/Changes index 54c264b1..34d53def 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Imager release history. Older releases can be found in Changes.old +Imager 0.86 +=========== + + - add simple tests for the Imager::Test test_image generators + Imager 0.85 - 29 Aug 2011 =========== diff --git a/lib/Imager/Test.pm b/lib/Imager/Test.pm index abc79793..b3ac4450 100644 --- a/lib/Imager/Test.pm +++ b/lib/Imager/Test.pm @@ -3,6 +3,7 @@ use strict; use Test::Builder; require Exporter; use vars qw(@ISA @EXPORT_OK $VERSION); +use Carp qw(croak); $VERSION = "1.000"; @@ -14,6 +15,10 @@ $VERSION = "1.000"; test_image_16 test_image test_image_double + test_image_mono + test_image_gray + test_image_gray_16 + test_image_named is_color1 is_color3 is_color4 @@ -321,8 +326,8 @@ sub test_image_16 { my $blue = Imager::Color->new(0, 0, 255, 255); my $red = Imager::Color->new(255, 0, 0, 255); my $img = Imager->new(xsize => 150, ysize => 150, bits => 16); - $img->box(filled => 1, color => $green, box => [ 70, 25, 130, 125 ]); - $img->box(filled => 1, color => $blue, box => [ 20, 25, 80, 125 ]); + $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]); + $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]); $img->arc(x => 75, y => 75, r => 30, color => $red); $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]); @@ -334,14 +339,73 @@ sub test_image_double { my $blue = Imager::Color->new(0, 0, 255, 255); my $red = Imager::Color->new(255, 0, 0, 255); my $img = Imager->new(xsize => 150, ysize => 150, bits => 'double'); - $img->box(filled => 1, color => $green, box => [ 70, 25, 130, 125 ]); - $img->box(filled => 1, color => $blue, box => [ 20, 25, 80, 125 ]); + $img->box(filled => 1, color => $green, box => [ 70, 24, 130, 124 ]); + $img->box(filled => 1, color => $blue, box => [ 20, 26, 80, 126 ]); $img->arc(x => 75, y => 75, r => 30, color => $red); $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]); $img; } +sub test_image_gray { + my $g50 = Imager::Color->new(128, 128, 128); + my $g30 = Imager::Color->new(76, 76, 76); + my $g70 = Imager::Color->new(178, 178, 178); + my $img = Imager->new(xsize => 150, ysize => 150, channels => 1); + $img->box(filled => 1, color => $g50, box => [ 70, 24, 130, 124 ]); + $img->box(filled => 1, color => $g30, box => [ 20, 26, 80, 126 ]); + $img->arc(x => 75, y => 75, r => 30, color => $g70); + $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]); + + return $img; +} + +sub test_image_gray_16 { + my $g50 = Imager::Color->new(128, 128, 128); + my $g30 = Imager::Color->new(76, 76, 76); + my $g70 = Imager::Color->new(178, 178, 178); + my $img = Imager->new(xsize => 150, ysize => 150, channels => 1, bits => 16); + $img->box(filled => 1, color => $g50, box => [ 70, 24, 130, 124 ]); + $img->box(filled => 1, color => $g30, box => [ 20, 26, 80, 126 ]); + $img->arc(x => 75, y => 75, r => 30, color => $g70); + $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]); + + return $img; +} + +sub test_image_mono { + require Imager::Fill; + my $fh = Imager::Fill->new(hatch => 'check1x1'); + my $img = Imager->new(xsize => 150, ysize => 150, type => "paletted"); + my $black = Imager::Color->new(0, 0, 0); + my $white = Imager::Color->new(255, 255, 255); + $img->addcolors(colors => [ $black, $white ]); + $img->box(fill => $fh, box => [ 70, 24, 130, 124 ]); + $img->box(filled => 1, color => $white, box => [ 20, 26, 80, 126 ]); + $img->arc(x => 75, y => 75, r => 30, color => $black, aa => 0); + + return $img; +} + +my %name_to_sub = + ( + basic => \&test_image, + basic16 => \&test_image_16, + basic_double => \&test_image_double, + gray => \&test_image_gray, + gray16 => \&test_image_gray_16, + mono => \&test_image_mono, + ); + +sub test_image_named { + my $name = shift + or croak("No name supplied to test_image_named()"); + my $sub = $name_to_sub{$name} + or croak("Unknown name $name supplied to test_image_named()"); + + return $sub->(); +} + sub _low_image_diff_check { my ($left, $right, $comment) = @_; diff --git a/t/t03test.t b/t/t03test.t new file mode 100644 index 00000000..984d212e --- /dev/null +++ b/t/t03test.t @@ -0,0 +1,65 @@ +#!perl -w +use strict; +use Imager; +use Imager::Test qw(test_image test_image_16 test_image_mono test_image_gray test_image_gray_16 test_image_double test_image_named); +use Test::More tests => 60; + +# test Imager::Test + +for my $named (0, 1) { + my $named_desc = $named ? " (by name)" : ""; + { + my $im = $named ? test_image_named("basic") : test_image(); + ok($im, "got basic test image$named_desc"); + is($im->type, "direct", "check basic image type"); + is($im->getchannels, 3, "check basic image channels"); + is($im->bits, 8, "check basic image bits"); + ok(!$im->is_bilevel, "check basic isn't mono"); + } + { + my $im = $named ? test_image_named("basic16") : test_image_16(); + ok($im, "got 16-bit basic test image$named_desc"); + is($im->type, "direct", "check 16-bit basic image type"); + is($im->getchannels, 3, "check 16-bit basic image channels"); + is($im->bits, 16, "check 16-bit basic image bits"); + ok(!$im->is_bilevel, "check 16-bit basic isn't mono"); + } + + { + my $im = $named ? test_image_named("basic_double") : test_image_double(); + ok($im, "got double basic test image$named_desc"); + is($im->type, "direct", "check double basic image type"); + is($im->getchannels, 3, "check double basic image channels"); + is($im->bits, "double", "check double basic image bits"); + ok(!$im->is_bilevel, "check double basic isn't mono"); + } + { + my $im = $named ? test_image_named("gray") : test_image_gray(); + ok($im, "got gray test image$named_desc"); + is($im->type, "direct", "check gray image type"); + is($im->getchannels, 1, "check gray image channels"); + is($im->bits, 8, "check gray image bits"); + ok(!$im->is_bilevel, "check gray isn't mono"); + $im->write(file => "testout/t03gray.pgm"); + } + + { + my $im = $named ? test_image_named("gray16") : test_image_gray_16(); + ok($im, "got gray test image$named_desc"); + is($im->type, "direct", "check 16-bit gray image type"); + is($im->getchannels, 1, "check 16-bit gray image channels"); + is($im->bits, 16, "check 16-bit gray image bits"); + ok(!$im->is_bilevel, "check 16-bit isn't mono"); + $im->write(file => "testout/t03gray16.pgm"); + } + + { + my $im = $named ? test_image_named("mono") : test_image_mono(); + ok($im, "got mono image$named_desc"); + is($im->type, "paletted", "check mono image type"); + is($im->getchannels, 3, "check mono image channels"); + is($im->bits, 8, "check mono image bits"); + ok($im->is_bilevel, "check mono is mono"); + $im->write(file => "testout/t03mono.pbm"); + } +}