bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / convwatch / ConvWatchStarter.java
blob5e1e09592f57ee984966f3a6c28618904018cf34
1 /*
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 .
19 package convwatch;
21 // imports
22 import java.util.ArrayList;
23 import java.io.File;
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;
38 /**
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:
52 /**
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";
59 // }
61 // The second of the mandatory functions: return all test methods as an
62 // array. There is only one test function in this example.
63 /**
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()
78 // MUST PARAMETER
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.");
85 bQuit = true;
87 else
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;
101 else
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.");
112 bQuit = true;
114 else
116 log.println("found " + PropertyName.DOC_COMPARATOR_OUTPUT_PATH + " " + sOUT);
117 m_sOutputPath = sOUT;
120 if (bQuit == true)
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)
132 else
134 log.println("found " + PropertyName.DOC_COMPARATOR_DIFF_PATH + " " + sDIFF);
135 m_sDiffPath = 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" );
161 // Ghostscript
162 aList.add( "gs -version" );
164 else
166 aList.add( "composite.exe -version" );
167 aList.add( "identify.exe -version" );
169 // Ghostscript
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
182 /* protected */
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();
191 if (aGTA == null)
193 assure("Must quit", false);
195 if (aGTA.cancelRequest())
197 return;
200 initMember();
202 aGTA.allowStore();
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() ;)
209 // {
210 // System.out.println(e.nextElement());
211 // }
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
234 // 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.");
242 else
244 for (int i=0;i<aList.length;i++)
246 String sEntry = (String)aList[i];
247 log.println("- next file is: ------------------------------");
248 log.println(sEntry);
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())
276 break;
281 else
283 // check exact name
284 if (aGTA.checkIfUsableDocumentType(m_sInputPath))
286 runGDCWithStatus(HTMLoutput, LISToutput, m_sInputPath, m_sOutputPath, m_sReferencePath, m_sDiffPath, "");
290 LISToutput.close();
291 HTMLoutput.close();
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())
308 // {
309 // aSemaphore.P(aSemaphore.getSemaphoreFile());
310 // }
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();
336 // better was:
337 // load document
338 // create postscript from document
339 // check file
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());
368 // Office shutdown
369 if (aProvider != null)
371 aProvider.closeExistingOffice(param, true);
372 // if (OSHelper.isWindows())
373 // {
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.
378 // }
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 -----------------
387 String sListFile;
388 if (_sNewSubDir.length() > 0)
390 sListFile = _sNewSubDir + fs + sFilenameNoSuffix + ".ini";
392 else
394 sListFile = sFilenameNoSuffix + ".ini";
396 _aLISToutput.writeValue(sListFile);
398 // -------------------- HTML --------------------
399 String sLink;
400 String sLinkDD;
401 String sLinkName;
402 String sLinkDDName;
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)
411 // {
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";
414 // }
415 // else
416 // {
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";
420 // }
421 sLinkName = sFilenameNoSuffix;
422 sLinkDDName = sFilenameNoSuffix + " (DiffDiff)";
424 if (_sDiffPath != null && _sDiffPath.length() > 0)
426 _aHTMLoutput.indexLine( sLinkDD, sLinkDDName, sLink, sLinkName, sStatusRunThrough, sStatusMessage );
428 else
430 _aHTMLoutput.indexLine( sLink, sLinkName, "", "", sStatusRunThrough, sStatusMessage );