merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / convwatch / ConvWatchStarter.java
blob82486571ef72150dddace13ad614b092a479061b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ConvWatchStarter.java,v $
10 * $Revision: 1.11.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package convwatch;
33 // imports
34 import java.util.ArrayList;
35 import java.io.File;
36 import java.io.FileFilter;
38 import convwatch.EnhancedComplexTestCase;
39 import com.sun.star.lang.XMultiServiceFactory;
41 import convwatch.ConvWatchException;
42 import convwatch.DirectoryHelper;
43 import convwatch.GraphicalTestArguments;
44 import convwatch.HTMLOutputter;
45 import helper.OfficeProvider;
46 import helper.OfficeWatcher;
47 import helper.OSHelper;
48 import convwatch.PerformanceContainer;
50 /**
51 * The following Complex Test will test
52 * an already created document and it's postscript output (by an older office version)
53 * with a new office version.
54 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick.
55 * Read the manual for more information.
57 * this is only the starter program
58 * more is found in qadevOOo/runner/convwatch/*
61 public class ConvWatchStarter extends EnhancedComplexTestCase
63 // The first of the mandatory functions:
64 /**
65 * Return the name of the test.
66 * In this case it is the actual name of the service.
67 * @return The tested service.
69 // public String getTestObjectName() {
70 // return "ConvWatch runner";
71 // }
73 // The second of the mandatory functions: return all test methods as an
74 // array. There is only one test function in this example.
75 /**
76 * Return all test methods.
77 * @return The test methods.
79 public String[] getTestMethodNames() {
80 return new String[]{"compareGraphicalDiffs"};
83 String m_sInputPath = "";
84 String m_sReferencePath = "";
85 String m_sOutputPath = "";
86 String m_sDiffPath = null;
88 private void initMember()
90 // MUST PARAMETER
91 // INPUTFILE ----------
92 String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH );
93 boolean bQuit = false;
94 if (sINPATH == null || sINPATH.length() == 0)
96 log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path.");
97 bQuit = true;
99 else
101 log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH);
102 m_sInputPath = sINPATH;
105 // REFERENCE_PATH ----------
106 String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH );
107 if (sREF == null || sREF.length() == 0)
109 // log.println("Please set reference file (path to good documents) REFERENCEFILE=path.");
110 log.println("Assumtion, reference directory and input directory are the same.");
111 m_sReferencePath = m_sInputPath;
113 else
115 log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF);
116 m_sReferencePath = sREF;
119 // OUTPUT_PATH ----------
120 String sOUT = (String)param.get( PropertyName.DOC_COMPARATOR_OUTPUT_PATH );
121 if (sOUT == null || sOUT.length() == 0)
123 log.println("Please set output path (path to a temp directory) " + PropertyName.DOC_COMPARATOR_OUTPUT_PATH + "=path.");
124 bQuit = true;
126 else
128 log.println("found " + PropertyName.DOC_COMPARATOR_OUTPUT_PATH + " " + sOUT);
129 m_sOutputPath = sOUT;
132 if (bQuit == true)
134 // log.println("must quit.");
135 assure("Must quit", false);
139 // DIFF_PATH ----------
140 String sDIFF = (String)param.get( PropertyName.DOC_COMPARATOR_DIFF_PATH );
141 if (sDIFF == null || sDIFF.length() == 0)
144 else
146 log.println("found " + PropertyName.DOC_COMPARATOR_DIFF_PATH + " " + sDIFF);
147 m_sDiffPath = sDIFF;
150 if (m_sInputPath.startsWith("file:") ||
151 m_sReferencePath.startsWith("file:") ||
152 m_sOutputPath.startsWith("file:"))
154 assure("We can't handle file: URL right, use system path instead.", false);
162 * @return a List of software which must accessable as an external executable
164 protected Object[] mustInstalledSoftware()
166 ArrayList aList = new ArrayList();
167 // Tools from ImageMagick
168 if (! OSHelper.isWindows())
170 aList.add( "composite -version" );
171 aList.add( "identify -version" );
173 // Ghostscript
174 aList.add( "gs -version" );
176 else
178 aList.add( "composite.exe -version" );
179 aList.add( "identify.exe -version" );
181 // Ghostscript
182 aList.add( "gswin32c.exe -version" );
185 return aList.toArray();
190 * The test method itself.
191 * Don't try to call it from outside, it is started only from qadevOOo runner
194 /* protected */
195 public void compareGraphicalDiffs()
197 GlobalLogWriter.set(log);
198 String sDBConnection = (String)param.get( PropertyName.DB_CONNECTION_STRING );
199 // check if all need software is installed and accessable
200 checkEnvironment(mustInstalledSoftware());
202 GraphicalTestArguments aGTA = getGraphicalTestArguments();
203 if (aGTA == null)
205 assure("Must quit", false);
207 if (aGTA.cancelRequest())
209 return;
212 initMember();
214 aGTA.allowStore();
216 String sBuildID = aGTA.getBuildID();
217 log.println("Current Office has buildid: " + sBuildID);
219 // LLA: sample code, how to access all parameters
220 // for (Enumeration e = param.keys() ; e.hasMoreElements() ;)
221 // {
222 // System.out.println(e.nextElement());
223 // }
225 String fs = System.getProperty("file.separator");
227 String sHTMLName = "index.html";
228 File aInputPathTest = new File(m_sInputPath);
229 if (!aInputPathTest.isDirectory())
231 int n = m_sInputPath.lastIndexOf(fs);
232 sHTMLName = m_sInputPath.substring(n + 1);
233 sHTMLName += ".html";
235 HTMLOutputter HTMLoutput = HTMLOutputter.create(m_sOutputPath, sHTMLName, "", "");
236 HTMLoutput.header( m_sOutputPath );
237 HTMLoutput.indexSection( m_sOutputPath );
238 LISTOutputter LISToutput = LISTOutputter.create(m_sOutputPath, "allfiles.txt");
240 DB.init(aGTA.getDBInfoString() + "," + sDBConnection);
242 File aInputPath = new File(m_sInputPath);
243 if (aInputPath.isDirectory())
245 // check a whole directory
246 // a whole directory
247 FileFilter aFileFilter = FileHelper.getFileFilter();
249 Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories());
250 if (aList.length == 0)
252 log.println("Nothing to do, there are no document files found.");
254 else
256 for (int i=0;i<aList.length;i++)
258 String sEntry = (String)aList[i];
259 log.println("- next file is: ------------------------------");
260 log.println(sEntry);
262 String sNewSubDir = FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath);
264 String sNewReferencePath = m_sReferencePath;
265 String sNewOutputPath = m_sOutputPath;
266 String sNewDiffPath = m_sDiffPath;
267 if (sNewSubDir.length() > 0)
269 if (sNewReferencePath != null)
270 sNewReferencePath = sNewReferencePath + fs + sNewSubDir;
271 // String sNameNoSuffix = FileHelper.getNameNoSuffix(FileHelper.getBasename(sEntry));
272 // sNewReferenceFile = sNewReferencePath + fs + sNameNoSuffix + ".prn";
274 sNewOutputPath = sNewOutputPath + fs + sNewSubDir;
275 if (sNewDiffPath != null)
276 sNewDiffPath = sNewDiffPath + fs + sNewSubDir;
279 // NameHelper aNameContainer = new NameHelper(m_sOutputPath, sNewSubDir, FileHelper.getBasename(sEntry));
280 // aNameContainer.print();
282 if (aGTA.checkIfUsableDocumentType(sEntry))
284 runGDCWithStatus(HTMLoutput, LISToutput, sEntry, sNewOutputPath, sNewReferencePath, sNewDiffPath, sNewSubDir);
286 if (aGTA.cancelRequest())
288 break;
293 else
295 // check exact name
296 if (aGTA.checkIfUsableDocumentType(m_sInputPath))
298 runGDCWithStatus(HTMLoutput, LISToutput, m_sInputPath, m_sOutputPath, m_sReferencePath, m_sDiffPath, "");
302 LISToutput.close();
303 HTMLoutput.close();
304 log.println("The file '" + HTMLoutput.getFilename() + "' shows a html based status.");
305 DB.writeHTMLFile(HTMLoutput.getFilename());
309 // -----------------------------------------------------------------------------
310 void runGDCWithStatus(HTMLOutputter _aHTMLoutput, LISTOutputter _aLISToutput, String _sInputFile, String _sOutputPath, String _sReferencePath, String _sDiffPath, String _sNewSubDir )
312 // start a fresh Office
313 GraphicalTestArguments aGTA = getGraphicalTestArguments();
315 OfficeProvider aProvider = null;
316 // SimpleFileSemaphore aSemaphore = new SimpleFileSemaphore();
317 if (aGTA.shouldOfficeStart())
319 // if (OSHelper.isWindows())
320 // {
321 // aSemaphore.P(aSemaphore.getSemaphoreFile());
322 // }
324 aGTA.getPerformance().startTime(PerformanceContainer.OfficeStart);
325 aProvider = new OfficeProvider();
326 XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param);
327 param.put("ServiceFactory", xMSF);
328 aGTA.getPerformance().stopTime(PerformanceContainer.OfficeStart);
330 long nStartTime = aGTA.getPerformance().getTime(PerformanceContainer.OfficeStart);
331 aGTA = getGraphicalTestArguments(); // get new TestArguments
332 aGTA.getPerformance().setTime(PerformanceContainer.OfficeStart, nStartTime);
335 // Watcher Object is need in log object to give a simple way to say if a running office is alive.
336 // As long as a log comes, it pings the Watcher and says the office is alive, if not an
337 // internal counter increase and at a given point (300 seconds) the office is killed.
338 GlobalLogWriter.get().println("Set office watcher");
339 OfficeWatcher aWatcher = (OfficeWatcher)param.get("Watcher");
340 GlobalLogWriter.get().setWatcher(aWatcher);
341 // initializeWatcher(param);
343 String sStatusRunThrough = "";
344 String sStatusMessage = "";
347 DB.destination_start();
348 // better was:
349 // load document
350 // create postscript from document
351 // check file
352 GraphicalDifferenceCheck.checkOneFile(_sInputFile, _sOutputPath, _sReferencePath, _sDiffPath, aGTA);
353 sStatusRunThrough = "PASSED, OK";
354 DB.destination_finished();
356 catch(ConvWatchCancelException e)
358 assure(e.getMessage(), false, true);
359 sStatusRunThrough = "CANCELLED, FAILED";
360 sStatusMessage = e.getMessage();
361 DB.destination_failed(sStatusRunThrough, sStatusMessage);
363 catch(ConvWatchException e)
365 assure(e.getMessage(), false, true);
366 sStatusMessage = e.getMessage();
367 sStatusRunThrough = "PASSED, FAILED";
368 DB.destination_failed(sStatusRunThrough, sStatusMessage);
370 catch(com.sun.star.lang.DisposedException e)
372 assure(e.getMessage(), false, true);
373 sStatusMessage = e.getMessage();
374 sStatusRunThrough = "FAILED, FAILED";
375 DB.destination_failed(sStatusRunThrough, sStatusMessage);
378 GlobalLogWriter.get().println("Watcher count is: " + aWatcher.getPing());
380 // Office shutdown
381 if (aProvider != null)
383 aProvider.closeExistingOffice(param, true);
384 // if (OSHelper.isWindows())
385 // {
386 // aSemaphore.V(aSemaphore.getSemaphoreFile());
387 // aSemaphore.sleep(2);
388 // // wait some time maybe an other process will take the semaphore
389 // // I know, this is absolutly dirty, but the whole convwatch is dirty and need a big cleanup.
390 // }
393 // -------------------- Status --------------------
394 String fs = System.getProperty("file.separator");
395 String sBasename = FileHelper.getBasename(_sInputFile);
396 String sFilenameNoSuffix = FileHelper.getNameNoSuffix(sBasename);
398 // -------------------- List of all files -----------------
399 String sListFile;
400 if (_sNewSubDir.length() > 0)
402 sListFile = _sNewSubDir + fs + sFilenameNoSuffix + ".ini";
404 else
406 sListFile = sFilenameNoSuffix + ".ini";
408 _aLISToutput.writeValue(sListFile);
410 // -------------------- HTML --------------------
411 String sLink;
412 String sLinkDD;
413 String sLinkName;
414 String sLinkDDName;
415 String sHTMLPrefix = aGTA.getHTMLOutputPrefix();
417 GlobalLogWriter.get().println("----------------------------------------------------------------------");
418 GlobalLogWriter.get().println(" OutputPath: " + _sOutputPath);
419 GlobalLogWriter.get().println(" NewPath: " + _sNewSubDir);
420 GlobalLogWriter.get().println("----------------------------------------------------------------------");
422 // if (_sNewSubDir.length() > 0)
423 // {
424 // sLink = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + _sNewSubDir + fs + sFilenameNoSuffix + ".ini";
425 // sLinkDD = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + _sNewSubDir + fs + "DiffDiff_" + sFilenameNoSuffix + ".ini";
426 // }
427 // else
428 // {
429 sLink = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + sFilenameNoSuffix + ".ini";
430 // sLinkDD = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + _sNewSubDir + fs + "DiffDiff_" + sFilenameNoSuffix + ".ini";
431 sLinkDD = sHTMLPrefix /* + "/cw.php?inifile=" */ + _sOutputPath + fs + "DiffDiff_" + sFilenameNoSuffix + ".ini";
432 // }
433 sLinkName = sFilenameNoSuffix;
434 sLinkDDName = sFilenameNoSuffix + " (DiffDiff)";
436 if (_sDiffPath != null && _sDiffPath.length() > 0)
438 _aHTMLoutput.indexLine( sLinkDD, sLinkDDName, sLink, sLinkName, sStatusRunThrough, sStatusMessage );
440 else
442 _aHTMLoutput.indexLine( sLink, sLinkName, "", "", sStatusRunThrough, sStatusMessage );