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