Experimental Image::BoxFind module: Image/t/08-follow_pixpat_methods.t
# Test file created outside of h2xs framework.
# Run this like so: `perl Image-BoxFind.t'
# doom@kzsu.stanford.edu 2007/10/22 03:04:14
use warnings;
use strict;
$|=1;
my $DEBUG = 0;
use Test::More;
BEGIN { plan tests => 11 };
use Data::Dumper;
use File::Basename qw( basename );
use FindBin qw( $Bin );
use lib "$Bin/../..";
my $lib = "$Bin/../..";
BEGIN { #1
use_ok( 'Image::BoxFind' );
}
# 2
ok(1, "Traditional: If we made it this far, we're ok.");
{
my $test_name = "follow_pixpat_x_plus";
my $image_file = "$Bin/dat/images/firefox_save_as.png";
my $basename = basename( $image_file );
$basename =~ s{\.png$}{}x;
my $bf = Image::BoxFind->new( { image_file => $image_file,
DEBUG => $DEBUG,
} );
{# 3
my ($spot_x, $spot_y) = (3, 4);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (190, 11);
my $end_point = $bf->follow_pixpat_x_plus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ 477, $y0 ];
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'Name' box top edge" );
}
{# 4
my ($spot_x, $spot_y) = (3, 4);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (155, 32);
my $end_point = $bf->follow_pixpat_x_plus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ 477, $y0 ];
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'Name' box bottom edge" );
}
{# 5
my ($spot_x, $spot_y) = (3, 4);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (338, 128);
my $end_point = $bf->follow_pixpat_x_plus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ 386, $y0 ];
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'Cancel' button" );
}
{# 6
my ($spot_x, $spot_y) = (3, 4);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (30, 90);
my $end_point = $bf->follow_pixpat_x_plus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ 31, $y0 ]; # Stopped instantly. Use a fuzzier test? TODO
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'B' in 'Browse'" );
}
{# 7
$test_name = "follow_pixpat_y_plus";
my ($spot_x, $spot_y) = (4, 3);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (112, 19);
my $end_point = $bf->follow_pixpat_y_plus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ $x0, 31 ]; # stops a few pixels early cause of spotwidth TODO
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'Name' box left side" );
}
{# 8
$test_name = "follow_pixpat_y_plus";
my ($spot_x, $spot_y) = (4, 3);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (478, 14);
my $end_point = $bf->follow_pixpat_y_plus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ $x0, 31 ];
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'Name' box right side" );
}
{# 9
$test_name = "follow_pixpat_x_minus";
my ($spot_x, $spot_y) = (3, 4);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (413, 46);
my $end_point = $bf->follow_pixpat_x_minus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ 112, $y0 ]; # in the minus direction charges *past* target by spot width TODO
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'folder' box top side" );
}
{# 10
$test_name = "follow_pixpat_y_minus";
my ($spot_x, $spot_y) = (4, 3);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (478, 28);
my $end_point = $bf->follow_pixpat_y_minus( $x0, $y0 );
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ $x0, 13 ];
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename $spot_str ($x0,$y0) 'Name' box right side" );
}
{# 11
$test_name = "follow_pixel_pattern";
my ($spot_x, $spot_y) = (4, 3);
$bf->set_spotsize_x( $spot_x );
$bf->set_spotsize_y( $spot_y );
my ($x0, $y0) = (478, 28);
$bf->set_cursor_x( $x0 );
$bf->set_cursor_y( $y0 );
my $end_point = $bf->follow_pixel_pattern('y_minus');
$bf->debug( "determine_pixpat: " . Dumper($end_point) . "\n" );
my $spot_str = $spot_x . 'x' . $spot_y;
my $expected_end = [ $x0, 13 ];
is_deeply( $end_point, $expected_end,
"Testing $test_name on $basename 'y_minus' $spot_str ($x0,$y0) 'Name' box right side" );
}
}
### TODO could also test:
# detected_change
# if I actually cared to use it for any reason.
Joseph Brenner,
Tue Nov 27 17:40:02 2007