1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package convwatch; 25 26 // imports 27 import java.io.File; 28 import java.io.FileFilter; 29 import java.util.ArrayList; 30 31 import com.sun.star.lang.XMultiServiceFactory; 32 33 import convwatch.DirectoryHelper; 34 import convwatch.ConvWatchException; 35 import convwatch.EnhancedComplexTestCase; 36 import convwatch.PropertyName; 37 import helper.OfficeProvider; 38 import convwatch.PerformanceContainer; 39 40 /** 41 * The following Complex Test will test 42 * an already created document and it's postscript output (by an older office version) 43 * with a new office version. 44 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick. 45 * Read the manual for more information. 46 * 47 * this is only the starter program 48 * more is found in qadevOOo/runner/convwatch/* 49 */ 50 51 public class ReferenceBuilder extends EnhancedComplexTestCase 52 { 53 // The first of the mandatory functions: 54 /** 55 * Return the name of the test. 56 * In this case it is the actual name of the service. 57 * @return The tested service. 58 */ getTestObjectName()59 public String getTestObjectName() { 60 return "ReferenceBuilder runner"; 61 } 62 63 // The second of the mandatory functions: return all test methods as an 64 // array. There is only one test function in this example. 65 /** 66 * Return all test methods. 67 * @return The test methods. 68 */ getTestMethodNames()69 public String[] getTestMethodNames() { 70 return new String[]{"buildreference"}; 71 } 72 73 // This test is fairly simple, so there is no need for before() or after() 74 // methods. 75 before()76 public void before() 77 { 78 // System.out.println("before()"); 79 } 80 after()81 public void after() 82 { 83 // System.out.println("after()"); 84 } 85 86 // The test method itself. 87 private String m_sInputPath = ""; 88 private String m_sReferencePath = ""; 89 private boolean m_bIncludeSubdirectories = true; 90 initMember()91 void initMember() 92 { 93 // MUST PARAMETER 94 // INPUT_PATH ---------- 95 String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH ); 96 boolean bQuit = false; 97 String sError = ""; 98 if (sINPATH == null || sINPATH.length() == 0) 99 { 100 log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path."); 101 bQuit = true; 102 } 103 else 104 { 105 log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH); 106 m_sInputPath = sINPATH; 107 } 108 109 // REFERENCE_PATH ---------- 110 String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH ); 111 if (sREF == null || sREF.length() == 0) 112 { 113 log.println("Please set output path (path to a directory, where the references should stay) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path."); 114 bQuit = true; 115 } 116 else 117 { 118 log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF); 119 m_sReferencePath = sREF; 120 } 121 122 if (bQuit == true) 123 { 124 // log.println("must quit."); 125 assure("Must quit, Parameter problems.", false); 126 } 127 128 if (m_sInputPath.startsWith("file:") || 129 m_sReferencePath.startsWith("file:")) 130 { 131 assure("We can't handle file: URL right, use system path instead.", false); 132 } 133 134 } 135 136 /** 137 * Function returns a List of software which must accessable as an external executable 138 */ mustInstalledSoftware()139 protected Object[] mustInstalledSoftware() 140 { 141 ArrayList aList = new ArrayList(); 142 aList.add("perl -version"); 143 return aList.toArray(); 144 } 145 146 // the test ====================================================================== buildreference()147 public void buildreference() 148 { 149 GlobalLogWriter.set(log); 150 String sDBConnection = (String)param.get( PropertyName.DB_CONNECTION_STRING ); 151 152 // check if all need software is installed and accessable 153 checkEnvironment(mustInstalledSoftware()); 154 155 // test_removeFirstDirectorysAndBasenameFrom(); 156 // Get the MultiServiceFactory. 157 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); 158 GraphicalTestArguments aGTA = getGraphicalTestArguments(); 159 if (aGTA == null) 160 { 161 assure("Must quit", false); 162 } 163 if (aGTA.cancelRequest()) 164 { 165 return; 166 } 167 168 initMember(); 169 DB.init(aGTA.getDBInfoString() + "," + sDBConnection); 170 File aInputPath = new File(m_sInputPath); 171 if (aInputPath.isDirectory()) 172 { 173 String fs = System.getProperty("file.separator"); 174 175 String sRemovePath = aInputPath.getAbsolutePath(); 176 // a whole directory 177 FileFilter aFileFilter = FileHelper.getFileFilter(); 178 179 Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories()); 180 // fill into DB 181 // DB.filesRemove(aGTA.getDBInfoString()); 182 // for (int j=0;j<aList.length;j++) 183 // { 184 // String sEntry = (String)aList[j]; 185 // DB.fileInsert(aGTA.getDBInfoString(), sEntry, sRemovePath); 186 // } 187 188 // normal run. 189 for (int i=0;i<aList.length;i++) 190 { 191 String sEntry = (String)aList[i]; 192 193 String sNewReferencePath = m_sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath); 194 log.println("- next file is: ------------------------------"); 195 log.println(sEntry); 196 log.println(sNewReferencePath); 197 198 if (aGTA.checkIfUsableDocumentType(sEntry)) 199 { 200 runGDC(sEntry, sNewReferencePath); 201 } 202 if (aGTA.cancelRequest()) 203 { 204 break; 205 } 206 } 207 } 208 else 209 { 210 // String sRemovePath = aInputPath.getAbsolutePath(); 211 // DB.fileInsert(aGTA.getDBInfoString(), m_sInputPath, sRemovePath); 212 // DB.updatestate_status(aGTA.getDBInfoString(), "started: " + m_sInputPath); 213 if (aGTA.checkIfUsableDocumentType(m_sInputPath)) 214 { 215 runGDC(m_sInputPath, m_sReferencePath); 216 } 217 } 218 } 219 runGDC(String _sInputPath, String _sReferencePath)220 void runGDC(String _sInputPath, String _sReferencePath) 221 { 222 // first do a check if the reference not already exist, this is a big speedup, due to the fact, 223 // we don't need to start a new office. 224 GraphicalTestArguments aGTA = getGraphicalTestArguments(); 225 if (GraphicalDifferenceCheck.isReferenceExists(_sInputPath, _sReferencePath, aGTA) == false) 226 { 227 // start a fresh Office 228 OfficeProvider aProvider = null; 229 // SimpleFileSemaphore aSemaphore = new SimpleFileSemaphore(); 230 if (aGTA.shouldOfficeStart()) 231 { 232 // if (OSHelper.isWindows()) 233 // { 234 // aSemaphore.P(aSemaphore.getSemaphoreFile()); 235 // } 236 aGTA.getPerformance().startTime(PerformanceContainer.OfficeStart); 237 aProvider = new OfficeProvider(); 238 XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param); 239 param.put("ServiceFactory", xMSF); 240 aGTA.getPerformance().stopTime(PerformanceContainer.OfficeStart); 241 242 long nStartTime = aGTA.getPerformance().getTime(PerformanceContainer.OfficeStart); 243 aGTA = getGraphicalTestArguments(); 244 aGTA.getPerformance().setTime(PerformanceContainer.OfficeStart, nStartTime); 245 } 246 247 // Watcher Object is need in log object to give a simple way to say if a running office is alive. 248 // As long as a log comes, it pings the Watcher and says the office is alive, if not an 249 // internal counter increase and at a given point (300 seconds) the office is killed. 250 GlobalLogWriter.get().println("Set office watcher"); 251 Object aWatcher = param.get("Watcher"); 252 GlobalLogWriter.get().setWatcher(aWatcher); 253 // initializeWatcher(param); 254 255 try 256 { 257 log.println("Reference type is " + aGTA.getReferenceType()); 258 DB.source_start(); 259 GraphicalDifferenceCheck.createOneReferenceFile(_sInputPath, _sReferencePath, aGTA); 260 DB.source_finished(); 261 } 262 catch(ConvWatchCancelException e) 263 { 264 assure(e.getMessage(), false); 265 DB.source_failed(e.getMessage()); 266 } 267 catch(ConvWatchException e) 268 { 269 assure(e.getMessage(), false); 270 DB.source_failed(e.getMessage()); 271 } 272 catch(com.sun.star.lang.DisposedException e) 273 { 274 assure(e.getMessage(), false, true); 275 DB.source_failed(e.getMessage()); 276 } 277 278 // Office shutdown 279 if (aProvider != null) 280 { 281 boolean bClosed = aProvider.closeExistingOffice(param, true); 282 // Hope I can check that the close of the office fails 283 assure("Office closed", bClosed, true); 284 // if (OSHelper.isWindows()) 285 // { 286 // aSemaphore.V(aSemaphore.getSemaphoreFile()); 287 // aSemaphore.sleep(2); 288 // // wait some time maybe an other process will take the semaphore 289 // // I know, this is absolutly dirty, but the whole convwatch is dirty and need a big cleanup. 290 // } 291 } 292 } 293 else 294 { 295 // Reference already exist, do nothing, but DB change 296 DB.source_finished(); 297 } 298 } 299 } 300 301