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.XNameContainer; 35 import com.sun.star.lang.XComponent; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.lang.XSingleServiceFactory; 38 import com.sun.star.presentation.XCustomPresentationSupplier; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.uno.XInterface; 41 42 /** 43 * Test for object which is represented by service 44 * <code>com.sun.star.presentation.CustomPresentationAccess</code>. <p> 45 * Object implements the following interfaces : 46 * <ul> 47 * <li> <code>com::sun::star::container::XNameAccess</code></li> 48 * <li> <code>com::sun::star::container::XElementAccess</code></li> 49 * <li> <code>com::sun::star::container::XNameReplace</code></li> 50 * <li> <code>com::sun::star::lang::XSingleServiceFactory</code></li> 51 * <li> <code>com::sun::star::container::XNameContainer</code></li> 52 * </ul> 53 * @see com.sun.star.presentation.CustomPresentationAccess 54 * @see com.sun.star.container.XNameAccess 55 * @see com.sun.star.container.XElementAccess 56 * @see com.sun.star.container.XNameReplace 57 * @see com.sun.star.lang.XSingleServiceFactory 58 * @see com.sun.star.container.XNameContainer 59 * @see ifc.container._XNameAccess 60 * @see ifc.container._XElementAccess 61 * @see ifc.container._XNameReplace 62 * @see ifc.lang._XSingleServiceFactory 63 * @see ifc.container._XNameContainer 64 */ 65 public class SdXCustomPresentationAccess extends TestCase { 66 XComponent xImpressDoc; 67 68 /** 69 * Creates Impress document. 70 */ initialize(TestParameters Param, PrintWriter log)71 protected void initialize(TestParameters Param, PrintWriter log) { 72 // get a soffice factory object 73 SOfficeFactory SOF = SOfficeFactory.getFactory( 74 (XMultiServiceFactory)Param.getMSF()); 75 76 try { 77 log.println( "creating a draw document" ); 78 xImpressDoc = SOF.createImpressDoc(null); 79 } catch (com.sun.star.uno.Exception e) { 80 // Some exception occures.FAILED 81 e.printStackTrace( log ); 82 throw new StatusException( "Couldn't create document", e ); 83 } 84 } 85 86 /** 87 * Disposes Impress document. 88 */ cleanup( TestParameters Param, PrintWriter log)89 protected void cleanup( TestParameters Param, PrintWriter log) { 90 log.println("disposing xImpressDoc"); 91 util.DesktopTools.closeDoc(xImpressDoc); 92 } 93 94 /** 95 * Creating a Testenvironment for the interfaces to be tested. 96 * Retrieves the collection of the CustomPresentation from the document 97 * using the interface <code>XCustomPresentationSupplier</code>. 98 * The retrieved collection is the instance of the servcie 99 * <code>com.sun.star.presentation.CustomPresentationAccess</code>. 100 * Creates two new instances of the custom presentation using the interface 101 * <code>XSingleServiceFactory</code>. Inserts one of them to the 102 * retrieved collection. Creates and inserts several instances of 103 * the presentation. 104 * Object relations created : 105 * <ul> 106 * <li> <code>'SecondInstance'</code> for 107 * {@link ifc.container._XNameContainer}(the second created instance 108 * of the custom presentation)</li> 109 * <li> <code>'XNameContainerINDEX'</code> for 110 * {@link ifc.container._XNameContainer}(the number of current running 111 * threads)</li> 112 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for 113 * {@link ifc.container._XNameReplace}, 114 * {@link ifc.container._XNameContainer}(the created instances of 115 * the presentation)</li> 116 * </ul> 117 * @see com.sun.star.presentation.XCustomPresentationSupplier 118 * @see com.sun.star.lang.XSingleServiceFactory 119 * @see com.sun.star.presentation.CustomPresentationAccess 120 */ createTestEnvironment( TestParameters Param, PrintWriter log)121 public TestEnvironment createTestEnvironment( 122 TestParameters Param, PrintWriter log) throws StatusException { 123 124 125 log.println( "creating a test environment" ); 126 127 log.println( "get presentation" ); 128 XCustomPresentationSupplier oPS = (XCustomPresentationSupplier) 129 UnoRuntime.queryInterface( 130 XCustomPresentationSupplier.class, xImpressDoc); 131 XInterface oObj = oPS.getCustomPresentations(); 132 133 134 XSingleServiceFactory oSingleMSF = (XSingleServiceFactory) 135 UnoRuntime.queryInterface(XSingleServiceFactory.class, oObj); 136 137 XInterface oInstance = null; 138 XInterface oSecondInstance = null; 139 try{ 140 oInstance = (XInterface) oSingleMSF.createInstance(); 141 oSecondInstance = (XInterface) oSingleMSF.createInstance(); 142 } catch (com.sun.star.uno.Exception e) { 143 e.printStackTrace(log); 144 throw new StatusException("Couldn't create instance", e); 145 } 146 147 XNameContainer aContainer = (XNameContainer) 148 UnoRuntime.queryInterface(XNameContainer.class, oObj); 149 150 if (aContainer.hasByName("FirstPresentation")) { 151 try { 152 aContainer.removeByName("FirstPresentation"); 153 } catch (com.sun.star.lang.WrappedTargetException e) { 154 e.printStackTrace(log); 155 throw new StatusException("Exception while removing instance", e); 156 } catch (com.sun.star.container.NoSuchElementException e) { 157 e.printStackTrace(log); 158 throw new StatusException("Exception while removing instance", e); 159 } 160 } 161 162 try { 163 aContainer.insertByName("FirstPresentation",oInstance); 164 } catch (com.sun.star.lang.WrappedTargetException e){ 165 e.printStackTrace(log); 166 throw new StatusException("Could't insert Instance", e); 167 } catch (com.sun.star.container.ElementExistException e){ 168 e.printStackTrace(log); 169 throw new StatusException("Could't insert Instance", e); 170 } catch (com.sun.star.lang.IllegalArgumentException e){ 171 e.printStackTrace(log); 172 throw new StatusException("Could't insert Instance", e); 173 } 174 175 log.println( "creating a new environment for XPresentation object" ); 176 TestEnvironment tEnv = new TestEnvironment( oObj ); 177 178 // adding an instance for insertByName ('XNameContainer') 179 tEnv.addObjRelation("SecondInstance", oSecondInstance); 180 181 int THRCNT = 1; 182 if ((String)Param.get("THRCNT") != null) { 183 THRCNT = Integer.parseInt((String)Param.get("THRCNT")); 184 } 185 186 // INDEX : _XNameContainer 187 log.println( "adding XNameContainerINDEX as mod relation to environment" ); 188 tEnv.addObjRelation("XNameContainerINDEX", 189 (new Integer(THRCNT)).toString()); 190 191 // INSTANCEn : _XNameContainer; _XNameReplace 192 log.println( "adding INSTANCEn as mod relation to environment" ); 193 try { 194 for (int n = 1; n < (2*THRCNT+1) ;n++ ) { 195 log.println( "adding INSTANCE" + n 196 +" as mod relation to environment" ); 197 oInstance = (XInterface) oSingleMSF.createInstance(); 198 tEnv.addObjRelation("INSTANCE" + n, oInstance); 199 } 200 } catch (com.sun.star.uno.Exception e) { 201 log.println("Could't adding INSTANCEn: " + e); 202 } 203 204 return tEnv; 205 } // finish method getTestEnvironment 206 207 } // finish class SdXCustomPresentationAccess 208 209