]> git.imager.perl.org - imager.git/blob - t/t22flood.t
add an unshipped test for checking sub-module versions are updated
[imager.git] / t / t22flood.t
1 #!perl -w
2 use strict;
3 use Test::More tests => 15;
4 use Imager;
5 use Imager::Test qw(is_image);
6
7 -d "testout" or mkdir "testout";
8
9 { # flood_fill wouldn't fill to the right if the area was just a
10   # single scan-line
11   my $im = Imager->new(xsize => 5, ysize => 3);
12   ok($im, "make flood_fill test image");
13   ok($im->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "white"),
14      "create fill area");
15   ok($im->flood_fill(x => 3, y => 1, color => "blue"),
16      "fill it");
17   my $cmp = Imager->new(xsize => 5, ysize => 3);
18   ok($cmp, "make test image");
19   ok($cmp->line(x1 => 0, y1 => 1, x2 => 4, y2 => 1, color => "blue"),
20      "synthezied filled area");
21   is_image($im, $cmp, "flood_fill filled horizontal line");
22 }
23
24 SKIP:
25 { # flood_fill won't fill entire line below if line above is shorter
26   my $im = Imager->new(file => "testimg/filltest.ppm");
27   ok($im, "Load test image")
28     or skip("Couldn't load test image: " . Imager->errstr, 3);
29
30   # fill from first bad place
31   my $fill1 = $im->copy;
32   ok($fill1->flood_fill(x => 8, y => 2, color => "#000000"),
33      "fill from a top most spot");
34   my $cmp = Imager->new(xsize => $im->getwidth, ysize => $im->getheight);
35   is_image($fill1, $cmp, "check it filled the lot");
36   ok($fill1->write(file => "testout/t22fill1.ppm"), "save");
37
38   # second bad place
39   my $fill2 = $im->copy;
40   ok($fill2->flood_fill(x => 17, y => 3, color => "#000000"),
41      "fill from not quite top most spot");
42   is_image($fill2, $cmp, "check it filled the lot");
43   ok($fill2->write(file => "testout/t22fill2.ppm"), "save");
44 }
45
46 { # verticals
47   my $im = vimage("FFFFFF");
48   my $cmp = vimage("FF0000");
49
50   ok($im->flood_fill(x => 4, y=> 8, color => "FF0000"),
51      "fill at bottom of vertical well");
52   is_image($im, $cmp, "check the result");
53 }
54
55 unless ($ENV{IMAGER_KEEP_FILES}) {
56   unlink "testout/t22fill1.ppm";
57   unlink "testout/t22fill2.ppm";
58 }
59
60 # make a vertical test image
61 sub vimage {
62   my $c = shift;
63
64   my $im = Imager->new(xsize => 10, ysize => 10);
65   $im->line(x1 => 1, y1 => 1, x2 => 8, y2 => 1, color => $c);
66   $im->line(x1 => 4, y1 => 2, x2 => 4, y2 => 8, color => $c);
67
68   return $im;
69 }