GD-Tiler

 view release on metacpan or  search on metacpan

t/01tiler.t  view on Meta::CPAN

#
#	GD::Tiler test script
#
use vars qw($tests $loaded);
BEGIN {
	push @INC, './t';
	$tests = 42;

	print STDERR "
 *** Note: test result images can be viewed by
 *** opening the generated results.html file
 *** in a web browser.
 ";
	$^W= 1;
	$| = 1;
	print "1..$tests\n";
}

END {print "not ok 1\n" unless $loaded;}

use strict;
use warnings;

use GD::Tiler;

use GD::Tiler qw(tile);

my $testno = 1;

my @imgfiles = ('t/imgs/smallimg.png', 't/imgs/mediumimg.png', 't/imgs/bigimg.png');
#
#	if standalone, add any path prefix
@imgfiles = map "$ARGV[0]/$_", @imgfiles
	if $ARGV[0];

my @images = ();
push @images, GD::Image->newFromPng($_)
	foreach (@imgfiles);

srand(time());

sub report_result {
	my ($result, $testmsg, $okmsg, $notokmsg) = @_;

	if ($result) {

		$okmsg = '' unless $okmsg;
		print STDOUT (($result eq 'skip') ?
			"ok $testno # skip $testmsg\n" :
			"ok $testno # $testmsg $okmsg\n");
	}
	else {
		$notokmsg = '' unless $notokmsg;
		print STDOUT
			"not ok $testno # $testmsg $notokmsg\n";
	}
	$testno++;
}

#
#	prelims: use shared test count for eventual
#	threaded tests
#
$loaded = 1;
report_result(1, 'load');
#	2. Tile single image, computed coords, not centered, default background, no margins

my $img = tile(Images => [ $images[0] ]);
saveimg($testno, $img);
report_result(defined $img, 'Tile single image, computed coords, not centered, default background, no margins');

#	3. Tile single image, computed coords, centered, default background, edge margin
$img = tile(Images => [ $images[0] ], Center => 1, EdgeMargin => 10);
saveimg($testno, $img);
report_result(defined $img, 'Tile single image, computed coords, centered, default background, edge margin');

#	4. Tile single image, computed coords, centered, named background, vert edge only
$img = tile(Images => [ $images[0] ], Center => 1, Background => 'lorange', VEdgeMargin => 10);
saveimg($testno, $img);
report_result(defined $img, 'Tile single image, computed coords, centered, named background, vert edge only');

#	5. Tile single image, computed coords, centered, hex background, horiz edge only
$img = tile(Images => [ $images[0] ], Center => 1, Background => '#FF00DEADBEEF', HEdgeMargin => 10);
saveimg($testno, $img);
report_result(defined $img, 'Tile single image, computed coords, centered, hex background, horiz edge only');

#	6. Tile single image, computed coords, centered, hex background, tile margin
$img = tile(Images => [ $images[0] ], Center => 1, Background => '#FF00DEADBEEF', TileMargin => 10);
saveimg($testno, $img);
report_result(defined $img, 'Tile single image, computed coords, centered, hex background, tile margin');

#	7. Tile single image, computed coords, centered, named background, vert tile only
$img = tile(Images => [ $images[0] ], Center => 1, Background => 'white', VTileMargin => 10);
saveimg($testno, $img);
report_result(defined $img, 'Tile single image, computed coords, centered, named background, vert tile only');

#	8. Tile single image, computed coords, centered, hex background, horiz tile only



( run in 1.106 second using v1.01-cache-2.11-cpan-d7f47b0818f )