1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._svx; 24 25 import com.sun.star.beans.XPropertySet; 26 import com.sun.star.document.XExporter; 27 import com.sun.star.drawing.XShape; 28 import com.sun.star.lang.XComponent; 29 import com.sun.star.lang.XMultiServiceFactory; 30 import com.sun.star.ucb.XSimpleFileAccess; 31 import com.sun.star.uno.UnoRuntime; 32 import com.sun.star.uno.XInterface; 33 import com.sun.star.util.URL; 34 35 import java.io.PrintWriter; 36 37 import lib.StatusException; 38 import lib.TestCase; 39 import lib.TestEnvironment; 40 import lib.TestParameters; 41 42 import util.DrawTools; 43 import util.SOfficeFactory; 44 import util.XMLTools; 45 46 47 /** 48 * Test for object which is represented by service 49 * <code>com.sun.star.drawing.GraphicExportFilter</code>. <p> 50 * 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::document::XFilter</code></li> 54 * <li> <code>com::sun::star::document::XMimeTypeInfo</code></li> 55 * <li> <code>com::sun::star::document::XExporter</code></li> 56 * </ul> <p> 57 * 58 * The following files used by this test : 59 * <ul> 60 * <li><b> space-metal.jpg </b> : the file used for GraphicObject 61 * creation. This image must be then exported. </li> 62 * </ul> <p> 63 * 64 * This object test <b> is NOT </b> designed to be run in several 65 * threads concurently. 66 * 67 * @see com.sun.star.document.XFilter 68 * @see com.sun.star.document.XMimeTypeInfo 69 * @see com.sun.star.document.XExporter 70 * @see ifc.document._XFilter 71 * @see ifc.document._XMimeTypeInfo 72 * @see ifc.document._XExporter 73 */ 74 public class GraphicExporter extends TestCase { 75 static XComponent xDrawDoc; 76 77 /** 78 * Creates a new draw document. 79 */ initialize(TestParameters tParam, PrintWriter log)80 protected void initialize(TestParameters tParam, PrintWriter log) { 81 log.println("creating a drawdoc"); 82 xDrawDoc = DrawTools.createDrawDoc( 83 (XMultiServiceFactory) tParam.getMSF()); 84 } 85 86 /** 87 * Disposes the draw document created before 88 */ cleanup(TestParameters tParam, PrintWriter log)89 protected void cleanup(TestParameters tParam, PrintWriter log) { 90 log.println(" disposing xDrawDoc "); 91 util.DesktopTools.closeDoc(xDrawDoc); 92 } 93 94 /** 95 * Creating a Testenvironment for the interfaces to be tested. 96 * Creates an instance of the service 97 * <code>com.sun.star.drawing.GraphicExportFilter</code> as 98 * a tested component. Then a <code>GraphicObjectShape</code> 99 * instance is added into the document and its image is obtained 100 * from JPEG file. This shape content is intended to be exported. 101 * 102 * Object relations created : 103 * <ul> 104 * <li> <code>'MediaDescriptor'</code> for 105 * {@link ifc.document._XFilter} : 106 * descriptor which contains target file name in 107 * the temporary directory, file type (JPEG) 108 * </li> 109 * <li> <code>'XFilter.Checker'</code> for 110 * {@link ifc.document._XFilter} : 111 * checks if the target file exists. 112 * In the case if SOffice is started in 'Hide' mode 113 * ('soapi.test.hidewindows' test parameter is 'true') 114 * the checker always returns <code>true</code>. 115 * </li> 116 * <li> <code>'SourceDocument'</code> for 117 * {@link ifc.document._XExporter} : 118 * the <code>GraphicObjectShape</code> component 119 * with loaded image. 120 * </li> 121 * </ul> 122 */ createTestEnvironment(TestParameters tParam, PrintWriter log)123 protected TestEnvironment createTestEnvironment(TestParameters tParam, 124 PrintWriter log) { 125 XInterface oObj = null; 126 XShape oShape = null; 127 Object go = null; 128 129 130 // creation of testobject here 131 // first we write what we are intend to do to log file 132 log.println("creating a test environment"); 133 134 try { 135 go = ((XMultiServiceFactory) tParam.getMSF()).createInstance( 136 "com.sun.star.drawing.GraphicExportFilter"); 137 } catch (com.sun.star.uno.Exception e) { 138 log.println("Couldn't create instance"); 139 e.printStackTrace(log); 140 } 141 142 // create testobject here 143 SOfficeFactory SOF = SOfficeFactory.getFactory( 144 (XMultiServiceFactory) tParam.getMSF()); 145 oShape = SOF.createShape(xDrawDoc, 5000, 5000, 1500, 1000, 146 "GraphicObject"); 147 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc, 0)).add(oShape); 148 149 XPropertySet oShapeProps = (XPropertySet) UnoRuntime.queryInterface( 150 XPropertySet.class, oShape); 151 XComponent xComp = null; 152 153 try { 154 oShapeProps.setPropertyValue("GraphicURL", 155 util.utils.getFullTestURL( 156 "space-metal.jpg")); 157 xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, 158 oShape); 159 160 XExporter xEx = (XExporter) UnoRuntime.queryInterface( 161 XExporter.class, (XInterface) go); 162 xEx.setSourceDocument(xComp); 163 } catch (com.sun.star.lang.WrappedTargetException e) { 164 e.printStackTrace(log); 165 throw new StatusException("Error while preparing component", e); 166 } catch (com.sun.star.lang.IllegalArgumentException e) { 167 e.printStackTrace(log); 168 throw new StatusException("Error while preparing component", e); 169 } catch (com.sun.star.beans.PropertyVetoException e) { 170 e.printStackTrace(log); 171 throw new StatusException("Error while preparing component", e); 172 } catch (com.sun.star.beans.UnknownPropertyException e) { 173 e.printStackTrace(log); 174 throw new StatusException("Error while preparing component", e); 175 } 176 177 final URL aURL = new URL(); 178 aURL.Complete = util.utils.getOfficeTemp( 179 (XMultiServiceFactory) tParam.getMSF()) + 180 "picture.jpg"; 181 182 final XSimpleFileAccess fAcc; 183 184 try { 185 Object oFAcc = ((XMultiServiceFactory) tParam.getMSF()).createInstance( 186 "com.sun.star.ucb.SimpleFileAccess"); 187 fAcc = (XSimpleFileAccess) UnoRuntime.queryInterface( 188 XSimpleFileAccess.class, oFAcc); 189 190 if (fAcc.exists(aURL.Complete)) { 191 fAcc.kill(aURL.Complete); 192 } 193 } catch (com.sun.star.uno.Exception e) { 194 log.println("Error accessing file system :"); 195 e.printStackTrace(log); 196 throw new StatusException("Error accessing file system.", e); 197 } 198 199 oObj = (XInterface) go; 200 log.println("ImplName " + util.utils.getImplName(oObj)); 201 202 TestEnvironment tEnv = new TestEnvironment(oObj); 203 tEnv.addObjRelation("MediaDescriptor", 204 XMLTools.createMediaDescriptor( 205 new String[] { 206 "FilterName", "URL", "MediaType" 207 }, new Object[] { "JPG", aURL, "image/jpeg" })); 208 tEnv.addObjRelation("SourceDocument", xComp); 209 210 log.println("adding ObjRelation for XFilter"); 211 log.println("This Component doesn't really support the cancel method"); 212 log.println("See #101725"); 213 tEnv.addObjRelation("NoFilter.cancel()", new Boolean(true)); 214 215 final String hideMode = (String) tParam.get("soapi.test.hidewindows"); 216 tEnv.addObjRelation("XFilter.Checker", 217 new ifc.document._XFilter.FilterChecker() { 218 public boolean checkFilter() { 219 try { 220 if ((hideMode != null) && hideMode.equals("true")) { 221 return true; 222 } 223 224 return fAcc.exists(aURL.Complete); 225 } catch (com.sun.star.uno.Exception e) { 226 return false; 227 } 228 } 229 }); 230 231 return tEnv; 232 } // finish method getTestEnvironment 233 } // finish class GraphicExporter 234