]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 286724: change testserver.pl to do a simpler check for image creation, thereby...
authorgerv%gerv.net <>
Thu, 5 Jan 2006 19:07:01 +0000 (19:07 +0000)
committergerv%gerv.net <>
Thu, 5 Jan 2006 19:07:01 +0000 (19:07 +0000)
t/testchart.gif [deleted file]
t/testchart.png [deleted file]
t/testgd.png [deleted file]
testserver.pl

diff --git a/t/testchart.gif b/t/testchart.gif
deleted file mode 100644 (file)
index a4ed080..0000000
Binary files a/t/testchart.gif and /dev/null differ
diff --git a/t/testchart.png b/t/testchart.png
deleted file mode 100644 (file)
index 720423e..0000000
Binary files a/t/testchart.png and /dev/null differ
diff --git a/t/testgd.png b/t/testgd.png
deleted file mode 100644 (file)
index 72c6aa5..0000000
Binary files a/t/testgd.png and /dev/null differ
index 7d3e2b15ccf78139a9d13abee481b767012c1d37..7cdacb0a3956e5e31f917bf32ab633c3636041d7 100755 (executable)
@@ -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 = <SOCK>)) {
@@ -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";
     }
 }