jl165 merging heads
[LibreOffice.git] / testgraphical / source / compare.pl
blob4aef877dc2b72e9e189a85be7ffa38c00c3ebff5
1 eval 'exec perl -wS $0 ${1+\"$@\"}'
2 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
31 BEGIN
33 # Adding the path of this script file to the include path in the hope
34 # that all used modules can be found in it.
35 $0 =~ /^(.*)[\/\\]/;
36 push @INC, $1;
37 # print "PATH: " . $1 . "\n";
40 # my $e;
41 # foreach $e (keys %ENV)
42 # {
43 # print "$e := $ENV{$e}" . "\n";
44 # }
46 use strict;
47 use graphical_compare;
48 use ConvwatchHelper;
49 use filehelper;
50 use timehelper;
51 use loghelper;
53 use Cwd;
54 use File::Basename;
55 use Getopt::Long;
56 use English; # $OSNAME, ...
57 use File::Path;
58 use Cwd 'chdir';
60 our $help; # Help option flag
61 our $version; # Version option flag
62 # our $test;
64 # our $MAJOR;
65 # our $MINOR;
66 # our $cwsname;
67 our $pool;
68 our $document;
69 our $creatortype;
70 our $prepareonly = 0;
71 our $force;
72 our $verbose = 0;
73 our $show = 0;
74 our $connectionstring;
76 # Prototypes
77 sub print_usage(*);
78 sub prepare();
79 sub CompareFiles($$);
81 # flush STDOUT
82 # my $old_handle = select (STDOUT); # "select" STDOUT and save # previously selected handle
83 # $| = 1; # perform flush after each write to STDOUT
84 # select ($old_handle); # restore previously selected handle
86 $OUTPUT_AUTOFLUSH=1; # works only if use English is used.
88 our $version_info = 'compare.pl';
90 GetOptions(
91 # "MAJOR=s" => \$MAJOR,
92 # "MINOR=s" => \$MINOR,
93 # "cwsname=s" => \$cwsname,
94 "pool=s" => \$pool,
95 "document=s" => \$document,
96 "creatortype=s" => \$creatortype,
97 "prepareonly=s" => \$prepareonly,
98 "connectionstring=s" => \$connectionstring,
100 "force" => \$force,
101 "verbose" => \$verbose,
102 "show" => \$show,
104 # "test" => \$test,
105 "help" => \$help,
106 "version" => \$version
109 if ($help)
111 print_usage(*STDOUT);
112 exit(0);
114 # Check for version option
115 if ($version)
117 print STDERR "$version_info\n";
118 exit(0);
121 if ($prepareonly)
123 $force=1;
126 prepare();
127 if ($connectionstring)
129 setConnectionString($connectionstring);
132 my $sDocumentPool = appendPath(getProjectRoot(), "document-pool");
133 # print "ProjectRoot: " . getProjectRoot() . "\n";
134 if ($ENV{DOCUMENTPOOL})
136 if ( -d $ENV{DOCUMENTPOOL})
138 print "overwrite default Documentpool: '$sDocumentPool'\n";
139 print " with \$ENV{DOCUMENTPOOL}: $ENV{DOCUMENTPOOL}\n";
140 $sDocumentPool = $ENV{DOCUMENTPOOL};
142 else
144 print "Given \$DOCUMENTPOOL doesn't exist.\n";
148 my $err = 0;
149 my $nCompareTime = getTime();
151 # if we want to check one file, give -pool and -document
152 # if we want to check the whole pool, give -pool
153 # if we want to check all, call without parameters
154 if ($pool)
156 if ($document)
158 $err = SingleDocumentCompare( $sDocumentPool,
159 $pool,
160 $document,
161 $creatortype,
162 $prepareonly,
163 $show
166 else
168 $err = CompareFiles($sDocumentPool, $pool);
171 else
173 local *DIR;
174 if (opendir (DIR, $sDocumentPool)) # Directory oeffnen
176 my $myfile;
177 while ($myfile = readdir(DIR))
178 { # ein filename holen
179 if ($myfile eq "." ||
180 $myfile eq "..")
182 next;
184 my $sDocumentPath = appendPath($sDocumentPool, $myfile);
185 if ( -d $sDocumentPath )
187 $err += CompareFiles($sDocumentPool, $myfile);
189 elsif ( -f $sDocumentPath )
191 print "Warning: the file '$myfile' will not compared.\n";
194 closedir(DIR);
196 # my $sPool = "eis-chart";
197 # $err += CompareFiles($sDocumentPool, "eis-chart");
198 # $err += CompareFiles($sDocumentPool, "eis-impress");
199 # $err += CompareFiles($sDocumentPool, "eis-writer");
200 # $err += CompareFiles($sDocumentPool, "eis-calc");
204 printTime(endTime($nCompareTime));
205 exit ($err);
207 # ------------------------------------------------------------------------------
209 sub CompareFiles($$)
211 my $sDocumentPath = shift;
212 my $sPool = shift;
213 my %aFailedHash;
214 my $startdir = appendPath($sDocumentPath, $sPool);
216 local *DIR;
217 if (opendir (DIR, $startdir)) # Directory oeffnen
219 my $myfile;
220 while ($myfile = readdir(DIR))
221 { # ein filename holen
222 if ($myfile eq "knownissues.xcl")
224 next;
226 my $sAbsoluteFile = appendPath($startdir, $myfile);
227 if (-f $sAbsoluteFile)
229 my $nIssue;
230 my $sIssueText;
231 ($nIssue, $sIssueText) = checkForKnownIssue($startdir, $myfile);
232 if ($nIssue == 0)
234 $err = SingleDocumentCompare(
235 # "/net/so-gfxcmp-documents.germany.sun.com/export/gfxcmp/document-pool", # $documentpoolpath,
236 $sDocumentPool,
237 $sPool, # $documentpool,
238 $myfile, # $documentname);
239 $creatortype, # $destinationcreatortype,
240 $prepareonly,
241 $show
243 $aFailedHash{$myfile} = $err;
245 else
247 print "$myfile [KNOWN ISSUE: #$sIssueText#]\n";
251 closedir(DIR);
254 print "***** State for graphical compare of pool: '$sPool' ******\n";
255 my $nErrorCount = 0;
256 my $file;
257 foreach $file (keys %aFailedHash)
259 if ($aFailedHash{$file} != 0)
261 print "Failed: $file\n";
262 $nErrorCount++;
265 print "Whole unit: ";
266 if ($nErrorCount > 0)
268 print "PASSED.FAILED\n";
270 else
272 print "PASSED.OK\n";
274 print "************************************************************\n";
275 return $nErrorCount;
277 # ------------------------------------------------------------------------------
278 # return issue number if file exists in knownissues.xcl file
279 sub checkForKnownIssue($$)
281 my $startdir = shift;
282 my $myfile = shift;
284 if ($force)
286 return 0,"";
289 my $sKnownIssueFile = appendPath($startdir, "knownissues.xcl");
290 my $sIssueText = "unknown";
291 local *ISSUES;
292 my $nIssue = 0;
293 my $sCurrentSection;
295 if (open(ISSUES, $sKnownIssueFile))
297 my $line;
298 while ($line = <ISSUES>)
300 chomp($line);
301 if ($line =~ /\[(.*)\]/ )
303 $sCurrentSection = $1;
304 next;
306 if ($sCurrentSection eq $creatortype)
308 if ($line =~ /\#\#\# (.*) \#\#\#/ )
310 $sIssueText = $1;
312 if ($line =~ /^${myfile}$/ )
314 $nIssue = 1;
315 last;
319 close(ISSUES);
321 return $nIssue, $sIssueText;
323 # ------------------------------------------------------------------------------
324 sub prepare()
326 # directory structure:
327 # documents will be found in
328 # ../document-pool/eis-tests
330 # references will be found in
331 # ../references/unxlngi/eis-tests
332 # ../references/wntmsci/eis-tests
334 # output goes to
335 # ../unxlngi6.pro/misc
337 if ($verbose)
339 setVerbose();
342 # TEST
343 if (!$ENV{INPATH})
345 if ($OSNAME eq "linux")
347 # just for debug
348 setINPATH("unxlngi6.pro");
351 else
353 setINPATH($ENV{INPATH});
356 if (! $creatortype)
358 $creatortype= "ps";
361 my $cwd = getcwd();
362 print "Current Directory: $cwd\n" if ($verbose);
363 my $sProjectBase;
364 if ($ENV{PRJ})
366 # print "cwd:=$cwd\n";
367 # print "PRJ:=$ENV{PRJ}\n";
368 $sProjectBase = appendPath($cwd, $ENV{PRJ});
370 else
372 $sProjectBase = dirname($cwd);
374 if ($OSNAME eq "cygwin")
376 $sProjectBase = `cygpath -w $sProjectBase`;
377 chomp($sProjectBase);
378 $sProjectBase = unixpath($sProjectBase);
379 # print "cygwin patch \$sProjectBase := $sProjectBase\n";
381 # print "Project base path: $sProjectBase\n";
382 setProjectRoot($sProjectBase);
385 # TEST TEST TEST
386 # exit (0);
388 # ------------------------------------------------------------------------------
389 sub print_usage(*)
391 local *HANDLE = $_[0];
392 my $tool_name = basename($0);
394 print(HANDLE <<END_OF_USAGE);
396 Usage: $tool_name [OPTIONS]
398 -pool Give pool name out of document-pool directory.
399 But all documents list in knownissues.xcl will not check.
400 -document Give a single document to test, the known issue list will ignored.
401 -creatortype=s s:ps create postscript files via print to file.
402 s:pdf create PDF file via export to pdf.
403 -h, --help Print this help, then exit
404 -v, --version Print version number, then exit
406 END_OF_USAGE