merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / graphical / EnhancedComplexTestCase.java
blob2183bc55dcb3c2fcb981e13fc573c11bdd40eefa
1 /*
2 * ************************************************************************
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2008 by Sun Microsystems, Inc.
7 *
8 * OpenOffice.org - a multi-platform office productivity suite
9 *
10 * $RCSfile: EnhancedComplexTestCase.java,v $
11 * $Revision: 1.1.2.7 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 * ***********************************************************************
33 package graphical;
35 import complexlib.ComplexTestCase;
36 import java.io.File;
37 import java.io.FileFilter;
38 import java.util.ArrayList;
40 /**
42 * @author ll93751
44 abstract public class EnhancedComplexTestCase extends ComplexTestCase implements IDocument
48 private void callEntry(String _sEntry, ParameterHelper _aParam)
50 log.println("- next file is: ------------------------------");
51 log.println(_sEntry);
52 // TODO: check if 'sEntry' is a guilty document.
53 File aFile = new File(_aParam.getInputPath());
54 String sPath = _aParam.getInputPath();
55 // problem here, isFile() checks also if the file exists, but a not existing file is not really a directory
56 // therefore we check if the given file a path (isDirectory()) if not it must be a file
57 if (aFile.isDirectory())
60 else
62 // special case, if a file is given in inputpath
63 sPath = FileHelper.getPath(_aParam.getInputPath());
65 String sNewSubDir = FileHelper.removeFirstDirectorysAndBasenameFrom(_sEntry, sPath);
67 // String sNewReferencePath = _aParam.getReferencePath();
68 String sNewOutputPath = _aParam.getOutputPath();
69 // String sNewDiffPath = m_sDiffPath;
71 // if there exist a subdirectory, add it to all result path
72 if (sNewSubDir.length() > 0)
74 // if (sNewReferencePath != null)
75 // {
76 // sNewReferencePath = FileHelper.appendPath(sNewReferencePath, sNewSubDir);
77 // }
79 sNewOutputPath = FileHelper.appendPath(sNewOutputPath, sNewSubDir);
80 // if (sNewDiffPath != null)
81 // {
82 // sNewDiffPath = FileHelper.appendPath(sNewDiffPath, sNewSubDir);
83 // }
85 log.println("sEntry: " + _sEntry + " " /* + sNewReferencePath + " " */ + sNewOutputPath);
88 // call interface with parameters
89 try
91 checkOneFile(_sEntry, sNewOutputPath, _aParam);
93 catch (OfficeException e)
95 // TODO: unhandled yet.
96 GlobalLogWriter.println("Warning: caught OfficeException " + e.getMessage());
97 assure("Exception caught: " + e.getMessage(), false);
103 * Run through all documents found in Inputpath.
104 * Call the IDocument interface function call(...);
105 * @param _aParam
107 public void foreachDocumentinInputPath(ParameterHelper _aParam)
109 // TODO: auslagern in eine function, die ein Interface annimmt.
110 File aInputPath = new File(_aParam.getInputPath());
111 if (aInputPath.isDirectory())
113 // check a whole directory
114 // a whole directory
115 FileFilter aFileFilter = FileHelper.getFileFilter();
116 traverseDirectory(aFileFilter, _aParam);
118 else
120 callEntry(_aParam.getInputPath(), _aParam);
124 private void traverseDirectory(FileFilter _aFileFilter, ParameterHelper _aParam)
126 Object[] aList = DirectoryHelper.traverse(_aParam.getInputPath(), _aFileFilter, _aParam.isIncludeSubDirectories());
127 if (aList.length == 0)
129 log.println("Nothing to do, there are no document files found.");
131 else
133 for (int i=0;i<aList.length;i++)
135 String sEntry = (String)aList[i];
136 callEntry(sEntry, _aParam);
141 * Run through a given index.ini or run through a given directory,
142 * find all postscript or pdf files.
143 * Call the IDocument interface function call(...);
144 * @param _aParam
146 public void foreachPSorPDFinInputPath(ParameterHelper _aParam)
148 // TODO: auslagern in eine function, die ein Interface annimmt.
149 String sInputPath = _aParam.getInputPath();
150 File aInputPath = new File(sInputPath);
151 // if (!aInputPath.exists())
152 // {
153 // GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
154 // assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
155 // }
156 if (aInputPath.isDirectory())
158 // check a whole directory
159 // a whole directory
160 FileFilter aFileFilter = FileHelper.getFileFilterPSorPDF();
161 traverseDirectory(aFileFilter, _aParam);
163 else
165 // the inputpath contains a file
166 if (sInputPath.toLowerCase().endsWith(".ini"))
168 IniFile aIniFile = new IniFile(_aParam.getInputPath());
169 while (aIniFile.hasMoreElements())
171 String sKey = (String)aIniFile.nextElement();
172 String sPath = FileHelper.getPath(_aParam.getInputPath());
173 String sEntry = FileHelper.appendPath(sPath, sKey);
174 File aFile = new File(sEntry);
175 assure("File '" + sEntry + "' doesn't exists.", aFile.exists(), true);
176 if (aFile.exists())
178 callEntry(sEntry, _aParam);
182 else
184 // call for a single pdf/ps file
185 if (sInputPath.toLowerCase().endsWith(".ps") ||
186 sInputPath.toLowerCase().endsWith(".pdf") ||
187 sInputPath.toLowerCase().endsWith(".prn"))
189 callEntry(sInputPath, _aParam);
191 else
193 String sPath = FileHelper.getPath(sInputPath);
194 String sBasename = FileHelper.getBasename(sInputPath);
196 // there exist an index file, therefore we assume the given
197 // file is already converted to postscript or pdf
198 runThroughEveryReportInIndex(sPath, sBasename, _aParam);
204 private void runThroughEveryReportInIndex(String _sPath, String _sBasename, ParameterHelper _aParam)
206 String sIndexFile = FileHelper.appendPath(_sPath, "index.ini");
207 File aIndexFile = new File(sIndexFile);
208 if (aIndexFile.exists())
210 IniFile aIniFile = new IniFile(sIndexFile);
212 if (aIniFile.hasSection(_sBasename))
214 // special case for odb files
215 int nFileCount = aIniFile.getIntValue(_sBasename, "reportcount", 0);
216 ArrayList aList = new ArrayList();
217 for (int i=0;i<nFileCount;i++)
219 String sValue = aIniFile.getValue(_sBasename, "report" + i);
221 String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, sValue);
222 if (sPSorPDFName.length() > 0)
224 String sEntry = FileHelper.appendPath(_sPath, sPSorPDFName);
225 aList.add(sEntry);
228 aIniFile.close();
230 int nOkStatus = 0;
231 String sStatusRunThrough = "";
232 String sStatusInfo = "";
233 // get the bad status and store it into the
234 for (int i=0;i<aList.size();i++)
236 String sEntry = (String)aList.get(i);
237 callEntry(sEntry, _aParam);
239 // we want to know the current status of the run through
240 // if the status is greater (more bad) then the current,
241 // we will remember this. Only the very bad status will
242 // seen.
243 int nCurrentOkStatus = _aParam.getTestParameters().getInt("current_ok_status");
244 if (nCurrentOkStatus > nOkStatus)
246 sStatusRunThrough = (String)_aParam.getTestParameters().get("current_state");
247 sStatusInfo = (String)_aParam.getTestParameters().get("current_info");
248 nOkStatus = nCurrentOkStatus;
251 if (nOkStatus > 0)
253 _aParam.getTestParameters().put("last_state", sStatusRunThrough);
254 _aParam.getTestParameters().put("last_info", sStatusInfo);
257 else
259 // runThroughOneFileInIndex();
260 String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, _sBasename);
262 aIniFile.close();
264 if (sPSorPDFName.length() > 0)
266 String sEntry = FileHelper.appendPath(_sPath, sPSorPDFName);
267 callEntry(sEntry, _aParam);
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.exists())
311 // {
312 // GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
313 // assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
314 // }
315 if (aInputPath.isDirectory())
317 // check a whole directory
318 // a whole directory
319 FileFilter aFileFilter = FileHelper.getFileFilterJPEG();
320 traverseDirectory(aFileFilter, _aParam);
322 else
324 // the inputpath contains a file
325 if (sInputPath.toLowerCase().endsWith(".ini"))
327 IniFile aIniFile = new IniFile(_aParam.getInputPath());
328 while (aIniFile.hasMoreElements())
330 String sSection = (String)aIniFile.nextElement();
331 // TODO: not supported yet.
332 // callEveryPictureInIniFile(aIniFile, sSection, _aParam);
335 else
337 // call for a single jpeg file
340 String sOutputFilename = _aParam.getOutputPath();
341 if (sInputPath.toLowerCase().endsWith(".jpg") ||
342 sInputPath.toLowerCase().endsWith(".jpeg") )
344 checkOneFile(sInputPath, sOutputFilename, _aParam);
346 else
348 // check if there exists a ini file
349 String sPath = FileHelper.getPath(sInputPath);
350 String sBasename = FileHelper.getBasename(sInputPath);
352 runThroughEveryReportInIndex(sPath, sBasename, _aParam);
354 String sStatusRunThrough = (String)_aParam.getTestParameters().get("last_state");
355 String sStatusInfo = (String)_aParam.getTestParameters().get("last_info");
357 if (sStatusRunThrough != null &&
358 sStatusInfo != null )
360 // store the bad status in the <Name>.odb.ps.ini file
361 String sOutputPath = _aParam.getOutputPath();
362 String sBasenameIni = FileHelper.appendPath(sOutputPath, sBasename + ".ps.ini");
363 IniFile aBasenameIni = new IniFile(sBasenameIni);
364 aBasenameIni.insertValue("global", "state", sStatusRunThrough);
365 aBasenameIni.insertValue("global", "info", sStatusInfo);
366 aBasenameIni.close();
371 catch (OfficeException e)
373 // TODO: unhandled yet.
374 GlobalLogWriter.println("Warning: caught OfficeException " + e.getMessage());
376 // callEntry(sInputPath, _aParam);
383 * Run through a given index.ini or run through a given directory,
384 * find all ini files.
385 * Call the IDocument interface function call(...);
386 * @param _aParam
388 public void foreachResultCreateHTML(ParameterHelper _aParam)
390 // TODO: auslagern in eine function, die ein Interface annimmt.
391 String sInputPath = _aParam.getInputPath();
392 File aInputPath = new File(sInputPath);
393 // if (!aInputPath.exists())
394 // {
395 // GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
396 // assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
397 // }
399 // call for a single ini file
400 if (sInputPath.toLowerCase().endsWith(".ini") )
402 callEntry(sInputPath, _aParam);
404 else
406 // check if there exists an ini file
407 String sPath = FileHelper.getPath(sInputPath);
408 String sBasename = FileHelper.getBasename(sInputPath);
410 runThroughEveryReportInIndex(sPath, sBasename, _aParam);
412 // Create a HTML page which shows locally to all files in .odb
413 if (sInputPath.toLowerCase().endsWith(".odb"))
415 String sIndexFile = FileHelper.appendPath(sPath, "index.ini");
416 File aIndexFile = new File(sIndexFile);
417 if (aIndexFile.exists())
419 IniFile aIniFile = new IniFile(sIndexFile);
421 if (aIniFile.hasSection(sBasename))
423 // special case for odb files
424 int nFileCount = aIniFile.getIntValue(sBasename, "reportcount", 0);
425 ArrayList aList = new ArrayList();
426 for (int i=0;i<nFileCount;i++)
428 String sValue = aIniFile.getValue(sBasename, "report" + i);
430 String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, sValue);
431 if (sPSorPDFName.length() > 0)
433 aList.add(sPSorPDFName);
436 if (aList.size() > 0)
438 // HTML output for the odb file, shows only all other documents.
439 HTMLResult aOutputter = new HTMLResult(sPath, sBasename + ".ps.html" );
440 aOutputter.header("content of DB file: " + sBasename);
441 aOutputter.indexSection(sBasename);
443 for (int i=0;i<aList.size();i++)
445 String sPSFile = (String)aList.get(i);
447 // TODO: this information has to come out of the ini files
448 String sStatusRunThrough = "";
449 String sStatusMessage = "";
451 String sHTMLFile = sPSFile + ".html";
452 aOutputter.indexLine(sHTMLFile, sPSFile, sStatusRunThrough, sStatusMessage);
454 aOutputter.close();
456 // String sHTMLFile = FileHelper.appendPath(sPath, sBasename + ".ps.html");
457 // try
458 // {
460 // FileOutputStream out2 = new FileOutputStream(sHTMLFile);
461 // PrintStream out = new PrintStream(out2);
463 // out.println("<HTML>");
464 // out.println("<BODY>");
465 // for (int i=0;i<aList.size();i++)
466 // {
467 // // <A href="link">blah</A>
468 // String sPSFile = (String)aList.get(i);
469 // out.print("<A href=\"");
470 // out.print(sPSFile + ".html");
471 // out.print("\">");
472 // out.print(sPSFile);
473 // out.println("</A>");
474 // out.println("<BR>");
475 // }
476 // out.println("</BODY></HTML>");
477 // out.close();
478 // out2.close();
479 // }
480 // catch (java.io.IOException e)
481 // {
483 // }
486 aIniFile.close();