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 * The view was switched to <b>NotesMode</b>. <p> 65 * Object implements the following interfaces : 66 * <ul> 67 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li> 68 * <li> <code>com::sun::star::lang::XComponent</code></li> 69 * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 70 * <li> <code>com::sun::star::frame::XController</code></li> 71 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 72 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li> 73 * <li> <code>com::sun::star::drawing::XDrawView</code></li> 74 * </ul> 75 * @see com.sun.star.drawing.DrawingDocumentDrawView 76 * @see com.sun.star.lang.XComponent 77 * @see com.sun.star.lang.XServiceInfo 78 * @see com.sun.star.frame.XController 79 * @see com.sun.star.beans.XPropertySet 80 * @see com.sun.star.view.XSelectionSupplier 81 * @see com.sun.star.drawing.XDrawView 82 * @see ifc.drawing._DrawingDocumentDrawView 83 * @see ifc.lang._XComponent 84 * @see ifc.lang._XServiceInfo 85 * @see ifc.frame._XController 86 * @see ifc.beans._XPropertySet 87 * @see ifc.view._XSelectionSupplier 88 * @see ifc.drawing._XDrawView 89 */ 90 public class DrawController_NotesView extends TestCase { 91 static XDesktop the_Desk; 92 static XComponent xDrawDoc; 93 static XComponent xSecondDrawDoc; 94 95 /** 96 * Creates the instance of the service 97 * <code>com.sun.star.frame.Desktop</code>. 98 * @see com.sun.star.frame.Desktop 99 */ 100 protected void initialize(TestParameters Param, PrintWriter log) { 101 the_Desk = (XDesktop) 102 UnoRuntime.queryInterface( 103 XDesktop.class, DesktopTools.createDesktop( 104 (XMultiServiceFactory)Param.getMSF()) ); 105 } 106 107 /** 108 * Called while disposing a <code>TestEnvironment</code>. 109 * Disposes Impress documents. 110 * @param tParam test parameters 111 * @param tEnv the environment to cleanup 112 * @param log writer to log information while testing 113 */ 114 protected void cleanup( TestParameters Param, PrintWriter log) { 115 log.println("disposing impress documents"); 116 util.DesktopTools.closeDoc(xDrawDoc); 117 util.DesktopTools.closeDoc(xSecondDrawDoc); 118 } 119 120 /** 121 * Creating a Testenvironment for the interfaces to be tested. 122 * Creates two impress documents. After creating 123 * of the documents makes short 124 * wait to allow frames to be loaded. Retrieves 125 * the collection of the draw pages 126 * from the first document and takes one of them. Inserts some shapes to the 127 * retrieved draw page. 128 * Switch to the <b>NotesMode</b>. 129 * Obtains a current controller from the first document 130 * using the interface <code>XModel</code>. The obtained controller is the 131 * instance of the service 132 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. 133 * Object relations created : 134 * <ul> 135 * <li> <code>'Pages'</code> for 136 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw 137 * pages) </li> 138 * <li> <code>'FirstModel'</code> for 139 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 140 * the first created document) </li> 141 * <li> <code>'Frame'</code> for 142 * {@link ifc.frame._XController}(the frame of the created 143 * document) </li> 144 * <li> <code>'SecondModel'</code> for 145 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 146 * the second created document) </li> 147 * <li> <code>'SecondController'</code> for 148 * {@link ifc.frame._XController}(the current controller of the second 149 * created document) </li> 150 * <li> <code>'DrawPage'</code> for 151 * {@link ifc.drawing.DrawingDocumentDrawView}(the draw page which will 152 * be new current page) </li> 153 * </ul> 154 * @see com.sun.star.frame.XModel 155 * @see com.sun.star.drawing.DrawingDocumentDrawView 156 */ 157 protected synchronized TestEnvironment createTestEnvironment 158 (TestParameters Param, PrintWriter log) { 159 160 log.println( "creating a test environment" ); 161 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 162 // get a soffice factory object 163 SOfficeFactory SOF = SOfficeFactory.getFactory(xMSF); 164 165 try { 166 log.println( "creating two impress documents" ); 167 xSecondDrawDoc = SOF.createImpressDoc(null); 168 shortWait(); 169 xDrawDoc = SOF.createImpressDoc(null); 170 shortWait(); 171 } catch (com.sun.star.uno.Exception e) { 172 e.printStackTrace( log ); 173 throw new StatusException("Couldn't create document", e); 174 } 175 176 // get the drawpage of drawing here 177 log.println( "getting Drawpage" ); 178 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 179 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); 180 XDrawPages the_pages = oDPS.getDrawPages(); 181 XIndexAccess oDPi = (XIndexAccess) 182 UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 183 184 XDrawPage oDrawPage = null; 185 try { 186 oDrawPage = (XDrawPage) AnyConverter.toObject( 187 new Type(XDrawPage.class),oDPi.getByIndex(0)); 188 } catch (com.sun.star.lang.WrappedTargetException e) { 189 e.printStackTrace( log ); 190 throw new StatusException("Couldn't get DrawPage", e); 191 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 192 e.printStackTrace( log ); 193 throw new StatusException("Couldn't get DrawPage", e); 194 } catch (com.sun.star.lang.IllegalArgumentException e) { 195 e.printStackTrace( log ); 196 throw new StatusException("Couldn't get DrawPage", e); 197 } 198 199 //put something on the drawpage 200 log.println( "inserting some Shapes" ); 201 XShapes oShapes = (XShapes) 202 UnoRuntime.queryInterface(XShapes.class, oDrawPage); 203 XShape shape1 = SOF.createShape( 204 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"); 205 XShape shape2 = SOF.createShape( 206 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 207 XShape shape3 = SOF.createShape( 208 xDrawDoc, 3000, 500, 5000, 1000, "Line"); 209 oShapes.add(shape1); 210 oShapes.add(shape2); 211 oShapes.add(shape3); 212 shortWait(); 213 214 log.println("switch to HandoutView..."); 215 try{ 216 utils.dispatchURL(xMSF, xDrawDoc, ".uno:NotesMode"); 217 } catch (Exception e){ 218 e.printStackTrace(log); 219 throw new StatusException(Status.failed(e.toString())); 220 } 221 222 utils.shortWait(500); 223 224 XModel aModel = (XModel) 225 UnoRuntime.queryInterface(XModel.class, xDrawDoc); 226 227 XInterface oObj = aModel.getCurrentController(); 228 229 log.println("bring first document to front..."); 230 DesktopTools.bringWindowToFront(aModel); 231 232 XModel aModel2 = (XModel) 233 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 234 235 XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface( 236 XWindow.class,aModel2.getCurrentController()); 237 238 log.println( "creating a new environment for impress view object" ); 239 TestEnvironment tEnv = new TestEnvironment( oObj ); 240 241 if (anotherWindow != null) { 242 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow); 243 } 244 245 Object oShapeCol1 = null; 246 Object oShapeCol2 = null; 247 try { 248 oShapeCol1 = xMSF. 249 createInstance("com.sun.star.drawing.ShapeCollection"); 250 oShapeCol2 = xMSF. 251 createInstance("com.sun.star.drawing.ShapeCollection"); 252 } catch(com.sun.star.uno.Exception e) { 253 e.printStackTrace(log); 254 throw new StatusException(Status.failed("Couldn't create instance")); 255 } 256 257 XShapes xShapes1 = (XShapes) 258 UnoRuntime.queryInterface(XShapes.class, oShapeCol1); 259 XShapes xShapes2 = (XShapes) 260 UnoRuntime.queryInterface(XShapes.class, oShapeCol2); 261 xShapes1.add(shape2); 262 xShapes1.add(shape3); 263 xShapes2.add(shape1); 264 shortWait(); 265 266 tEnv.addObjRelation("Selections", new Object[] { 267 oDrawPage, oShapeCol1, oShapeCol2}); 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 286 tEnv.addObjRelation("Pages", the_pages); 287 288 //Adding ObjRelations for XController 289 tEnv.addObjRelation("FirstModel", aModel); 290 291 tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 292 293 XFrame the_frame = the_Desk.getCurrentFrame(); 294 tEnv.addObjRelation("Frame", the_frame); 295 296 aModel = (XModel) 297 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 298 //Adding ObjRelations for XController 299 tEnv.addObjRelation("SecondModel", aModel); 300 301 XController secondController = aModel.getCurrentController(); 302 tEnv.addObjRelation("SecondController", secondController); 303 tEnv.addObjRelation("XDispatchProvider.URL", 304 "slot:27009"); 305 306 //Adding relations for DrawingDocumentDrawView 307 XDrawPage new_page = the_pages.insertNewByIndex(1); 308 tEnv.addObjRelation("DrawPage", new_page); 309 310 log.println("Implementation Name: "+utils.getImplName(oObj)); 311 312 XModifiable modify = (XModifiable) 313 UnoRuntime.queryInterface(XModifiable.class,xDrawDoc); 314 315 tEnv.addObjRelation("Modifiable",modify); 316 317 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc); 318 319 320 return tEnv; 321 322 } // finish method getTestEnvironment 323 324 private void shortWait() { 325 try { 326 Thread.sleep(1000) ; 327 } catch (InterruptedException e) { 328 System.out.println("While waiting :" + e) ; 329 } 330 } 331 332 333 } 334 335