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