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