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
.OfficePrint
;
39 import convwatch
.ConvWatchException
;
40 import convwatch
.EnhancedComplexTestCase
;
41 import convwatch
.PropertyName
;
42 import helper
.OfficeProvider
;
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 DocumentConverter
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 "DocumentConverter 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
[]{"convert"};
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 convert()
153 GlobalLogWriter
.set(log
);
154 // check if all need software is installed and accessable
155 checkEnvironment(mustInstalledSoftware());
157 // test_removeFirstDirectorysAndBasenameFrom();
158 // Get the MultiServiceFactory.
159 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
160 GraphicalTestArguments aGTA
= getGraphicalTestArguments();
163 assure("Must quit", false);
168 File aInputPath
= new File(m_sInputPath
);
169 if (aInputPath
.isDirectory())
171 String fs
= System
.getProperty("file.separator");
173 String sRemovePath
= aInputPath
.getAbsolutePath();
175 FileFilter aFileFilter
= FileHelper
.getFileFilter();
177 Object
[] aList
= DirectoryHelper
.traverse(m_sInputPath
, aFileFilter
, aGTA
.includeSubDirectories());
178 for (int i
=0;i
<aList
.length
;i
++)
180 String sEntry
= (String
)aList
[i
];
182 String sNewReferencePath
= m_sReferencePath
+ fs
+ FileHelper
.removeFirstDirectorysAndBasenameFrom(sEntry
, m_sInputPath
);
183 log
.println("- next file is: ------------------------------");
186 if (aGTA
.checkIfUsableDocumentType(sEntry
))
188 runGDC(sEntry
, sNewReferencePath
);
190 if (aGTA
.cancelRequest())
198 if (aGTA
.checkIfUsableDocumentType(m_sInputPath
))
200 runGDC(m_sInputPath
, m_sReferencePath
);
205 void runGDC(String _sInputFile
, String _sReferencePath
)
207 // first do a check if the reference not already exist, this is a big speedup, due to the fact,
208 // we don't need to start a new office.
209 GraphicalTestArguments aGTA_local
= getGraphicalTestArguments();
210 // if (GraphicalDifferenceCheck.isReferenceExists(_sInputFile, _sReferencePath, aGTA_local) == false)
212 // start a fresh Office
213 OfficeProvider aProvider
= null;
214 if (aGTA_local
.restartOffice())
216 aProvider
= new OfficeProvider();
217 XMultiServiceFactory xMSF
= (XMultiServiceFactory
) aProvider
.getManager(param
);
218 param
.put("ServiceFactory", xMSF
);
220 GraphicalTestArguments aGTA
= getGraphicalTestArguments();
222 if (aGTA
.getOfficeProgram().toLowerCase().equals("msoffice"))
224 // ReferenceType is MSOffice
225 GlobalLogWriter
.get().println("USE MSOFFICE AS EXPORT FORMAT.");
226 MSOfficePrint a
= new MSOfficePrint();
229 String sInputFileBasename
= FileHelper
.getBasename(_sInputFile
);
230 String fs
= System
.getProperty("file.separator");
231 FileHelper
.makeDirectories("", _sReferencePath
);
232 String sOutputFile
= _sReferencePath
;
233 if (sOutputFile
.endsWith(fs
))
235 sOutputFile
+= sInputFileBasename
;
239 sOutputFile
+= fs
+ sInputFileBasename
;
242 a
.storeToFileWithMSOffice(aGTA
, _sInputFile
, sOutputFile
);
244 catch(ConvWatchCancelException e
)
246 GlobalLogWriter
.get().println(e
.getMessage());
248 catch(java
.io
.IOException e
)
250 GlobalLogWriter
.get().println(e
.getMessage());
257 OfficePrint
.convertDocument(_sInputFile
, _sReferencePath
, aGTA
);
259 catch(ConvWatchCancelException e
)
261 assure(e
.getMessage(), false);
263 catch(ConvWatchException e
)
265 assure(e
.getMessage(), false);
269 if (aGTA
.restartOffice())
272 aProvider
.closeExistingOffice(param
, true);