merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / convwatch / ReferenceBuilder.java
blob30dd67f6ddd95e37ca2f5b414ae1510f00b7d1e2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ReferenceBuilder.java,v $
10 * $Revision: 1.12.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package convwatch;
33 // imports
34 import java.io.File;
35 import java.io.FileFilter;
36 import java.util.ArrayList;
38 import com.sun.star.lang.XMultiServiceFactory;
40 import convwatch.DirectoryHelper;
41 import convwatch.ConvWatchException;
42 import convwatch.EnhancedComplexTestCase;
43 import convwatch.PropertyName;
44 import helper.OfficeProvider;
45 import convwatch.PerformanceContainer;
47 /**
48 * The following Complex Test will test
49 * an already created document and it's postscript output (by an older office version)
50 * with a new office version.
51 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick.
52 * Read the manual for more information.
54 * this is only the starter program
55 * more is found in qadevOOo/runner/convwatch/*
58 public class ReferenceBuilder extends EnhancedComplexTestCase
60 // The first of the mandatory functions:
61 /**
62 * Return the name of the test.
63 * In this case it is the actual name of the service.
64 * @return The tested service.
66 public String getTestObjectName() {
67 return "ReferenceBuilder runner";
70 // The second of the mandatory functions: return all test methods as an
71 // array. There is only one test function in this example.
72 /**
73 * Return all test methods.
74 * @return The test methods.
76 public String[] getTestMethodNames() {
77 return new String[]{"buildreference"};
80 // This test is fairly simple, so there is no need for before() or after()
81 // methods.
83 public void before()
85 // System.out.println("before()");
88 public void after()
90 // System.out.println("after()");
93 // The test method itself.
94 private String m_sInputPath = "";
95 private String m_sReferencePath = "";
96 private boolean m_bIncludeSubdirectories = true;
98 void initMember()
100 // MUST PARAMETER
101 // INPUT_PATH ----------
102 String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH );
103 boolean bQuit = false;
104 String sError = "";
105 if (sINPATH == null || sINPATH.length() == 0)
107 log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path.");
108 bQuit = true;
110 else
112 log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH);
113 m_sInputPath = sINPATH;
116 // REFERENCE_PATH ----------
117 String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH );
118 if (sREF == null || sREF.length() == 0)
120 log.println("Please set output path (path to a directory, where the references should stay) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path.");
121 bQuit = true;
123 else
125 log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF);
126 m_sReferencePath = sREF;
129 if (bQuit == true)
131 // log.println("must quit.");
132 assure("Must quit, Parameter problems.", false);
135 if (m_sInputPath.startsWith("file:") ||
136 m_sReferencePath.startsWith("file:"))
138 assure("We can't handle file: URL right, use system path instead.", false);
144 * Function returns a List of software which must accessable as an external executable
146 protected Object[] mustInstalledSoftware()
148 ArrayList aList = new ArrayList();
149 aList.add("perl -version");
150 return aList.toArray();
153 // the test ======================================================================
154 public void buildreference()
156 GlobalLogWriter.set(log);
157 String sDBConnection = (String)param.get( PropertyName.DB_CONNECTION_STRING );
159 // check if all need software is installed and accessable
160 checkEnvironment(mustInstalledSoftware());
162 // test_removeFirstDirectorysAndBasenameFrom();
163 // Get the MultiServiceFactory.
164 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
165 GraphicalTestArguments aGTA = getGraphicalTestArguments();
166 if (aGTA == null)
168 assure("Must quit", false);
170 if (aGTA.cancelRequest())
172 return;
175 initMember();
176 DB.init(aGTA.getDBInfoString() + "," + sDBConnection);
177 File aInputPath = new File(m_sInputPath);
178 if (aInputPath.isDirectory())
180 String fs = System.getProperty("file.separator");
182 String sRemovePath = aInputPath.getAbsolutePath();
183 // a whole directory
184 FileFilter aFileFilter = FileHelper.getFileFilter();
186 Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories());
187 // fill into DB
188 // DB.filesRemove(aGTA.getDBInfoString());
189 // for (int j=0;j<aList.length;j++)
190 // {
191 // String sEntry = (String)aList[j];
192 // DB.fileInsert(aGTA.getDBInfoString(), sEntry, sRemovePath);
193 // }
195 // normal run.
196 for (int i=0;i<aList.length;i++)
198 String sEntry = (String)aList[i];
200 String sNewReferencePath = m_sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath);
201 log.println("- next file is: ------------------------------");
202 log.println(sEntry);
203 log.println(sNewReferencePath);
205 if (aGTA.checkIfUsableDocumentType(sEntry))
207 runGDC(sEntry, sNewReferencePath);
209 if (aGTA.cancelRequest())
211 break;
215 else
217 // String sRemovePath = aInputPath.getAbsolutePath();
218 // DB.fileInsert(aGTA.getDBInfoString(), m_sInputPath, sRemovePath);
219 // DB.updatestate_status(aGTA.getDBInfoString(), "started: " + m_sInputPath);
220 if (aGTA.checkIfUsableDocumentType(m_sInputPath))
222 runGDC(m_sInputPath, m_sReferencePath);
227 void runGDC(String _sInputPath, String _sReferencePath)
229 // first do a check if the reference not already exist, this is a big speedup, due to the fact,
230 // we don't need to start a new office.
231 GraphicalTestArguments aGTA = getGraphicalTestArguments();
232 if (GraphicalDifferenceCheck.isReferenceExists(_sInputPath, _sReferencePath, aGTA) == false)
234 // start a fresh Office
235 OfficeProvider aProvider = null;
236 // SimpleFileSemaphore aSemaphore = new SimpleFileSemaphore();
237 if (aGTA.shouldOfficeStart())
239 // if (OSHelper.isWindows())
240 // {
241 // aSemaphore.P(aSemaphore.getSemaphoreFile());
242 // }
243 aGTA.getPerformance().startTime(PerformanceContainer.OfficeStart);
244 aProvider = new OfficeProvider();
245 XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param);
246 param.put("ServiceFactory", xMSF);
247 aGTA.getPerformance().stopTime(PerformanceContainer.OfficeStart);
249 long nStartTime = aGTA.getPerformance().getTime(PerformanceContainer.OfficeStart);
250 aGTA = getGraphicalTestArguments();
251 aGTA.getPerformance().setTime(PerformanceContainer.OfficeStart, nStartTime);
254 // Watcher Object is need in log object to give a simple way to say if a running office is alive.
255 // As long as a log comes, it pings the Watcher and says the office is alive, if not an
256 // internal counter increase and at a given point (300 seconds) the office is killed.
257 GlobalLogWriter.get().println("Set office watcher");
258 Object aWatcher = param.get("Watcher");
259 GlobalLogWriter.get().setWatcher(aWatcher);
260 // initializeWatcher(param);
264 log.println("Reference type is " + aGTA.getReferenceType());
265 DB.source_start();
266 GraphicalDifferenceCheck.createOneReferenceFile(_sInputPath, _sReferencePath, aGTA);
267 DB.source_finished();
269 catch(ConvWatchCancelException e)
271 assure(e.getMessage(), false);
272 DB.source_failed(e.getMessage());
274 catch(ConvWatchException e)
276 assure(e.getMessage(), false);
277 DB.source_failed(e.getMessage());
279 catch(com.sun.star.lang.DisposedException e)
281 assure(e.getMessage(), false, true);
282 DB.source_failed(e.getMessage());
285 // Office shutdown
286 if (aProvider != null)
288 boolean bClosed = aProvider.closeExistingOffice(param, true);
289 // Hope I can check that the close of the office fails
290 assure("Office closed", bClosed, true);
291 // if (OSHelper.isWindows())
292 // {
293 // aSemaphore.V(aSemaphore.getSemaphoreFile());
294 // aSemaphore.sleep(2);
295 // // wait some time maybe an other process will take the semaphore
296 // // I know, this is absolutly dirty, but the whole convwatch is dirty and need a big cleanup.
297 // }
300 else
302 // Reference already exist, do nothing, but DB change
303 DB.source_finished();