1 package graphical_compare
;
3 #*************************************************************************
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 # Copyright 2000, 2010 Oracle and/or its affiliates.
9 # OpenOffice.org - a multi-platform office productivity suite
11 # This file is part of OpenOffice.org.
13 # OpenOffice.org is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Lesser General Public License version 3
15 # only, as published by the Free Software Foundation.
17 # OpenOffice.org is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Lesser General Public License version 3 for more details
21 # (a copy is included in the LICENSE file that accompanied this code).
23 # You should have received a copy of the GNU Lesser General Public License
24 # version 3 along with OpenOffice.org. If not, see
25 # <http://www.openoffice.org/license.html>
26 # for a copy of the LGPLv3 License.
28 #*************************************************************************
36 use cwstestresulthelper
;
44 use English
; # $OSNAME, ...
54 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
57 # if using RCS/CVS, this may be preferred
58 $VERSION = do { my @r = (q
$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x
$#r, @r }; # must be all one line, for MakeMaker
60 @EXPORT = qw(&SingleDocumentCompare &setPrefix &setConnectionString);
61 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
62 # your exported package globals go here,
63 # as well as any optionally exported functions
64 @EXPORT_OK = ( ); # qw($Var1 %Hashit &func3);
68 our $nTimeOut = 300 * 1000;
72 our $overwritereference;
74 our $sConncectionString;
76 sub setConnectionString
($)
78 $sConncectionString=shift;
81 sub getOOoRunnerClasspath
()
84 my $sUPDExtensions = "";
85 if (defined ($ENV{SOL_TMP
}) && defined ($ENV{SOLARVERSION
}))
87 $sSourceRoot = $ENV{SOLARVERSION
};
89 elsif (defined $ENV{SOURCE_ROOT
})
91 $sSourceRoot = $ENV{SOURCE_ROOT
};
92 $sSourceRoot = appendPath
($sSourceRoot, $ENV{WORK_STAMP
});
96 $sSourceRoot = $ENV{SOLARVERSION
};
97 $sUPDExtensions = ".$ENV{UPDMINOR}";
99 $sSourceRoot = appendPath
($sSourceRoot, $ENV{INPATH
});
100 my $sSourceRootBin = appendPath
($sSourceRoot, "bin" . $sUPDExtensions);
101 my $sSourceRootLib = appendPath
($sSourceRoot, "lib" . $sUPDExtensions);
103 if (! -d
$sSourceRoot )
105 log_print
( "SourceRoot not found, search it in '$sSourceRoot'\n");
109 my $sOOoRunnerPath = $sSourceRootBin;
110 my $sUnoilPath = $sSourceRootBin;
111 my $sRidlPath = $sSourceRootBin;
112 my $sJurtPath = $sSourceRootBin;
113 my $sJuhPath = $sSourceRootBin;
114 my $sJavaUnoPath = $sSourceRootBin;
116 my $sOOoRunnerClasspath =
117 appendPath
( $sRidlPath, "ridl.jar") . getJavaPathSeparator
() .
118 appendPath
( $sUnoilPath, "unoil.jar") . getJavaPathSeparator
() .
119 appendPath
( $sJurtPath, "jurt.jar") . getJavaPathSeparator
() .
120 appendPath
( $sJuhPath, "juh.jar") . getJavaPathSeparator
() .
121 appendPath
( $sJavaUnoPath, "java_uno.jar") . getJavaPathSeparator
() .
122 appendPath
( $sOOoRunnerPath, "OOoRunnerLight.jar");
123 if (isWindowsEnvironment
())
125 $sOOoRunnerClasspath .= getJavaPathSeparator
() . $sSourceRootBin;
129 $sOOoRunnerClasspath .= getJavaPathSeparator
() . $sSourceRootLib;
131 return $sOOoRunnerClasspath;
134 # ------------------------------------------------------------------------------
138 if (isWindowsEnvironment
())
140 $sTempPath = "C:/temp";
142 elsif (isUnixEnvironment
())
148 die "getTempPath() Failed, due to unsupported environment.\n";
152 # ------------------------------------------------------------------------------
154 sub getProjectOutput
()
156 my $sOutput = appendPath
(getProjectRoot
(), $ENV{INPATH
});
157 $sOutput = appendPath
($sOutput, "misc");
161 # ------------------------------------------------------------------------------
162 sub getProjectOutputReference
()
164 my $sOutput = appendPath
(getProjectRoot
(), $ENV{INPATH
});
165 $sOutput = appendPath
($sOutput, "reference");
170 sub searchForReference
($)
177 if ( -e
$sFile . ".ps")
181 if ( -e
$sFile . ".pdf")
187 # ------------------------------------------------------------------------------
189 # my $sOfficeName = $officeprefixname . $officename;
190 sub SingleDocumentCompare
($$$$$$)
192 # get all about the document to compare
193 my $sDocumentPoolPath = shift;
194 my $sDocumentPool = shift;
195 my $sDocumentName = shift;
198 # get all about the destination office
199 my $sCreatorType = shift;
202 # log_print( "parameter -creatortype not given. Use 'OOo'\n");
203 $sCreatorType = "ps";
205 my $prepareonly = shift;
208 # my $nSimpleCompareTime = getTime();
210 my $nConvwatchFailed = 0;
211 set_logfile
( appendPath
(getProjectOutput
(), $sDocumentName . ".txt" ));
213 print("$sDocumentName");
215 log_print
("Graphical compare on document: '$sDocumentName'\n");
216 # ------------------------------------------------------------------------------
217 # create postscript or pdf from first installed office
218 # ------------------------------------------------------------------------------
220 my $sOOoRunnerClasspath = quoteIfNeed
(getOOoRunnerClasspath
());
221 if ($OSNAME eq "cygwin")
223 if (!startswith
($sOOoRunnerClasspath, "\""))
225 $sOOoRunnerClasspath = quote
($sOOoRunnerClasspath);
228 if (length($sOOoRunnerClasspath) == 0)
230 $nConvwatchFailed == 1;
232 # ------------------------------------------------------------------------------
233 # create postscript or pdf from second installed office
234 # ------------------------------------------------------------------------------
236 my $sPathesIni = appendPath
(getProjectOutput
(), "pathes.ini");
237 my $gspath = getFromPathes
($sPathesIni, "gs.path");
238 my $gsexe = getFromPathes
($sPathesIni, "gs.exe");
239 my $impath = getFromPathes
($sPathesIni, "imagemagick.path");
240 my $javaexe = getFromPathes
($sPathesIni, "java.exe");
241 setJavaExecutable
($javaexe);
243 log_print
("----- CREATE POSTSCRIPT OR PDF WITH RUNNING OFFICE -----\n");
244 # my $nPrepareSecondPostscriptTime = getTime();
245 if ($nConvwatchFailed == 0)
247 my $sInputPath = $sDocumentPoolPath;
248 $sInputPath = appendPath
($sInputPath, $sDocumentPool);
249 $sInputPath = appendPath
($sInputPath, $sDocumentName);
251 if (! -f
$sInputPath )
253 $nConvwatchFailed = 1;
254 log_print
("ERROR: File '$sInputPath' doesn't exists.\n");
258 my $sOutputPath = getProjectOutput
();
259 my $sPropertyFile = appendPath
(getProjectOutput
() , $sDocumentName . ".build.props");
262 if (open(PROPERTYFILE
, ">$sPropertyFile"))
264 print PROPERTYFILE
"# This file is automatically created by graphical_compare.pl\n";
265 print PROPERTYFILE
"DOC_COMPARATOR_PRINT_MAX_PAGE=9999\n";
266 print PROPERTYFILE
"DOC_COMPARATOR_GFX_OUTPUT_DPI_RESOLUTION=180\n";
267 print PROPERTYFILE
"DOC_COMPARATOR_REFERENCE_CREATOR_TYPE=$sCreatorType\n";
268 print PROPERTYFILE
"TEMPPATH=" . getTempPath
() . "\n";
269 if ($sConncectionString)
271 print PROPERTYFILE
"ConnectionString=$sConncectionString\n";
275 print PROPERTYFILE
"ConnectionString=pipe,name=" . getUsername
() . "\n";
277 print PROPERTYFILE
"OFFICE_VIEWABLE=true\n";
278 print PROPERTYFILE
"CREATE_DEFAULT_REFERENCE=true\n";
279 print PROPERTYFILE
"DOC_COMPARATOR_INPUT_PATH=$sInputPath\n";
280 print PROPERTYFILE
"DOC_COMPARATOR_OUTPUT_PATH=$sOutputPath\n";
281 if (isWindowsEnvironment
())
283 print PROPERTYFILE
"DOC_COMPARATOR_PRINTER_NAME=CrossOffice Generic Printer\n";
285 print PROPERTYFILE
"NoOffice=true\n";
291 print "Can't open '$sPropertyFile' for write.\n";
293 if ( -e
"$sPropertyFile")
297 # $sOOoRunnerClasspathFromDestinationName = quoteIfNeed(getOOoRunnerClasspath());
301 $sParams = "-Dperl.exe=" . convertCygwinPath
($ENV{PERL
});
304 $sParams .= " -cp " . $sOOoRunnerClasspath .
305 " org.openoffice.Runner" .
306 " -TimeOut $nTimeOut" .
307 " -tb java_complex" .
308 " -ini $sPropertyFile" .
309 " -o graphical.PostscriptCreator";
310 # $sParams .= " -cs pipe,name=$USER";
312 # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y";
313 my $err = calljava
(getJavaExecutable
(), $sParams, $sDebug);
318 my $sFailure = "Failed after try to create Postscript/pdf document for " . $sDocumentName;
319 log_print
("ERROR: $sFailure\n");
320 $nConvwatchFailed = 1;
325 my $sFailure = "There is no propertyfile: $sPropertyFile";
326 log_print
( "ERROR: $sFailure\n");
331 # set prepareonly and it is possible to only create ps or pdf files
334 print(" [only create ");
335 if ($sCreatorType eq "ps" || $sCreatorType eq "pdf")
337 print(" $sCreatorType");
341 print(" (${sCreatorType}?)");
343 if ($nConvwatchFailed == 0)
352 return $nConvwatchFailed;
356 # ------------------------------------------------------------------------------
357 # create jpeg from postscript or pdf from second installed office
358 # ------------------------------------------------------------------------------
360 if ($nConvwatchFailed == 0)
362 log_print
("----- CREATE JPEG FROM POSTSCRIPT OR PDF FROM RUNNING OFFICE -----\n");
364 my $sInputPath = getProjectOutput
();
365 $sInputPath = appendPath
($sInputPath, $sDocumentName);
367 my $sOutputPath = getProjectOutput
();
369 my $sParams = "-cp " . $sOOoRunnerClasspath .
370 " org.openoffice.Runner" .
371 " -TimeOut $nTimeOut" .
372 " -tb java_complex" .
373 " -DOC_COMPARATOR_INPUT_PATH " . quoteIfNeed
($sInputPath) .
374 " -DOC_COMPARATOR_OUTPUT_PATH " . quoteIfNeed
($sOutputPath) .
375 " -DOC_COMPARATOR_REFERENCE_CREATOR_TYPE $sCreatorType" .
377 " -NoSmallPictures" .
378 " -o graphical.JPEGCreator";
381 $sParams .= " -gs.path " . quoteIfNeed
($gspath);
385 $sParams .= " -gs.exe $gsexe";
388 # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y";
389 my $err = calljava
(getJavaExecutable
(), $sParams, $sDebug);
391 # log_print( "\n\n");
394 my $sFailure = "Failed after try to create JPEG from Postscript/pdf document for " . $sDocumentName;
395 log_print
("ERROR: $sFailure\n");
396 $nConvwatchFailed = 1;
401 # ------------------------------------------------------------------------------
402 # create jpeg from postscript or pdf from references
403 # ------------------------------------------------------------------------------
405 if ($nConvwatchFailed == 0)
407 log_print
("----- CREATE JPEG FROM POSTSCRIPT OR PDF FROM REFERENCE -----\n");
410 my $sInputPath = appendPath
(getProjectRoot
(), "references");
411 $sInputPath = appendPath
($sInputPath, getEnvironment
());
412 $sInputPath = appendPath
($sInputPath, $sDocumentPool);
413 $sInputPath = appendPath
($sInputPath, $sDocumentName);
415 my $err = searchForReference
($sInputPath);
418 log_print
("ERROR: Can't find Postscript or PDF reference for '$sInputPath'\n");
419 $nConvwatchFailed = 1;
423 my $sOutputPath = getProjectOutputReference
();
426 my $sIndexFile = appendPath
($sOutputPath, "index.ini");
427 # we need the index.ini for better run through
429 if ( ! -e
$sIndexFile)
431 if (open(INDEXINI
, ">$sIndexFile"))
433 # print INDEXINI "[$sDocumentName]\n";
437 my $sParams = "-cp " . $sOOoRunnerClasspath .
438 " org.openoffice.Runner" .
439 " -TimeOut $nTimeOut" .
440 " -tb java_complex" .
441 " -DOC_COMPARATOR_INPUT_PATH " . quoteIfNeed
($sInputPath) .
442 " -DOC_COMPARATOR_OUTPUT_PATH " . quoteIfNeed
($sOutputPath) .
443 " -DOC_COMPARATOR_REFERENCE_CREATOR_TYPE $sCreatorType" .
445 " -NoSmallPictures" .
446 " -o graphical.JPEGCreator";
449 $sParams .= " -gs.path " . quoteIfNeed
($gspath);
453 $sParams .= " -gs.exe $gsexe";
456 # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y";
457 my $err = calljava
(getJavaExecutable
(), $sParams, $sDebug);
459 # log_print( "\n\n");
462 my $sFailure = "Failed after try to create JPEG from Postscript/pdf document for references.";
463 log_print
("ERROR: $sFailure\n");
464 $nConvwatchFailed = 1;
468 # ------------------------------------------------------------------------------
470 # ------------------------------------------------------------------------------
472 if ($nConvwatchFailed == 0)
474 log_print
("----- COMPARE JPEGS -----\n");
475 my $sInputPath = appendPath
(getProjectOutputReference
(), $sDocumentName);
477 my $sOutputPath = getProjectOutput
();
479 my $sParams = "-Xmx512m" .
480 " -cp " . $sOOoRunnerClasspath .
481 " org.openoffice.Runner" .
482 " -TimeOut $nTimeOut" .
483 " -tb java_complex" .
484 " -DOC_COMPARATOR_INPUT_PATH " . quoteIfNeed
($sInputPath) .
485 " -DOC_COMPARATOR_OUTPUT_PATH " . quoteIfNeed
($sOutputPath) .
487 " -NoSmallPictures" .
488 " -o graphical.JPEGComparator";
491 $sParams .= " -imagemagick.path " . quoteIfNeed
($impath);
495 # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y";
496 my $err = calljava
(getJavaExecutable
(), $sParams, $sDebug);
501 my $sFailure = "Failed after compare JPEGs $sDocumentName\n";
502 log_print
("ERROR: $sFailure\n");
503 $nConvwatchFailed = 1;
507 # try to execute new java tool to show graphical compare
508 my $sJavaProgram = appendPath
(getProjectRoot
(), $ENV{INPATH
});
509 $sJavaProgram = appendPath
($sJavaProgram, "class");
510 $sJavaProgram = appendPath
($sJavaProgram, "ConvwatchGUIProject.jar");
511 if ( -e
"$sJavaProgram")
513 my $sInputPath = appendPath
(getProjectOutput
(), $sDocumentName . ".ps.ini");
514 if (! -e
$sInputPath)
516 $sInputPath = appendPath
(getProjectOutput
(), $sDocumentName . ".pdf.ini");
517 if (! -e
$sInputPath)
524 my $sParams = "-Xms128m -Xmx512m -jar $sJavaProgram $sInputPath";
525 # $sParams .= " -cs pipe,name=$USER";
526 # my $sJavaExe = "C:/Program Files/Java/jdk1.6.0_16/bin/java.exe"; # getJavaExecutable()
527 my $sJavaExe = getJavaExecutable
();
528 # $sDebug = "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9001,suspend=y";
529 my $err = calljava
($sJavaExe, $sParams, $sDebug);
531 # log_print( "\n\n");
534 # my $sFailure = "Failed after try to create Postscript/pdf document for " . $sDocumentName;
535 # log_print("ERROR: $sFailure\n");
536 # $nConvwatchFailed = 1;
542 print "WARNING: The show program '$sJavaProgram' doesn't exists.\n";
551 if ($nConvwatchFailed == 0)
557 print(" [FAILED]\n");
558 print("\nPrint output of test: $sDocumentName\n");
559 my $sLogFile = appendPath
(getProjectOutput
(), $sDocumentName . ".txt");
562 # printTime(endTime($nSimpleCompareTime));
564 return $nConvwatchFailed;
567 # ------------------------------------------------------------------------------
573 if (open(LOGFILE
, "$logfile"))
576 while ($line = <LOGFILE
>)