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