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>OutlineMode</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_OutlineView 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>OutlineMode</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 XIndexAccess oDPi = (XIndexAccess) 178 UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 179 180 XDrawPage oDrawPage = null; 181 try { 182 oDrawPage = (XDrawPage) AnyConverter.toObject( 183 new Type(XDrawPage.class),oDPi.getByIndex(0)); 184 } catch (com.sun.star.lang.WrappedTargetException e) { 185 e.printStackTrace( log ); 186 throw new StatusException("Couldn't get DrawPage", e); 187 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 188 e.printStackTrace( log ); 189 throw new StatusException("Couldn't get DrawPage", e); 190 } catch (com.sun.star.lang.IllegalArgumentException e) { 191 e.printStackTrace( log ); 192 throw new StatusException("Couldn't get DrawPage", e); 193 } 194 195 //put something on the drawpage 196 log.println( "inserting some Shapes" ); 197 XShapes oShapes = (XShapes) 198 UnoRuntime.queryInterface(XShapes.class, oDrawPage); 199 XShape shape1 = SOF.createShape( 200 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"); 201 XShape shape2 = SOF.createShape( 202 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 203 XShape shape3 = SOF.createShape( 204 xDrawDoc, 3000, 500, 5000, 1000, "Line"); 205 oShapes.add(shape1); 206 oShapes.add(shape2); 207 oShapes.add(shape3); 208 shortWait(); 209 210 log.println("switch to HandoutView..."); 211 try{ 212 utils.dispatchURL(xMSF, xDrawDoc, ".uno:OutlineMode"); 213 } catch (Exception e){ 214 e.printStackTrace(log); 215 throw new StatusException(Status.failed(e.toString())); 216 } 217 218 utils.shortWait(500); 219 220 XModel aModel = (XModel) 221 UnoRuntime.queryInterface(XModel.class, xDrawDoc); 222 223 XInterface oObj = aModel.getCurrentController(); 224 225 log.println("bring first document to front..."); 226 DesktopTools.bringWindowToFront(aModel); 227 228 XModel aModel2 = (XModel) 229 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 230 231 XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface( 232 XWindow.class,aModel2.getCurrentController()); 233 234 log.println( "creating a new environment for impress view object" ); 235 TestEnvironment tEnv = new TestEnvironment( oObj ); 236 237 if (anotherWindow != null) { 238 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow); 239 } 240 241 Object oShapeCol1 = null; 242 Object oShapeCol2 = null; 243 try { 244 oShapeCol1 = xMSF. 245 createInstance("com.sun.star.drawing.ShapeCollection"); 246 oShapeCol2 = xMSF. 247 createInstance("com.sun.star.drawing.ShapeCollection"); 248 } catch(com.sun.star.uno.Exception e) { 249 e.printStackTrace(log); 250 throw new StatusException(Status.failed("Couldn't create instance")); 251 } 252 253 XShapes xShapes1 = (XShapes) 254 UnoRuntime.queryInterface(XShapes.class, oShapeCol1); 255 XShapes xShapes2 = (XShapes) 256 UnoRuntime.queryInterface(XShapes.class, oShapeCol2); 257 xShapes1.add(shape2); 258 xShapes1.add(shape3); 259 xShapes2.add(shape1); 260 shortWait(); 261 262 tEnv.addObjRelation("Selections", new Object[] { 263 oDrawPage, oShapeCol1, oShapeCol2}); 264 tEnv.addObjRelation("Comparer", new Comparator() { 265 public int compare(Object o1, Object o2) { 266 XIndexAccess indAc1 = (XIndexAccess) 267 UnoRuntime.queryInterface(XIndexAccess.class, o1); 268 XIndexAccess indAc2 = (XIndexAccess) 269 UnoRuntime.queryInterface(XIndexAccess.class, o2); 270 if (indAc1 == null || indAc2 == null) return -1; 271 if (indAc1.getCount() == indAc2.getCount()) { 272 return 0; 273 } 274 return 1; 275 } 276 public boolean equals(Object obj) { 277 return compare(this, obj) == 0; 278 } }); 279 280 281 282 tEnv.addObjRelation("Pages", the_pages); 283 284 //Adding ObjRelations for XController 285 tEnv.addObjRelation("FirstModel", aModel); 286 287 tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 288 289 XFrame the_frame = the_Desk.getCurrentFrame(); 290 tEnv.addObjRelation("Frame", the_frame); 291 292 aModel = (XModel) 293 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 294 //Adding ObjRelations for XController 295 tEnv.addObjRelation("SecondModel", aModel); 296 297 XController secondController = aModel.getCurrentController(); 298 tEnv.addObjRelation("SecondController", secondController); 299 tEnv.addObjRelation("XDispatchProvider.URL", 300 "slot:27009"); 301 302 //Adding relations for DrawingDocumentDrawView 303 XDrawPage new_page = the_pages.insertNewByIndex(1); 304 tEnv.addObjRelation("DrawPage", new_page); 305 306 log.println("Implementation Name: "+utils.getImplName(oObj)); 307 308 XModifiable modify = (XModifiable) 309 UnoRuntime.queryInterface(XModifiable.class,xDrawDoc); 310 311 tEnv.addObjRelation("Modifiable",modify); 312 313 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc); 314 315 316 return tEnv; 317 318 } // finish method getTestEnvironment 319 320 private void shortWait() { 321 try { 322 Thread.sleep(1000) ; 323 } catch (InterruptedException e) { 324 System.out.println("While waiting :" + e) ; 325 } 326 } 327 328 329 } 330 331