]> git.imager.perl.org - imager.git/commitdiff
- minor clean up of rubthrough() method
authorTony Cook <tony@develop=help.com>
Thu, 16 Feb 2006 06:41:41 +0000 (06:41 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 16 Feb 2006 06:41:41 +0000 (06:41 +0000)
- error handling tests for rubthrough()

Changes
Imager.pm
t/t69rubthru.t

diff --git a/Changes b/Changes
index 705a2052967aebe3460c6cf3be246525c51ae756..7d62ccf03fffa2bfae766b38fed491d0273d48ee 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1347,6 +1347,8 @@ Revision history for Perl extension Imager.
 - expand documentation of scaleX()/scaleY()
 - rotate()s back parameter now accepts color names like other methods
 - convert t/t69rubthru.t to Test::More
+- minor clean up of rubthrough() method
+- error handling tests for rubthrough()
 
 =================================================================
 
index 55ef61525006997e2080556f5da1777689871ea8..b4d15e4232b9c343c72f02437172ce1051819766 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -2050,8 +2050,14 @@ sub rubthrough {
   my $self=shift;
   my %opts=(tx => 0,ty => 0, @_);
 
-  unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
-  unless ($opts{src} && $opts{src}->{IMG}) { $self->{ERRSTR}='empty input image for source'; return undef; }
+  unless ($self->{IMG}) { 
+    $self->{ERRSTR}='empty input image'; 
+    return undef;
+  }
+  unless ($opts{src} && $opts{src}->{IMG}) {
+    $self->{ERRSTR}='empty input image for src'; 
+    return undef;
+  }
 
   %opts = (src_minx => 0,
           src_miny => 0,
@@ -2060,8 +2066,9 @@ sub rubthrough {
           %opts);
 
   unless (i_rubthru($self->{IMG}, $opts{src}->{IMG}, $opts{tx}, $opts{ty},
-         $opts{src_minx}, $opts{src_miny}, $opts{src_maxx}, $opts{src_maxy})) {
-    $self->{ERRSTR} = $self->_error_as_msg();
+                    $opts{src_minx}, $opts{src_miny}, 
+                    $opts{src_maxx}, $opts{src_maxy})) {
+    $self->_set_error($self->_error_as_msg());
     return undef;
   }
   return $self;
index 44785a01d350a8ad955d846f4751225884e821f1..2e49ad90efa512bc55e45ee2af11f6626868cab8 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 23;
+use Test::More tests => 28;
 BEGIN { use_ok(Imager => qw(:all :handy)); }
 
 init_log("testout/t69rubthru.log", 1);
@@ -75,6 +75,19 @@ ok(color_cmp(Imager::i_get_pixel($ootarg->{IMG}, 30, 30), NC(128, 0, 0)) == 0,
 my $oogtarg = Imager->new(xsize=>100, ysize=>100, channels=>1);
 ok(!$oogtarg->rubthrough(src=>$oosrc), "check oo fails correctly");
 
+is($oogtarg->errstr, 
+   'rubthru can only work where (dest, src) channels are (3,4), (3,2) or (1,2)',
+   "check error message");
+
+{ # check empty image errors
+  my $empty = Imager->new;
+  ok(!$empty->rubthrough(src => $oosrc), "check empty target");
+  is($empty->errstr, 'empty input image', "check error message");
+  ok(!$oogtarg->rubthrough(src=>$empty), "check empty source");
+  is($oogtarg->errstr, 'empty input image for src',
+     "check error message");
+}
+
 sub color_cmp {
   my ($l, $r) = @_;
   my @l = $l->rgba;