1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package convwatch; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir // imports 31*cdf0e10cSrcweir import java.io.File; 32*cdf0e10cSrcweir import java.io.FileFilter; 33*cdf0e10cSrcweir import java.util.ArrayList; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir import convwatch.DirectoryHelper; 38*cdf0e10cSrcweir import convwatch.OfficePrint; 39*cdf0e10cSrcweir import convwatch.ConvWatchException; 40*cdf0e10cSrcweir import convwatch.EnhancedComplexTestCase; 41*cdf0e10cSrcweir import convwatch.PropertyName; 42*cdf0e10cSrcweir import helper.OfficeProvider; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir /** 45*cdf0e10cSrcweir * The following Complex Test will test 46*cdf0e10cSrcweir * an already created document and it's postscript output (by an older office version) 47*cdf0e10cSrcweir * with a new office version. 48*cdf0e10cSrcweir * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick. 49*cdf0e10cSrcweir * Read the manual for more information. 50*cdf0e10cSrcweir * 51*cdf0e10cSrcweir * this is only the starter program 52*cdf0e10cSrcweir * more is found in qadevOOo/runner/convwatch/* 53*cdf0e10cSrcweir */ 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir public class DocumentConverter extends EnhancedComplexTestCase 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir // The first of the mandatory functions: 58*cdf0e10cSrcweir /** 59*cdf0e10cSrcweir * Return the name of the test. 60*cdf0e10cSrcweir * In this case it is the actual name of the service. 61*cdf0e10cSrcweir * @return The tested service. 62*cdf0e10cSrcweir */ 63*cdf0e10cSrcweir public String getTestObjectName() { 64*cdf0e10cSrcweir return "DocumentConverter runner"; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir // The second of the mandatory functions: return all test methods as an 68*cdf0e10cSrcweir // array. There is only one test function in this example. 69*cdf0e10cSrcweir /** 70*cdf0e10cSrcweir * Return all test methods. 71*cdf0e10cSrcweir * @return The test methods. 72*cdf0e10cSrcweir */ 73*cdf0e10cSrcweir public String[] getTestMethodNames() { 74*cdf0e10cSrcweir return new String[]{"convert"}; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // This test is fairly simple, so there is no need for before() or after() 78*cdf0e10cSrcweir // methods. 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir public void before() 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir // System.out.println("before()"); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir public void after() 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir // System.out.println("after()"); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // The test method itself. 91*cdf0e10cSrcweir private String m_sInputPath = ""; 92*cdf0e10cSrcweir private String m_sReferencePath = ""; 93*cdf0e10cSrcweir private boolean m_bIncludeSubdirectories = true; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir void initMember() 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir // MUST PARAMETER 98*cdf0e10cSrcweir // INPUT_PATH ---------- 99*cdf0e10cSrcweir String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH ); 100*cdf0e10cSrcweir boolean bQuit = false; 101*cdf0e10cSrcweir String sError = ""; 102*cdf0e10cSrcweir if (sINPATH == null || sINPATH.length() == 0) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path."); 105*cdf0e10cSrcweir bQuit = true; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir else 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH); 110*cdf0e10cSrcweir m_sInputPath = sINPATH; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // REFERENCE_PATH ---------- 114*cdf0e10cSrcweir String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH ); 115*cdf0e10cSrcweir if (sREF == null || sREF.length() == 0) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir log.println("Please set output path (path to a directory, where the references should stay) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path."); 118*cdf0e10cSrcweir bQuit = true; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir else 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF); 123*cdf0e10cSrcweir m_sReferencePath = sREF; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir if (bQuit == true) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir // log.println("must quit."); 129*cdf0e10cSrcweir assure("Must quit, Parameter problems.", false); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir if (m_sInputPath.startsWith("file:") || 133*cdf0e10cSrcweir m_sReferencePath.startsWith("file:")) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir assure("We can't handle file: URL right, use system path instead.", false); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir /** 141*cdf0e10cSrcweir * Function returns a List of software which must accessable as an external executable 142*cdf0e10cSrcweir */ 143*cdf0e10cSrcweir protected Object[] mustInstalledSoftware() 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir ArrayList aList = new ArrayList(); 146*cdf0e10cSrcweir // aList.add("perl -version"); 147*cdf0e10cSrcweir return aList.toArray(); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir // the test ====================================================================== 151*cdf0e10cSrcweir public void convert() 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir GlobalLogWriter.set(log); 154*cdf0e10cSrcweir // check if all need software is installed and accessable 155*cdf0e10cSrcweir checkEnvironment(mustInstalledSoftware()); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // test_removeFirstDirectorysAndBasenameFrom(); 158*cdf0e10cSrcweir // Get the MultiServiceFactory. 159*cdf0e10cSrcweir // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); 160*cdf0e10cSrcweir GraphicalTestArguments aGTA = getGraphicalTestArguments(); 161*cdf0e10cSrcweir if (aGTA == null) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir assure("Must quit", false); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir initMember(); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir File aInputPath = new File(m_sInputPath); 169*cdf0e10cSrcweir if (aInputPath.isDirectory()) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir String fs = System.getProperty("file.separator"); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir String sRemovePath = aInputPath.getAbsolutePath(); 174*cdf0e10cSrcweir // a whole directory 175*cdf0e10cSrcweir FileFilter aFileFilter = FileHelper.getFileFilter(); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories()); 178*cdf0e10cSrcweir for (int i=0;i<aList.length;i++) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir String sEntry = (String)aList[i]; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir String sNewReferencePath = m_sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath); 183*cdf0e10cSrcweir log.println("- next file is: ------------------------------"); 184*cdf0e10cSrcweir log.println(sEntry); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir if (aGTA.checkIfUsableDocumentType(sEntry)) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir runGDC(sEntry, sNewReferencePath); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir if (aGTA.cancelRequest()) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir break; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir else 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir if (aGTA.checkIfUsableDocumentType(m_sInputPath)) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir runGDC(m_sInputPath, m_sReferencePath); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir void runGDC(String _sInputFile, String _sReferencePath) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir // first do a check if the reference not already exist, this is a big speedup, due to the fact, 208*cdf0e10cSrcweir // we don't need to start a new office. 209*cdf0e10cSrcweir GraphicalTestArguments aGTA_local = getGraphicalTestArguments(); 210*cdf0e10cSrcweir // if (GraphicalDifferenceCheck.isReferenceExists(_sInputFile, _sReferencePath, aGTA_local) == false) 211*cdf0e10cSrcweir // { 212*cdf0e10cSrcweir // start a fresh Office 213*cdf0e10cSrcweir OfficeProvider aProvider = null; 214*cdf0e10cSrcweir if (aGTA_local.restartOffice()) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir aProvider = new OfficeProvider(); 217*cdf0e10cSrcweir XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param); 218*cdf0e10cSrcweir param.put("ServiceFactory", xMSF); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir GraphicalTestArguments aGTA = getGraphicalTestArguments(); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir if (aGTA.getOfficeProgram().toLowerCase().equals("msoffice")) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir // ReferenceType is MSOffice 225*cdf0e10cSrcweir GlobalLogWriter.get().println("USE MSOFFICE AS EXPORT FORMAT."); 226*cdf0e10cSrcweir MSOfficePrint a = new MSOfficePrint(); 227*cdf0e10cSrcweir try 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir String sInputFileBasename = FileHelper.getBasename(_sInputFile); 230*cdf0e10cSrcweir String fs = System.getProperty("file.separator"); 231*cdf0e10cSrcweir FileHelper.makeDirectories("", _sReferencePath); 232*cdf0e10cSrcweir String sOutputFile = _sReferencePath; 233*cdf0e10cSrcweir if (sOutputFile.endsWith(fs)) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir sOutputFile += sInputFileBasename; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir else 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir sOutputFile += fs + sInputFileBasename; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir a.storeToFileWithMSOffice(aGTA, _sInputFile, sOutputFile); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir catch(ConvWatchCancelException e) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir GlobalLogWriter.get().println(e.getMessage()); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir catch(java.io.IOException e) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir GlobalLogWriter.get().println(e.getMessage()); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir else 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir try 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir OfficePrint.convertDocument(_sInputFile, _sReferencePath, aGTA); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir catch(ConvWatchCancelException e) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir assure(e.getMessage(), false); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir catch(ConvWatchException e) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir assure(e.getMessage(), false); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir if (aGTA.restartOffice()) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir // Office shutdown 272*cdf0e10cSrcweir aProvider.closeExistingOffice(param, true); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir // } 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278