i_psamp()/i_psampf() bad channel count tests
authorTony Cook <tony@develop-help.com>
Fri, 10 Feb 2012 09:30:47 +0000 (20:30 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 13 Feb 2012 10:01:51 +0000 (21:01 +1100)
t/t82inline.t

index 653e4a85946d3095f5804a9fac1b215ccee6bfb9..b30d831bb5b2b6d01b07266ca2565b747888e778 100644 (file)
@@ -19,7 +19,7 @@ plan skip_all => "perl 5.005_04, 5.005_05 too buggy"
 
 -d "testout" or mkdir "testout";
 
-plan tests => 82;
+plan tests => 106;
 require Inline;
 Inline->import(with => 'Imager');
 Inline->import("FORCE"); # force rebuild
@@ -394,6 +394,22 @@ test_render_color(Imager work_8) {
   return 1;
 }
 
+int
+raw_psamp(Imager im, int chan_count) {
+  static i_sample_t samps[] = { 0, 127, 255 };
+
+  i_clear_error();
+  return i_psamp(im, 0, 1, 0, samps, NULL, chan_count);
+}
+
+int
+raw_psampf(Imager im, int chan_count) {
+  static i_fsample_t samps[] = { 0, 0.5, 1.0 };
+
+  i_clear_error();
+  return i_psampf(im, 0, 1, 0, samps, NULL, chan_count);
+}
+
 EOS
 
 my $im = Imager->new(xsize=>50, ysize=>50);
@@ -544,3 +560,73 @@ for my $bits (8, 16) {
              "check 255 coverage, alpha 0 color, bits $bits");
   }
 }
+
+{
+  my $im = Imager->new(xsize => 10, ysize => 10);
+  is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psamp($im, 0), -1, "bad channel list (0) for psamp should fail");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+}
+
+{
+  my $im = Imager->new(xsize => 10, ysize => 10, bits => 16);
+  is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail (16-bit)");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psamp($im, 0), -1, "bad channel list (0) for psamp should fail (16-bit)");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail (16-bit)");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail (16-bit)");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+}
+
+{
+  my $im = Imager->new(xsize => 10, ysize => 10, bits => 'double');
+  is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail (double)");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psamp($im, 0), -1,, "bad channel list (0) for psamp should fail (double)");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail (double)");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail (double)");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+}
+
+{
+  my $im = Imager->new(xsize => 10, ysize => 10, type => "paletted");
+  is(raw_psamp($im, 4), -1, "bad channel list (4) for psamp should fail (paletted)");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psamp($im, 0), -1, "bad channel list (0) for psamp should fail (paletted)");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 4), -1, "bad channel list (4) for psampf should fail (paletted)");
+  is(_get_error(), "chan_count 4 out of range, must be >0, <= channels",
+     "check message");
+  is(raw_psampf($im, 0), -1, "bad channel list (0) for psampf should fail (paletted)");
+  is(_get_error(), "chan_count 0 out of range, must be >0, <= channels",
+     "check message");
+  is($im->type, "paletted", "make sure we kept the image type");
+}
+
+sub _get_error {
+  my @errors = Imager::i_errors();
+  return join(": ", map $_->[0], @errors);
+}