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 import java.util.ArrayList; 31*cdf0e10cSrcweir import convwatch.EnhancedComplexTestCase; 32*cdf0e10cSrcweir import convwatch.PRNCompare; 33*cdf0e10cSrcweir import convwatch.GraphicalTestArguments; 34*cdf0e10cSrcweir import helper.URLHelper; 35*cdf0e10cSrcweir import convwatch.OfficePrint; 36*cdf0e10cSrcweir import java.io.File; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir public class GfxCompare extends EnhancedComplexTestCase 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir // The first of the mandatory functions: 41*cdf0e10cSrcweir /** 42*cdf0e10cSrcweir * Return the name of the test. 43*cdf0e10cSrcweir * In this case it is the actual name of the service. 44*cdf0e10cSrcweir * @return The tested service. 45*cdf0e10cSrcweir */ 46*cdf0e10cSrcweir // public String getTestObjectName() { 47*cdf0e10cSrcweir // return "ConvWatch runner"; 48*cdf0e10cSrcweir // } 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // The second of the mandatory functions: return all test methods as an 51*cdf0e10cSrcweir // array. There is only one test function in this example. 52*cdf0e10cSrcweir /** 53*cdf0e10cSrcweir * Return all test methods. 54*cdf0e10cSrcweir * @return The test methods. 55*cdf0e10cSrcweir */ 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir public String[] getTestMethodNames() { 58*cdf0e10cSrcweir return new String[]{"gfxcompare"}; 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir /** 62*cdf0e10cSrcweir * 63*cdf0e10cSrcweir * @return a List of software which must accessable as an external executable 64*cdf0e10cSrcweir */ 65*cdf0e10cSrcweir protected Object[] mustInstalledSoftware() 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir ArrayList aList = new ArrayList(); 68*cdf0e10cSrcweir // Tools from ImageMagick 69*cdf0e10cSrcweir aList.add( "composite -version" ); 70*cdf0e10cSrcweir aList.add( "identify -version" ); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir // Ghostscript 73*cdf0e10cSrcweir aList.add( "gs -version" ); 74*cdf0e10cSrcweir return aList.toArray(); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir GraphicalTestArguments m_aArguments = null; 79*cdf0e10cSrcweir /** 80*cdf0e10cSrcweir * The test method itself. 81*cdf0e10cSrcweir * Don't try to call it from outside, it is started only from qadevOOo runner 82*cdf0e10cSrcweir */ 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir /* protected */ 85*cdf0e10cSrcweir public void gfxcompare() 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir GlobalLogWriter.set(log); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // check if all need software is installed and accessable 90*cdf0e10cSrcweir checkEnvironment(mustInstalledSoftware()); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir m_aArguments = getGraphicalTestArguments(); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir String sFile1 = (String)param.get("FILE1"); 95*cdf0e10cSrcweir String sFile2 = (String)param.get("FILE2"); 96*cdf0e10cSrcweir compare(sFile1, sFile2); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir String createJPEG(String _sFile, String _sAdditional) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir String sJPEGFile = ""; 104*cdf0e10cSrcweir if (_sFile.startsWith("file:///")) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir _sFile = FileHelper.getSystemPathFromFileURL(_sFile); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir File aFile = new File(_sFile); 109*cdf0e10cSrcweir if (aFile.exists()) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir String sAbsFile = aFile.getAbsolutePath(); 112*cdf0e10cSrcweir if (!sAbsFile.equals(_sFile)) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir _sFile = sAbsFile; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir else 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir GlobalLogWriter.get().println("File: '" + _sFile + "' doesn't exist."); 120*cdf0e10cSrcweir return ""; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir String sFileDir = FileHelper.getPath(_sFile); 123*cdf0e10cSrcweir String sBasename = FileHelper.getBasename(_sFile); 124*cdf0e10cSrcweir String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir String fs = System.getProperty("file.separator"); 127*cdf0e10cSrcweir String sTmpDir = util.utils.getUsersTempDir(); 128*cdf0e10cSrcweir if (m_aArguments.getOutputPath() != null) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir sTmpDir = m_aArguments.getOutputPath(); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if (_sFile.toLowerCase().endsWith("ps") || 134*cdf0e10cSrcweir _sFile.toLowerCase().endsWith("prn") || 135*cdf0e10cSrcweir _sFile.toLowerCase().endsWith("pdf")) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir // seems to be a Postscript of PDF file 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir String[] aList = PRNCompare.createJPEGFromPostscript(sTmpDir, sFileDir, sBasename, m_aArguments.getResolutionInDPI()); 140*cdf0e10cSrcweir sJPEGFile = aList[0]; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir else if (_sFile.toLowerCase().endsWith("jpg") || 143*cdf0e10cSrcweir _sFile.toLowerCase().endsWith("jpeg")) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir // do nothing, it's already a picture. 146*cdf0e10cSrcweir return _sFile; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir // we assume it's an office document. 151*cdf0e10cSrcweir String sInputURL; 152*cdf0e10cSrcweir String sOutputURL; 153*cdf0e10cSrcweir String sPrintFileURL; 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir String sInputFile = sFileDir + fs + sBasename; 156*cdf0e10cSrcweir sInputURL = URLHelper.getFileURLFromSystemPath(sInputFile); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir String sOutputFile = sTmpDir + fs + sBasename; 159*cdf0e10cSrcweir sOutputURL = URLHelper.getFileURLFromSystemPath(sOutputFile); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir String sPrintFile = sTmpDir + fs + sNameNoSuffix + _sAdditional + ".ps"; 162*cdf0e10cSrcweir sPrintFileURL = URLHelper.getFileURLFromSystemPath(sPrintFile); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir try 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir OfficePrint.printToFile(m_aArguments, sInputURL, sOutputURL, sPrintFileURL); 167*cdf0e10cSrcweir sJPEGFile = createJPEG(sPrintFile, _sAdditional); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir catch (ConvWatchCancelException e) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir GlobalLogWriter.get().println("Exception caught, can't create:" + sPrintFileURL); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir return sJPEGFile; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir public String compare(String _sFile1, String _sFile2) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir String sJPEGFile1 = createJPEG(_sFile1, "-1"); 181*cdf0e10cSrcweir String sJPEGFile2 = createJPEG(_sFile2, "-2"); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir if (sJPEGFile1.length() > 0 && sJPEGFile2.length() > 0) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir String sDiffFile = PRNCompare.compareJPEGs(sJPEGFile1, sJPEGFile2); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir if (sDiffFile.length() > 0) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir GlobalLogWriter.get().println("Difference created: " + sDiffFile); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir return sDiffFile; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir return ""; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir } 197