xref: /aoo42x/main/testgraphical/source/compare.pl (revision 7e90fac2)
1eval 'exec perl -wS $0 ${1+\"$@\"}'
2    if 0;
3
4#**************************************************************
5#
6#  Licensed to the Apache Software Foundation (ASF) under one
7#  or more contributor license agreements.  See the NOTICE file
8#  distributed with this work for additional information
9#  regarding copyright ownership.  The ASF licenses this file
10#  to you under the Apache License, Version 2.0 (the
11#  "License"); you may not use this file except in compliance
12#  with the License.  You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16#  Unless required by applicable law or agreed to in writing,
17#  software distributed under the License is distributed on an
18#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19#  KIND, either express or implied.  See the License for the
20#  specific language governing permissions and limitations
21#  under the License.
22#
23#**************************************************************
24
25
26
27BEGIN
28{
29    #       Adding the path of this script file to the include path in the hope
30    #       that all used modules can be found in it.
31    $0 =~ /^(.*)[\/\\]/;
32    push @INC, $1;
33    # print "PATH: " . $1 . "\n";
34}
35
36# my $e;
37# foreach $e (keys %ENV)
38# {
39#     print "$e := $ENV{$e}" . "\n";
40# }
41
42use strict;
43use graphical_compare;
44use ConvwatchHelper;
45use filehelper;
46use timehelper;
47use loghelper;
48
49use Cwd;
50use File::Basename;
51use Getopt::Long;
52use English;                  # $OSNAME, ...
53use File::Path;
54use Cwd 'chdir';
55
56our $help;                    # Help option flag
57our $version;                 # Version option flag
58# our $test;
59
60# our $MAJOR;
61# our $MINOR;
62# our $cwsname;
63our $pool;
64our $document;
65our $creatortype;
66our $prepareonly = 0;
67our $force;
68our $verbose = 0;
69our $show = 0;
70our $connectionstring;
71
72# Prototypes
73sub print_usage(*);
74sub prepare();
75sub CompareFiles($$);
76
77# flush STDOUT
78# my $old_handle = select (STDOUT); # "select" STDOUT and save # previously selected handle
79# $| = 1; # perform flush after each write to STDOUT
80# select ($old_handle); # restore previously selected handle
81
82$OUTPUT_AUTOFLUSH=1; # works only if use English is used.
83
84our $version_info = 'compare.pl';
85
86GetOptions(
87#            "MAJOR=s"       => \$MAJOR,
88#            "MINOR=s"       => \$MINOR,
89#            "cwsname=s"     => \$cwsname,
90           "pool=s"        => \$pool,
91           "document=s"    => \$document,
92           "creatortype=s" => \$creatortype,
93           "prepareonly=s" => \$prepareonly,
94           "connectionstring=s" => \$connectionstring,
95
96           "force"         => \$force,
97           "verbose"       => \$verbose,
98           "show"          => \$show,
99
100#           "test"          => \$test,
101           "help"          => \$help,
102           "version"       => \$version
103           );
104
105if ($help)
106{
107    print_usage(*STDOUT);
108    exit(0);
109}
110# Check for version option
111if ($version)
112{
113    print STDERR "$version_info\n";
114    exit(0);
115}
116
117if ($prepareonly)
118{
119    $force=1;
120}
121
122prepare();
123if ($connectionstring)
124{
125    setConnectionString($connectionstring);
126}
127
128my $sDocumentPool = appendPath(getProjectRoot(), "document-pool");
129# print "ProjectRoot: " . getProjectRoot() . "\n";
130if ($ENV{DOCUMENTPOOL})
131{
132    if ( -d $ENV{DOCUMENTPOOL})
133    {
134        print "overwrite default Documentpool: '$sDocumentPool'\n";
135        print "       with \$ENV{DOCUMENTPOOL}: $ENV{DOCUMENTPOOL}\n";
136        $sDocumentPool = $ENV{DOCUMENTPOOL};
137    }
138    else
139    {
140        print "Given \$DOCUMENTPOOL doesn't exist.\n";
141    }
142}
143
144my $err = 0;
145my $nCompareTime = getTime();
146
147# if we want to check one file, give -pool and -document
148# if we want to check the whole pool, give -pool
149# if we want to check all, call without parameters
150if ($pool)
151{
152    if ($document)
153    {
154        $err = SingleDocumentCompare( $sDocumentPool,
155                                      $pool,
156                                      $document,
157                                      $creatortype,
158                                      $prepareonly,
159                                      $show
160                                     );
161    }
162    else
163    {
164        $err = CompareFiles($sDocumentPool, $pool);
165    }
166}
167else
168{
169    local *DIR;
170    if (opendir (DIR, $sDocumentPool))           # Directory oeffnen
171    {
172        my $myfile;
173        while ($myfile = readdir(DIR))
174        {                                        # ein filename holen
175            if ($myfile eq "." ||
176                $myfile eq "..")
177            {
178                next;
179            }
180            my $sDocumentPath = appendPath($sDocumentPool, $myfile);
181            if ( -d $sDocumentPath )
182            {
183                $err += CompareFiles($sDocumentPool, $myfile);
184            }
185            elsif ( -f $sDocumentPath )
186            {
187                print "Warning: the file '$myfile' will not compared.\n";
188            }
189        }
190        closedir(DIR);
191    }
192    # my $sPool = "eis-chart";
193    # $err += CompareFiles($sDocumentPool, "eis-chart");
194    # $err += CompareFiles($sDocumentPool, "eis-impress");
195    # $err += CompareFiles($sDocumentPool, "eis-writer");
196    # $err += CompareFiles($sDocumentPool, "eis-calc");
197
198}
199
200printTime(endTime($nCompareTime));
201exit ($err);
202
203# ------------------------------------------------------------------------------
204
205sub CompareFiles($$)
206{
207    my $sDocumentPath = shift;
208    my $sPool = shift;
209    my %aFailedHash;
210    my $startdir = appendPath($sDocumentPath, $sPool);
211
212    local *DIR;
213    if (opendir (DIR, $startdir))           # Directory oeffnen
214    {
215        my $myfile;
216        while ($myfile = readdir(DIR))
217        {                                  # ein filename holen
218            if ($myfile eq "knownissues.xcl")
219            {
220                next;
221            }
222            my $sAbsoluteFile = appendPath($startdir, $myfile);
223            if (-f $sAbsoluteFile)
224            {
225                my $nIssue;
226                my $sIssueText;
227                ($nIssue, $sIssueText) = checkForKnownIssue($startdir, $myfile);
228                if ($nIssue == 0)
229                {
230                    $err = SingleDocumentCompare(
231                                             # "/net/so-gfxcmp-documents.germany.sun.com/export/gfxcmp/document-pool", # $documentpoolpath,
232                                             $sDocumentPool,
233                                             $sPool,                  # $documentpool,
234                                             $myfile,                 # $documentname);
235                                             $creatortype,            # $destinationcreatortype,
236                                             $prepareonly,
237                                             $show
238                                             );
239                    $aFailedHash{$myfile} = $err;
240                }
241                else
242                {
243                    print "$myfile [KNOWN ISSUE: #$sIssueText#]\n";
244                }
245            }
246        }
247        closedir(DIR);
248    }
249
250    print "***** State for graphical compare of pool: '$sPool' ******\n";
251    my $nErrorCount = 0;
252    my $file;
253    foreach $file (keys %aFailedHash)
254    {
255        if ($aFailedHash{$file} != 0)
256        {
257            print "Failed: $file\n";
258            $nErrorCount++;
259        }
260    }
261    print "Whole unit: ";
262    if ($nErrorCount > 0)
263    {
264        print "PASSED.FAILED\n";
265    }
266    else
267    {
268        print "PASSED.OK\n";
269    }
270    print "************************************************************\n";
271    return $nErrorCount;
272}
273# ------------------------------------------------------------------------------
274# return issue number if file exists in knownissues.xcl file
275sub checkForKnownIssue($$)
276{
277    my $startdir = shift;
278    my $myfile = shift;
279
280    if ($force)
281    {
282        return 0,"";
283    }
284
285    my $sKnownIssueFile = appendPath($startdir, "knownissues.xcl");
286    my $sIssueText = "unknown";
287    local *ISSUES;
288    my $nIssue = 0;
289    my $sCurrentSection;
290
291    if (open(ISSUES, $sKnownIssueFile))
292    {
293        my $line;
294        while ($line = <ISSUES>)
295        {
296            chomp($line);
297            if ($line =~ /\[(.*)\]/ )
298            {
299                $sCurrentSection = $1;
300                next;
301            }
302            if ($sCurrentSection eq $creatortype)
303            {
304                if ($line =~ /\#\#\# (.*) \#\#\#/ )
305                {
306                    $sIssueText = $1;
307                }
308                if ($line =~ /^${myfile}$/ )
309                {
310                    $nIssue = 1;
311                    last;
312                }
313            }
314        }
315        close(ISSUES);
316    }
317    return $nIssue, $sIssueText;
318}
319# ------------------------------------------------------------------------------
320sub prepare()
321{
322    # directory structure:
323    # documents will be found in
324    # ../document-pool/eis-tests
325
326    # references will be found in
327    # ../references/unxlngi/eis-tests
328    # ../references/wntmsci/eis-tests
329
330    # output goes to
331    # ../unxlngi6.pro/misc
332
333    if ($verbose)
334    {
335        setVerbose();
336    }
337
338    # TEST
339    if (!$ENV{INPATH})
340    {
341        if ($OSNAME eq "linux")
342        {
343            # just for debug
344            setINPATH("unxlngi6.pro");
345        }
346    }
347    else
348    {
349        setINPATH($ENV{INPATH});
350    }
351
352    if (! $creatortype)
353    {
354        $creatortype= "ps";
355    }
356
357    my $cwd = getcwd();
358    print "Current Directory: $cwd\n" if ($verbose);
359    my $sProjectBase;
360    if ($ENV{PRJ})
361    {
362        # print "cwd:=$cwd\n";
363        # print "PRJ:=$ENV{PRJ}\n";
364        $sProjectBase = appendPath($cwd, $ENV{PRJ});
365    }
366    else
367    {
368        $sProjectBase = dirname($cwd);
369    }
370    if ($OSNAME eq "cygwin")
371    {
372        $sProjectBase = `cygpath -w $sProjectBase`;
373        chomp($sProjectBase);
374        $sProjectBase = unixpath($sProjectBase);
375        # print "cygwin patch \$sProjectBase := $sProjectBase\n";
376    }
377    # print "Project base path: $sProjectBase\n";
378    setProjectRoot($sProjectBase);
379
380
381    # TEST TEST TEST
382    # exit (0);
383}
384# ------------------------------------------------------------------------------
385sub print_usage(*)
386{
387    local *HANDLE = $_[0];
388    my $tool_name = basename($0);
389
390    print(HANDLE <<END_OF_USAGE);
391
392Usage: $tool_name [OPTIONS]
393
394    -pool                    Give pool name out of document-pool directory.
395                             But all documents list in knownissues.xcl will not check.
396    -document                Give a single document to test, the known issue list will ignored.
397    -creatortype=s           s:ps  create postscript files via print to file.
398                             s:pdf create PDF file via export to pdf.
399    -h, --help               Print this help, then exit
400    -v, --version            Print version number, then exit
401
402END_OF_USAGE
403;
404}
405