bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdXCustomPresentation.java
blobfb1f79e4aac3e6ae30be9c286cc9fab5c8da801e
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._sd;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.container.XIndexContainer;
31 import com.sun.star.container.XNameContainer;
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XDrawPages;
34 import com.sun.star.drawing.XDrawPagesSupplier;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XSingleServiceFactory;
37 import com.sun.star.presentation.XCustomPresentationSupplier;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.presentation.CustomPresentation</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::container::XNamed</code></li>
49 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
50 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
51 * <li> <code>com::sun::star::container::XElementAccess</code></li>
52 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
53 * </ul>
54 * @see com.sun.star.presentation.CustomPresentation
55 * @see com.sun.star.container.XNamed
56 * @see com.sun.star.container.XIndexContainer
57 * @see com.sun.star.container.XIndexAccess
58 * @see com.sun.star.container.XElementAccess
59 * @see com.sun.star.container.XIndexReplace
60 * @see ifc.container._XNamed
61 * @see ifc.container._XIndexContainer
62 * @see ifc.container._XIndexAccess
63 * @see ifc.container._XElementAccess
64 * @see ifc.container._XIndexReplace
66 public class SdXCustomPresentation extends TestCase {
67 XComponent xImpressDoc;
69 /**
70 * Creates Impress document.
72 @Override
73 protected void initialize(TestParameters Param, PrintWriter log) {
74 // get a soffice factory object
75 SOfficeFactory SOF = SOfficeFactory.getFactory(
76 Param.getMSF());
78 try {
79 log.println( "creating a draw document" );
80 xImpressDoc = SOF.createImpressDoc(null);
81 } catch (com.sun.star.uno.Exception e) {
82 // Some exception occurs.FAILED
83 e.printStackTrace( log );
84 throw new StatusException( "Couldn't create document", e );
89 /**
90 * Disposes Impress document.
92 @Override
93 protected void cleanup( TestParameters Param, PrintWriter log) {
94 log.println("disposing xImpressDoc");
95 util.DesktopTools.closeDoc(xImpressDoc);
98 /**
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Retrieves the collection of the CustomPresentation from the document
101 * using the interface <code>XCustomPresentationSupplier</code>. Creates and
102 * inserts new instance of the presentation to the collection. The created
103 * instance is the instance of the service
104 * <code>com.sun.star.presentation.CustomPresentation</code>. Obtains
105 * the collection of draw pages from the document and takes one of them.
106 * Inserts the obtained draw page to the created instance. Inserts some new
107 * draw pages.
108 * Object relations created :
109 * <ul>
110 * <li> <code>'XIndexContainerINDEX'</code> for
111 * {@link ifc.container._XIndexContainer}(the string representation of
112 * the zero)</li>
113 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
114 * {@link ifc.container._XIndexContainer}(the new inserted draw pages)</li>
115 * </ul>
116 * @see com.sun.star.presentation.XCustomPresentationSupplier
117 * @see com.sun.star.presentation.CustomPresentation
119 @Override
120 protected TestEnvironment createTestEnvironment(
121 TestParameters Param, PrintWriter log) {
124 log.println( "creating a test environment" );
126 log.println( "get presentation" );
127 XCustomPresentationSupplier oPS = UnoRuntime.queryInterface(
128 XCustomPresentationSupplier.class, xImpressDoc);
129 XInterface oObj = oPS.getCustomPresentations();
131 XSingleServiceFactory oSingleMSF = UnoRuntime.queryInterface(XSingleServiceFactory.class, oObj);
133 XInterface oInstance = null;
134 try {
135 oInstance = (XInterface) oSingleMSF.createInstance();
136 } catch (com.sun.star.uno.Exception e) {
137 e.printStackTrace(log);
138 throw new StatusException("Couldn't create instance", e);
141 XNameContainer aContainer = UnoRuntime.queryInterface(XNameContainer.class, oObj);
143 try {
144 aContainer.insertByName("FirstPresentation", oInstance);
145 } catch (com.sun.star.lang.WrappedTargetException e){
146 e.printStackTrace(log);
147 throw new StatusException("Could't insert Presentation", e);
148 } catch (com.sun.star.container.ElementExistException e){
149 e.printStackTrace(log);
150 throw new StatusException("Could't insert Presentation", e);
151 } catch (com.sun.star.lang.IllegalArgumentException e){
152 e.printStackTrace(log);
153 throw new StatusException("Could't insert Presentation", e);
156 // get the drawpage of drawing here
157 log.println( "getting Drawpage" );
158 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc);
159 XDrawPages oDPn = oDPS.getDrawPages();
160 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class, oDPn);
162 XDrawPage oDrawPage = null;
163 try {
164 oDrawPage = (XDrawPage) AnyConverter.toObject(
165 new Type(XDrawPage.class),oDPi.getByIndex(0));
166 } catch (com.sun.star.lang.WrappedTargetException e) {
167 e.printStackTrace(log);
168 throw new StatusException("Couldn't get by index", e);
169 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
170 e.printStackTrace(log);
171 throw new StatusException("Couldn't get by index", e);
172 } catch (com.sun.star.lang.IllegalArgumentException e) {
173 e.printStackTrace(log);
174 throw new StatusException("Couldn't get by index", e);
177 XIndexContainer aIContainer = UnoRuntime.queryInterface(XIndexContainer.class,oInstance);
179 try {
180 aIContainer.insertByIndex(0, oDrawPage);
181 } catch (com.sun.star.lang.WrappedTargetException e){
182 e.printStackTrace(log);
183 throw new StatusException("Could't insert DrawPage", e);
184 } catch (com.sun.star.lang.IllegalArgumentException e){
185 e.printStackTrace(log);
186 throw new StatusException("Could't insert DrawPage", e);
187 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
188 e.printStackTrace(log);
189 throw new StatusException("Could't insert DrawPage", e);
192 log.println( "creating a new environment for XPresentation object" );
193 TestEnvironment tEnv = new TestEnvironment( oInstance );
195 int THRCNT=1;
196 if ((String)Param.get("THRCNT") != null) {
197 THRCNT = Integer.parseInt((String)Param.get("THRCNT"));
200 // INDEX : _XNameContainer
201 log.println( "adding XIndexContainerINDEX as mod relation to environment" );
202 tEnv.addObjRelation("XIndexContainerINDEX", "0");
204 // INSTANCEn : _XNameContainer; _XNameReplace
205 log.println( "adding INSTANCEn as mod relation to environment" );
206 try {
207 for (int n = 1; n < (2*THRCNT+1) ;n++ ) {
208 log.println( "adding INSTANCE" + n
209 +" as mod relation to environment" );
210 oDPn.insertNewByIndex(0);
211 oDrawPage = (XDrawPage) AnyConverter.toObject(
212 new Type(XDrawPage.class),oDPi.getByIndex(0));
213 tEnv.addObjRelation("INSTANCE" + n, oDrawPage);
215 } catch (com.sun.star.lang.WrappedTargetException e) {
216 e.printStackTrace(log);
217 throw new StatusException("Could't adding INSTANCEn", e);
218 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
219 e.printStackTrace(log);
220 throw new StatusException("Could't adding INSTANCEn", e);
221 } catch (com.sun.star.lang.IllegalArgumentException e) {
222 e.printStackTrace(log);
223 throw new StatusException("Could't adding INSTANCEn", e);
226 return tEnv;
228 } // finish method getTestEnvironment
230 } // finish class SdXCustomPresentation