source: subversion/applications/rendering/tilesAtHome-dev/trunk/runTests.pl @ 22032

Revision 22032, 4.9 KB checked in by deelkar, 4 years ago (diff)

undo damage of last night

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2#-------------------------------------------------------------
3# OpenStreetMap tiles@home
4#
5# Contact Deelkar on the Openstreetmap wiki for help using this program
6#-----------------------------------------------------------------------------
7# Copyright 2010, Dirk-Lueder Kreie and others
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation; either version 2
12# of the License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22#-----------------------------------------------------------------------------
23
24use warnings;
25use strict;
26use lib './lib';
27use tahlib;
28use TahConf;
29use File::Temp qw(tempfile tempdir);
30use File::Spec;
31use File::Path qw(rmtree);
32use GD 2 qw(:DEFAULT :cmp);
33
34
35delete $ENV{LC_ALL};
36delete $ENV{LC_NUMERIC};
37delete $ENV{LANG};
38$ENV{LANG} = 'C';
39
40print "- Reading Config ... ";
41my %EnvironmentInfo;
42my $Config = TahConf->getConfig();
43print "OK\n";
44
45print "- Testing Basic Config ... ";
46%EnvironmentInfo = $Config->CheckBasicConfig();
47print "OK\n";
48
49
50print "- Testing Full Config ... ";
51%EnvironmentInfo = $Config->CheckConfig();
52print "OK\n";
53
54print "- Start offline tests:\n";
55my $Cmd;
56my $success;
57my $PID;
58
59#$Cmd = "perl ./tilesGen.pl localFile tests/emptyfile_12_0_0.osm"; ## must fail
60#$success = runCommand($Cmd,$PID);
61
62##FIXME check result for failure
63
64print " * fonttest (will take some time) ... ";
65$Cmd = "perl ./tilesGen.pl --tile_MaxZoom=14 --Verbose=3 --CreateTilesetFile=0 localFile tests/fonttest_12_0_0.osm tile"; ##should create zips for font-comparison
66my $retval = system($Cmd);
67##FIXME check result for failure, otherwise graphically compare image
68print STDERR "\n\n";
69
70my $tempdir = tempdir ( DIR => $Config->get("WorkingDirectory") );
71my $comparedir = tempdir ( DIR => $Config->get("WorkingDirectory") );
72my $zipfile = File::Spec->join($Config->get("WorkingDirectory"),"uploadable","tile_12_0_0_*.zip");
73$Cmd = sprintf("unzip -d %s -q %s",$tempdir,$zipfile);
74$success = runCommand($Cmd,$PID);
75
76if ($success) # remove all zips from the test, because they should not be uploaded to the server.
77{ 
78    my @files = glob($zipfile); 
79    foreach my $zip (@files) 
80    {
81        print STDERR "removing $zip \n";
82        unlink($zip) or die "cannot delete $zip";
83    }
84}
85
86my @pngList = ("_14_0_2.png","_14_0_3.png","_14_1_1.png","_14_2_2.png","_14_3_3.png"); # these tiles contain font samples"
87my @failedImages;
88my ($loopmax,$I);
89
90foreach my $pngSuffix (@pngList)
91{
92    print STDERR "testing tests/fonttest".$pngSuffix."\n";
93
94    rename(File::Spec->join($tempdir,"tile".$pngSuffix),File::Spec->join($comparedir,"tile".$pngSuffix)); #move interesting images to $comparedir
95
96    my $renderResult = File::Spec->join($comparedir,"tile".$pngSuffix);
97    my $Image = undef;
98    eval { $Image = GD::Image->newFromPng($renderResult); };
99    die "$renderResult not found" if( not defined $Image );
100
101    my @fonttestRef = undef;
102    my @ReferenceImage = undef;
103    $loopmax = 1000; #just to prevent endless loops.
104    $I = 0;
105    for (; $I <= $loopmax;)
106    {
107        $fonttestRef[$I] = File::Spec->join("tests","fonttest".$I.$pngSuffix);
108        $ReferenceImage[$I] = undef;
109        eval { $ReferenceImage[$I] = GD::Image->newFromPng($fonttestRef[$I]); };
110        if (not defined $ReferenceImage[$I]) # this means we ran out of tests, without finding a match.
111        {
112            pop(@fonttestRef);
113            print STDERR "\nFonttest failed, check installed fonts. $renderResult doesn't match any of ";
114            print STDERR join(", ",@fonttestRef);
115            print STDERR "\n";
116            push(@failedImages, $renderResult);
117            die $fonttestRef[$I]." not found" if($I == 0);
118            last; 
119        }
120         
121        # libGD comparison returns true if images are different.
122        if (not $Image->compare($ReferenceImage[$I]) & GD_CMP_IMAGE)
123        {
124            last; #we found a match, so the client is OK.
125        }
126        else
127        {
128            $I++
129        }
130    }
131}
132
133rmtree($tempdir); #clean up all remaining images not useful for comparison
134
135if (scalar(@failedImages))
136{
137    print STDERR "Please e-mail the following failed images to tah\@deelkar.net:\n";
138    print STDERR "Failed images reference number: 2010062402\n";
139    print STDERR join("\n",@failedImages);
140    print STDERR "\n";
141    exit(7);
142}
143else
144{
145    rmtree($comparedir);
146    print "OK\n";
147}
148
149die "something went very wrong\n" if ($I >= $loopmax);
150
151print "- done testing.\n";
Note: See TracBrowser for help on using the repository browser.