PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/qadevOOo/runner/convwatch/ConvWatch.java

https://bitbucket.org/markjenkins/libreoffice_ubuntu-debian-fixes
Java | 419 lines | 255 code | 65 blank | 99 comment | 42 complexity | 8825461b67d504c992261d6c2d7ab543 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause-No-Nuclear-License-2014
  1. /*
  2. * This file is part of the LibreOffice project.
  3. *
  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/.
  7. *
  8. * This file incorporates work covered by the following license notice:
  9. *
  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 .
  17. */
  18. package convwatch;
  19. import convwatch.ConvWatchException;
  20. import convwatch.ConvWatchCancelException;
  21. import convwatch.FileHelper;
  22. import convwatch.OfficePrint;
  23. import convwatch.PRNCompare;
  24. import convwatch.StatusHelper;
  25. import helper.URLHelper;
  26. import java.io.File;
  27. public class ConvWatch
  28. {
  29. String getBuildID_FromFile(String _sInfoFile)
  30. {
  31. String sBuildID = "";
  32. IniFile aIniFile = new IniFile(_sInfoFile);
  33. if (aIniFile.is())
  34. {
  35. sBuildID = aIniFile.getValue("", "buildid");
  36. }
  37. return sBuildID;
  38. }
  39. /**
  40. * Check if given document (_sAbsoluteInputFile) and it's postscript representation (_sAbsoluteReferenceFile) produce
  41. * the same output like the StarOffice / OpenOffice.org which is accessable with XMultiServiceFactory.
  42. * Here a simple graphically difference check is run through.
  43. *
  44. * Hint: In the OutputPath all needed files will create, there must
  45. * be very much space. It's not possible to say how much.
  46. * One page need up to 800kb as jpeg.
  47. * Sample: If a document contains 2 pages, we need 2*800kb for prn
  48. * output and 2*800kb for ps output and 2*800kb for it's difference
  49. * output. So up to 4800kb or 4.8mb.
  50. *
  51. * RAM is need least 300mb. Will say, it's tested on a pc with 128mb RAM and 256mb swap.
  52. *
  53. * It's also absolutlly impossible to say, how much time this functions consume.
  54. */
  55. StatusHelper[] createPostscriptStartCheck(GraphicalTestArguments _aGTA,
  56. String _sOutputPath, String _sAbsoluteInputFile, String _sAbsoluteReferenceFile)
  57. throws ConvWatchCancelException
  58. {
  59. // TODO: some more checks
  60. if (! FileHelper.exists(_sAbsoluteInputFile))
  61. {
  62. throw new ConvWatchCancelException("createPostscriptStartCheck: Input file: " + _sAbsoluteInputFile + " does not exist.");
  63. }
  64. if (_sAbsoluteReferenceFile == null)
  65. {
  66. // we assume, that the prn file is near the document
  67. String sAbsoluteInputFileNoSuffix = FileHelper.getNameNoSuffix(_sAbsoluteInputFile);
  68. _sAbsoluteReferenceFile = sAbsoluteInputFileNoSuffix + ".prn";
  69. }
  70. String fs = System.getProperty("file.separator");
  71. File aAbsoluteReferenceFile = new File(_sAbsoluteReferenceFile);
  72. if (aAbsoluteReferenceFile.isDirectory())
  73. {
  74. String sBasename = FileHelper.getBasename(_sAbsoluteInputFile);
  75. String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename);
  76. String sAbsoluteReferenceFileInfo = _sAbsoluteReferenceFile + fs + sNameNoSuffix + ".info";
  77. _sAbsoluteReferenceFile = _sAbsoluteReferenceFile + fs + sNameNoSuffix + ".prn";
  78. // Read the reference from the info file
  79. String sRefBuildID = "";
  80. if (FileHelper.exists(sAbsoluteReferenceFileInfo))
  81. {
  82. sRefBuildID = getBuildID_FromFile(sAbsoluteReferenceFileInfo);
  83. }
  84. _aGTA.setRefBuildID(sRefBuildID);
  85. }
  86. else
  87. {
  88. // java file has problems to check for directories, if the given directory doesn't exist.
  89. String sName = FileHelper.getBasename(_sAbsoluteReferenceFile);
  90. // thanks to Mircosoft, every document has a suffix, so if a name doesn't have a suffix, it must be a directory name
  91. int nIdx = sName.indexOf('.');
  92. if (nIdx == -1)
  93. {
  94. // must be a directory
  95. throw new ConvWatchCancelException("createPostscriptStartCheck: Given reference directory: '" + _sAbsoluteReferenceFile + "' does not exist.");
  96. }
  97. }
  98. boolean bAbsoluteReferenceFile = true;
  99. if (! FileHelper.exists(_sAbsoluteReferenceFile))
  100. {
  101. if (_aGTA.createDefaultReference())
  102. {
  103. GlobalLogWriter.get().println("Reference File doesn't exist, will create a default");
  104. bAbsoluteReferenceFile = false;
  105. }
  106. else
  107. {
  108. throw new ConvWatchCancelException("createPostscriptStartCheck: Given reference file: " + _sAbsoluteReferenceFile + " does not exist.");
  109. }
  110. }
  111. FileHelper.makeDirectories("", _sOutputPath);
  112. // runner.convwatch.compare();
  113. String sAbsoluteInputFileURL = URLHelper.getFileURLFromSystemPath(_sAbsoluteInputFile);
  114. String sInputFile = FileHelper.getBasename(_sAbsoluteInputFile);
  115. // System.out.println("InputFile: " + sInputFile);
  116. FileHelper.getNameNoSuffix(sInputFile);
  117. String sAbsoluteOutputFile = _sOutputPath + fs + sInputFile;
  118. String sAbsoluteOutputFileURL = URLHelper.getFileURLFromSystemPath(sAbsoluteOutputFile);
  119. String sReferenceFile = FileHelper.getBasename(_sAbsoluteReferenceFile);
  120. String sReferenceFileNoSuffix = FileHelper.getNameNoSuffix(sReferenceFile);
  121. String sPostScriptFile = sReferenceFileNoSuffix + ".ps";
  122. // System.out.println("PostscriptFile: " + sPostScriptFile);
  123. String sAbsolutePrintFile = _sOutputPath + fs + sPostScriptFile;
  124. String sAbsolutePrintFileURL = URLHelper.getFileURLFromSystemPath(sAbsolutePrintFile);
  125. // System.out.println("AbsoluteInputFileURL: " + sAbsoluteInputFileURL);
  126. // System.out.println("AbsoluteOutputFileURL: " + sAbsoluteOutputFileURL);
  127. // System.out.println("AbsolutePrintFileURL: " + sAbsolutePrintFileURL);
  128. // store and print the sAbsoluteInputFileURL file with StarOffice / OpenOffice.org
  129. OfficePrint.printToFile(_aGTA, sAbsoluteInputFileURL, sAbsoluteOutputFileURL, sAbsolutePrintFileURL);
  130. // wait(2);
  131. if (! FileHelper.exists(sAbsolutePrintFile))
  132. {
  133. throw new ConvWatchCancelException("createPostscriptStartCheck: Printed file " + sAbsolutePrintFile + " does not exist.");
  134. }
  135. if (bAbsoluteReferenceFile == false)
  136. {
  137. // copy AbsolutePrintFile to AbsoluteReferenceFile
  138. String sDestinationFile = sAbsolutePrintFile; // URLHelper.getSystemPathFromFileURL(...)
  139. String sSourceFile = _sAbsoluteReferenceFile;
  140. FileHelper.copy(sDestinationFile, sSourceFile);
  141. // now the fix reference of the AbsoluteReferenceFile should exist.
  142. if (! FileHelper.exists(_sAbsoluteReferenceFile))
  143. {
  144. throw new ConvWatchCancelException("createPostscriptStartCheck: Given reference file: " + _sAbsoluteReferenceFile + " does not exist, after try to copy.");
  145. }
  146. }
  147. PRNCompare a = new PRNCompare();
  148. String sInputPath = FileHelper.getPath(_sAbsoluteInputFile);
  149. String sReferencePath = FileHelper.getPath(_sAbsoluteReferenceFile);
  150. // String sReferenceFile = FileHelper.getBasename(sAbsoluteReferenceFile);
  151. // System.out.println("InputPath: " + sInputPath);
  152. // System.out.println("sReferencePath: " + sReferencePath);
  153. // System.out.println("sReferenceFile: " + sReferenceFile);
  154. a.setInputPath( sInputPath );
  155. a.setReferencePath( sReferencePath );
  156. a.setOutputPath( _sOutputPath );
  157. // a.setDocFile( "1_Gov.ppt");
  158. a.setReferenceFile( sReferenceFile );
  159. a.setPostScriptFile(sPostScriptFile );
  160. if (_aGTA.printAllPages() == true)
  161. {
  162. a.setMaxPages(9999);
  163. }
  164. else
  165. {
  166. if (_aGTA.getMaxPages() > 0)
  167. {
  168. a.setMaxPages(_aGTA.getMaxPages());
  169. }
  170. if (_aGTA.getOnlyPages().length() != 0)
  171. {
  172. // we can't interpret the string of getOnlyPages() right without much logic, so print all pages here!
  173. a.setMaxPages(9999);
  174. }
  175. }
  176. a.setResolutionInDPI(_aGTA.getResolutionInDPI());
  177. a.setBorderMove(_aGTA.getBorderMove());
  178. a.setDocumentType(_aGTA.getDocumentType());
  179. StatusHelper[] aList = a.compare();
  180. _aGTA.setBorderMove(a.getBorderMove());
  181. return aList;
  182. }
  183. // -----------------------------------------------------------------------------
  184. // This creates a status for exact on document
  185. static boolean createINIStatus(StatusHelper[] aList, String _sFilenamePrefix, String _sOutputPath, String _sAbsoluteInputFile, String _sBuildID, String _sRefBuildID)
  186. {
  187. System.getProperty("file.separator");
  188. String sBasename = FileHelper.getBasename(_sAbsoluteInputFile);
  189. String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename);
  190. // String sHTMLFile = _sFilenamePrefix + sNameNoSuffix + ".html";
  191. // HTMLOutputter HTMLoutput = HTMLOutputter.create(_sOutputPath, sHTMLFile, "", "");
  192. // HTMLoutput.header(sNameNoSuffix);
  193. // TODO: version info was fine
  194. // HTMLoutput.checkSection(sBasename);
  195. // Status end
  196. String sINIFile = _sFilenamePrefix + sNameNoSuffix + ".ini";
  197. INIOutputter INIoutput = INIOutputter.create(_sOutputPath, sINIFile, "", "");
  198. INIoutput.createHeader();
  199. // TODO: version info was fine
  200. INIoutput.writeSection("global");
  201. INIoutput.writeValue("pages", String.valueOf(aList.length));
  202. INIoutput.writeValue("buildid", _sBuildID);
  203. INIoutput.writeValue("refbuildid", _sRefBuildID);
  204. INIoutput.writeValue("diffdiff", "no");
  205. INIoutput.writeValue("basename", sBasename);
  206. boolean bResultIsOk = true; // result over all pages
  207. for (int i=0;i<aList.length; i++)
  208. {
  209. INIoutput.writeSection("page" + String.valueOf(i + 1)); // list start at point 0, but this is page 1 and so on... current_page = (i + 1)
  210. aList[i].printStatus();
  211. boolean bCurrentResult = true; // result over exact one page
  212. int nCurrentDiffStatus = aList[i].nDiffStatus;
  213. // check if the status is in a defined range
  214. if (nCurrentDiffStatus == StatusHelper.DIFF_NO_DIFFERENCES)
  215. {
  216. // ok.
  217. }
  218. else if (nCurrentDiffStatus == StatusHelper.DIFF_DIFFERENCES_FOUND && aList[i].nPercent < 5)
  219. {
  220. // ok.
  221. }
  222. else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS)
  223. {
  224. // ok.
  225. }
  226. else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND && aList[i].nPercent2 < 5)
  227. {
  228. // ok.
  229. }
  230. else
  231. {
  232. // failed.
  233. bCurrentResult = false; // logic: nDiff==0 = true if there is no difference
  234. }
  235. // Status
  236. // HTMLoutput.checkLine(aList[i], bCurrentResult);
  237. INIoutput.checkLine(aList[i], bCurrentResult);
  238. bResultIsOk &= bCurrentResult;
  239. }
  240. // Status
  241. // HTMLoutput.close();
  242. INIoutput.close();
  243. return bResultIsOk;
  244. }
  245. // -----------------------------------------------------------------------------
  246. static void createINIStatus_DiffDiff(StatusHelper[] aDiffDiffList, String _sFilenamePrefix, String _sOutputPath, String _sAbsoluteInputFile, String _sBuildID)
  247. {
  248. System.getProperty("file.separator");
  249. String sBasename = FileHelper.getBasename(_sAbsoluteInputFile);
  250. String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename);
  251. String sINIFile = _sFilenamePrefix + sNameNoSuffix + ".ini";
  252. // HTMLOutputter HTMLoutput = HTMLOutputter.create(_sOutputPath, sHTMLFile, _sFilenamePrefix, "");
  253. // HTMLoutput.header(sNameNoSuffix);
  254. // HTMLoutput.checkDiffDiffSection(sBasename);
  255. INIOutputter INIoutput = INIOutputter.create(_sOutputPath, sINIFile, _sFilenamePrefix, "");
  256. INIoutput.createHeader();
  257. // LLA? what if the are no values in the list? true or false;
  258. INIoutput.writeSection("global");
  259. INIoutput.writeValue("pages", String.valueOf(aDiffDiffList.length));
  260. INIoutput.writeValue("buildid", _sBuildID);
  261. INIoutput.writeValue("diffdiff", "yes");
  262. INIoutput.writeValue("basename", sBasename);
  263. for (int i=0;i<aDiffDiffList.length; i++)
  264. {
  265. INIoutput.writeSection("page" + String.valueOf(i + 1)); // list start at point 0, but this is page 1 and so on... current_page = (i + 1)
  266. boolean bCurrentResult = (aDiffDiffList[i].nDiffStatus == StatusHelper.DIFF_NO_DIFFERENCES); // logic: nDiff==0 = true if there is no difference
  267. // HTMLoutput.checkDiffDiffLine(aDiffDiffList[i], bCurrentResult);
  268. INIoutput.checkDiffDiffLine(aDiffDiffList[i], bCurrentResult);
  269. }
  270. // Status
  271. // HTMLoutput.close();
  272. INIoutput.close();
  273. }
  274. // -----------------------------------------------------------------------------
  275. public static boolean check(GraphicalTestArguments _aGTA,
  276. String _sOutputPath, String _sAbsoluteInputFile, String _sAbsoluteReferenceFile)
  277. throws ConvWatchCancelException, ConvWatchException
  278. {
  279. ConvWatch a = new ConvWatch();
  280. StatusHelper[] aList = a.createPostscriptStartCheck(_aGTA, _sOutputPath, _sAbsoluteInputFile, _sAbsoluteReferenceFile);
  281. DB.writeNumberOfPages(aList.length);
  282. boolean bResultIsOk = createINIStatus(aList, "", _sOutputPath, _sAbsoluteInputFile, _aGTA.getBuildID(), _aGTA.getRefBuildID());
  283. if (! bResultIsOk)
  284. {
  285. // it could be that this will store in a DB, there are problems with '\'
  286. String sErrorMessage = "Graphical compare failed with file ";
  287. String sErrorFile = _sAbsoluteInputFile.replace('\\', '/');
  288. sErrorMessage = sErrorMessage + "'" + sErrorFile + "'";
  289. DB.writeErrorFile(sErrorFile);
  290. throw new ConvWatchException(sErrorMessage);
  291. }
  292. return bResultIsOk;
  293. }
  294. // -----------------------------------------------------------------------------
  295. public static boolean checkDiffDiff(GraphicalTestArguments _aGTA,
  296. String _sOutputPath, String _sAbsoluteInputFile, String _sAbsoluteReferenceFile,
  297. String _sAbsoluteDiffPath)
  298. throws ConvWatchCancelException, ConvWatchException
  299. {
  300. ConvWatch a = new ConvWatch();
  301. _aGTA.setBorderMove(TriState.FALSE);
  302. StatusHelper[] aList = a.createPostscriptStartCheck(_aGTA, _sOutputPath, _sAbsoluteInputFile, _sAbsoluteReferenceFile);
  303. createINIStatus(aList, "", _sOutputPath, _sAbsoluteInputFile, _aGTA.getBuildID(), _aGTA.getRefBuildID());
  304. StatusHelper[] aDiffDiffList = new StatusHelper[aList.length];
  305. String fs = System.getProperty("file.separator");
  306. boolean bDiffIsOk = true;
  307. boolean bFoundAOldDiff = false;
  308. PRNCompare aCompare = new PRNCompare();
  309. // LLA? what if the are no values in the list? true or false;
  310. for (int i=0;i<aList.length; i++)
  311. {
  312. String sOrigDiffName = aList[i].m_sDiffGfx;
  313. String sDiffBasename = FileHelper.getBasename(sOrigDiffName);
  314. String sNewDiffName = _sAbsoluteDiffPath + fs + sDiffBasename;
  315. if (! FileHelper.exists(sNewDiffName))
  316. {
  317. GlobalLogWriter.get().println("checkDiffDiff: Old diff file: '" + sNewDiffName + "' does not exist." );
  318. continue;
  319. }
  320. // String sNewDiffName = _sAbsoluteDiffPath + fs + sDiffBasename;
  321. // make a simple difference between these both diff files.
  322. String sSourcePath1 = FileHelper.getPath(sOrigDiffName);
  323. String sSourceFile1 = sDiffBasename;
  324. String sSourcePath2 = _sAbsoluteDiffPath;
  325. String sSourceFile2 = sDiffBasename;
  326. StatusHelper aCurrentStatus = aCompare.checkDiffDiff(_sOutputPath, sSourcePath1, sSourceFile1, sSourcePath2, sSourceFile2);
  327. boolean bCurrentResult = (aCurrentStatus.nDiffStatus == StatusHelper.DIFF_NO_DIFFERENCES); // logic: nDiff==0 = true if there is no difference
  328. bDiffIsOk &= bCurrentResult;
  329. bFoundAOldDiff = true;
  330. aDiffDiffList[i] = aCurrentStatus;
  331. }
  332. createINIStatus_DiffDiff(aDiffDiffList, "DiffDiff_", _sOutputPath, _sAbsoluteInputFile, _aGTA.getBuildID());
  333. if (bFoundAOldDiff == false)
  334. {
  335. throw new ConvWatchCancelException("No old difference file found." );
  336. }
  337. if (! bDiffIsOk)
  338. {
  339. throw new ConvWatchException("Graphical difference compare failed with file '" + _sAbsoluteInputFile + "'");
  340. }
  341. return bDiffIsOk;
  342. }
  343. // public static void main( String[] argv )
  344. // {
  345. // PRNCompare a = new PRNCompare();
  346. // a.setInputPath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
  347. // a.setDocFile( "1_Gov.ppt");
  348. // a.setReferencePath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
  349. // a.setReferenceFile( "1_Gov.prn" );
  350. //
  351. // a.setOutputPath( "/tmp/convwatch_java");
  352. // a.setPostScriptFile("1_Gov.ps" );
  353. // }
  354. }