bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / convwatch / DocumentConverter.java
blob9c68edbdb5ad66b09067ff8f5db932a22c202776
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 java.util.ArrayList;
26 import com.sun.star.lang.XMultiServiceFactory;
28 import convwatch.DirectoryHelper;
29 import convwatch.OfficePrint;
30 import convwatch.EnhancedComplexTestCase;
31 import convwatch.PropertyName;
32 import helper.OfficeProvider;
34 /**
35 * The following Complex Test will test
36 * an already created document and it's postscript output (by an older office version)
37 * with a new office version.
38 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick.
39 * Read the manual for more information.
41 * this is only the starter program
42 * more is found in qadevOOo/runner/convwatch/*
45 public class DocumentConverter extends EnhancedComplexTestCase
47 // The first of the mandatory functions:
48 /**
49 * Return the name of the test.
50 * In this case it is the actual name of the service.
51 * @return The tested service.
53 public String getTestObjectName() {
54 return "DocumentConverter runner";
57 // The second of the mandatory functions: return all test methods as an
58 // array. There is only one test function in this example.
59 /**
60 * Return all test methods.
61 * @return The test methods.
63 public String[] getTestMethodNames() {
64 return new String[]{"convert"};
67 // This test is fairly simple, so there is no need for before() or after()
68 // methods.
70 public void before()
72 // System.out.println("before()");
75 public void after()
77 // System.out.println("after()");
80 // The test method itself.
81 private String m_sInputPath = "";
82 private String m_sReferencePath = "";
83 void initMember()
85 // MUST PARAMETER
86 // INPUT_PATH ----------
87 String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH );
88 boolean bQuit = false;
89 if (sINPATH == null || sINPATH.length() == 0)
91 log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path.");
92 bQuit = true;
94 else
96 log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH);
97 m_sInputPath = sINPATH;
100 // REFERENCE_PATH ----------
101 String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH );
102 if (sREF == null || sREF.length() == 0)
104 log.println("Please set output path (path to a directory, where the references should stay) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path.");
105 bQuit = true;
107 else
109 log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF);
110 m_sReferencePath = sREF;
113 if (bQuit == true)
115 // log.println("must quit.");
116 assure("Must quit, Parameter problems.", false);
119 if (m_sInputPath.startsWith("file:") ||
120 m_sReferencePath.startsWith("file:"))
122 assure("We can't handle file: URL right, use system path instead.", false);
128 * Function returns a List of software which must accessible as an external executable
130 protected String[] mustInstalledSoftware()
132 ArrayList<String> aList = new ArrayList<String>();
133 // aList.add("perl -version");
134 return aList.toArray(new String[aList.size()]);
137 // the test ======================================================================
138 public void convert()
140 GlobalLogWriter.set(log);
141 // check if all need software is installed and accessible
142 checkEnvironment(mustInstalledSoftware());
144 // test_removeFirstDirectorysAndBasenameFrom();
145 // Get the MultiServiceFactory.
146 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
147 GraphicalTestArguments aGTA = getGraphicalTestArguments();
148 if (aGTA == null)
150 assure("Must quit", false);
153 initMember();
155 File aInputPath = new File(m_sInputPath);
156 if (aInputPath.isDirectory())
158 String fs = System.getProperty("file.separator");
160 aInputPath.getAbsolutePath();
161 // a whole directory
162 FileFilter aFileFilter = FileHelper.getFileFilter();
164 Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories());
165 for (int i=0;i<aList.length;i++)
167 String sEntry = (String)aList[i];
169 String sNewReferencePath = m_sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath);
170 log.println("- next file is: ------------------------------");
171 log.println(sEntry);
173 if (aGTA.checkIfUsableDocumentType(sEntry))
175 runGDC(sEntry, sNewReferencePath);
177 if (aGTA.cancelRequest())
179 break;
183 else
185 if (aGTA.checkIfUsableDocumentType(m_sInputPath))
187 runGDC(m_sInputPath, m_sReferencePath);
192 void runGDC(String _sInputFile, String _sReferencePath)
194 // first do a check if the reference not already exist, this is a big speedup, due to the fact,
195 // we don't need to start a new office.
196 GraphicalTestArguments aGTA_local = getGraphicalTestArguments();
197 // if (GraphicalDifferenceCheck.isReferenceExists(_sInputFile, _sReferencePath, aGTA_local) == false)
198 // {
199 // start a fresh Office
200 OfficeProvider aProvider = null;
201 if (aGTA_local.restartOffice())
203 aProvider = new OfficeProvider();
204 XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param);
205 param.put("ServiceFactory", xMSF);
207 GraphicalTestArguments aGTA = getGraphicalTestArguments();
209 if (aGTA.getOfficeProgram().toLowerCase().equals("msoffice"))
211 // ReferenceType is MSOffice
212 GlobalLogWriter.get().println("USE MSOFFICE AS EXPORT FORMAT.");
213 MSOfficePrint a = new MSOfficePrint();
216 String sInputFileBasename = FileHelper.getBasename(_sInputFile);
217 String fs = System.getProperty("file.separator");
218 FileHelper.makeDirectories("", _sReferencePath);
219 String sOutputFile = _sReferencePath;
220 if (sOutputFile.endsWith(fs))
222 sOutputFile += sInputFileBasename;
224 else
226 sOutputFile += fs + sInputFileBasename;
229 a.storeToFileWithMSOffice(aGTA, _sInputFile, sOutputFile);
231 catch(ConvWatchCancelException e)
233 GlobalLogWriter.get().println(e.getMessage());
235 catch(java.io.IOException e)
237 GlobalLogWriter.get().println(e.getMessage());
240 else
244 OfficePrint.convertDocument(_sInputFile, _sReferencePath, aGTA);
246 catch(ConvWatchCancelException e)
248 assure(e.getMessage(), false);
252 if (aGTA.restartOffice())
254 // Office shutdown
255 aProvider.closeExistingOffice(param, true);
257 // }