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