From e4b964454ad9d9c366b0d4d321269576f7edf232 Mon Sep 17 00:00:00 2001 From: "gerv%gerv.net" <> Date: Thu, 5 Jan 2006 19:07:01 +0000 Subject: Bug 286724: change testserver.pl to do a simpler check for image creation, thereby avoiding false negatives. Patch by gerv; r=glob, a=justdave. --- testserver.pl | 61 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'testserver.pl') diff --git a/testserver.pl b/testserver.pl index 7d3e2b15c..7cdacb0a3 100755 --- a/testserver.pl +++ b/testserver.pl @@ -123,37 +123,37 @@ Check your webserver configuration.\n"; print "TEST-OK Webserver is preventing fetch of $url.\n"; } +# Test chart generation eval 'use GD'; if ($@ eq '') { undef $/; # 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) { - my $gdlib = `gdlib-config --version 2>&1`; + my $gdlib = `gdlib-config --version 2>&1` || ""; $gdlib =~ s/\n$//; if (!$gdlib) { - print "TEST-WARNING Failed to run gdlib-config, assuming gdlib " . - "version 1.x\n"; - $gdlib = '1.x'; + print "TEST-WARNING Failed to run gdlib-config; can't compare " . + "GD versions.\n"; } - my $gd = $GD::VERSION; - - my $verstring = "GD version $gd, libgd version $gdlib"; - - $gdlib =~ s/^([^\.]+)\..*/$1/; - $gd =~ s/^([^\.]+)\..*/$1/; - - if ($gdlib == $gd) { - print "TEST-OK $verstring; Major versions match.\n"; - } else { - print "TEST-FAIL $verstring; Major versions do not match\n"; + else { + my $gd = $GD::VERSION; + + my $verstring = "GD version $gd, libgd version $gdlib"; + + $gdlib =~ s/^([^\.]+)\..*/$1/; + $gd =~ s/^([^\.]+)\..*/$1/; + + if ($gdlib == $gd) { + print "TEST-OK $verstring; Major versions match.\n"; + } else { + print "TEST-FAILED $verstring; Major versions do not match.\n"; + } } } # Test GD - eval { my $image = new GD::Image(100, 100); my $black = $image->colorAllocate(0, 0, 0); @@ -167,9 +167,9 @@ if ($@ eq '') { if ($image->can('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 { - die "GD doesn't support PNG generation\n"; + print "TEST-FAILED GD doesn't support PNG generation.\n"; } }; if ($@ ne '') { @@ -177,10 +177,9 @@ if ($@ eq '') { } # Test Chart - eval 'use Chart::Lines'; if ($@) { - print "TEST-FAILED Chart::Lines is not installed\n"; + print "TEST-FAILED Chart::Lines is not installed.\n"; } else { eval { my $chart = Chart::Lines->new(400, 400); @@ -188,10 +187,8 @@ if ($@ eq '') { $chart->add_pt('foo', 30, 25); $chart->add_pt('bar', 16, 32); - my $type = $chart->can('gif') ? 'gif' : 'png'; - $chart->$type("$datadir/testchart-local.$type"); - check_image("$datadir/testchart-local.$type", "t/testchart.$type", - "Chart", uc($type)); + $chart->png("$datadir/testchart-local.png"); + check_image("$datadir/testchart-local.png", "Chart"); }; if ($@ ne '') { print "TEST-FAILED Chart returned: $@\n"; @@ -227,7 +224,6 @@ sub fetch { select((select(SOCK), $| = 1)[0]); # get content - print SOCK "GET $file HTTP/1.0\015\012host: $host:$port\015\012\015\012"; my $header = ''; while (defined(my $line = )) { @@ -247,14 +243,13 @@ sub fetch { } sub check_image { - my ($local_file, $test_file, $library, $image_type) = @_; - if (read_file($local_file) eq read_file($test_file)) { - print "TEST-OK $library library generated a good $image_type image\n"; + my ($local_file, $library) = @_; + my $filedata = read_file($local_file); + if ($filedata =~ /^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A/) { + print "TEST-OK $library library generated a good PNG image.\n"; unlink $local_file; } else { - print "TEST-WARNING $library library generated a $image_type that " . - "didn't match the expected image.\nIt has been saved as " . - "$local_file and should be compared with $test_file\n"; + print "TEST-WARNING $library library did not generate a good PNG.\n"; } } -- cgit v1.2.3-24-g4f1b