1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sd; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.container.XIndexAccess; 39 import com.sun.star.container.XIndexContainer; 40 import com.sun.star.container.XNameContainer; 41 import com.sun.star.drawing.XDrawPage; 42 import com.sun.star.drawing.XDrawPages; 43 import com.sun.star.drawing.XDrawPagesSupplier; 44 import com.sun.star.lang.XComponent; 45 import com.sun.star.lang.XMultiServiceFactory; 46 import com.sun.star.lang.XSingleServiceFactory; 47 import com.sun.star.presentation.XCustomPresentationSupplier; 48 import com.sun.star.uno.AnyConverter; 49 import com.sun.star.uno.Type; 50 import com.sun.star.uno.UnoRuntime; 51 import com.sun.star.uno.XInterface; 52 53 /** 54 * Test for object which is represented by service 55 * <code>com.sun.star.presentation.CustomPresentation</code>. <p> 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::container::XNamed</code></li> 59 * <li> <code>com::sun::star::container::XIndexContainer</code></li> 60 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 61 * <li> <code>com::sun::star::container::XElementAccess</code></li> 62 * <li> <code>com::sun::star::container::XIndexReplace</code></li> 63 * </ul> 64 * @see com.sun.star.presentation.CustomPresentation 65 * @see com.sun.star.container.XNamed 66 * @see com.sun.star.container.XIndexContainer 67 * @see com.sun.star.container.XIndexAccess 68 * @see com.sun.star.container.XElementAccess 69 * @see com.sun.star.container.XIndexReplace 70 * @see ifc.container._XNamed 71 * @see ifc.container._XIndexContainer 72 * @see ifc.container._XIndexAccess 73 * @see ifc.container._XElementAccess 74 * @see ifc.container._XIndexReplace 75 */ 76 public class SdXCustomPresentation extends TestCase { 77 XComponent xImpressDoc; 78 79 /** 80 * Creates Impress document. 81 */ 82 protected void initialize(TestParameters Param, PrintWriter log) { 83 // get a soffice factory object 84 SOfficeFactory SOF = SOfficeFactory.getFactory( 85 (XMultiServiceFactory)Param.getMSF()); 86 87 try { 88 log.println( "creating a draw document" ); 89 xImpressDoc = SOF.createImpressDoc(null);; 90 } catch (com.sun.star.uno.Exception e) { 91 // Some exception occures.FAILED 92 e.printStackTrace( log ); 93 throw new StatusException( "Couldn't create document", e ); 94 } 95 96 } 97 98 /** 99 * Disposes Impress document. 100 */ 101 protected void cleanup( TestParameters Param, PrintWriter log) { 102 log.println("disposing xImpressDoc"); 103 util.DesktopTools.closeDoc(xImpressDoc);; 104 } 105 106 /** 107 * Creating a Testenvironment for the interfaces to be tested. 108 * Retrieves the collection of the CustomPresentation from the document 109 * using the interface <code>XCustomPresentationSupplier</code>. Creates and 110 * inserts new instance of the presentation to the collection. The created 111 * instance is the instance of the service 112 * <code>com.sun.star.presentation.CustomPresentation</code>. Obtains 113 * the collection of draw pages from the document and takes one of them. 114 * Inserts the obtained draw page to the created instance. Inserts some new 115 * draw pages. 116 * Object relations created : 117 * <ul> 118 * <li> <code>'XIndexContainerINDEX'</code> for 119 * {@link ifc.container._XIndexContainer}(the string representation of 120 * the zero)</li> 121 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for 122 * {@link ifc.container._XIndexContainer}(the new inserted draw pages)</li> 123 * </ul> 124 * @see com.sun.star.presentation.XCustomPresentationSupplier 125 * @see com.sun.star.presentation.CustomPresentation 126 */ 127 protected TestEnvironment createTestEnvironment( 128 TestParameters Param, PrintWriter log) { 129 130 131 log.println( "creating a test environment" ); 132 133 log.println( "get presentation" ); 134 XCustomPresentationSupplier oPS = (XCustomPresentationSupplier) 135 UnoRuntime.queryInterface( 136 XCustomPresentationSupplier.class, xImpressDoc); 137 XInterface oObj = oPS.getCustomPresentations(); 138 139 XSingleServiceFactory oSingleMSF = (XSingleServiceFactory) 140 UnoRuntime.queryInterface(XSingleServiceFactory.class, oObj); 141 142 XInterface oInstance = null; 143 try { 144 oInstance = (XInterface) oSingleMSF.createInstance(); 145 } catch (com.sun.star.uno.Exception e) { 146 e.printStackTrace(log); 147 throw new StatusException("Couldn't create instance", e); 148 } 149 150 XNameContainer aContainer = (XNameContainer) 151 UnoRuntime.queryInterface(XNameContainer.class, oObj); 152 153 try { 154 aContainer.insertByName("FirstPresentation", oInstance); 155 } catch (com.sun.star.lang.WrappedTargetException e){ 156 e.printStackTrace(log); 157 throw new StatusException("Could't insert Presentation", e); 158 } catch (com.sun.star.container.ElementExistException e){ 159 e.printStackTrace(log); 160 throw new StatusException("Could't insert Presentation", e); 161 } catch (com.sun.star.lang.IllegalArgumentException e){ 162 e.printStackTrace(log); 163 throw new StatusException("Could't insert Presentation", e); 164 } 165 166 // get the drawpage of drawing here 167 log.println( "getting Drawpage" ); 168 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 169 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc); 170 XDrawPages oDPn = oDPS.getDrawPages(); 171 XIndexAccess oDPi = (XIndexAccess) 172 UnoRuntime.queryInterface(XIndexAccess.class, oDPn); 173 174 XDrawPage oDrawPage = null; 175 try { 176 oDrawPage = (XDrawPage) AnyConverter.toObject( 177 new Type(XDrawPage.class),oDPi.getByIndex(0)); 178 } catch (com.sun.star.lang.WrappedTargetException e) { 179 e.printStackTrace(log); 180 throw new StatusException("Couldn't get by index", e); 181 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 182 e.printStackTrace(log); 183 throw new StatusException("Couldn't get by index", e); 184 } catch (com.sun.star.lang.IllegalArgumentException e) { 185 e.printStackTrace(log); 186 throw new StatusException("Couldn't get by index", e); 187 } 188 189 XIndexContainer aIContainer = (XIndexContainer) 190 UnoRuntime.queryInterface(XIndexContainer.class,oInstance); 191 192 try { 193 aIContainer.insertByIndex(0, oDrawPage); 194 } catch (com.sun.star.lang.WrappedTargetException e){ 195 e.printStackTrace(log); 196 throw new StatusException("Could't insert DrawPage", e); 197 } catch (com.sun.star.lang.IllegalArgumentException e){ 198 e.printStackTrace(log); 199 throw new StatusException("Could't insert DrawPage", e); 200 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 201 e.printStackTrace(log); 202 throw new StatusException("Could't insert DrawPage", e); 203 } 204 205 log.println( "creating a new environment for XPresentation object" ); 206 TestEnvironment tEnv = new TestEnvironment( oInstance ); 207 208 int THRCNT=1; 209 if ((String)Param.get("THRCNT") != null) { 210 THRCNT = Integer.parseInt((String)Param.get("THRCNT")); 211 } 212 213 // INDEX : _XNameContainer 214 log.println( "adding XIndexContainerINDEX as mod relation to environment" ); 215 tEnv.addObjRelation("XIndexContainerINDEX", "0"); 216 217 // INSTANCEn : _XNameContainer; _XNameReplace 218 log.println( "adding INSTANCEn as mod relation to environment" ); 219 try { 220 for (int n = 1; n < (2*THRCNT+1) ;n++ ) { 221 log.println( "adding INSTANCE" + n 222 +" as mod relation to environment" ); 223 oDPn.insertNewByIndex(0); 224 oDrawPage = (XDrawPage) AnyConverter.toObject( 225 new Type(XDrawPage.class),oDPi.getByIndex(0)); 226 tEnv.addObjRelation("INSTANCE" + n, oDrawPage); 227 } 228 } catch (com.sun.star.lang.WrappedTargetException e) { 229 e.printStackTrace(log); 230 throw new StatusException("Could't adding INSTANCEn", e); 231 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 232 e.printStackTrace(log); 233 throw new StatusException("Could't adding INSTANCEn", e); 234 } catch (com.sun.star.lang.IllegalArgumentException e) { 235 e.printStackTrace(log); 236 throw new StatusException("Could't adding INSTANCEn", e); 237 } 238 239 return tEnv; 240 241 } // finish method getTestEnvironment 242 243 } // finish class SdXCustomPresentation 244