Experimental Image::BoxFind module: Image/t/19-draw_rects.t
# Test file created outside of h2xs framework.
# Run this like so: `perl Image-BoxFind.t'
# doom@kzsu.stanford.edu 2007/10/22 04:50:12
use warnings;
use strict;
$|=1;
my $DEBUG = 0;
use Data::Dumper;
use Test::More;
BEGIN { plan tests => 4 };
use Test::Number::Delta;
use Test::File;
use Test::File::Contents;
use File::Basename qw( basename fileparse);
use File::Path qw(mkpath);
use FindBin qw( $Bin );
use lib "$Bin/../..";
use lib "$Bin/lib";
my $image_dir = "$Bin/dat/images";
my $modified_dir = "$image_dir/output";
my $expected_dir = "$image_dir/expected";
BEGIN { #1
use_ok( 'Image::BoxFind' );
}
use Image::BoxFind::Testing::Eyeballs ':all';
#2
ok(1, "Traditional: If we made it this far, we're ok.");
my @image_files =
(
"$Bin/dat/images/simple_test_3.png",
# "$Bin/dat/images/firefox_save_as.png",
# "$Bin/dat/images/rhythmbox_prefs.png",
# "$Bin/dat/images/gimp_open_dialog.png",
);
{
my $test_name = "draw_rects";
foreach my $image_file ( @image_files ) {
my $basename = ( fileparse($image_file, qr{\.png} ) )[0];
my $bf = Image::BoxFind->new( { image_file => $image_file,
DEBUG => $DEBUG,
} );
# Three rectangles to draw on the image.
my $rects = [
[
[ 50, 172 ],
[ 122, 172 ],
[ 122, 211 ],
[ 50, 211 ]
],
[
[ 118, 38 ],
[ 209, 38 ],
[ 209, 152 ],
[ 118, 152 ]
],
[
[ 136, 173 ],
[ 208, 175 ],
[ 208, 212 ],
[ 136, 212 ]
]
];
my $output_file = "$basename-rex.png";
mkpath("$output_file");
my $output_full = "$modified_dir/$output_file";
unlink( $output_full ) if -e $output_full;
my $expected_output = "$expected_dir/$output_file";
$bf->draw_rects( $rects );
# my $status = (-f "$output_full");
# is( $status, 1, "Testing $test_name created output file: $output_file");
file_exists_ok( "$output_full", "Testing $test_name created output file: $output_file");
# Compare this file to a reference copy of it.
file_contents_identical($output_full, $expected_output,
"Testing $test_name contents matches expectations: $output_file");
}
}
Joseph Brenner,
Tue Nov 27 17:40:02 2007