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