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