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 32*cdf0e10cSrcweir import lib.StatusException; 33*cdf0e10cSrcweir import lib.TestCase; 34*cdf0e10cSrcweir import lib.TestEnvironment; 35*cdf0e10cSrcweir import lib.TestParameters; 36*cdf0e10cSrcweir import util.DesktopTools; 37*cdf0e10cSrcweir import util.SOfficeFactory; 38*cdf0e10cSrcweir import util.utils; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir import com.sun.star.awt.XWindow; 41*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 42*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages; 43*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier; 44*cdf0e10cSrcweir import com.sun.star.frame.XController; 45*cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 46*cdf0e10cSrcweir import com.sun.star.frame.XDispatch; 47*cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider; 48*cdf0e10cSrcweir import com.sun.star.frame.XFrame; 49*cdf0e10cSrcweir import com.sun.star.frame.XModel; 50*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 51*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 52*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 53*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 54*cdf0e10cSrcweir import com.sun.star.util.URL; 55*cdf0e10cSrcweir import com.sun.star.util.XURLTransformer; 56*cdf0e10cSrcweir /** 57*cdf0e10cSrcweir * Test for object which is represented by service 58*cdf0e10cSrcweir * <code>com.sun.star.present.OutlineView</code>. <p> 59*cdf0e10cSrcweir * Object implements the following interfaces : 60*cdf0e10cSrcweir * <ul> 61*cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 62*cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 63*cdf0e10cSrcweir * <li> <code>com::sun::star::frame::XController</code></li> 64*cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 65*cdf0e10cSrcweir * <li> <code>com::sun::star::presentation::OutlineView</code></li> 66*cdf0e10cSrcweir * <li> <code>com::sun::star::frame::XDispatchProvider</code></li> 67*cdf0e10cSrcweir * <li> <code>com::sun::star::awt::XWindow</code></li> 68*cdf0e10cSrcweir * </ul> 69*cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 70*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 71*cdf0e10cSrcweir * @see com.sun.star.frame.XController 72*cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 73*cdf0e10cSrcweir * @see com.sun.star.presentation.OutlineView 74*cdf0e10cSrcweir * @see com.sun.star.awt.XWindow 75*cdf0e10cSrcweir * @see com.sun.star.frame.XDispatchProvider 76*cdf0e10cSrcweir * @see ifc.lang._XComponent 77*cdf0e10cSrcweir * @see ifc.lang._XServiceInfo 78*cdf0e10cSrcweir * @see ifc.frame._XController 79*cdf0e10cSrcweir * @see ifc.beans._XPropertySet 80*cdf0e10cSrcweir * @see ifc.awt._XWindow 81*cdf0e10cSrcweir * @see ifc.presentation._OutlineView 82*cdf0e10cSrcweir * @see ifc.frame._XDispatchProvider 83*cdf0e10cSrcweir */ 84*cdf0e10cSrcweir public class SdUnoOutlineView extends TestCase { 85*cdf0e10cSrcweir XDesktop the_Desk; 86*cdf0e10cSrcweir XComponent xImpressDoc; 87*cdf0e10cSrcweir XComponent xSecondDrawDoc; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /** 90*cdf0e10cSrcweir * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>. 91*cdf0e10cSrcweir * @see com.sun.star.frame.Desktop 92*cdf0e10cSrcweir */ 93*cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 94*cdf0e10cSrcweir the_Desk = (XDesktop) 95*cdf0e10cSrcweir UnoRuntime.queryInterface( 96*cdf0e10cSrcweir XDesktop.class, DesktopTools.createDesktop( 97*cdf0e10cSrcweir (XMultiServiceFactory)Param.getMSF()) ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir /** 101*cdf0e10cSrcweir * Called while disposing a <code>TestEnvironment</code>. 102*cdf0e10cSrcweir * Disposes Impress documents. 103*cdf0e10cSrcweir * @param tParam test parameters 104*cdf0e10cSrcweir * @param tEnv the environment to cleanup 105*cdf0e10cSrcweir * @param log writer to log information while testing 106*cdf0e10cSrcweir */ 107*cdf0e10cSrcweir protected void cleanup( TestParameters Param, PrintWriter log) { 108*cdf0e10cSrcweir log.println("disposing impress documents"); 109*cdf0e10cSrcweir util.DesktopTools.closeDoc(xImpressDoc);; 110*cdf0e10cSrcweir util.DesktopTools.closeDoc(xSecondDrawDoc);; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir /** 114*cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 115*cdf0e10cSrcweir * Creates two impress documents. After creating of the documents makes short 116*cdf0e10cSrcweir * wait to allow frames to be loaded. Retrieves the collection of the draw pages 117*cdf0e10cSrcweir * from the first document and takes one of them. Inserts some shapes to the 118*cdf0e10cSrcweir * retrieved draw page. Obtains a current controller from the first document 119*cdf0e10cSrcweir * using the interface <code>XModel</code>. The obtained controller is the 120*cdf0e10cSrcweir * instance of the service <code>com.sun.star.presentation.OutlineView</code>. 121*cdf0e10cSrcweir * Object relations created : 122*cdf0e10cSrcweir * <ul> 123*cdf0e10cSrcweir * <li> <code>'FirstModel'</code> for 124*cdf0e10cSrcweir * {@link ifc.frame._XController}(the interface <code>XModel</code> of 125*cdf0e10cSrcweir * the first created document) </li> 126*cdf0e10cSrcweir * <li> <code>'Frame'</code> for 127*cdf0e10cSrcweir * {@link ifc.frame._XController}(the frame of the created 128*cdf0e10cSrcweir * document) </li> 129*cdf0e10cSrcweir * <li> <code>'SecondModel'</code> for 130*cdf0e10cSrcweir * {@link ifc.frame._XController}(the interface <code>XModel</code> of 131*cdf0e10cSrcweir * the second created document) </li> 132*cdf0e10cSrcweir * <li> <code>'SecondController'</code> for 133*cdf0e10cSrcweir * {@link ifc.frame._XController}(the current controller of the second 134*cdf0e10cSrcweir * created document) </li> 135*cdf0e10cSrcweir * </ul> 136*cdf0e10cSrcweir * @see com.sun.star.frame.XModel 137*cdf0e10cSrcweir */ 138*cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment 139*cdf0e10cSrcweir (TestParameters Param, PrintWriter log) { 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir log.println( "creating a test environment" ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // get a soffice factory object 144*cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir try { 147*cdf0e10cSrcweir log.println( "creating a impress document" ); 148*cdf0e10cSrcweir xImpressDoc = SOF.createImpressDoc(null); 149*cdf0e10cSrcweir shortWait(); 150*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 151*cdf0e10cSrcweir e.printStackTrace( log ); 152*cdf0e10cSrcweir throw new StatusException("Couldn't create document", e); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 156*cdf0e10cSrcweir UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc); 157*cdf0e10cSrcweir XDrawPages the_pages = oDPS.getDrawPages(); 158*cdf0e10cSrcweir XIndexAccess oDPi = (XIndexAccess) 159*cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir XModel aModel = (XModel) 162*cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xImpressDoc); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir XInterface oObj = aModel.getCurrentController(); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir //Change to Outline view 167*cdf0e10cSrcweir try { 168*cdf0e10cSrcweir String aSlotID = "slot:27010"; 169*cdf0e10cSrcweir XDispatchProvider xDispProv = (XDispatchProvider) 170*cdf0e10cSrcweir UnoRuntime.queryInterface( XDispatchProvider.class, oObj ); 171*cdf0e10cSrcweir XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 172*cdf0e10cSrcweir UnoRuntime.queryInterface(XURLTransformer.class, 173*cdf0e10cSrcweir ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 174*cdf0e10cSrcweir // Because it's an in/out parameter we must use an array of URL objects. 175*cdf0e10cSrcweir URL[] aParseURL = new URL[1]; 176*cdf0e10cSrcweir aParseURL[0] = new URL(); 177*cdf0e10cSrcweir aParseURL[0].Complete = aSlotID; 178*cdf0e10cSrcweir xParser.parseStrict(aParseURL); 179*cdf0e10cSrcweir URL aURL = aParseURL[0]; 180*cdf0e10cSrcweir XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 181*cdf0e10cSrcweir if( xDispatcher != null ) 182*cdf0e10cSrcweir xDispatcher.dispatch( aURL, null ); 183*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 184*cdf0e10cSrcweir log.println("Couldn't change mode"); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir try { 188*cdf0e10cSrcweir log.println( "creating a second impress document" ); 189*cdf0e10cSrcweir xSecondDrawDoc = SOF.createImpressDoc(null); 190*cdf0e10cSrcweir shortWait(); 191*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 192*cdf0e10cSrcweir e.printStackTrace( log ); 193*cdf0e10cSrcweir throw new StatusException("Couldn't create document", e); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir XModel aModel2 = (XModel) 197*cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface( 200*cdf0e10cSrcweir XWindow.class,aModel2.getCurrentController()); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir oObj = aModel.getCurrentController(); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir log.println( "creating a new environment for impress view object" ); 206*cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir if (anotherWindow != null) { 209*cdf0e10cSrcweir tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir //Adding ObjRelations for XController 213*cdf0e10cSrcweir tEnv.addObjRelation("FirstModel", aModel); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir XFrame the_frame = the_Desk.getCurrentFrame(); 218*cdf0e10cSrcweir tEnv.addObjRelation("Frame", the_frame); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir aModel = (XModel) 221*cdf0e10cSrcweir UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 222*cdf0e10cSrcweir //Adding ObjRelations for XController 223*cdf0e10cSrcweir tEnv.addObjRelation("SecondModel", aModel); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir XController secondController = aModel.getCurrentController(); 226*cdf0e10cSrcweir tEnv.addObjRelation("SecondController", secondController); 227*cdf0e10cSrcweir tEnv.addObjRelation("XDispatchProvider.URL", 228*cdf0e10cSrcweir "slot:27069"); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir log.println("Implementation Name: " + utils.getImplName(oObj)); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir return tEnv; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir } // finish method getTestEnvironment 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir private void shortWait() { 237*cdf0e10cSrcweir try { 238*cdf0e10cSrcweir Thread.sleep(5000) ; 239*cdf0e10cSrcweir } catch (InterruptedException e) { 240*cdf0e10cSrcweir System.out.println("While waiting :" + e) ; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir } // finish class SdUnoOutlineView 246*cdf0e10cSrcweir 247