1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sd; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir import java.util.Comparator; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import lib.Status; 30cdf0e10cSrcweir import lib.StatusException; 31cdf0e10cSrcweir import lib.TestCase; 32cdf0e10cSrcweir import lib.TestEnvironment; 33cdf0e10cSrcweir import lib.TestParameters; 34cdf0e10cSrcweir import util.DesktopTools; 35cdf0e10cSrcweir import util.SOfficeFactory; 36cdf0e10cSrcweir import util.utils; 37cdf0e10cSrcweir 38cdf0e10cSrcweir import com.sun.star.awt.XWindow; 39cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 40cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 41cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages; 42cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier; 43cdf0e10cSrcweir import com.sun.star.drawing.XShape; 44cdf0e10cSrcweir import com.sun.star.drawing.XShapes; 45cdf0e10cSrcweir import com.sun.star.frame.XController; 46cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 47cdf0e10cSrcweir import com.sun.star.frame.XFrame; 48cdf0e10cSrcweir import com.sun.star.frame.XModel; 49cdf0e10cSrcweir import com.sun.star.lang.XComponent; 50cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 51cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 52cdf0e10cSrcweir import com.sun.star.uno.Type; 53cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 54cdf0e10cSrcweir import com.sun.star.uno.XInterface; 55cdf0e10cSrcweir import com.sun.star.util.XModifiable; 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** 58cdf0e10cSrcweir * Test for object which is represented by service 59cdf0e10cSrcweir * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p> 60cdf0e10cSrcweir * The view was switched to <b>OutlineMode</b>. <p> 61cdf0e10cSrcweir * Object implements the following interfaces : 62cdf0e10cSrcweir * <ul> 63cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li> 64cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 65cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 66cdf0e10cSrcweir * <li> <code>com::sun::star::frame::XController</code></li> 67cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 68cdf0e10cSrcweir * <li> <code>com::sun::star::view::XSelectionSupplier</code></li> 69cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::XDrawView</code></li> 70cdf0e10cSrcweir * </ul> 71cdf0e10cSrcweir * @see com.sun.star.drawing.DrawingDocumentDrawView 72cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 73cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 74cdf0e10cSrcweir * @see com.sun.star.frame.XController 75cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 76cdf0e10cSrcweir * @see com.sun.star.view.XSelectionSupplier 77cdf0e10cSrcweir * @see com.sun.star.drawing.XDrawView 78cdf0e10cSrcweir * @see ifc.drawing._DrawingDocumentDrawView 79cdf0e10cSrcweir * @see ifc.lang._XComponent 80cdf0e10cSrcweir * @see ifc.lang._XServiceInfo 81cdf0e10cSrcweir * @see ifc.frame._XController 82cdf0e10cSrcweir * @see ifc.beans._XPropertySet 83cdf0e10cSrcweir * @see ifc.view._XSelectionSupplier 84cdf0e10cSrcweir * @see ifc.drawing._XDrawView 85cdf0e10cSrcweir */ 86cdf0e10cSrcweir public class DrawController_OutlineView extends TestCase { 87cdf0e10cSrcweir static XDesktop the_Desk; 88cdf0e10cSrcweir static XComponent xDrawDoc; 89cdf0e10cSrcweir static XComponent xSecondDrawDoc; 90cdf0e10cSrcweir 91cdf0e10cSrcweir /** 92cdf0e10cSrcweir * Creates the instance of the service 93cdf0e10cSrcweir * <code>com.sun.star.frame.Desktop</code>. 94cdf0e10cSrcweir * @see com.sun.star.frame.Desktop 95cdf0e10cSrcweir */ initialize(TestParameters Param, PrintWriter log)96cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 97cdf0e10cSrcweir the_Desk = (XDesktop) 98cdf0e10cSrcweir UnoRuntime.queryInterface( 99cdf0e10cSrcweir XDesktop.class, DesktopTools.createDesktop( 100cdf0e10cSrcweir (XMultiServiceFactory)Param.getMSF()) ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir /** 104cdf0e10cSrcweir * Called while disposing a <code>TestEnvironment</code>. 105cdf0e10cSrcweir * Disposes Impress documents. 106*e6b649b5SPedro Giffuni * @param Param test parameters 107cdf0e10cSrcweir * @param log writer to log information while testing 108cdf0e10cSrcweir */ cleanup( TestParameters Param, PrintWriter log)109cdf0e10cSrcweir protected void cleanup( TestParameters Param, PrintWriter log) { 110cdf0e10cSrcweir log.println("disposing impress documents"); 111cdf0e10cSrcweir util.DesktopTools.closeDoc(xDrawDoc); 112cdf0e10cSrcweir util.DesktopTools.closeDoc(xSecondDrawDoc); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir /** 116cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 117cdf0e10cSrcweir * Creates two impress documents. After creating 118cdf0e10cSrcweir * of the documents makes short 119cdf0e10cSrcweir * wait to allow frames to be loaded. Retrieves 120cdf0e10cSrcweir * the collection of the draw pages 121cdf0e10cSrcweir * from the first document and takes one of them. Inserts some shapes to the 122cdf0e10cSrcweir * retrieved draw page. 123cdf0e10cSrcweir * Switch to the <b>OutlineMode</b>. 124cdf0e10cSrcweir * Obtains a current controller from the first document 125cdf0e10cSrcweir * using the interface <code>XModel</code>. The obtained controller is the 126cdf0e10cSrcweir * instance of the service 127cdf0e10cSrcweir * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. 128cdf0e10cSrcweir * Object relations created : 129cdf0e10cSrcweir * <ul> 130cdf0e10cSrcweir * <li> <code>'Pages'</code> for 131cdf0e10cSrcweir * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw 132cdf0e10cSrcweir * pages) </li> 133cdf0e10cSrcweir * <li> <code>'FirstModel'</code> for 134cdf0e10cSrcweir * {@link ifc.frame._XController}(the interface <code>XModel</code> of 135cdf0e10cSrcweir * the first created document) </li> 136cdf0e10cSrcweir * <li> <code>'Frame'</code> for 137cdf0e10cSrcweir * {@link ifc.frame._XController}(the frame of the created 138cdf0e10cSrcweir * document) </li> 139cdf0e10cSrcweir * <li> <code>'SecondModel'</code> for 140cdf0e10cSrcweir * {@link ifc.frame._XController}(the interface <code>XModel</code> of 141cdf0e10cSrcweir * the second created document) </li> 142cdf0e10cSrcweir * <li> <code>'SecondController'</code> for 143cdf0e10cSrcweir * {@link ifc.frame._XController}(the current controller of the second 144cdf0e10cSrcweir * created document) </li> 145cdf0e10cSrcweir * <li> <code>'DrawPage'</code> for 146*e6b649b5SPedro Giffuni * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will 147cdf0e10cSrcweir * be new current page) </li> 148cdf0e10cSrcweir * </ul> 149cdf0e10cSrcweir * @see com.sun.star.frame.XModel 150cdf0e10cSrcweir * @see com.sun.star.drawing.DrawingDocumentDrawView 151cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)152cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment 153cdf0e10cSrcweir (TestParameters Param, PrintWriter log) { 154cdf0e10cSrcweir 155cdf0e10cSrcweir log.println( "creating a test environment" ); 156cdf0e10cSrcweir XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 157cdf0e10cSrcweir // get a soffice factory object 158cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory(xMSF); 159cdf0e10cSrcweir 160cdf0e10cSrcweir try { 161cdf0e10cSrcweir log.println( "creating two impress documents" ); 162cdf0e10cSrcweir xSecondDrawDoc = SOF.createImpressDoc(null); 163cdf0e10cSrcweir shortWait(); 164cdf0e10cSrcweir xDrawDoc = SOF.createImpressDoc(null); 165cdf0e10cSrcweir shortWait(); 166cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 167cdf0e10cSrcweir e.printStackTrace( log ); 168cdf0e10cSrcweir throw new StatusException("Couldn't create document", e); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir // get the drawpage of drawing here 172cdf0e10cSrcweir log.println( "getting Drawpage" ); 173cdf0e10cSrcweir XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 174cdf0e10cSrcweir UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); 175cdf0e10cSrcweir XDrawPages the_pages = oDPS.getDrawPages(); 176cdf0e10cSrcweir XIndexAccess oDPi = (XIndexAccess) 177cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 178cdf0e10cSrcweir 179cdf0e10cSrcweir XDrawPage oDrawPage = null; 180cdf0e10cSrcweir try { 181cdf0e10cSrcweir oDrawPage = (XDrawPage) AnyConverter.toObject( 182cdf0e10cSrcweir new Type(XDrawPage.class),oDPi.getByIndex(0)); 183cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 184cdf0e10cSrcweir e.printStackTrace( log ); 185cdf0e10cSrcweir throw new StatusException("Couldn't get DrawPage", e); 186cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 187cdf0e10cSrcweir e.printStackTrace( log ); 188cdf0e10cSrcweir throw new StatusException("Couldn't get DrawPage", e); 189cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 190cdf0e10cSrcweir e.printStackTrace( log ); 191cdf0e10cSrcweir throw new StatusException("Couldn't get DrawPage", e); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir //put something on the drawpage 195cdf0e10cSrcweir log.println( "inserting some Shapes" ); 196cdf0e10cSrcweir XShapes oShapes = (XShapes) 197cdf0e10cSrcweir UnoRuntime.queryInterface(XShapes.class, oDrawPage); 198cdf0e10cSrcweir XShape shape1 = SOF.createShape( 199cdf0e10cSrcweir xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"); 200cdf0e10cSrcweir XShape shape2 = SOF.createShape( 201cdf0e10cSrcweir xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 202cdf0e10cSrcweir XShape shape3 = SOF.createShape( 203cdf0e10cSrcweir xDrawDoc, 3000, 500, 5000, 1000, "Line"); 204cdf0e10cSrcweir oShapes.add(shape1); 205cdf0e10cSrcweir oShapes.add(shape2); 206cdf0e10cSrcweir oShapes.add(shape3); 207cdf0e10cSrcweir shortWait(); 208cdf0e10cSrcweir 209cdf0e10cSrcweir log.println("switch to HandoutView..."); 210cdf0e10cSrcweir try{ 211cdf0e10cSrcweir utils.dispatchURL(xMSF, xDrawDoc, ".uno:OutlineMode"); 212cdf0e10cSrcweir } catch (Exception e){ 213cdf0e10cSrcweir e.printStackTrace(log); 214cdf0e10cSrcweir throw new StatusException(Status.failed(e.toString())); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir utils.shortWait(500); 218cdf0e10cSrcweir 219cdf0e10cSrcweir XModel aModel = (XModel) 220cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xDrawDoc); 221cdf0e10cSrcweir 222cdf0e10cSrcweir XInterface oObj = aModel.getCurrentController(); 223cdf0e10cSrcweir 224cdf0e10cSrcweir log.println("bring first document to front..."); 225cdf0e10cSrcweir DesktopTools.bringWindowToFront(aModel); 226cdf0e10cSrcweir 227cdf0e10cSrcweir XModel aModel2 = (XModel) 228cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 229cdf0e10cSrcweir 230cdf0e10cSrcweir XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface( 231cdf0e10cSrcweir XWindow.class,aModel2.getCurrentController()); 232cdf0e10cSrcweir 233cdf0e10cSrcweir log.println( "creating a new environment for impress view object" ); 234cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 235cdf0e10cSrcweir 236cdf0e10cSrcweir if (anotherWindow != null) { 237cdf0e10cSrcweir tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir Object oShapeCol1 = null; 241cdf0e10cSrcweir Object oShapeCol2 = null; 242cdf0e10cSrcweir try { 243cdf0e10cSrcweir oShapeCol1 = xMSF. 244cdf0e10cSrcweir createInstance("com.sun.star.drawing.ShapeCollection"); 245cdf0e10cSrcweir oShapeCol2 = xMSF. 246cdf0e10cSrcweir createInstance("com.sun.star.drawing.ShapeCollection"); 247cdf0e10cSrcweir } catch(com.sun.star.uno.Exception e) { 248cdf0e10cSrcweir e.printStackTrace(log); 249cdf0e10cSrcweir throw new StatusException(Status.failed("Couldn't create instance")); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir XShapes xShapes1 = (XShapes) 253cdf0e10cSrcweir UnoRuntime.queryInterface(XShapes.class, oShapeCol1); 254cdf0e10cSrcweir XShapes xShapes2 = (XShapes) 255cdf0e10cSrcweir UnoRuntime.queryInterface(XShapes.class, oShapeCol2); 256cdf0e10cSrcweir xShapes1.add(shape2); 257cdf0e10cSrcweir xShapes1.add(shape3); 258cdf0e10cSrcweir xShapes2.add(shape1); 259cdf0e10cSrcweir shortWait(); 260cdf0e10cSrcweir 261cdf0e10cSrcweir tEnv.addObjRelation("Selections", new Object[] { 262cdf0e10cSrcweir oDrawPage, oShapeCol1, oShapeCol2}); 263cdf0e10cSrcweir tEnv.addObjRelation("Comparer", new Comparator() { 264cdf0e10cSrcweir public int compare(Object o1, Object o2) { 265cdf0e10cSrcweir XIndexAccess indAc1 = (XIndexAccess) 266cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class, o1); 267cdf0e10cSrcweir XIndexAccess indAc2 = (XIndexAccess) 268cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class, o2); 269cdf0e10cSrcweir if (indAc1 == null || indAc2 == null) return -1; 270cdf0e10cSrcweir if (indAc1.getCount() == indAc2.getCount()) { 271cdf0e10cSrcweir return 0; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir return 1; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir public boolean equals(Object obj) { 276cdf0e10cSrcweir return compare(this, obj) == 0; 277cdf0e10cSrcweir } }); 278cdf0e10cSrcweir 279cdf0e10cSrcweir 280cdf0e10cSrcweir 281cdf0e10cSrcweir tEnv.addObjRelation("Pages", the_pages); 282cdf0e10cSrcweir 283cdf0e10cSrcweir //Adding ObjRelations for XController 284cdf0e10cSrcweir tEnv.addObjRelation("FirstModel", aModel); 285cdf0e10cSrcweir 286cdf0e10cSrcweir tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 287cdf0e10cSrcweir 288cdf0e10cSrcweir XFrame the_frame = the_Desk.getCurrentFrame(); 289cdf0e10cSrcweir tEnv.addObjRelation("Frame", the_frame); 290cdf0e10cSrcweir 291cdf0e10cSrcweir aModel = (XModel) 292cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 293cdf0e10cSrcweir //Adding ObjRelations for XController 294cdf0e10cSrcweir tEnv.addObjRelation("SecondModel", aModel); 295cdf0e10cSrcweir 296cdf0e10cSrcweir XController secondController = aModel.getCurrentController(); 297cdf0e10cSrcweir tEnv.addObjRelation("SecondController", secondController); 298cdf0e10cSrcweir tEnv.addObjRelation("XDispatchProvider.URL", 299cdf0e10cSrcweir "slot:27009"); 300cdf0e10cSrcweir 301cdf0e10cSrcweir //Adding relations for DrawingDocumentDrawView 302cdf0e10cSrcweir XDrawPage new_page = the_pages.insertNewByIndex(1); 303cdf0e10cSrcweir tEnv.addObjRelation("DrawPage", new_page); 304cdf0e10cSrcweir 305cdf0e10cSrcweir log.println("Implementation Name: "+utils.getImplName(oObj)); 306cdf0e10cSrcweir 307cdf0e10cSrcweir XModifiable modify = (XModifiable) 308cdf0e10cSrcweir UnoRuntime.queryInterface(XModifiable.class,xDrawDoc); 309cdf0e10cSrcweir 310cdf0e10cSrcweir tEnv.addObjRelation("Modifiable",modify); 311cdf0e10cSrcweir 312cdf0e10cSrcweir tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc); 313cdf0e10cSrcweir 314cdf0e10cSrcweir 315cdf0e10cSrcweir return tEnv; 316cdf0e10cSrcweir 317cdf0e10cSrcweir } // finish method getTestEnvironment 318cdf0e10cSrcweir shortWait()319cdf0e10cSrcweir private void shortWait() { 320cdf0e10cSrcweir try { 321cdf0e10cSrcweir Thread.sleep(1000) ; 322cdf0e10cSrcweir } catch (InterruptedException e) { 323cdf0e10cSrcweir System.out.println("While waiting :" + e) ; 324cdf0e10cSrcweir } 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir 328cdf0e10cSrcweir } 329cdf0e10cSrcweir 330