]> git.imager.perl.org - imager.git/blobdiff - t/t022double.t
change version to avoid indexer confusion
[imager.git] / t / t022double.t
index c3c1155748357d7b597225ba232e3e3604531fbf..fa2e07b9f9dab41c9d7519a73d6b4ee8bc614daa 100644 (file)
@@ -1,13 +1,15 @@
 #!perl -w
 use strict;
-use lib 't';
-use Test::More tests => 49;
+use Test::More tests => 83;
 
 BEGIN { use_ok(Imager => qw(:all :handy)) }
-require "t/testtools.pl";
+
+-d "testout" or mkdir "testout";
 
 init_log("testout/t022double.log", 1);
 
+use Imager::Test qw(image_bounds_checks test_colorf_gpix test_colorf_glin mask_tests);
+
 use Imager::Color::Float;
 
 my $im_g = Imager::i_img_double_new(100, 101, 1);
@@ -52,21 +54,23 @@ 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');
 ok($ooimg, "couldn't make double image");
-ok($ooimg->bits eq 'double', "oo didn't give double image");
+is($ooimg->bits, 'double', "oo didn't give double image");
+ok(!$ooimg->is_bilevel, 'not monochrome');
 
 # check that the image is copied correctly
 my $oocopy = $ooimg->copy;
-ok($oocopy->bits eq 'double', "oo copy didn't give double image");
+is($oocopy->bits, 'double', "oo copy didn't give double image");
 
 ok(!Imager->new(xsize=>0, ysize=>1, bits=>'double'),
     "fail making 0 width image");
@@ -136,35 +140,14 @@ cmp_ok(Imager->errstr, '=~', qr/channels must be between 1 and 4/,
   }
 }
 
-sub NCF {
-  return Imager::Color::Float->new(@_);
-}
-
-sub test_colorf_gpix {
-  my ($im, $x, $y, $expected) = @_;
-  my $c = Imager::i_gpixf($im, $x, $y);
-  ok($c, "got gpix ($x, $y)");
-  ok(colorf_cmp($c, $expected) == 0,
-     "got right color ($x, $y)");
-}
-
-sub test_colorf_glin {
-  my ($im, $x, $y, @pels) = @_;
+{ # check the channel mask function
+  
+  my $im = Imager->new(xsize => 10, ysize=>10, bits=>'double');
 
-  my @got = Imager::i_glinf($im, $x, $x+@pels, $y);
-  is(@got, @pels, "check number of pixels ($x, $y)");
-  ok(!grep(colorf_cmp($pels[$_], $got[$_]), 0..$#got),
-     "check colors ($x, $y)");
+  mask_tests($im);
 }
 
-sub colorf_cmp {
-  my ($c1, $c2) = @_;
-  my @s1 = map { int($_*65535.99) } $c1->rgba;
-  my @s2 = map { int($_*65535.99) } $c2->rgba;
-
-  # print "# (",join(",", @s1[0..2]),") <=> (",join(",", @s2[0..2]),")\n";
-  return $s1[0] <=> $s2[0] 
-    || $s1[1] <=> $s2[1]
-      || $s1[2] <=> $s2[2];
+{ # bounds checking
+  my $im = Imager->new(xsize => 10, ysize=>10, bits=>'double');
+  image_bounds_checks($im);
 }
-