From 0aae8858d9af176ca94d447f7d67550fb7992f85 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 20 Oct 2010 05:42:03 +0000 Subject: [PATCH] fill out the documentation of Imager::Test, and test the doc coverage added is_fcolor3() --- lib/Imager/Test.pm | 149 +++++++++++++++++++++++++++++++++++++-------- t/t93podcover.t | 3 +- 2 files changed, 126 insertions(+), 26 deletions(-) diff --git a/lib/Imager/Test.pm b/lib/Imager/Test.pm index f1e2b8b7..0b4e776e 100644 --- a/lib/Imager/Test.pm +++ b/lib/Imager/Test.pm @@ -18,6 +18,7 @@ $VERSION = "1.000"; is_color3 is_color4 is_color_close3 + is_fcolor3 is_fcolor4 color_cmp is_image @@ -184,6 +185,45 @@ END_DIAG return 1; } +sub is_fcolor3($$$$$;$) { + my ($color, $red, $green, $blue, $comment_or_diff, $comment_or_undef) = @_; + my ($comment, $mindiff); + if (defined $comment_or_undef) { + ( $mindiff, $comment ) = ( $comment_or_diff, $comment_or_undef ) + } + else { + ( $mindiff, $comment ) = ( 0.001, $comment_or_diff ) + } + + my $builder = Test::Builder->new; + + unless (defined $color) { + $builder->ok(0, $comment); + $builder->diag("color is undef"); + return; + } + unless ($color->can('rgba')) { + $builder->ok(0, $comment); + $builder->diag("color is not a color object"); + return; + } + + my ($cr, $cg, $cb) = $color->rgba; + unless ($builder->ok(abs($cr - $red) <= $mindiff + && abs($cg - $green) <= $mindiff + && abs($cb - $blue) <= $mindiff, $comment)) { + $builder->diag(< for the test to pass. The color comparison is done at 8-bits per pixel. The color representation such as direct vs paletted, bits per sample are not checked. -=item test_image_raw() +=item isnt_image($im1, $im2, $comment) -Returns a 150x150x3 Imager::ImgRaw test image. +Tests that the two images are different. For regressions tests where +something (like text output of "0") produced no change, but should +have produced a change. -=item test_image() +=item test_colorf_gpix($im, $x, $y, $expected, $epsilon, $comment) -Returns a 150x150x3 8-bit/sample OO test image. +Retrieves the pixel ($x,$y) from the low-level image $im and compares +it to the floating point color $expected, with a tolerance of epsilon. -=item test_image_16() +=item test_color_gpix($im, $x, $y, $expected, $comment) -Returns a 150x150x3 16-bit/sample OO test image. +Retrieves the pixel ($x,$y) from the low-level image $im and compares +it to the floating point color $expected. -=item test_image_double() +=item test_colorf_glin($im, $x, $y, $pels, $comment) -Returns a 150x150x3 double/sample OO test image. +Retrieves the floating point pixels ($x, $y)-[$x+@$pels, $y] from the +low level image $im and compares them against @$pels. + +=item is_color_close3($color, $red, $green, $blue, $tolerance, $comment) + +Tests if $color's first three channels are within $tolerance of ($red, +$green, $blue). + +=back + +=head2 Test suite functions + +Functions that perform one or more tests, typically used to test +various parts of Imager's implementation. + +=over + +=item image_bounds_checks($im) + +Attempts to write to various pixel positions outside the edge of the +image to ensure that it fails in those locations. + +Any new image type should pass these tests. Does 16 separate tests. + +=item mask_tests($im, $epsilon) + +Perform a standard set of mask tests on the OO image $im. Does 24 +separate tests. =item diff_text_with_nul($test_name, $text1, $text2, @options) @@ -664,31 +759,35 @@ color or channel parameter. This was explicitly created for regression tests on #21770. -=item image_bounds_checks($im) +=back -Attempts to write to various pixel positions outside the edge of the -image to ensure that it fails in those locations. +=head2 Helper functions -Any new image type should pass these tests. Does 16 separate tests. +=over -=item test_colorf_gpix($im, $x, $y, $expected, $epsilon, $comment) +=item test_image_raw() -Retrieves the pixel ($x,$y) from the low-level image $im and compares -it to the floating point color $expected, with a tolerance of epsilon. +Returns a 150x150x3 Imager::ImgRaw test image. -=item test_color_gpix($im, $x, $y, $expected, $comment) +=item test_image() -Retrieves the pixel ($x,$y) from the low-level image $im and compares -it to the floating point color $expected. +Returns a 150x150x3 8-bit/sample OO test image. -=item test_colorf_glin($im, $x, $y, $pels, $comment) +=item test_image_16() -Retrieves the floating point pixels ($x, $y)-[$x+@$pels, $y] from the -low level image $im and compares them against @$pels. +Returns a 150x150x3 16-bit/sample OO test image. -=item mask_tests($im, $epsilon) +=item test_image_double() + +Returns a 150x150x3 double/sample OO test image. + +=item color_cmp($c1, $c2) + +Performs an ordering of 3-channel colors (like <=>). + +=item colorf_cmp($c1, $c2) -Perform a standard set of mask tests on the OO image $im. +Performs an ordering of 3-channel floating point colors (like <=>). =back diff --git a/t/t93podcover.t b/t/t93podcover.t index 804b2d54..994f8312 100644 --- a/t/t93podcover.t +++ b/t/t93podcover.t @@ -25,7 +25,7 @@ my @private = ); my @trustme = ( '^open$', ); -plan tests => 18; +plan tests => 19; { pod_coverage_ok('Imager', { also_private => \@private, @@ -50,6 +50,7 @@ plan tests => 18; pod_coverage_ok('Imager::Matrix2d'); pod_coverage_ok('Imager::Regops'); pod_coverage_ok('Imager::Transform'); + pod_coverage_ok('Imager::Test'); } { -- 2.39.5