1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
32 import java
.io
.FileFilter
;
33 import java
.util
.ArrayList
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import convwatch
.DirectoryHelper
;
38 import convwatch
.ConvWatchException
;
39 import convwatch
.EnhancedComplexTestCase
;
40 import convwatch
.PropertyName
;
41 import helper
.OfficeProvider
;
42 import convwatch
.PerformanceContainer
;
45 * The following Complex Test will test
46 * an already created document and it's postscript output (by an older office version)
47 * with a new office version.
48 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick.
49 * Read the manual for more information.
51 * this is only the starter program
52 * more is found in qadevOOo/runner/convwatch/*
55 public class ReferenceBuilder
extends EnhancedComplexTestCase
57 // The first of the mandatory functions:
59 * Return the name of the test.
60 * In this case it is the actual name of the service.
61 * @return The tested service.
63 public String
getTestObjectName() {
64 return "ReferenceBuilder runner";
67 // The second of the mandatory functions: return all test methods as an
68 // array. There is only one test function in this example.
70 * Return all test methods.
71 * @return The test methods.
73 public String
[] getTestMethodNames() {
74 return new String
[]{"buildreference"};
77 // This test is fairly simple, so there is no need for before() or after()
82 // System.out.println("before()");
87 // System.out.println("after()");
90 // The test method itself.
91 private String m_sInputPath
= "";
92 private String m_sReferencePath
= "";
93 private boolean m_bIncludeSubdirectories
= true;
98 // INPUT_PATH ----------
99 String sINPATH
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_INPUT_PATH
);
100 boolean bQuit
= false;
102 if (sINPATH
== null || sINPATH
.length() == 0)
104 log
.println("Please set input path (path to documents) " + PropertyName
.DOC_COMPARATOR_INPUT_PATH
+ "=path.");
109 log
.println("found " + PropertyName
.DOC_COMPARATOR_INPUT_PATH
+ " " + sINPATH
);
110 m_sInputPath
= sINPATH
;
113 // REFERENCE_PATH ----------
114 String sREF
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_REFERENCE_PATH
);
115 if (sREF
== null || sREF
.length() == 0)
117 log
.println("Please set output path (path to a directory, where the references should stay) " + PropertyName
.DOC_COMPARATOR_REFERENCE_PATH
+ "=path.");
122 log
.println("found " + PropertyName
.DOC_COMPARATOR_REFERENCE_PATH
+ " " + sREF
);
123 m_sReferencePath
= sREF
;
128 // log.println("must quit.");
129 assure("Must quit, Parameter problems.", false);
132 if (m_sInputPath
.startsWith("file:") ||
133 m_sReferencePath
.startsWith("file:"))
135 assure("We can't handle file: URL right, use system path instead.", false);
141 * Function returns a List of software which must accessable as an external executable
143 protected Object
[] mustInstalledSoftware()
145 ArrayList aList
= new ArrayList();
146 aList
.add("perl -version");
147 return aList
.toArray();
150 // the test ======================================================================
151 public void buildreference()
153 GlobalLogWriter
.set(log
);
154 String sDBConnection
= (String
)param
.get( PropertyName
.DB_CONNECTION_STRING
);
156 // check if all need software is installed and accessable
157 checkEnvironment(mustInstalledSoftware());
159 // test_removeFirstDirectorysAndBasenameFrom();
160 // Get the MultiServiceFactory.
161 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
162 GraphicalTestArguments aGTA
= getGraphicalTestArguments();
165 assure("Must quit", false);
167 if (aGTA
.cancelRequest())
173 DB
.init(aGTA
.getDBInfoString() + "," + sDBConnection
);
174 File aInputPath
= new File(m_sInputPath
);
175 if (aInputPath
.isDirectory())
177 String fs
= System
.getProperty("file.separator");
179 String sRemovePath
= aInputPath
.getAbsolutePath();
181 FileFilter aFileFilter
= FileHelper
.getFileFilter();
183 Object
[] aList
= DirectoryHelper
.traverse(m_sInputPath
, aFileFilter
, aGTA
.includeSubDirectories());
185 // DB.filesRemove(aGTA.getDBInfoString());
186 // for (int j=0;j<aList.length;j++)
188 // String sEntry = (String)aList[j];
189 // DB.fileInsert(aGTA.getDBInfoString(), sEntry, sRemovePath);
193 for (int i
=0;i
<aList
.length
;i
++)
195 String sEntry
= (String
)aList
[i
];
197 String sNewReferencePath
= m_sReferencePath
+ fs
+ FileHelper
.removeFirstDirectorysAndBasenameFrom(sEntry
, m_sInputPath
);
198 log
.println("- next file is: ------------------------------");
200 log
.println(sNewReferencePath
);
202 if (aGTA
.checkIfUsableDocumentType(sEntry
))
204 runGDC(sEntry
, sNewReferencePath
);
206 if (aGTA
.cancelRequest())
214 // String sRemovePath = aInputPath.getAbsolutePath();
215 // DB.fileInsert(aGTA.getDBInfoString(), m_sInputPath, sRemovePath);
216 // DB.updatestate_status(aGTA.getDBInfoString(), "started: " + m_sInputPath);
217 if (aGTA
.checkIfUsableDocumentType(m_sInputPath
))
219 runGDC(m_sInputPath
, m_sReferencePath
);
224 void runGDC(String _sInputPath
, String _sReferencePath
)
226 // first do a check if the reference not already exist, this is a big speedup, due to the fact,
227 // we don't need to start a new office.
228 GraphicalTestArguments aGTA
= getGraphicalTestArguments();
229 if (GraphicalDifferenceCheck
.isReferenceExists(_sInputPath
, _sReferencePath
, aGTA
) == false)
231 // start a fresh Office
232 OfficeProvider aProvider
= null;
233 // SimpleFileSemaphore aSemaphore = new SimpleFileSemaphore();
234 if (aGTA
.shouldOfficeStart())
236 // if (OSHelper.isWindows())
238 // aSemaphore.P(aSemaphore.getSemaphoreFile());
240 aGTA
.getPerformance().startTime(PerformanceContainer
.OfficeStart
);
241 aProvider
= new OfficeProvider();
242 XMultiServiceFactory xMSF
= (XMultiServiceFactory
) aProvider
.getManager(param
);
243 param
.put("ServiceFactory", xMSF
);
244 aGTA
.getPerformance().stopTime(PerformanceContainer
.OfficeStart
);
246 long nStartTime
= aGTA
.getPerformance().getTime(PerformanceContainer
.OfficeStart
);
247 aGTA
= getGraphicalTestArguments();
248 aGTA
.getPerformance().setTime(PerformanceContainer
.OfficeStart
, nStartTime
);
251 // Watcher Object is need in log object to give a simple way to say if a running office is alive.
252 // As long as a log comes, it pings the Watcher and says the office is alive, if not an
253 // internal counter increase and at a given point (300 seconds) the office is killed.
254 GlobalLogWriter
.get().println("Set office watcher");
255 Object aWatcher
= param
.get("Watcher");
256 GlobalLogWriter
.get().setWatcher(aWatcher
);
257 // initializeWatcher(param);
261 log
.println("Reference type is " + aGTA
.getReferenceType());
263 GraphicalDifferenceCheck
.createOneReferenceFile(_sInputPath
, _sReferencePath
, aGTA
);
264 DB
.source_finished();
266 catch(ConvWatchCancelException e
)
268 assure(e
.getMessage(), false);
269 DB
.source_failed(e
.getMessage());
271 catch(ConvWatchException e
)
273 assure(e
.getMessage(), false);
274 DB
.source_failed(e
.getMessage());
276 catch(com
.sun
.star
.lang
.DisposedException e
)
278 assure(e
.getMessage(), false, true);
279 DB
.source_failed(e
.getMessage());
283 if (aProvider
!= null)
285 boolean bClosed
= aProvider
.closeExistingOffice(param
, true);
286 // Hope I can check that the close of the office fails
287 assure("Office closed", bClosed
, true);
288 // if (OSHelper.isWindows())
290 // aSemaphore.V(aSemaphore.getSemaphoreFile());
291 // aSemaphore.sleep(2);
292 // // wait some time maybe an other process will take the semaphore
293 // // I know, this is absolutly dirty, but the whole convwatch is dirty and need a big cleanup.
299 // Reference already exist, do nothing, but DB change
300 DB
.source_finished();