2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 import java
.util
.ArrayList
;
24 import java
.io
.FileFilter
;
26 import convwatch
.EnhancedComplexTestCase
;
27 import com
.sun
.star
.lang
.XMultiServiceFactory
;
29 import convwatch
.ConvWatchException
;
30 import convwatch
.DirectoryHelper
;
31 import convwatch
.GraphicalTestArguments
;
32 import convwatch
.HTMLOutputter
;
33 import helper
.OfficeProvider
;
34 import helper
.OfficeWatcher
;
35 import helper
.OSHelper
;
36 import convwatch
.PerformanceContainer
;
39 * The following Complex Test will test
40 * an already created document and it's postscript output (by an older office version)
41 * with a new office version.
42 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick.
43 * Read the manual for more information.
45 * this is only the starter program
46 * more is found in qadevOOo/runner/convwatch/*
49 public class ConvWatchStarter
extends EnhancedComplexTestCase
51 // The first of the mandatory functions:
53 * Return the name of the test.
54 * In this case it is the actual name of the service.
55 * @return The tested service.
57 // public String getTestObjectName() {
58 // return "ConvWatch runner";
61 // The second of the mandatory functions: return all test methods as an
62 // array. There is only one test function in this example.
64 * Return all test methods.
65 * @return The test methods.
67 public String
[] getTestMethodNames() {
68 return new String
[]{"compareGraphicalDiffs"};
71 String m_sInputPath
= "";
72 String m_sReferencePath
= "";
73 String m_sOutputPath
= "";
74 String m_sDiffPath
= null;
76 private void initMember()
79 // INPUTFILE ----------
80 String sINPATH
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_INPUT_PATH
);
81 boolean bQuit
= false;
82 if (sINPATH
== null || sINPATH
.length() == 0)
84 log
.println("Please set input path (path to documents) " + PropertyName
.DOC_COMPARATOR_INPUT_PATH
+ "=path.");
89 log
.println("found " + PropertyName
.DOC_COMPARATOR_INPUT_PATH
+ " " + sINPATH
);
90 m_sInputPath
= sINPATH
;
93 // REFERENCE_PATH ----------
94 String sREF
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_REFERENCE_PATH
);
95 if (sREF
== null || sREF
.length() == 0)
97 // log.println("Please set reference file (path to good documents) REFERENCEFILE=path.");
98 log
.println("Assumtion, reference directory and input directory are the same.");
99 m_sReferencePath
= m_sInputPath
;
103 log
.println("found " + PropertyName
.DOC_COMPARATOR_REFERENCE_PATH
+ " " + sREF
);
104 m_sReferencePath
= sREF
;
107 // OUTPUT_PATH ----------
108 String sOUT
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
);
109 if (sOUT
== null || sOUT
.length() == 0)
111 log
.println("Please set output path (path to a temp directory) " + PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
+ "=path.");
116 log
.println("found " + PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
+ " " + sOUT
);
117 m_sOutputPath
= sOUT
;
122 // log.println("must quit.");
123 assure("Must quit", false);
127 // DIFF_PATH ----------
128 String sDIFF
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_DIFF_PATH
);
129 if (sDIFF
== null || sDIFF
.length() == 0)
134 log
.println("found " + PropertyName
.DOC_COMPARATOR_DIFF_PATH
+ " " + sDIFF
);
138 if (m_sInputPath
.startsWith("file:") ||
139 m_sReferencePath
.startsWith("file:") ||
140 m_sOutputPath
.startsWith("file:"))
142 assure("We can't handle file: URL right, use system path instead.", false);
150 * @return a List of software which must accessible as an external executable
152 protected String
[] mustInstalledSoftware()
154 ArrayList
<String
> aList
= new ArrayList
<String
>();
155 // Tools from ImageMagick
156 if (! OSHelper
.isWindows())
158 aList
.add( "composite -version" );
159 aList
.add( "identify -version" );
162 aList
.add( "gs -version" );
166 aList
.add( "composite.exe -version" );
167 aList
.add( "identify.exe -version" );
170 aList
.add( "gswin32c.exe -version" );
173 return aList
.toArray(new String
[aList
.size()]);
178 * The test method itself.
179 * Don't try to call it from outside, it is started only from qadevOOo runner
183 public void compareGraphicalDiffs()
185 GlobalLogWriter
.set(log
);
186 String sDBConnection
= (String
)param
.get( PropertyName
.DB_CONNECTION_STRING
);
187 // check if all need software is installed and accessible
188 checkEnvironment(mustInstalledSoftware());
190 GraphicalTestArguments aGTA
= getGraphicalTestArguments();
193 assure("Must quit", false);
195 if (aGTA
.cancelRequest())
204 String sBuildID
= aGTA
.getBuildID();
205 log
.println("Current Office has buildid: " + sBuildID
);
207 // LLA: sample code, how to access all parameters
208 // for (Enumeration e = param.keys() ; e.hasMoreElements() ;)
210 // System.out.println(e.nextElement());
213 String fs
= System
.getProperty("file.separator");
215 String sHTMLName
= "index.html";
216 File aInputPathTest
= new File(m_sInputPath
);
217 if (!aInputPathTest
.isDirectory())
219 int n
= m_sInputPath
.lastIndexOf(fs
);
220 sHTMLName
= m_sInputPath
.substring(n
+ 1);
221 sHTMLName
+= ".html";
223 HTMLOutputter HTMLoutput
= HTMLOutputter
.create(m_sOutputPath
, sHTMLName
, "", "");
224 HTMLoutput
.header( m_sOutputPath
);
225 HTMLoutput
.indexSection( m_sOutputPath
);
226 LISTOutputter LISToutput
= LISTOutputter
.create(m_sOutputPath
, "allfiles.txt");
228 DB
.init(aGTA
.getDBInfoString() + "," + sDBConnection
);
230 File aInputPath
= new File(m_sInputPath
);
231 if (aInputPath
.isDirectory())
233 // check a whole directory
235 FileFilter aFileFilter
= FileHelper
.getFileFilter();
237 Object
[] aList
= DirectoryHelper
.traverse(m_sInputPath
, aFileFilter
, aGTA
.includeSubDirectories());
238 if (aList
.length
== 0)
240 log
.println("Nothing to do, there are no document files found.");
244 for (int i
=0;i
<aList
.length
;i
++)
246 String sEntry
= (String
)aList
[i
];
247 log
.println("- next file is: ------------------------------");
250 String sNewSubDir
= FileHelper
.removeFirstDirectorysAndBasenameFrom(sEntry
, m_sInputPath
);
252 String sNewReferencePath
= m_sReferencePath
;
253 String sNewOutputPath
= m_sOutputPath
;
254 String sNewDiffPath
= m_sDiffPath
;
255 if (sNewSubDir
.length() > 0)
257 if (sNewReferencePath
!= null)
258 sNewReferencePath
= sNewReferencePath
+ fs
+ sNewSubDir
;
259 // String sNameNoSuffix = FileHelper.getNameNoSuffix(FileHelper.getBasename(sEntry));
260 // sNewReferenceFile = sNewReferencePath + fs + sNameNoSuffix + ".prn";
262 sNewOutputPath
= sNewOutputPath
+ fs
+ sNewSubDir
;
263 if (sNewDiffPath
!= null)
264 sNewDiffPath
= sNewDiffPath
+ fs
+ sNewSubDir
;
267 // NameHelper aNameContainer = new NameHelper(m_sOutputPath, sNewSubDir, FileHelper.getBasename(sEntry));
268 // aNameContainer.print();
270 if (aGTA
.checkIfUsableDocumentType(sEntry
))
272 runGDCWithStatus(HTMLoutput
, LISToutput
, sEntry
, sNewOutputPath
, sNewReferencePath
, sNewDiffPath
, sNewSubDir
);
274 if (aGTA
.cancelRequest())
284 if (aGTA
.checkIfUsableDocumentType(m_sInputPath
))
286 runGDCWithStatus(HTMLoutput
, LISToutput
, m_sInputPath
, m_sOutputPath
, m_sReferencePath
, m_sDiffPath
, "");
292 log
.println("The file '" + HTMLoutput
.getFilename() + "' shows a html based status.");
293 DB
.writeHTMLFile(HTMLoutput
.getFilename());
297 // -----------------------------------------------------------------------------
298 void runGDCWithStatus(HTMLOutputter _aHTMLoutput
, LISTOutputter _aLISToutput
, String _sInputFile
, String _sOutputPath
, String _sReferencePath
, String _sDiffPath
, String _sNewSubDir
)
300 // start a fresh Office
301 GraphicalTestArguments aGTA
= getGraphicalTestArguments();
303 OfficeProvider aProvider
= null;
304 // SimpleFileSemaphore aSemaphore = new SimpleFileSemaphore();
305 if (aGTA
.shouldOfficeStart())
307 // if (OSHelper.isWindows())
309 // aSemaphore.P(aSemaphore.getSemaphoreFile());
312 aGTA
.getPerformance().startTime(PerformanceContainer
.OfficeStart
);
313 aProvider
= new OfficeProvider();
314 XMultiServiceFactory xMSF
= (XMultiServiceFactory
) aProvider
.getManager(param
);
315 param
.put("ServiceFactory", xMSF
);
316 aGTA
.getPerformance().stopTime(PerformanceContainer
.OfficeStart
);
318 long nStartTime
= aGTA
.getPerformance().getTime(PerformanceContainer
.OfficeStart
);
319 aGTA
= getGraphicalTestArguments(); // get new TestArguments
320 aGTA
.getPerformance().setTime(PerformanceContainer
.OfficeStart
, nStartTime
);
323 // Watcher Object is need in log object to give a simple way to say if a running office is alive.
324 // As long as a log comes, it pings the Watcher and says the office is alive, if not an
325 // internal counter increase and at a given point (300 seconds) the office is killed.
326 GlobalLogWriter
.get().println("Set office watcher");
327 OfficeWatcher aWatcher
= (OfficeWatcher
)param
.get("Watcher");
328 GlobalLogWriter
.get().setWatcher(aWatcher
);
329 // initializeWatcher(param);
331 String sStatusRunThrough
= "";
332 String sStatusMessage
= "";
335 DB
.destination_start();
338 // create postscript from document
340 GraphicalDifferenceCheck
.checkOneFile(_sInputFile
, _sOutputPath
, _sReferencePath
, _sDiffPath
, aGTA
);
341 sStatusRunThrough
= "PASSED, OK";
342 DB
.destination_finished();
344 catch(ConvWatchCancelException e
)
346 assure(e
.getMessage(), false, true);
347 sStatusRunThrough
= "CANCELLED, FAILED";
348 sStatusMessage
= e
.getMessage();
349 DB
.destination_failed(sStatusRunThrough
, sStatusMessage
);
351 catch(ConvWatchException e
)
353 assure(e
.getMessage(), false, true);
354 sStatusMessage
= e
.getMessage();
355 sStatusRunThrough
= "PASSED, FAILED";
356 DB
.destination_failed(sStatusRunThrough
, sStatusMessage
);
358 catch(com
.sun
.star
.lang
.DisposedException e
)
360 assure(e
.getMessage(), false, true);
361 sStatusMessage
= e
.getMessage();
362 sStatusRunThrough
= "FAILED, FAILED";
363 DB
.destination_failed(sStatusRunThrough
, sStatusMessage
);
366 GlobalLogWriter
.get().println("Watcher count is: " + aWatcher
.getPing());
369 if (aProvider
!= null)
371 aProvider
.closeExistingOffice(param
, true);
372 // if (OSHelper.isWindows())
374 // aSemaphore.V(aSemaphore.getSemaphoreFile());
375 // aSemaphore.sleep(2);
376 // // wait some time maybe an other process will take the semaphore
377 // // I know, this is absolutly dirty, but the whole convwatch is dirty and need a big cleanup.
381 // -------------------- Status --------------------
382 String fs
= System
.getProperty("file.separator");
383 String sBasename
= FileHelper
.getBasename(_sInputFile
);
384 String sFilenameNoSuffix
= FileHelper
.getNameNoSuffix(sBasename
);
386 // -------------------- List of all files -----------------
388 if (_sNewSubDir
.length() > 0)
390 sListFile
= _sNewSubDir
+ fs
+ sFilenameNoSuffix
+ ".ini";
394 sListFile
= sFilenameNoSuffix
+ ".ini";
396 _aLISToutput
.writeValue(sListFile
);
398 // -------------------- HTML --------------------
403 String sHTMLPrefix
= aGTA
.getHTMLOutputPrefix();
405 GlobalLogWriter
.get().println("----------------------------------------------------------------------");
406 GlobalLogWriter
.get().println(" OutputPath: " + _sOutputPath
);
407 GlobalLogWriter
.get().println(" NewPath: " + _sNewSubDir
);
408 GlobalLogWriter
.get().println("----------------------------------------------------------------------");
410 // if (_sNewSubDir.length() > 0)
412 // sLink = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + _sNewSubDir + fs + sFilenameNoSuffix + ".ini";
413 // sLinkDD = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + _sNewSubDir + fs + "DiffDiff_" + sFilenameNoSuffix + ".ini";
417 sLink
= sHTMLPrefix
/* + "/cw.php?inifile=" */ + _sOutputPath
+ fs
+ sFilenameNoSuffix
+ ".ini";
418 // sLinkDD = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + _sNewSubDir + fs + "DiffDiff_" + sFilenameNoSuffix + ".ini";
419 sLinkDD
= sHTMLPrefix
/* + "/cw.php?inifile=" */ + _sOutputPath
+ fs
+ "DiffDiff_" + sFilenameNoSuffix
+ ".ini";
421 sLinkName
= sFilenameNoSuffix
;
422 sLinkDDName
= sFilenameNoSuffix
+ " (DiffDiff)";
424 if (_sDiffPath
!= null && _sDiffPath
.length() > 0)
426 _aHTMLoutput
.indexLine( sLinkDD
, sLinkDDName
, sLink
, sLinkName
, sStatusRunThrough
, sStatusMessage
);
430 _aHTMLoutput
.indexLine( sLink
, sLinkName
, "", "", sStatusRunThrough
, sStatusMessage
);