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 ************************************************************************/
30 import java
.util
.ArrayList
;
31 import convwatch
.EnhancedComplexTestCase
;
32 import convwatch
.PRNCompare
;
33 import convwatch
.GraphicalTestArguments
;
34 import helper
.URLHelper
;
35 import convwatch
.OfficePrint
;
38 public class GfxCompare
extends EnhancedComplexTestCase
40 // The first of the mandatory functions:
42 * Return the name of the test.
43 * In this case it is the actual name of the service.
44 * @return The tested service.
46 // public String getTestObjectName() {
47 // return "ConvWatch runner";
50 // The second of the mandatory functions: return all test methods as an
51 // array. There is only one test function in this example.
53 * Return all test methods.
54 * @return The test methods.
57 public String
[] getTestMethodNames() {
58 return new String
[]{"gfxcompare"};
63 * @return a List of software which must accessable as an external executable
65 protected Object
[] mustInstalledSoftware()
67 ArrayList aList
= new ArrayList();
68 // Tools from ImageMagick
69 aList
.add( "composite -version" );
70 aList
.add( "identify -version" );
73 aList
.add( "gs -version" );
74 return aList
.toArray();
78 GraphicalTestArguments m_aArguments
= null;
80 * The test method itself.
81 * Don't try to call it from outside, it is started only from qadevOOo runner
85 public void gfxcompare()
87 GlobalLogWriter
.set(log
);
89 // check if all need software is installed and accessable
90 checkEnvironment(mustInstalledSoftware());
92 m_aArguments
= getGraphicalTestArguments();
94 String sFile1
= (String
)param
.get("FILE1");
95 String sFile2
= (String
)param
.get("FILE2");
96 compare(sFile1
, sFile2
);
99 // -----------------------------------------------------------------------------
101 String
createJPEG(String _sFile
, String _sAdditional
)
103 String sJPEGFile
= "";
104 if (_sFile
.startsWith("file:///"))
106 _sFile
= FileHelper
.getSystemPathFromFileURL(_sFile
);
108 File aFile
= new File(_sFile
);
111 String sAbsFile
= aFile
.getAbsolutePath();
112 if (!sAbsFile
.equals(_sFile
))
119 GlobalLogWriter
.get().println("File: '" + _sFile
+ "' doesn't exist.");
122 String sFileDir
= FileHelper
.getPath(_sFile
);
123 String sBasename
= FileHelper
.getBasename(_sFile
);
124 String sNameNoSuffix
= FileHelper
.getNameNoSuffix(sBasename
);
126 String fs
= System
.getProperty("file.separator");
127 String sTmpDir
= util
.utils
.getUsersTempDir();
128 if (m_aArguments
.getOutputPath() != null)
130 sTmpDir
= m_aArguments
.getOutputPath();
133 if (_sFile
.toLowerCase().endsWith("ps") ||
134 _sFile
.toLowerCase().endsWith("prn") ||
135 _sFile
.toLowerCase().endsWith("pdf"))
137 // seems to be a Postscript of PDF file
139 String
[] aList
= PRNCompare
.createJPEGFromPostscript(sTmpDir
, sFileDir
, sBasename
, m_aArguments
.getResolutionInDPI());
140 sJPEGFile
= aList
[0];
142 else if (_sFile
.toLowerCase().endsWith("jpg") ||
143 _sFile
.toLowerCase().endsWith("jpeg"))
145 // do nothing, it's already a picture.
150 // we assume it's an office document.
153 String sPrintFileURL
;
155 String sInputFile
= sFileDir
+ fs
+ sBasename
;
156 sInputURL
= URLHelper
.getFileURLFromSystemPath(sInputFile
);
158 String sOutputFile
= sTmpDir
+ fs
+ sBasename
;
159 sOutputURL
= URLHelper
.getFileURLFromSystemPath(sOutputFile
);
161 String sPrintFile
= sTmpDir
+ fs
+ sNameNoSuffix
+ _sAdditional
+ ".ps";
162 sPrintFileURL
= URLHelper
.getFileURLFromSystemPath(sPrintFile
);
166 OfficePrint
.printToFile(m_aArguments
, sInputURL
, sOutputURL
, sPrintFileURL
);
167 sJPEGFile
= createJPEG(sPrintFile
, _sAdditional
);
169 catch (ConvWatchCancelException e
)
171 GlobalLogWriter
.get().println("Exception caught, can't create:" + sPrintFileURL
);
178 public String
compare(String _sFile1
, String _sFile2
)
180 String sJPEGFile1
= createJPEG(_sFile1
, "-1");
181 String sJPEGFile2
= createJPEG(_sFile2
, "-2");
183 if (sJPEGFile1
.length() > 0 && sJPEGFile2
.length() > 0)
185 String sDiffFile
= PRNCompare
.compareJPEGs(sJPEGFile1
, sJPEGFile2
);
187 if (sDiffFile
.length() > 0)
189 GlobalLogWriter
.get().println("Difference created: " + sDiffFile
);