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.SOfficeFactory; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 39*cdf0e10cSrcweir import com.sun.star.container.XIndexContainer; 40*cdf0e10cSrcweir import com.sun.star.container.XNameContainer; 41*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 42*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages; 43*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier; 44*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 45*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 46*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 47*cdf0e10cSrcweir import com.sun.star.presentation.XCustomPresentationSupplier; 48*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 49*cdf0e10cSrcweir import com.sun.star.uno.Type; 50*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 51*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir /** 54*cdf0e10cSrcweir * Test for object which is represented by service 55*cdf0e10cSrcweir * <code>com.sun.star.presentation.CustomPresentation</code>. <p> 56*cdf0e10cSrcweir * Object implements the following interfaces : 57*cdf0e10cSrcweir * <ul> 58*cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNamed</code></li> 59*cdf0e10cSrcweir * <li> <code>com::sun::star::container::XIndexContainer</code></li> 60*cdf0e10cSrcweir * <li> <code>com::sun::star::container::XIndexAccess</code></li> 61*cdf0e10cSrcweir * <li> <code>com::sun::star::container::XElementAccess</code></li> 62*cdf0e10cSrcweir * <li> <code>com::sun::star::container::XIndexReplace</code></li> 63*cdf0e10cSrcweir * </ul> 64*cdf0e10cSrcweir * @see com.sun.star.presentation.CustomPresentation 65*cdf0e10cSrcweir * @see com.sun.star.container.XNamed 66*cdf0e10cSrcweir * @see com.sun.star.container.XIndexContainer 67*cdf0e10cSrcweir * @see com.sun.star.container.XIndexAccess 68*cdf0e10cSrcweir * @see com.sun.star.container.XElementAccess 69*cdf0e10cSrcweir * @see com.sun.star.container.XIndexReplace 70*cdf0e10cSrcweir * @see ifc.container._XNamed 71*cdf0e10cSrcweir * @see ifc.container._XIndexContainer 72*cdf0e10cSrcweir * @see ifc.container._XIndexAccess 73*cdf0e10cSrcweir * @see ifc.container._XElementAccess 74*cdf0e10cSrcweir * @see ifc.container._XIndexReplace 75*cdf0e10cSrcweir */ 76*cdf0e10cSrcweir public class SdXCustomPresentation extends TestCase { 77*cdf0e10cSrcweir XComponent xImpressDoc; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir /** 80*cdf0e10cSrcweir * Creates Impress document. 81*cdf0e10cSrcweir */ 82*cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 83*cdf0e10cSrcweir // get a soffice factory object 84*cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( 85*cdf0e10cSrcweir (XMultiServiceFactory)Param.getMSF()); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir try { 88*cdf0e10cSrcweir log.println( "creating a draw document" ); 89*cdf0e10cSrcweir xImpressDoc = SOF.createImpressDoc(null);; 90*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 91*cdf0e10cSrcweir // Some exception occures.FAILED 92*cdf0e10cSrcweir e.printStackTrace( log ); 93*cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /** 99*cdf0e10cSrcweir * Disposes Impress document. 100*cdf0e10cSrcweir */ 101*cdf0e10cSrcweir protected void cleanup( TestParameters Param, PrintWriter log) { 102*cdf0e10cSrcweir log.println("disposing xImpressDoc"); 103*cdf0e10cSrcweir util.DesktopTools.closeDoc(xImpressDoc);; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /** 107*cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 108*cdf0e10cSrcweir * Retrieves the collection of the CustomPresentation from the document 109*cdf0e10cSrcweir * using the interface <code>XCustomPresentationSupplier</code>. Creates and 110*cdf0e10cSrcweir * inserts new instance of the presentation to the collection. The created 111*cdf0e10cSrcweir * instance is the instance of the service 112*cdf0e10cSrcweir * <code>com.sun.star.presentation.CustomPresentation</code>. Obtains 113*cdf0e10cSrcweir * the collection of draw pages from the document and takes one of them. 114*cdf0e10cSrcweir * Inserts the obtained draw page to the created instance. Inserts some new 115*cdf0e10cSrcweir * draw pages. 116*cdf0e10cSrcweir * Object relations created : 117*cdf0e10cSrcweir * <ul> 118*cdf0e10cSrcweir * <li> <code>'XIndexContainerINDEX'</code> for 119*cdf0e10cSrcweir * {@link ifc.container._XIndexContainer}(the string representation of 120*cdf0e10cSrcweir * the zero)</li> 121*cdf0e10cSrcweir * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for 122*cdf0e10cSrcweir * {@link ifc.container._XIndexContainer}(the new inserted draw pages)</li> 123*cdf0e10cSrcweir * </ul> 124*cdf0e10cSrcweir * @see com.sun.star.presentation.XCustomPresentationSupplier 125*cdf0e10cSrcweir * @see com.sun.star.presentation.CustomPresentation 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir protected TestEnvironment createTestEnvironment( 128*cdf0e10cSrcweir TestParameters Param, PrintWriter log) { 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir log.println( "creating a test environment" ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir log.println( "get presentation" ); 134*cdf0e10cSrcweir XCustomPresentationSupplier oPS = (XCustomPresentationSupplier) 135*cdf0e10cSrcweir UnoRuntime.queryInterface( 136*cdf0e10cSrcweir XCustomPresentationSupplier.class, xImpressDoc); 137*cdf0e10cSrcweir XInterface oObj = oPS.getCustomPresentations(); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir XSingleServiceFactory oSingleMSF = (XSingleServiceFactory) 140*cdf0e10cSrcweir UnoRuntime.queryInterface(XSingleServiceFactory.class, oObj); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir XInterface oInstance = null; 143*cdf0e10cSrcweir try { 144*cdf0e10cSrcweir oInstance = (XInterface) oSingleMSF.createInstance(); 145*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 146*cdf0e10cSrcweir e.printStackTrace(log); 147*cdf0e10cSrcweir throw new StatusException("Couldn't create instance", e); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir XNameContainer aContainer = (XNameContainer) 151*cdf0e10cSrcweir UnoRuntime.queryInterface(XNameContainer.class, oObj); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir try { 154*cdf0e10cSrcweir aContainer.insertByName("FirstPresentation", oInstance); 155*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 156*cdf0e10cSrcweir e.printStackTrace(log); 157*cdf0e10cSrcweir throw new StatusException("Could't insert Presentation", e); 158*cdf0e10cSrcweir } catch (com.sun.star.container.ElementExistException e){ 159*cdf0e10cSrcweir e.printStackTrace(log); 160*cdf0e10cSrcweir throw new StatusException("Could't insert Presentation", e); 161*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e){ 162*cdf0e10cSrcweir e.printStackTrace(log); 163*cdf0e10cSrcweir throw new StatusException("Could't insert Presentation", e); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // get the drawpage of drawing here 167*cdf0e10cSrcweir log.println( "getting Drawpage" ); 168*cdf0e10cSrcweir XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 169*cdf0e10cSrcweir UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc); 170*cdf0e10cSrcweir XDrawPages oDPn = oDPS.getDrawPages(); 171*cdf0e10cSrcweir XIndexAccess oDPi = (XIndexAccess) 172*cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class, oDPn); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir XDrawPage oDrawPage = null; 175*cdf0e10cSrcweir try { 176*cdf0e10cSrcweir oDrawPage = (XDrawPage) AnyConverter.toObject( 177*cdf0e10cSrcweir new Type(XDrawPage.class),oDPi.getByIndex(0)); 178*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 179*cdf0e10cSrcweir e.printStackTrace(log); 180*cdf0e10cSrcweir throw new StatusException("Couldn't get by index", e); 181*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 182*cdf0e10cSrcweir e.printStackTrace(log); 183*cdf0e10cSrcweir throw new StatusException("Couldn't get by index", e); 184*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 185*cdf0e10cSrcweir e.printStackTrace(log); 186*cdf0e10cSrcweir throw new StatusException("Couldn't get by index", e); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir XIndexContainer aIContainer = (XIndexContainer) 190*cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexContainer.class,oInstance); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir try { 193*cdf0e10cSrcweir aIContainer.insertByIndex(0, oDrawPage); 194*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 195*cdf0e10cSrcweir e.printStackTrace(log); 196*cdf0e10cSrcweir throw new StatusException("Could't insert DrawPage", e); 197*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e){ 198*cdf0e10cSrcweir e.printStackTrace(log); 199*cdf0e10cSrcweir throw new StatusException("Could't insert DrawPage", e); 200*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 201*cdf0e10cSrcweir e.printStackTrace(log); 202*cdf0e10cSrcweir throw new StatusException("Could't insert DrawPage", e); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir log.println( "creating a new environment for XPresentation object" ); 206*cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oInstance ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir int THRCNT=1; 209*cdf0e10cSrcweir if ((String)Param.get("THRCNT") != null) { 210*cdf0e10cSrcweir THRCNT = Integer.parseInt((String)Param.get("THRCNT")); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // INDEX : _XNameContainer 214*cdf0e10cSrcweir log.println( "adding XIndexContainerINDEX as mod relation to environment" ); 215*cdf0e10cSrcweir tEnv.addObjRelation("XIndexContainerINDEX", "0"); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // INSTANCEn : _XNameContainer; _XNameReplace 218*cdf0e10cSrcweir log.println( "adding INSTANCEn as mod relation to environment" ); 219*cdf0e10cSrcweir try { 220*cdf0e10cSrcweir for (int n = 1; n < (2*THRCNT+1) ;n++ ) { 221*cdf0e10cSrcweir log.println( "adding INSTANCE" + n 222*cdf0e10cSrcweir +" as mod relation to environment" ); 223*cdf0e10cSrcweir oDPn.insertNewByIndex(0); 224*cdf0e10cSrcweir oDrawPage = (XDrawPage) AnyConverter.toObject( 225*cdf0e10cSrcweir new Type(XDrawPage.class),oDPi.getByIndex(0)); 226*cdf0e10cSrcweir tEnv.addObjRelation("INSTANCE" + n, oDrawPage); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 229*cdf0e10cSrcweir e.printStackTrace(log); 230*cdf0e10cSrcweir throw new StatusException("Could't adding INSTANCEn", e); 231*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 232*cdf0e10cSrcweir e.printStackTrace(log); 233*cdf0e10cSrcweir throw new StatusException("Could't adding INSTANCEn", e); 234*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 235*cdf0e10cSrcweir e.printStackTrace(log); 236*cdf0e10cSrcweir throw new StatusException("Could't adding INSTANCEn", e); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir return tEnv; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir } // finish method getTestEnvironment 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir } // finish class SdXCustomPresentation 244