Commit e4b96445 authored by gerv%gerv.net's avatar gerv%gerv.net

Bug 286724: change testserver.pl to do a simpler check for image creation,…

Bug 286724: change testserver.pl to do a simpler check for image creation, thereby avoiding false negatives. Patch by gerv; r=glob, a=justdave.
parent 38f51edb
...@@ -123,37 +123,37 @@ Check your webserver configuration.\n"; ...@@ -123,37 +123,37 @@ Check your webserver configuration.\n";
print "TEST-OK Webserver is preventing fetch of $url.\n"; print "TEST-OK Webserver is preventing fetch of $url.\n";
} }
# Test chart generation
eval 'use GD'; eval 'use GD';
if ($@ eq '') { if ($@ eq '') {
undef $/; undef $/;
# Ensure major versions of GD and libgd match # Ensure major versions of GD and libgd match
# Windows's GD module include libgd.dll, guarenteed to match # Windows's GD module include libgd.dll, guaranteed to match
if ($^O !~ /MSWin32/i) { if ($^O !~ /MSWin32/i) {
my $gdlib = `gdlib-config --version 2>&1`; my $gdlib = `gdlib-config --version 2>&1` || "";
$gdlib =~ s/\n$//; $gdlib =~ s/\n$//;
if (!$gdlib) { if (!$gdlib) {
print "TEST-WARNING Failed to run gdlib-config, assuming gdlib " . print "TEST-WARNING Failed to run gdlib-config; can't compare " .
"version 1.x\n"; "GD versions.\n";
$gdlib = '1.x';
} }
my $gd = $GD::VERSION; else {
my $gd = $GD::VERSION;
my $verstring = "GD version $gd, libgd version $gdlib";
my $verstring = "GD version $gd, libgd version $gdlib";
$gdlib =~ s/^([^\.]+)\..*/$1/;
$gd =~ s/^([^\.]+)\..*/$1/; $gdlib =~ s/^([^\.]+)\..*/$1/;
$gd =~ s/^([^\.]+)\..*/$1/;
if ($gdlib == $gd) {
print "TEST-OK $verstring; Major versions match.\n"; if ($gdlib == $gd) {
} else { print "TEST-OK $verstring; Major versions match.\n";
print "TEST-FAIL $verstring; Major versions do not match\n"; } else {
print "TEST-FAILED $verstring; Major versions do not match.\n";
}
} }
} }
# Test GD # Test GD
eval { eval {
my $image = new GD::Image(100, 100); my $image = new GD::Image(100, 100);
my $black = $image->colorAllocate(0, 0, 0); my $black = $image->colorAllocate(0, 0, 0);
...@@ -167,9 +167,9 @@ if ($@ eq '') { ...@@ -167,9 +167,9 @@ if ($@ eq '') {
if ($image->can('png')) { if ($image->can('png')) {
create_file("$datadir/testgd-local.png", $image->png); create_file("$datadir/testgd-local.png", $image->png);
check_image("$datadir/testgd-local.png", 't/testgd.png', 'GD', 'PNG'); check_image("$datadir/testgd-local.png", 'GD');
} else { } else {
die "GD doesn't support PNG generation\n"; print "TEST-FAILED GD doesn't support PNG generation.\n";
} }
}; };
if ($@ ne '') { if ($@ ne '') {
...@@ -177,10 +177,9 @@ if ($@ eq '') { ...@@ -177,10 +177,9 @@ if ($@ eq '') {
} }
# Test Chart # Test Chart
eval 'use Chart::Lines'; eval 'use Chart::Lines';
if ($@) { if ($@) {
print "TEST-FAILED Chart::Lines is not installed\n"; print "TEST-FAILED Chart::Lines is not installed.\n";
} else { } else {
eval { eval {
my $chart = Chart::Lines->new(400, 400); my $chart = Chart::Lines->new(400, 400);
...@@ -188,10 +187,8 @@ if ($@ eq '') { ...@@ -188,10 +187,8 @@ if ($@ eq '') {
$chart->add_pt('foo', 30, 25); $chart->add_pt('foo', 30, 25);
$chart->add_pt('bar', 16, 32); $chart->add_pt('bar', 16, 32);
my $type = $chart->can('gif') ? 'gif' : 'png'; $chart->png("$datadir/testchart-local.png");
$chart->$type("$datadir/testchart-local.$type"); check_image("$datadir/testchart-local.png", "Chart");
check_image("$datadir/testchart-local.$type", "t/testchart.$type",
"Chart", uc($type));
}; };
if ($@ ne '') { if ($@ ne '') {
print "TEST-FAILED Chart returned: $@\n"; print "TEST-FAILED Chart returned: $@\n";
...@@ -227,7 +224,6 @@ sub fetch { ...@@ -227,7 +224,6 @@ sub fetch {
select((select(SOCK), $| = 1)[0]); select((select(SOCK), $| = 1)[0]);
# get content # get content
print SOCK "GET $file HTTP/1.0\015\012host: $host:$port\015\012\015\012"; print SOCK "GET $file HTTP/1.0\015\012host: $host:$port\015\012\015\012";
my $header = ''; my $header = '';
while (defined(my $line = <SOCK>)) { while (defined(my $line = <SOCK>)) {
...@@ -247,14 +243,13 @@ sub fetch { ...@@ -247,14 +243,13 @@ sub fetch {
} }
sub check_image { sub check_image {
my ($local_file, $test_file, $library, $image_type) = @_; my ($local_file, $library) = @_;
if (read_file($local_file) eq read_file($test_file)) { my $filedata = read_file($local_file);
print "TEST-OK $library library generated a good $image_type image\n"; if ($filedata =~ /^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A/) {
print "TEST-OK $library library generated a good PNG image.\n";
unlink $local_file; unlink $local_file;
} else { } else {
print "TEST-WARNING $library library generated a $image_type that " . print "TEST-WARNING $library library did not generate a good PNG.\n";
"didn't match the expected image.\nIt has been saved as " .
"$local_file and should be compared with $test_file\n";
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment