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