2 * ************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 * ***********************************************************************
32 import complexlib
.ComplexTestCase
;
34 import java
.io
.FileFilter
;
35 import java
.util
.ArrayList
;
41 abstract public class EnhancedComplexTestCase
extends ComplexTestCase
implements IDocument
45 private void callEntry(String _sEntry
, ParameterHelper _aParam
)
47 // log.println("- next file is: ------------------------------");
48 log
.println(" File: " + _sEntry
);
49 // TODO: check if 'sEntry' is a guilty document.
50 File aFile
= new File(_aParam
.getInputPath());
51 String sPath
= _aParam
.getInputPath();
52 // problem here, isFile() checks also if the file exists, but a not existing file is not really a directory
53 // therefore we check if the given file a path (isDirectory()) if not it must be a file
54 if (aFile
.isDirectory())
59 // special case, if a file is given in inputpath
60 sPath
= FileHelper
.getPath(_aParam
.getInputPath());
62 String sNewSubDir
= FileHelper
.removeFirstDirectorysAndBasenameFrom(_sEntry
, sPath
);
64 // String sNewReferencePath = _aParam.getReferencePath();
65 String sNewOutputPath
= _aParam
.getOutputPath();
66 // String sNewDiffPath = m_sDiffPath;
68 // if there exist a subdirectory, add it to all result path
69 if (sNewSubDir
.length() > 0)
71 // if (sNewReferencePath != null)
73 // sNewReferencePath = FileHelper.appendPath(sNewReferencePath, sNewSubDir);
76 sNewOutputPath
= FileHelper
.appendPath(sNewOutputPath
, sNewSubDir
);
77 // if (sNewDiffPath != null)
79 // sNewDiffPath = FileHelper.appendPath(sNewDiffPath, sNewSubDir);
82 // log.println("sEntry: " + _sEntry + " " /* + sNewReferencePath + " " */ + sNewOutputPath);
83 log
.println("Outputpath: " + sNewOutputPath
);
86 // call interface with parameters
89 checkOneFile(_sEntry
, sNewOutputPath
, _aParam
);
91 catch (OfficeException e
)
93 // TODO: unhandled yet.
94 GlobalLogWriter
.println("Warning: caught OfficeException " + e
.getMessage());
95 assure("Exception caught: " + e
.getMessage(), false);
101 * Run through all documents found in Inputpath.
102 * Call the IDocument interface function call(...);
105 public void foreachDocumentinInputPath(ParameterHelper _aParam
)
107 // TODO: auslagern in eine function, die ein Interface annimmt.
108 File aInputPath
= new File(_aParam
.getInputPath());
109 if (aInputPath
.isDirectory())
111 // check a whole directory
113 FileFilter aFileFilter
= FileHelper
.getFileFilter();
114 traverseDirectory(aFileFilter
, _aParam
);
118 callEntry(_aParam
.getInputPath(), _aParam
);
122 private void traverseDirectory(FileFilter _aFileFilter
, ParameterHelper _aParam
)
124 Object
[] aList
= DirectoryHelper
.traverse(_aParam
.getInputPath(), _aFileFilter
, _aParam
.isIncludeSubDirectories());
125 if (aList
.length
== 0)
127 log
.println("Nothing to do, there are no document files found.");
131 for (int i
=0;i
<aList
.length
;i
++)
133 String sEntry
= (String
)aList
[i
];
134 callEntry(sEntry
, _aParam
);
139 * Run through a given index.ini or run through a given directory,
140 * find all postscript or pdf files.
141 * Call the IDocument interface function call(...);
144 public void foreachPSorPDFinInputPath(ParameterHelper _aParam
)
146 // TODO: auslagern in eine function, die ein Interface annimmt.
147 String sInputPath
= _aParam
.getInputPath();
148 File aInputPath
= new File(sInputPath
);
149 // if (!aInputPath.exists())
151 // GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
152 // assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
154 if (aInputPath
.isDirectory())
156 // check a whole directory
158 FileFilter aFileFilter
= FileHelper
.getFileFilterPSorPDF();
159 traverseDirectory(aFileFilter
, _aParam
);
163 // the inputpath contains a file
164 if (sInputPath
.toLowerCase().endsWith(".ini"))
166 IniFile aIniFile
= new IniFile(_aParam
.getInputPath());
167 while (aIniFile
.hasMoreElements())
169 String sKey
= (String
)aIniFile
.nextElement();
170 String sPath
= FileHelper
.getPath(_aParam
.getInputPath());
171 String sEntry
= FileHelper
.appendPath(sPath
, sKey
);
172 File aFile
= new File(sEntry
);
173 assure("File '" + sEntry
+ "' doesn't exists.", aFile
.exists(), true);
176 callEntry(sEntry
, _aParam
);
182 // call for a single pdf/ps file
183 if (sInputPath
.toLowerCase().endsWith(".ps") ||
184 sInputPath
.toLowerCase().endsWith(".pdf") ||
185 sInputPath
.toLowerCase().endsWith(".prn"))
187 callEntry(sInputPath
, _aParam
);
191 String sInputPathWithPDF
= sInputPath
+ ".pdf";
192 File aInputPathWithPDF
= new File(sInputPathWithPDF
);
194 if (aInputPathWithPDF
.exists() &&
195 _aParam
.getReferenceType().toLowerCase().equals("pdf"))
197 // create PDF only if a pdf file exists and creatortype is set to PDF
198 callEntry(sInputPathWithPDF
, _aParam
);
202 String sInputPathWithPS
= sInputPath
+ ".ps";
204 File aInputPathWithPS
= new File(sInputPathWithPS
);
205 if (aInputPathWithPS
.exists())
207 callEntry(sInputPathWithPS
, _aParam
);
211 String sPath
= FileHelper
.getPath(sInputPath
);
212 String sBasename
= FileHelper
.getBasename(sInputPath
);
214 // there exist an index file, therefore we assume the given
215 // file is already converted to postscript or pdf
216 runThroughEveryReportInIndex(sPath
, sBasename
, _aParam
);
224 private void runThroughEveryReportInIndex(String _sPath
, String _sBasename
, ParameterHelper _aParam
)
226 String sIndexFile
= FileHelper
.appendPath(_sPath
, "index.ini");
227 File aIndexFile
= new File(sIndexFile
);
228 if (aIndexFile
.exists())
230 IniFile aIniFile
= new IniFile(sIndexFile
);
232 if (aIniFile
.hasSection(_sBasename
))
234 // special case for odb files
235 int nFileCount
= aIniFile
.getIntValue(_sBasename
, "reportcount", 0);
236 ArrayList
<String
> aList
= new ArrayList
<String
>();
237 for (int i
=0;i
<nFileCount
;i
++)
239 String sValue
= aIniFile
.getValue(_sBasename
, "report" + i
);
241 String sPSorPDFName
= getPSorPDFNameFromIniFile(aIniFile
, sValue
);
242 if (sPSorPDFName
.length() > 0)
244 String sEntry
= FileHelper
.appendPath(_sPath
, sPSorPDFName
);
251 String sStatusRunThrough
= "";
252 String sStatusInfo
= "";
253 // get the bad status and store it into the
254 for (int i
=0;i
<aList
.size();i
++)
256 String sEntry
= aList
.get(i
);
259 callEntry(sEntry
, _aParam
);
261 catch (AssureException e
)
263 // we only need to catch the assure()
266 // we want to know the current status of the run through
267 // if the status is greater (more bad) then the current,
268 // we will remember this. Only the very bad status will
270 int nCurrentOkStatus
= _aParam
.getTestParameters().getInt("current_ok_status");
271 if (nCurrentOkStatus
> nOkStatus
)
273 sStatusRunThrough
= (String
)_aParam
.getTestParameters().get("current_state");
274 sStatusInfo
= (String
)_aParam
.getTestParameters().get("current_info");
275 nOkStatus
= nCurrentOkStatus
;
280 _aParam
.getTestParameters().put("last_state", sStatusRunThrough
);
281 _aParam
.getTestParameters().put("last_info", sStatusInfo
);
286 // runThroughOneFileInIndex();
287 String sPSorPDFName
= getPSorPDFNameFromIniFile(aIniFile
, _sBasename
);
291 if (sPSorPDFName
.length() > 0)
293 String sEntry
= FileHelper
.appendPath(_sPath
, sPSorPDFName
);
294 callEntry(sEntry
, _aParam
);
300 assure("File '" + sIndexFile
+ "' doesn't exists.", aIndexFile
.exists(), true);
304 private String
getPSorPDFNameFromIniFile(IniFile _aIniFile
, String _sName
)
306 boolean bHasPostscriptOrPDF
= false;
307 String sPSBasename
= _sName
+ ".ps";
308 if (_aIniFile
.hasSection(sPSBasename
)) // checks for Postscript
310 bHasPostscriptOrPDF
= true;
314 sPSBasename
= _sName
+ ".pdf"; // checks for PDF
315 if (_aIniFile
.hasSection(sPSBasename
))
317 bHasPostscriptOrPDF
= true;
320 if (bHasPostscriptOrPDF
)
327 public void runThroughOneFileInIndex(String _sPath
, String _sBasename
, ParameterHelper _aParam
)
332 * Run through a given index.ini or run through a given directory,
333 * find all postscript or pdf files.
334 * Call the IDocument interface function call(...);
337 public void foreachJPEGcompareWithJPEG(ParameterHelper _aParam
)
339 // TODO: auslagern in eine function, die ein Interface annimmt.
340 String sInputPath
= _aParam
.getInputPath();
341 File aInputPath
= new File(sInputPath
);
342 // if (!aInputPath.exists())
344 // GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
345 // assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
347 if (aInputPath
.isDirectory())
349 // check a whole directory
351 FileFilter aFileFilter
= FileHelper
.getFileFilterJPEG();
352 traverseDirectory(aFileFilter
, _aParam
);
356 // the inputpath contains a file
357 if (sInputPath
.toLowerCase().endsWith(".ini"))
359 IniFile aIniFile
= new IniFile(_aParam
.getInputPath());
360 while (aIniFile
.hasMoreElements())
362 String sSection
= (String
)aIniFile
.nextElement();
363 // TODO: not supported yet.
364 // callEveryPictureInIniFile(aIniFile, sSection, _aParam);
369 // call for a single jpeg file
372 String sOutputFilename
= _aParam
.getOutputPath();
373 if (sInputPath
.toLowerCase().endsWith(".jpg") ||
374 sInputPath
.toLowerCase().endsWith(".jpeg") )
376 checkOneFile(sInputPath
, sOutputFilename
, _aParam
);
380 // check if there exists a ini file
381 String sPath
= FileHelper
.getPath(sInputPath
);
382 String sBasename
= FileHelper
.getBasename(sInputPath
);
384 runThroughEveryReportInIndex(sPath
, sBasename
, _aParam
);
386 String sStatusRunThrough
= (String
)_aParam
.getTestParameters().get("last_state");
387 String sStatusInfo
= (String
)_aParam
.getTestParameters().get("last_info");
389 if (sStatusRunThrough
!= null &&
390 sStatusInfo
!= null )
392 // store the bad status in the <Name>.odb.ps.ini file
393 String sOutputPath
= _aParam
.getOutputPath();
394 String sBasenameIni
= FileHelper
.appendPath(sOutputPath
, sBasename
+ ".ps.ini");
395 IniFile aBasenameIni
= new IniFile(sBasenameIni
);
396 aBasenameIni
.insertValue("global", "state", sStatusRunThrough
);
397 aBasenameIni
.insertValue("global", "info", sStatusInfo
);
398 aBasenameIni
.close();
403 catch (OfficeException e
)
405 // TODO: unhandled yet.
406 GlobalLogWriter
.println("Warning: caught OfficeException " + e
.getMessage());
408 // callEntry(sInputPath, _aParam);
415 * Run through a given index.ini or run through a given directory,
416 * find all ini files.
417 * Call the IDocument interface function call(...);
420 public void foreachResultCreateHTML(ParameterHelper _aParam
)
422 // TODO: auslagern in eine function, die ein Interface annimmt.
423 String sInputPath
= _aParam
.getInputPath();
424 File aInputPath
= new File(sInputPath
);
425 // if (!aInputPath.exists())
427 // GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
428 // assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
431 // call for a single ini file
432 if (sInputPath
.toLowerCase().endsWith(".ini") )
434 callEntry(sInputPath
, _aParam
);
438 // check if there exists an ini file
439 String sPath
= FileHelper
.getPath(sInputPath
);
440 String sBasename
= FileHelper
.getBasename(sInputPath
);
442 runThroughEveryReportInIndex(sPath
, sBasename
, _aParam
);
444 // Create a HTML page which shows locally to all files in .odb
445 if (sInputPath
.toLowerCase().endsWith(".odb"))
447 String sIndexFile
= FileHelper
.appendPath(sPath
, "index.ini");
448 File aIndexFile
= new File(sIndexFile
);
449 if (aIndexFile
.exists())
451 IniFile aIniFile
= new IniFile(sIndexFile
);
453 if (aIniFile
.hasSection(sBasename
))
455 // special case for odb files
456 int nFileCount
= aIniFile
.getIntValue(sBasename
, "reportcount", 0);
457 ArrayList
<String
> aList
= new ArrayList
<String
>();
458 for (int i
=0;i
<nFileCount
;i
++)
460 String sValue
= aIniFile
.getValue(sBasename
, "report" + i
);
462 String sPSorPDFName
= getPSorPDFNameFromIniFile(aIniFile
, sValue
);
463 if (sPSorPDFName
.length() > 0)
465 aList
.add(sPSorPDFName
);
468 if (aList
.size() > 0)
470 // HTML output for the odb file, shows only all other documents.
471 HTMLResult aOutputter
= new HTMLResult(sPath
, sBasename
+ ".ps.html" );
472 aOutputter
.header("content of DB file: " + sBasename
);
473 aOutputter
.indexSection(sBasename
);
475 for (int i
=0;i
<aList
.size();i
++)
477 String sPSFile
= aList
.get(i
);
479 // Read information out of the ini files
480 String sIndexFile2
= FileHelper
.appendPath(sPath
, sPSFile
+ ".ini");
481 IniFile aIniFile2
= new IniFile(sIndexFile2
);
482 String sStatusRunThrough
= aIniFile2
.getValue("global", "state");
483 String sStatusMessage
= ""; // aIniFile2.getValue("global", "info");
487 String sHTMLFile
= sPSFile
+ ".html";
488 aOutputter
.indexLine(sHTMLFile
, sPSFile
, sStatusRunThrough
, sStatusMessage
);
492 // String sHTMLFile = FileHelper.appendPath(sPath, sBasename + ".ps.html");
496 // FileOutputStream out2 = new FileOutputStream(sHTMLFile);
497 // PrintStream out = new PrintStream(out2);
499 // out.println("<HTML>");
500 // out.println("<BODY>");
501 // for (int i=0;i<aList.size();i++)
503 // // <A href="link">blah</A>
504 // String sPSFile = (String)aList.get(i);
505 // out.print("<A href=\"");
506 // out.print(sPSFile + ".html");
508 // out.print(sPSFile);
509 // out.println("</A>");
510 // out.println("<BR>");
512 // out.println("</BODY></HTML>");
516 // catch (java.io.IOException e)