bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / GraphicExporter.java
blobd4d430a8d637e9f5de57a45c0ddf6710d954cb6f
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 .
18 package mod._svx;
20 import com.sun.star.beans.XPropertySet;
21 import com.sun.star.document.XExporter;
22 import com.sun.star.drawing.XShape;
23 import com.sun.star.lang.XComponent;
24 import com.sun.star.lang.XMultiServiceFactory;
25 import com.sun.star.ucb.XSimpleFileAccess;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
28 import com.sun.star.util.URL;
30 import java.io.PrintWriter;
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
37 import util.DrawTools;
38 import util.SOfficeFactory;
39 import util.XMLTools;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.drawing.GraphicExportFilter</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::document::XFilter</code></li>
49 * <li> <code>com::sun::star::document::XMimeTypeInfo</code></li>
50 * <li> <code>com::sun::star::document::XExporter</code></li>
51 * </ul> <p>
53 * The following files used by this test :
54 * <ul>
55 * <li><b> space-metal.jpg </b> : the file used for GraphicObject
56 * creation. This image must be then exported. </li>
57 * </ul> <p>
59 * This object test <b> is NOT </b> designed to be run in several
60 * threads concurently.
62 * @see com.sun.star.document.XFilter
63 * @see com.sun.star.document.XMimeTypeInfo
64 * @see com.sun.star.document.XExporter
65 * @see ifc.document._XFilter
66 * @see ifc.document._XMimeTypeInfo
67 * @see ifc.document._XExporter
69 public class GraphicExporter extends TestCase {
70 static XComponent xDrawDoc;
72 /**
73 * Creates a new draw document.
75 protected void initialize(TestParameters tParam, PrintWriter log) {
76 log.println("creating a drawdoc");
77 xDrawDoc = DrawTools.createDrawDoc(
78 (XMultiServiceFactory) tParam.getMSF());
81 /**
82 * Disposes the draw document created before
84 protected void cleanup(TestParameters tParam, PrintWriter log) {
85 log.println(" disposing xDrawDoc ");
86 util.DesktopTools.closeDoc(xDrawDoc);
89 /**
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.drawing.GraphicExportFilter</code> as
93 * a tested component. Then a <code>GraphicObjectShape</code>
94 * instance is added into the document and its image is obtained
95 * from JPEG file. This shape content is intended to be exported.
97 * Object relations created :
98 * <ul>
99 * <li> <code>'MediaDescriptor'</code> for
100 * {@link ifc.document._XFilter} :
101 * descriptor which contains target file name in
102 * the temporary directory, file type (JPEG)
103 * </li>
104 * <li> <code>'XFilter.Checker'</code> for
105 * {@link ifc.document._XFilter} :
106 * checks if the target file exists.
107 * In the case if SOffice is started in 'Hide' mode
108 * ('soapi.test.hidewindows' test parameter is 'true')
109 * the checker always returns <code>true</code>.
110 * </li>
111 * <li> <code>'SourceDocument'</code> for
112 * {@link ifc.document._XExporter} :
113 * the <code>GraphicObjectShape</code> component
114 * with loaded image.
115 * </li>
116 * </ul>
118 protected TestEnvironment createTestEnvironment(TestParameters tParam,
119 PrintWriter log) {
120 XInterface oObj = null;
121 XShape oShape = null;
122 Object go = null;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log.println("creating a test environment");
129 try {
130 go = ((XMultiServiceFactory) tParam.getMSF()).createInstance(
131 "com.sun.star.drawing.GraphicExportFilter");
132 } catch (com.sun.star.uno.Exception e) {
133 log.println("Couldn't create instance");
134 e.printStackTrace(log);
137 // create testobject here
138 SOfficeFactory SOF = SOfficeFactory.getFactory(
139 (XMultiServiceFactory) tParam.getMSF());
140 oShape = SOF.createShape(xDrawDoc, 5000, 5000, 1500, 1000,
141 "GraphicObject");
142 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc, 0)).add(oShape);
144 XPropertySet oShapeProps = UnoRuntime.queryInterface(
145 XPropertySet.class, oShape);
146 XComponent xComp = null;
148 try {
149 oShapeProps.setPropertyValue("GraphicURL",
150 util.utils.getFullTestURL(
151 "space-metal.jpg"));
152 xComp = UnoRuntime.queryInterface(XComponent.class,
153 oShape);
155 XExporter xEx = UnoRuntime.queryInterface(
156 XExporter.class, go);
157 xEx.setSourceDocument(xComp);
158 } catch (com.sun.star.lang.WrappedTargetException e) {
159 e.printStackTrace(log);
160 throw new StatusException("Error while preparing component", e);
161 } catch (com.sun.star.lang.IllegalArgumentException e) {
162 e.printStackTrace(log);
163 throw new StatusException("Error while preparing component", e);
164 } catch (com.sun.star.beans.PropertyVetoException e) {
165 e.printStackTrace(log);
166 throw new StatusException("Error while preparing component", e);
167 } catch (com.sun.star.beans.UnknownPropertyException e) {
168 e.printStackTrace(log);
169 throw new StatusException("Error while preparing component", e);
172 final URL aURL = new URL();
173 aURL.Complete = util.utils.getOfficeTemp(
174 (XMultiServiceFactory) tParam.getMSF()) +
175 "picture.jpg";
177 final XSimpleFileAccess fAcc;
179 try {
180 Object oFAcc = ((XMultiServiceFactory) tParam.getMSF()).createInstance(
181 "com.sun.star.ucb.SimpleFileAccess");
182 fAcc = UnoRuntime.queryInterface(
183 XSimpleFileAccess.class, oFAcc);
185 if (fAcc.exists(aURL.Complete)) {
186 fAcc.kill(aURL.Complete);
188 } catch (com.sun.star.uno.Exception e) {
189 log.println("Error accessing file system :");
190 e.printStackTrace(log);
191 throw new StatusException("Error accessing file system.", e);
194 oObj = (XInterface) go;
195 log.println("ImplName " + util.utils.getImplName(oObj));
197 TestEnvironment tEnv = new TestEnvironment(oObj);
198 tEnv.addObjRelation("MediaDescriptor",
199 XMLTools.createMediaDescriptor(
200 new String[] {
201 "FilterName", "URL", "MediaType"
202 }, new Object[] { "JPG", aURL, "image/jpeg" }));
203 tEnv.addObjRelation("SourceDocument", xComp);
205 log.println("adding ObjRelation for XFilter");
206 log.println("This Component doesn't really support the cancel method");
207 log.println("See #101725");
208 tEnv.addObjRelation("NoFilter.cancel()", new Boolean(true));
210 final String hideMode = (String) tParam.get("soapi.test.hidewindows");
211 tEnv.addObjRelation("XFilter.Checker",
212 new ifc.document._XFilter.FilterChecker() {
213 public boolean checkFilter() {
214 try {
215 if ((hideMode != null) && hideMode.equals("true")) {
216 return true;
219 return fAcc.exists(aURL.Complete);
220 } catch (com.sun.star.uno.Exception e) {
221 return false;
226 return tEnv;
227 } // finish method getTestEnvironment
228 } // finish class GraphicExporter