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 24 package mod._sd; 25 26 import java.io.PrintWriter; 27 import java.util.Comparator; 28 29 import lib.Status; 30 import lib.StatusException; 31 import lib.TestCase; 32 import lib.TestEnvironment; 33 import lib.TestParameters; 34 import util.DesktopTools; 35 import util.SOfficeFactory; 36 import util.utils; 37 38 import com.sun.star.awt.XWindow; 39 import com.sun.star.container.XIndexAccess; 40 import com.sun.star.drawing.XDrawPage; 41 import com.sun.star.drawing.XDrawPages; 42 import com.sun.star.drawing.XDrawPagesSupplier; 43 import com.sun.star.drawing.XShape; 44 import com.sun.star.drawing.XShapes; 45 import com.sun.star.frame.XController; 46 import com.sun.star.frame.XDesktop; 47 import com.sun.star.frame.XFrame; 48 import com.sun.star.frame.XModel; 49 import com.sun.star.lang.XComponent; 50 import com.sun.star.lang.XMultiServiceFactory; 51 import com.sun.star.uno.AnyConverter; 52 import com.sun.star.uno.Type; 53 import com.sun.star.uno.UnoRuntime; 54 import com.sun.star.uno.XInterface; 55 import com.sun.star.util.XModifiable; 56 57 /** 58 * Test for object which is represented by service 59 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p> 60 * Object implements the following interfaces : 61 * <ul> 62 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li> 63 * <li> <code>com::sun::star::lang::XComponent</code></li> 64 * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 65 * <li> <code>com::sun::star::frame::XController</code></li> 66 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 67 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li> 68 * <li> <code>com::sun::star::drawing::XDrawView</code></li> 69 * </ul> 70 * @see com.sun.star.drawing.DrawingDocumentDrawView 71 * @see com.sun.star.lang.XComponent 72 * @see com.sun.star.lang.XServiceInfo 73 * @see com.sun.star.frame.XController 74 * @see com.sun.star.beans.XPropertySet 75 * @see com.sun.star.view.XSelectionSupplier 76 * @see com.sun.star.drawing.XDrawView 77 * @see ifc.drawing._DrawingDocumentDrawView 78 * @see ifc.lang._XComponent 79 * @see ifc.lang._XServiceInfo 80 * @see ifc.frame._XController 81 * @see ifc.beans._XPropertySet 82 * @see ifc.view._XSelectionSupplier 83 * @see ifc.drawing._XDrawView 84 */ 85 public class SdUnoDrawView extends TestCase { 86 static XDesktop the_Desk; 87 static XComponent xDrawDoc; 88 static XComponent xSecondDrawDoc; 89 90 /** 91 * Creates the instance of the service 92 * <code>com.sun.star.frame.Desktop</code>. 93 * @see com.sun.star.frame.Desktop 94 */ initialize(TestParameters Param, PrintWriter log)95 protected void initialize(TestParameters Param, PrintWriter log) { 96 the_Desk = (XDesktop) 97 UnoRuntime.queryInterface( 98 XDesktop.class, DesktopTools.createDesktop( 99 (XMultiServiceFactory)Param.getMSF()) ); 100 } 101 102 /** 103 * Called while disposing a <code>TestEnvironment</code>. 104 * Disposes Impress documents. 105 * @param Param test parameters 106 * @param log writer to log information while testing 107 */ cleanup( TestParameters Param, PrintWriter log)108 protected void cleanup( TestParameters Param, PrintWriter log) { 109 log.println("disposing draw documents"); 110 util.DesktopTools.closeDoc(xDrawDoc); 111 util.DesktopTools.closeDoc(xSecondDrawDoc); 112 } 113 114 /** 115 * Creating a Testenvironment for the interfaces to be tested. 116 * Creates two impress documents. After creating 117 * of the documents makes short 118 * wait to allow frames to be loaded. Retrieves 119 * the collection of the draw pages 120 * from the first document and takes one of them. Inserts some shapes to the 121 * retrieved draw page. Obtains a current controller from the first document 122 * using the interface <code>XModel</code>. The obtained controller is the 123 * instance of the service 124 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. 125 * Object relations created : 126 * <ul> 127 * <li> <code>'Pages'</code> for 128 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw 129 * pages) </li> 130 * <li> <code>'FirstModel'</code> for 131 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 132 * the first created document) </li> 133 * <li> <code>'Frame'</code> for 134 * {@link ifc.frame._XController}(the frame of the created 135 * document) </li> 136 * <li> <code>'SecondModel'</code> for 137 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 138 * the second created document) </li> 139 * <li> <code>'SecondController'</code> for 140 * {@link ifc.frame._XController}(the current controller of the second 141 * created document) </li> 142 * <li> <code>'DrawPage'</code> for 143 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will 144 * be new current page) </li> 145 * </ul> 146 * @see com.sun.star.frame.XModel 147 * @see com.sun.star.drawing.DrawingDocumentDrawView 148 */ createTestEnvironment(TestParameters Param, PrintWriter log)149 public synchronized lib.TestEnvironment createTestEnvironment 150 (TestParameters Param, PrintWriter log) { 151 152 log.println( "creating a test environment" ); 153 154 // get a soffice factory object 155 SOfficeFactory SOF = SOfficeFactory.getFactory( 156 (XMultiServiceFactory)Param.getMSF()); 157 158 try { 159 log.println( "creating two draw documents" ); 160 xDrawDoc = SOF.createDrawDoc(null); 161 shortWait(); 162 xSecondDrawDoc = SOF.createDrawDoc(null); 163 shortWait(); 164 } catch (com.sun.star.uno.Exception e) { 165 e.printStackTrace( log ); 166 throw new StatusException("Couldn't create document", e); 167 } 168 169 // get the drawpage of drawing here 170 log.println( "getting Drawpage" ); 171 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 172 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); 173 XDrawPages the_pages = oDPS.getDrawPages(); 174 XIndexAccess oDPi = (XIndexAccess) 175 UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 176 177 XDrawPage oDrawPage = null; 178 try { 179 oDrawPage = (XDrawPage) AnyConverter.toObject( 180 new Type(XDrawPage.class),oDPi.getByIndex(0)); 181 } catch (com.sun.star.lang.WrappedTargetException e) { 182 e.printStackTrace( log ); 183 throw new StatusException("Couldn't get DrawPage", e); 184 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 185 e.printStackTrace( log ); 186 throw new StatusException("Couldn't get DrawPage", e); 187 } catch (com.sun.star.lang.IllegalArgumentException e) { 188 e.printStackTrace( log ); 189 throw new StatusException("Couldn't get DrawPage", e); 190 } 191 192 //put something on the drawpage 193 log.println( "inserting some Shapes" ); 194 XShapes oShapes = (XShapes) 195 UnoRuntime.queryInterface(XShapes.class, oDrawPage); 196 XShape shape1 = SOF.createShape( 197 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"); 198 XShape shape2 = SOF.createShape( 199 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 200 XShape shape3 = SOF.createShape( 201 xDrawDoc, 3000, 500, 5000, 1000, "Line"); 202 oShapes.add(shape1); 203 oShapes.add(shape2); 204 oShapes.add(shape3); 205 shortWait(); 206 207 XModel aModel = (XModel) 208 UnoRuntime.queryInterface(XModel.class, xDrawDoc); 209 210 XInterface oObj = aModel.getCurrentController(); 211 212 XModel aModel2 = (XModel) 213 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 214 215 XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface( 216 XWindow.class,aModel2.getCurrentController()); 217 218 log.println( "creating a new environment for impress view object" ); 219 TestEnvironment tEnv = new TestEnvironment( oObj ); 220 221 if (anotherWindow != null) { 222 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow); 223 } 224 225 226 tEnv.addObjRelation("Selections", new Object[] { 227 shape1, shape2, shape3}); 228 229 230 tEnv.addObjRelation("Pages", the_pages); 231 232 //Adding ObjRelations for XController 233 tEnv.addObjRelation("FirstModel", aModel); 234 235 tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 236 237 XFrame the_frame = the_Desk.getCurrentFrame(); 238 tEnv.addObjRelation("Frame", the_frame); 239 240 aModel = (XModel) 241 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 242 //Adding ObjRelations for XController 243 tEnv.addObjRelation("SecondModel", aModel); 244 245 XController secondController = aModel.getCurrentController(); 246 tEnv.addObjRelation("SecondController", secondController); 247 tEnv.addObjRelation("XDispatchProvider.URL", 248 "slot:27009"); 249 250 //Adding relations for DrawingDocumentDrawView 251 XDrawPage new_page = the_pages.insertNewByIndex(1); 252 tEnv.addObjRelation("DrawPage", new_page); 253 254 log.println("Implementation Name: "+utils.getImplName(oObj)); 255 256 XModifiable modify = (XModifiable) 257 UnoRuntime.queryInterface(XModifiable.class,xDrawDoc); 258 259 tEnv.addObjRelation("Modifiable",modify); 260 261 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc); 262 263 tEnv.addObjRelation("Comparer", new Comparator() { 264 public int compare(Object o1, Object o2) { 265 XIndexAccess indAc1 = (XIndexAccess) 266 UnoRuntime.queryInterface(XIndexAccess.class, o1); 267 XIndexAccess indAc2 = (XIndexAccess) 268 UnoRuntime.queryInterface(XIndexAccess.class, o2); 269 if (indAc1 == null || indAc2 == null) return -1; 270 if (indAc1.getCount() == indAc2.getCount()) { 271 return 0; 272 } 273 return 1; 274 } 275 public boolean equals(Object obj) { 276 return compare(this, obj) == 0; 277 } }); 278 279 280 return tEnv; 281 282 } // finish method getTestEnvironment 283 shortWait()284 private void shortWait() { 285 try { 286 Thread.sleep(1000) ; 287 } catch (InterruptedException e) { 288 System.out.println("While waiting :" + e) ; 289 } 290 } 291 292 293 } // finish class SdUnoDrawView 294 295