1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: GfxCompare.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.util
.ArrayList
;
34 import convwatch
.EnhancedComplexTestCase
;
35 import convwatch
.PRNCompare
;
36 import convwatch
.GraphicalTestArguments
;
37 import helper
.URLHelper
;
38 import convwatch
.OfficePrint
;
41 public class GfxCompare
extends EnhancedComplexTestCase
43 // The first of the mandatory functions:
45 * Return the name of the test.
46 * In this case it is the actual name of the service.
47 * @return The tested service.
49 // public String getTestObjectName() {
50 // return "ConvWatch runner";
53 // The second of the mandatory functions: return all test methods as an
54 // array. There is only one test function in this example.
56 * Return all test methods.
57 * @return The test methods.
60 public String
[] getTestMethodNames() {
61 return new String
[]{"gfxcompare"};
66 * @return a List of software which must accessable as an external executable
68 protected Object
[] mustInstalledSoftware()
70 ArrayList aList
= new ArrayList();
71 // Tools from ImageMagick
72 aList
.add( "composite -version" );
73 aList
.add( "identify -version" );
76 aList
.add( "gs -version" );
77 return aList
.toArray();
81 GraphicalTestArguments m_aArguments
= null;
83 * The test method itself.
84 * Don't try to call it from outside, it is started only from qadevOOo runner
88 public void gfxcompare()
90 GlobalLogWriter
.set(log
);
92 // check if all need software is installed and accessable
93 checkEnvironment(mustInstalledSoftware());
95 m_aArguments
= getGraphicalTestArguments();
97 String sFile1
= (String
)param
.get("FILE1");
98 String sFile2
= (String
)param
.get("FILE2");
99 compare(sFile1
, sFile2
);
102 // -----------------------------------------------------------------------------
104 String
createJPEG(String _sFile
, String _sAdditional
)
106 String sJPEGFile
= "";
107 if (_sFile
.startsWith("file:///"))
109 _sFile
= FileHelper
.getSystemPathFromFileURL(_sFile
);
111 File aFile
= new File(_sFile
);
114 String sAbsFile
= aFile
.getAbsolutePath();
115 if (!sAbsFile
.equals(_sFile
))
122 GlobalLogWriter
.get().println("File: '" + _sFile
+ "' doesn't exist.");
125 String sFileDir
= FileHelper
.getPath(_sFile
);
126 String sBasename
= FileHelper
.getBasename(_sFile
);
127 String sNameNoSuffix
= FileHelper
.getNameNoSuffix(sBasename
);
129 String fs
= System
.getProperty("file.separator");
130 String sTmpDir
= util
.utils
.getUsersTempDir();
131 if (m_aArguments
.getOutputPath() != null)
133 sTmpDir
= m_aArguments
.getOutputPath();
136 if (_sFile
.toLowerCase().endsWith("ps") ||
137 _sFile
.toLowerCase().endsWith("prn") ||
138 _sFile
.toLowerCase().endsWith("pdf"))
140 // seems to be a Postscript of PDF file
142 String
[] aList
= PRNCompare
.createJPEGFromPostscript(sTmpDir
, sFileDir
, sBasename
, m_aArguments
.getResolutionInDPI());
143 sJPEGFile
= aList
[0];
145 else if (_sFile
.toLowerCase().endsWith("jpg") ||
146 _sFile
.toLowerCase().endsWith("jpeg"))
148 // do nothing, it's already a picture.
153 // we assume it's an office document.
156 String sPrintFileURL
;
158 String sInputFile
= sFileDir
+ fs
+ sBasename
;
159 sInputURL
= URLHelper
.getFileURLFromSystemPath(sInputFile
);
161 String sOutputFile
= sTmpDir
+ fs
+ sBasename
;
162 sOutputURL
= URLHelper
.getFileURLFromSystemPath(sOutputFile
);
164 String sPrintFile
= sTmpDir
+ fs
+ sNameNoSuffix
+ _sAdditional
+ ".ps";
165 sPrintFileURL
= URLHelper
.getFileURLFromSystemPath(sPrintFile
);
169 OfficePrint
.printToFile(m_aArguments
, sInputURL
, sOutputURL
, sPrintFileURL
);
170 sJPEGFile
= createJPEG(sPrintFile
, _sAdditional
);
172 catch (ConvWatchCancelException e
)
174 GlobalLogWriter
.get().println("Exception caught, can't create:" + sPrintFileURL
);
181 public String
compare(String _sFile1
, String _sFile2
)
183 String sJPEGFile1
= createJPEG(_sFile1
, "-1");
184 String sJPEGFile2
= createJPEG(_sFile2
, "-2");
186 if (sJPEGFile1
.length() > 0 && sJPEGFile2
.length() > 0)
188 String sDiffFile
= PRNCompare
.compareJPEGs(sJPEGFile1
, sJPEGFile2
);
190 if (sDiffFile
.length() > 0)
192 GlobalLogWriter
.get().println("Difference created: " + sDiffFile
);