bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / graphical / EnhancedComplexTestCase.java
blob65a2ce6f8360cb715d1bca6f15551d356b4af98e
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 graphical;
21 import complexlib.ComplexTestCase;
22 import java.io.File;
23 import java.io.FileFilter;
24 import java.util.ArrayList;
26 abstract public class EnhancedComplexTestCase extends ComplexTestCase implements IDocument
30 private void callEntry(String _sEntry, ParameterHelper _aParam)
32 log.println(" File: " + _sEntry);
33 // TODO: check if 'sEntry' is a guilty document.
34 File aFile = new File(_aParam.getInputPath());
35 String sPath = _aParam.getInputPath();
36 // problem here, isFile() checks also if the file exists, but a not existing file is not really a directory
37 // therefore we check if the given file a path (isDirectory()) if not it must be a file
38 if (aFile.isDirectory())
41 else
43 // special case, if a file is given in inputpath
44 sPath = FileHelper.getPath(_aParam.getInputPath());
46 String sNewSubDir = FileHelper.removeFirstDirectorysAndBasenameFrom(_sEntry, sPath);
48 String sNewOutputPath = _aParam.getOutputPath();
50 // if there exist a subdirectory, add it to all result path
51 if (sNewSubDir.length() > 0)
54 sNewOutputPath = FileHelper.appendPath(sNewOutputPath, sNewSubDir);
56 log.println("Outputpath: " + sNewOutputPath);
59 // call interface with parameters
60 try
62 checkOneFile(_sEntry, sNewOutputPath, _aParam);
64 catch (OfficeException e)
66 // TODO: unhandled yet.
67 GlobalLogWriter.println("Warning: caught OfficeException " + e.getMessage());
68 assure("Exception caught: " + e.getMessage(), false);
73 /**
74 * Run through all documents found in Inputpath.
75 * Call the IDocument interface function call(...);
76 * @param _aParam
78 public void foreachDocumentinInputPath(ParameterHelper _aParam)
80 // TODO: auslagern in eine function, die ein Interface annimmt.
81 File aInputPath = new File(_aParam.getInputPath());
82 if (aInputPath.isDirectory())
84 // check a whole directory
85 // a whole directory
86 FileFilter aFileFilter = FileHelper.getFileFilter();
87 traverseDirectory(aFileFilter, _aParam);
89 else
91 callEntry(_aParam.getInputPath(), _aParam);
95 private void traverseDirectory(FileFilter _aFileFilter, ParameterHelper _aParam)
97 Object[] aList = DirectoryHelper.traverse(_aParam.getInputPath(), _aFileFilter, _aParam.isIncludeSubDirectories());
98 if (aList.length == 0)
100 log.println("Nothing to do, there are no document files found.");
102 else
104 for (int i=0;i<aList.length;i++)
106 String sEntry = (String)aList[i];
107 callEntry(sEntry, _aParam);
112 * Run through a given index.ini or run through a given directory,
113 * find all postscript or pdf files.
114 * Call the IDocument interface function call(...);
115 * @param _aParam
117 public void foreachPSorPDFinInputPath(ParameterHelper _aParam)
119 // TODO: auslagern in eine function, die ein Interface annimmt.
120 String sInputPath = _aParam.getInputPath();
121 File aInputPath = new File(sInputPath);
122 if (aInputPath.isDirectory())
124 // check a whole directory
125 // a whole directory
126 FileFilter aFileFilter = FileHelper.getFileFilterPSorPDF();
127 traverseDirectory(aFileFilter, _aParam);
129 else
131 // the inputpath contains a file
132 if (sInputPath.toLowerCase().endsWith(".ini"))
134 IniFile aIniFile = new IniFile(_aParam.getInputPath());
135 while (aIniFile.hasMoreElements())
137 String sKey = aIniFile.nextElement();
138 String sPath = FileHelper.getPath(_aParam.getInputPath());
139 String sEntry = FileHelper.appendPath(sPath, sKey);
140 File aFile = new File(sEntry);
141 assure("File '" + sEntry + "' doesn't exists.", aFile.exists(), true);
142 if (aFile.exists())
144 callEntry(sEntry, _aParam);
148 else
150 // call for a single pdf/ps file
151 if (sInputPath.toLowerCase().endsWith(".ps") ||
152 sInputPath.toLowerCase().endsWith(".pdf") ||
153 sInputPath.toLowerCase().endsWith(".prn"))
155 callEntry(sInputPath, _aParam);
157 else
159 String sInputPathWithPDF = sInputPath + ".pdf";
160 File aInputPathWithPDF = new File(sInputPathWithPDF);
162 if (aInputPathWithPDF.exists() &&
163 _aParam.getReferenceType().toLowerCase().equals("pdf"))
165 // create PDF only if a pdf file exists and creatortype is set to PDF
166 callEntry(sInputPathWithPDF, _aParam);
168 else
170 String sInputPathWithPS = sInputPath + ".ps";
172 File aInputPathWithPS = new File(sInputPathWithPS);
173 if (aInputPathWithPS.exists())
175 callEntry(sInputPathWithPS, _aParam);
177 else
179 String sPath = FileHelper.getPath(sInputPath);
180 String sBasename = FileHelper.getBasename(sInputPath);
182 // there exist an index file, therefore we assume the given
183 // file is already converted to postscript or pdf
184 runThroughEveryReportInIndex(sPath, sBasename, _aParam);
192 private void runThroughEveryReportInIndex(String _sPath, String _sBasename, ParameterHelper _aParam)
194 String sIndexFile = FileHelper.appendPath(_sPath, "index.ini");
195 File aIndexFile = new File(sIndexFile);
196 if (aIndexFile.exists())
198 IniFile aIniFile = new IniFile(sIndexFile);
200 if (aIniFile.hasSection(_sBasename))
202 // special case for odb files
203 int nFileCount = aIniFile.getIntValue(_sBasename, "reportcount", 0);
204 ArrayList<String> aList = new ArrayList<String>();
205 for (int i=0;i<nFileCount;i++)
207 String sValue = aIniFile.getValue(_sBasename, "report" + i);
209 String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, sValue);
210 if (sPSorPDFName.length() > 0)
212 String sEntry = FileHelper.appendPath(_sPath, sPSorPDFName);
213 aList.add(sEntry);
216 aIniFile.close();
218 int nOkStatus = 0;
219 String sStatusRunThrough = "";
220 String sStatusInfo = "";
221 // get the bad status and store it into the
222 for (int i=0;i<aList.size();i++)
224 String sEntry = aList.get(i);
227 callEntry(sEntry, _aParam);
229 catch (AssureException e)
231 // we only need to catch the assure()
232 // nOkStatus += 2;
234 // we want to know the current status of the run through
235 // if the status is greater (more bad) then the current,
236 // we will remember this. Only the very bad status will
237 // seen.
238 int nCurrentOkStatus = _aParam.getTestParameters().getInt("current_ok_status");
239 if (nCurrentOkStatus > nOkStatus)
241 sStatusRunThrough = (String)_aParam.getTestParameters().get("current_state");
242 sStatusInfo = (String)_aParam.getTestParameters().get("current_info");
243 nOkStatus = nCurrentOkStatus;
246 if (nOkStatus > 0)
248 _aParam.getTestParameters().put("last_state", sStatusRunThrough);
249 _aParam.getTestParameters().put("last_info", sStatusInfo);
252 else
254 // runThroughOneFileInIndex();
255 String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, _sBasename);
257 aIniFile.close();
259 if (sPSorPDFName.length() > 0)
261 String sEntry = FileHelper.appendPath(_sPath, sPSorPDFName);
262 callEntry(sEntry, _aParam);
266 else
268 assure("File '" + sIndexFile + "' doesn't exists.", aIndexFile.exists(), true);
272 private String getPSorPDFNameFromIniFile(IniFile _aIniFile, String _sName)
274 boolean bHasPostscriptOrPDF = false;
275 String sPSBasename = _sName + ".ps";
276 if (_aIniFile.hasSection(sPSBasename)) // checks for Postscript
278 bHasPostscriptOrPDF = true;
280 else
282 sPSBasename = _sName + ".pdf"; // checks for PDF
283 if (_aIniFile.hasSection(sPSBasename))
285 bHasPostscriptOrPDF = true;
288 if (bHasPostscriptOrPDF)
290 return sPSBasename;
292 return "";
295 public void runThroughOneFileInIndex(String _sPath, String _sBasename, ParameterHelper _aParam)
300 * Run through a given index.ini or run through a given directory,
301 * find all postscript or pdf files.
302 * Call the IDocument interface function call(...);
303 * @param _aParam
305 public void foreachJPEGcompareWithJPEG(ParameterHelper _aParam)
307 // TODO: auslagern in eine function, die ein Interface annimmt.
308 String sInputPath = _aParam.getInputPath();
309 File aInputPath = new File(sInputPath);
310 if (aInputPath.isDirectory())
312 // check a whole directory
313 // a whole directory
314 FileFilter aFileFilter = FileHelper.getFileFilterJPEG();
315 traverseDirectory(aFileFilter, _aParam);
317 else
319 // the inputpath contains a file
320 if (sInputPath.toLowerCase().endsWith(".ini"))
322 IniFile aIniFile = new IniFile(_aParam.getInputPath());
323 while (aIniFile.hasMoreElements())
325 aIniFile.nextElement();
328 else
330 // call for a single jpeg file
333 String sOutputFilename = _aParam.getOutputPath();
334 if (sInputPath.toLowerCase().endsWith(".jpg") ||
335 sInputPath.toLowerCase().endsWith(".jpeg") )
337 checkOneFile(sInputPath, sOutputFilename, _aParam);
339 else
341 // check if there exists a ini file
342 String sPath = FileHelper.getPath(sInputPath);
343 String sBasename = FileHelper.getBasename(sInputPath);
345 runThroughEveryReportInIndex(sPath, sBasename, _aParam);
347 String sStatusRunThrough = (String)_aParam.getTestParameters().get("last_state");
348 String sStatusInfo = (String)_aParam.getTestParameters().get("last_info");
350 if (sStatusRunThrough != null &&
351 sStatusInfo != null )
353 // store the bad status in the <Name>.odb.ps.ini file
354 String sOutputPath = _aParam.getOutputPath();
355 String sBasenameIni = FileHelper.appendPath(sOutputPath, sBasename + ".ps.ini");
356 IniFile aBasenameIni = new IniFile(sBasenameIni);
357 aBasenameIni.insertValue("global", "state", sStatusRunThrough);
358 aBasenameIni.insertValue("global", "info", sStatusInfo);
359 aBasenameIni.close();
364 catch (OfficeException e)
366 // TODO: unhandled yet.
367 GlobalLogWriter.println("Warning: caught OfficeException " + e.getMessage());
375 * Run through a given index.ini or run through a given directory,
376 * find all ini files.
377 * Call the IDocument interface function call(...);
378 * @param _aParam
380 public void foreachResultCreateHTML(ParameterHelper _aParam)
382 // TODO: auslagern in eine function, die ein Interface annimmt.
383 String sInputPath = _aParam.getInputPath();
384 new File(sInputPath);
386 // call for a single ini file
387 if (sInputPath.toLowerCase().endsWith(".ini") )
389 callEntry(sInputPath, _aParam);
391 else
393 // check if there exists an ini file
394 String sPath = FileHelper.getPath(sInputPath);
395 String sBasename = FileHelper.getBasename(sInputPath);
397 runThroughEveryReportInIndex(sPath, sBasename, _aParam);
399 // Create a HTML page which shows locally to all files in .odb
400 if (sInputPath.toLowerCase().endsWith(".odb"))
402 String sIndexFile = FileHelper.appendPath(sPath, "index.ini");
403 File aIndexFile = new File(sIndexFile);
404 if (aIndexFile.exists())
406 IniFile aIniFile = new IniFile(sIndexFile);
408 if (aIniFile.hasSection(sBasename))
410 // special case for odb files
411 int nFileCount = aIniFile.getIntValue(sBasename, "reportcount", 0);
412 ArrayList<String> aList = new ArrayList<String>();
413 for (int i=0;i<nFileCount;i++)
415 String sValue = aIniFile.getValue(sBasename, "report" + i);
417 String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, sValue);
418 if (sPSorPDFName.length() > 0)
420 aList.add(sPSorPDFName);
423 if (aList.size() > 0)
425 // HTML output for the odb file, shows only all other documents.
426 HTMLResult aOutputter = new HTMLResult(sPath, sBasename + ".ps.html" );
427 aOutputter.header("content of DB file: " + sBasename);
428 aOutputter.indexSection(sBasename);
430 for (int i=0;i<aList.size();i++)
432 String sPSFile = aList.get(i);
434 // Read information out of the ini files
435 String sIndexFile2 = FileHelper.appendPath(sPath, sPSFile + ".ini");
436 IniFile aIniFile2 = new IniFile(sIndexFile2);
437 String sStatusRunThrough = aIniFile2.getValue("global", "state");
438 String sStatusMessage = "";
439 aIniFile2.close();
442 String sHTMLFile = sPSFile + ".html";
443 aOutputter.indexLine(sHTMLFile, sPSFile, sStatusRunThrough, sStatusMessage);
445 aOutputter.close();
449 aIniFile.close();