Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _sd / SdXCustomPresentationAccess.java
blob43b41e18758241a06623cf91fd7cd70c41dc1761
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SdXCustomPresentationAccess.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sd;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.container.XNameContainer;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.lang.XSingleServiceFactory;
45 import com.sun.star.presentation.XCustomPresentationSupplier;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
49 /**
50 * Test for object which is represented by service
51 * <code>com.sun.star.presentation.CustomPresentationAccess</code>. <p>
52 * Object implements the following interfaces :
53 * <ul>
54 * <li> <code>com::sun::star::container::XNameAccess</code></li>
55 * <li> <code>com::sun::star::container::XElementAccess</code></li>
56 * <li> <code>com::sun::star::container::XNameReplace</code></li>
57 * <li> <code>com::sun::star::lang::XSingleServiceFactory</code></li>
58 * <li> <code>com::sun::star::container::XNameContainer</code></li>
59 * </ul>
60 * @see com.sun.star.presentation.CustomPresentationAccess
61 * @see com.sun.star.container.XNameAccess
62 * @see com.sun.star.container.XElementAccess
63 * @see com.sun.star.container.XNameReplace
64 * @see com.sun.star.lang.XSingleServiceFactory
65 * @see com.sun.star.container.XNameContainer
66 * @see ifc.container._XNameAccess
67 * @see ifc.container._XElementAccess
68 * @see ifc.container._XNameReplace
69 * @see ifc.lang._XSingleServiceFactory
70 * @see ifc.container._XNameContainer
72 public class SdXCustomPresentationAccess extends TestCase {
73 XComponent xImpressDoc;
75 /**
76 * Creates Impress document.
78 protected void initialize(TestParameters Param, PrintWriter log) {
79 // get a soffice factory object
80 SOfficeFactory SOF = SOfficeFactory.getFactory(
81 (XMultiServiceFactory)Param.getMSF());
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 occures.FAILED
88 e.printStackTrace( log );
89 throw new StatusException( "Couldn't create document", e );
93 /**
94 * Disposes Impress document.
96 protected void cleanup( TestParameters Param, PrintWriter log) {
97 log.println("disposing xImpressDoc");
98 util.DesktopTools.closeDoc(xImpressDoc);;
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Retrieves the collection of the CustomPresentation from the document
104 * using the interface <code>XCustomPresentationSupplier</code>.
105 * The retrieved collection is the instance of the servcie
106 * <code>com.sun.star.presentation.CustomPresentationAccess</code>.
107 * Creates two new instances of the custom presentation using the interface
108 * <code>XSingleServiceFactory</code>. Inserts one of them to the
109 * retrieved collection. Creates and inserts several instances of
110 * the presentation.
111 * Object relations created :
112 * <ul>
113 * <li> <code>'SecondInstance'</code> for
114 * {@link ifc.container._XNameContainer}(the second created instance
115 * of the custom presentation)</li>
116 * <li> <code>'XNameContainerINDEX'</code> for
117 * {@link ifc.container._XNameContainer}(the number of current running
118 * threads)</li>
119 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
120 * {@link ifc.container._XNameReplace},
121 * {@link ifc.container._XNameContainer}(the created instances of
122 * the presentation)</li>
123 * </ul>
124 * @see com.sun.star.presentation.XCustomPresentationSupplier
125 * @see com.sun.star.lang.XSingleServiceFactory
126 * @see com.sun.star.presentation.CustomPresentationAccess
128 public TestEnvironment createTestEnvironment(
129 TestParameters Param, PrintWriter log) throws StatusException {
132 log.println( "creating a test environment" );
134 log.println( "get presentation" );
135 XCustomPresentationSupplier oPS = (XCustomPresentationSupplier)
136 UnoRuntime.queryInterface(
137 XCustomPresentationSupplier.class, xImpressDoc);
138 XInterface oObj = oPS.getCustomPresentations();
141 XSingleServiceFactory oSingleMSF = (XSingleServiceFactory)
142 UnoRuntime.queryInterface(XSingleServiceFactory.class, oObj);
144 XInterface oInstance = null;
145 XInterface oSecondInstance = null;
146 try{
147 oInstance = (XInterface) oSingleMSF.createInstance();
148 oSecondInstance = (XInterface) oSingleMSF.createInstance();
149 } catch (com.sun.star.uno.Exception e) {
150 e.printStackTrace(log);
151 throw new StatusException("Couldn't create instance", e);
154 XNameContainer aContainer = (XNameContainer)
155 UnoRuntime.queryInterface(XNameContainer.class, oObj);
157 if (aContainer.hasByName("FirstPresentation")) {
158 try {
159 aContainer.removeByName("FirstPresentation");
160 } catch (com.sun.star.lang.WrappedTargetException e) {
161 e.printStackTrace(log);
162 throw new StatusException("Exception while removing instance", e);
163 } catch (com.sun.star.container.NoSuchElementException e) {
164 e.printStackTrace(log);
165 throw new StatusException("Exception while removing instance", e);
169 try {
170 aContainer.insertByName("FirstPresentation",oInstance);
171 } catch (com.sun.star.lang.WrappedTargetException e){
172 e.printStackTrace(log);
173 throw new StatusException("Could't insert Instance", e);
174 } catch (com.sun.star.container.ElementExistException e){
175 e.printStackTrace(log);
176 throw new StatusException("Could't insert Instance", e);
177 } catch (com.sun.star.lang.IllegalArgumentException e){
178 e.printStackTrace(log);
179 throw new StatusException("Could't insert Instance", e);
182 log.println( "creating a new environment for XPresentation object" );
183 TestEnvironment tEnv = new TestEnvironment( oObj );
185 // adding an instance for insertByName ('XNameContainer')
186 tEnv.addObjRelation("SecondInstance", oSecondInstance);
188 int THRCNT = 1;
189 if ((String)Param.get("THRCNT") != null) {
190 THRCNT = Integer.parseInt((String)Param.get("THRCNT"));
193 // INDEX : _XNameContainer
194 log.println( "adding XNameContainerINDEX as mod relation to environment" );
195 tEnv.addObjRelation("XNameContainerINDEX",
196 (new Integer(THRCNT)).toString());
198 // INSTANCEn : _XNameContainer; _XNameReplace
199 log.println( "adding INSTANCEn as mod relation to environment" );
200 try {
201 for (int n = 1; n < (2*THRCNT+1) ;n++ ) {
202 log.println( "adding INSTANCE" + n
203 +" as mod relation to environment" );
204 oInstance = (XInterface) oSingleMSF.createInstance();
205 tEnv.addObjRelation("INSTANCE" + n, oInstance);
207 } catch (com.sun.star.uno.Exception e) {
208 log.println("Could't adding INSTANCEn: " + e);
211 return tEnv;
212 } // finish method getTestEnvironment
214 } // finish class SdXCustomPresentationAccess