bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / convwatch / ReferenceBuilder.java
blob6f17598d99713f898a2aad08f11dde9dfbcb9d1c
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 convwatch;
21 // imports
22 import java.io.File;
23 import java.io.FileFilter;
24 import com.sun.star.lang.XMultiServiceFactory;
26 import convwatch.DirectoryHelper;
27 import convwatch.ConvWatchException;
28 import convwatch.EnhancedComplexTestCase;
29 import convwatch.PropertyName;
30 import helper.OfficeProvider;
31 import convwatch.PerformanceContainer;
33 /**
34 * The following Complex Test will test
35 * an already created document and it's postscript output (by an older office version)
36 * with a new office version.
37 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick.
38 * Read the manual for more information.
40 * this is only the starter program
41 * more is found in qadevOOo/runner/convwatch/*
44 public class ReferenceBuilder extends EnhancedComplexTestCase
46 // The first of the mandatory functions:
47 /**
48 * Return the name of the test.
49 * In this case it is the actual name of the service.
50 * @return The tested service.
52 public String getTestObjectName() {
53 return "ReferenceBuilder runner";
56 // The second of the mandatory functions: return all test methods as an
57 // array. There is only one test function in this example.
58 /**
59 * Return all test methods.
60 * @return The test methods.
62 public String[] getTestMethodNames() {
63 return new String[]{"buildreference"};
66 // This test is fairly simple, so there is no need for before() or after()
67 // methods.
69 public void before()
71 // System.out.println("before()");
74 public void after()
76 // System.out.println("after()");
79 // The test method itself.
80 private String m_sInputPath = "";
81 private String m_sReferencePath = "";
82 void initMember()
84 // MUST PARAMETER
85 // INPUT_PATH ----------
86 String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH );
87 boolean bQuit = false;
88 if (sINPATH == null || sINPATH.length() == 0)
90 log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path.");
91 bQuit = true;
93 else
95 log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH);
96 m_sInputPath = sINPATH;
99 // REFERENCE_PATH ----------
100 String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH );
101 if (sREF == null || sREF.length() == 0)
103 log.println("Please set output path (path to a directory, where the references should stay) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path.");
104 bQuit = true;
106 else
108 log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF);
109 m_sReferencePath = sREF;
112 if (bQuit == true)
114 // log.println("must quit.");
115 assure("Must quit, Parameter problems.", false);
118 if (m_sInputPath.startsWith("file:") ||
119 m_sReferencePath.startsWith("file:"))
121 assure("We can't handle file: URL right, use system path instead.", false);
127 * Function returns a List of software which must accessible as an external executable
129 protected String[] mustInstalledSoftware()
131 return new String[] { "perl -version" };
134 // the test ======================================================================
135 public void buildreference()
137 GlobalLogWriter.set(log);
138 String sDBConnection = (String)param.get( PropertyName.DB_CONNECTION_STRING );
140 // check if all need software is installed and accessible
141 checkEnvironment(mustInstalledSoftware());
143 // test_removeFirstDirectorysAndBasenameFrom();
144 // Get the MultiServiceFactory.
145 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
146 GraphicalTestArguments aGTA = getGraphicalTestArguments();
147 if (aGTA == null)
149 assure("Must quit", false);
151 if (aGTA.cancelRequest())
153 return;
156 initMember();
157 DB.init(aGTA.getDBInfoString() + "," + sDBConnection);
158 File aInputPath = new File(m_sInputPath);
159 if (aInputPath.isDirectory())
161 String fs = System.getProperty("file.separator");
163 aInputPath.getAbsolutePath();
164 // a whole directory
165 FileFilter aFileFilter = FileHelper.getFileFilter();
167 Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories());
168 // fill into DB
169 // DB.filesRemove(aGTA.getDBInfoString());
170 // for (int j=0;j<aList.length;j++)
171 // {
172 // String sEntry = (String)aList[j];
173 // DB.fileInsert(aGTA.getDBInfoString(), sEntry, sRemovePath);
174 // }
176 // normal run.
177 for (int i=0;i<aList.length;i++)
179 String sEntry = (String)aList[i];
181 String sNewReferencePath = m_sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath);
182 log.println("- next file is: ------------------------------");
183 log.println(sEntry);
184 log.println(sNewReferencePath);
186 if (aGTA.checkIfUsableDocumentType(sEntry))
188 runGDC(sEntry, sNewReferencePath);
190 if (aGTA.cancelRequest())
192 break;
196 else
198 // String sRemovePath = aInputPath.getAbsolutePath();
199 // DB.fileInsert(aGTA.getDBInfoString(), m_sInputPath, sRemovePath);
200 // DB.updatestate_status(aGTA.getDBInfoString(), "started: " + m_sInputPath);
201 if (aGTA.checkIfUsableDocumentType(m_sInputPath))
203 runGDC(m_sInputPath, m_sReferencePath);
208 void runGDC(String _sInputPath, String _sReferencePath)
210 // first do a check if the reference not already exist, this is a big speedup, due to the fact,
211 // we don't need to start a new office.
212 GraphicalTestArguments aGTA = getGraphicalTestArguments();
213 if (GraphicalDifferenceCheck.isReferenceExists(_sInputPath, _sReferencePath, aGTA) == false)
215 // start a fresh Office
216 OfficeProvider aProvider = null;
217 // SimpleFileSemaphore aSemaphore = new SimpleFileSemaphore();
218 if (aGTA.shouldOfficeStart())
220 // if (OSHelper.isWindows())
221 // {
222 // aSemaphore.P(aSemaphore.getSemaphoreFile());
223 // }
224 aGTA.getPerformance().startTime(PerformanceContainer.OfficeStart);
225 aProvider = new OfficeProvider();
226 XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param);
227 param.put("ServiceFactory", xMSF);
228 aGTA.getPerformance().stopTime(PerformanceContainer.OfficeStart);
230 long nStartTime = aGTA.getPerformance().getTime(PerformanceContainer.OfficeStart);
231 aGTA = getGraphicalTestArguments();
232 aGTA.getPerformance().setTime(PerformanceContainer.OfficeStart, nStartTime);
235 // Watcher Object is need in log object to give a simple way to say if a running office is alive.
236 // As long as a log comes, it pings the Watcher and says the office is alive, if not an
237 // internal counter increase and at a given point (300 seconds) the office is killed.
238 GlobalLogWriter.get().println("Set office watcher");
239 Object aWatcher = param.get("Watcher");
240 GlobalLogWriter.get().setWatcher(aWatcher);
241 // initializeWatcher(param);
245 log.println("Reference type is " + aGTA.getReferenceType());
246 DB.source_start();
247 GraphicalDifferenceCheck.createOneReferenceFile(_sInputPath, _sReferencePath, aGTA);
248 DB.source_finished();
250 catch(ConvWatchCancelException e)
252 assure(e.getMessage(), false);
253 DB.source_failed(e.getMessage());
255 catch(ConvWatchException e)
257 assure(e.getMessage(), false);
258 DB.source_failed(e.getMessage());
260 catch(com.sun.star.lang.DisposedException e)
262 assure(e.getMessage(), false, true);
263 DB.source_failed(e.getMessage());
266 // Office shutdown
267 if (aProvider != null)
269 boolean bClosed = aProvider.closeExistingOffice(param, true);
270 // Hope I can check that the close of the office fails
271 assure("Office closed", bClosed, true);
272 // if (OSHelper.isWindows())
273 // {
274 // aSemaphore.V(aSemaphore.getSemaphoreFile());
275 // aSemaphore.sleep(2);
276 // // wait some time maybe an other process will take the semaphore
277 // // I know, this is absolutly dirty, but the whole convwatch is dirty and need a big cleanup.
278 // }
281 else
283 // Reference already exist, do nothing, but DB change
284 DB.source_finished();