]> git.imager.perl.org - imager.git/blobdiff - t/t01introvert.t
prefer static first
[imager.git] / t / t01introvert.t
index d63eb5dbe13073f794e513c6442538ffeddecc44..4a1e4b51c5349f7d37d1803ad20d4bf9dfc20ab8 100644 (file)
@@ -3,7 +3,7 @@
 # to make sure we get expected values
 
 use strict;
-use Test::More tests => 431;
+use Test::More tests => 466;
 
 BEGIN { use_ok(Imager => qw(:handy :all)) }
 
@@ -125,9 +125,21 @@ is(Imager::i_img_type($im_pal), 0, "pal img shouldn't be paletted now");
   is_color3($colors[1], 0, 255, 0, "still green");
   is_color3($colors[2], 0, 0, 255, "still blue");
   is_color3($colors[3], 0, 0, 0, "still black");
-  is(Imager::i_gsamp($im_pal2, 0, 100, 0, [ 0, 1, 2 ]),
-     "\0\xFF\0\0\0\0"."\xFF\0\0" x 48 . "\0\0\xFF" x 50,
-     "colors are still correct");
+  my @samples = Imager::i_gsamp($im_pal2, 0, 100, 0, [ 0, 1, 2 ]);
+  my @expect = unpack("C*", "\0\xFF\0\0\0\0"."\xFF\0\0" x 48 . "\0\0\xFF" x 50);
+  my $match_list = is_deeply(\@samples, \@expect, "colors are still correct");
+  my $samples = Imager::i_gsamp($im_pal2, 0, 100, 0, [ 0, 1, 2 ]);
+  my $match_scalar = is_deeply([ unpack("C*", $samples) ],
+                              \@expect, "colors are still correct (scalar)");
+  unless ($match_list && $match_scalar) {
+    # this has been failing on a particular smoker, provide more
+    # diagnostic information
+    print STDERR "Pallete:\n";
+    print STDERR "  $_: ", join(",", $colors[$_]->rgba), "\n" for 0..$#colors;
+    print STDERR "Samples (list): ", join(",", @samples), "\n";
+    print STDERR "Samples (scalar): ", join(",", unpack("C*", $samples)), "\n";
+    print STDERR "Indexes: ", join(",", Imager::i_gpal($im_pal2, 0, 100, 0)), "\n";
+  }
 }
 
 # test the OO interfaces
@@ -185,11 +197,36 @@ is($impal2->getheight, 201, "check height");
   is($impal3->type, 'paletted', "and is paletted");
 }
 
-{ # to_rgb on incomplete image
+{
   my $im = Imager->new;
   ok($im, "make empty image");
   ok(!$im->to_rgb8, "convert to rgb8");
-  is($im->errstr, "empty input image", "check message");
+  is($im->errstr, "to_rgb8: empty input image", "check message");
+  is($im->bits, undef, "can't call bits on an empty image");
+  is($im->errstr, "bits: empty input image", "check message");
+  is($im->type, undef, "can't call type on an empty image");
+  is($im->errstr, "type: empty input image", "check message");
+  is($im->virtual, undef, "can't call virtual on an empty image");
+  is($im->errstr, "virtual: empty input image", "check message");
+  is($im->is_bilevel, undef, "can't call virtual on an empty image");
+  is($im->errstr, "is_bilevel: empty input image", "check message");
+  ok(!$im->getscanline(y => 0), "can't call getscanline on an empty image");
+  is($im->errstr, "getscanline: empty input image", "check message");
+  ok(!$im->setscanline(y => 0, pixels => [ $red, $blue ]),
+     "can't call setscanline on an empty image");
+  is($im->errstr, "setscanline: empty input image", "check message");
+  ok(!$im->getsamples(y => 0), "can't call getsamples on an empty image");
+  is($im->errstr, "getsamples: empty input image", "check message");
+  is($im->getwidth, undef, "can't get width of empty image");
+  is($im->errstr, "getwidth: empty input image", "check message");
+  is($im->getheight, undef, "can't get height of empty image");
+  is($im->errstr, "getheight: empty input image", "check message");
+  is($im->getchannels, undef, "can't get channels of empty image");
+  is($im->errstr, "getchannels: empty input image", "check message");
+  is($im->getmask, undef, "can't get mask of empty image");
+  is($im->errstr, "getmask: empty input image", "check message");
+  is($im->setmask, undef, "can't set mask of empty image");
+  is($im->errstr, "setmask: empty input image", "check message");
 }
 
 { # basic checks, 8-bit direct images
@@ -526,28 +563,28 @@ my $psamp_outside_error = "Image position outside of image";
   {
     is(Imager::i_psampf($imraw, 0, 2, undef, [ 1, 0.5, 0.25 ]), 3,
        "i_psampf def channels, 3 samples");
-    is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 127, 63,
+    is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
              "check color written");
     Imager::i_img_setmask($imraw, 5);
     is(Imager::i_psampf($imraw, 1, 3, undef, [ 0.25, 0.5, 0.75 ]), 3,
        "i_psampf def channels, 3 samples, masked");
-    is_color3(Imager::i_get_pixel($imraw, 1, 3), 63, 0, 191,
+    is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 191,
              "check color written");
     is(Imager::i_psampf($imraw, 1, 7, [ 0, 1, 2 ], [ 0.25, 0.5, 0.75 ]), 3,
        "i_psampf channels listed, 3 samples, masked");
-    is_color3(Imager::i_get_pixel($imraw, 1, 7), 63, 0, 191,
+    is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 191,
              "check color written");
     Imager::i_img_setmask($imraw, ~0);
     is(Imager::i_psampf($imraw, 2, 4, [ 0, 1 ], [ 1, 0.5, 0.25, 0.125 ]), 4,
        "i_psampf channels [0, 1], 4 samples");
-    is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 127, 0,
+    is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
              "check first color written");
-    is_color3(Imager::i_get_pixel($imraw, 3, 4), 63, 31, 0,
+    is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
              "check second color written");
     is(Imager::i_psampf($imraw, 0, 5, [ 0, 1, 2 ], [ (0.5, 0.25, 0.125) x 10 ]), 30,
        "write a full row");
     is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
-             [ (127, 63, 31) x 10 ],
+             [ (128, 64, 32) x 10 ],
              "check full row");
     is(Imager::i_psampf($imraw, 8, 8, [ 0, 1, 2 ],
                        [ 1.0, 0.5, 0.125, 0.25, 0.125, 0.0625, 0.125, 0, 1 ]),
@@ -848,6 +885,11 @@ my $psamp_outside_error = "Image position outside of image";
   is($im->errstr, "setsamples: data parameter missing",
      "check error message");
 
+  is($im->setsamples(y => 5, data => undef),
+     undef, "setsamples with undef data");
+  is($im->errstr, "setsamples: data parameter not defined",
+     "check error message");
+
   my $imempty = Imager->new;
   is($imempty->setsamples(y => 0, data => [ (0) x 3 ]), undef,
      "setsamples to empty image");
@@ -1059,6 +1101,24 @@ my $psamp_outside_error = "Image position outside of image";
   }
 }
 
+{
+  my $empty = Imager->new;
+  ok(!$empty->addtag(name => "foo", value => 1),
+     "can't addtag on an empty image");
+  is($empty->errstr, "addtag: empty input image",
+    "check error message");
+  ok(!$empty->settag(name => "foo", value => 1),
+     "can't settag on an empty image");
+  is($empty->errstr, "settag: empty input image",
+    "check error message");
+  ok(!$empty->deltag(name => "foo"), "can't deltag on an empty image");
+  is($empty->errstr, "deltag: empty input image",
+     "check error message");
+  ok(!$empty->tags(name => "foo"), "can't tags on an empty image");
+  is($empty->errstr, "tags: empty input image",
+     "check error message");
+}
+
 Imager->close_log();
 
 unless ($ENV{IMAGER_KEEP_FILES}) {