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