Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / ModuleManager.java
blob014379d2239f68e0ecebf7793c72ecaefdd08cb1
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._fwk;
21 import com.sun.star.beans.PropertyValue;
22 import com.sun.star.frame.XController;
23 import com.sun.star.frame.XFrame;
24 import com.sun.star.frame.XModel;
25 import com.sun.star.lang.XComponent;
26 import lib.*;
27 import util.DesktopTools;
28 import util.SOfficeFactory;
31 import com.sun.star.uno.Exception;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
34 import java.io.PrintWriter;
35 import com.sun.star.sheet.XSpreadsheetDocument;
36 import com.sun.star.text.XTextDocument;
38 /** Test for object that implements the following interfaces :
39 * <ul>
40 * <li><code>com::sun::star::frame::XModuleManager</code></li>
41 * <li><code>com::sun::star::container::XNameAccess</code></li>
42 * <li><code>com::sun::star::container::XElementAccess</code></li>
43 * </ul><p>
44 * @see com.sun.star.frame.XModuleManager
45 * @see com.sun.star.container.XNameAccess
46 * @see com.sun.star.container.XElementAccess
47 * @see ifc.frame._XModuleManager
48 * @see ifc.container._XNameAccess
49 * @see ifc.container._XElementAccess
51 public class ModuleManager extends TestCase {
53 XTextDocument xTextDoc = null;
54 XComponent xWebDoc = null;
55 XComponent xGlobalDoc = null;
56 XSpreadsheetDocument xSheetDoc = null;
57 XComponent xDrawDoc = null;
58 XComponent xImpressDoc = null;
59 XComponent xMathDoc = null;
61 /** Creating a Testenvironment for the interfaces to be tested.
62 * @param Param test parameters
63 * @param log simple logger
64 * @throws StatusException was thrwon on error
65 * @return the test environement
67 @Override
68 public TestEnvironment createTestEnvironment( TestParameters Param,
69 PrintWriter log ) throws StatusException {
71 XInterface oObj = null;
73 try {
74 oObj = (XInterface)Param.getMSF().createInstance(
75 "com.sun.star.comp.framework.ModuleManager");
76 } catch(Exception e) {
77 throw new StatusException(e, Status.failed("Couldn't create instance"));
79 // get a soffice factory object
80 SOfficeFactory SOF = SOfficeFactory.getFactory(
81 Param.getMSF());
83 // get text document interfaces
84 try {
85 log.println("creating a text document");
86 xTextDoc = SOF.createTextDoc(null);
88 } catch (Exception e) {
89 e.printStackTrace(log);
90 throw new StatusException("Couldn't create document ", e);
92 XModel xTextMode1 = UnoRuntime.queryInterface(XModel.class,
93 xTextDoc);
94 XController xTextController = xTextMode1.getCurrentController();
95 XFrame xTextFrame = xTextController.getFrame();
98 // get webdoc interfaces
99 try {
100 log.println("creating a web document");
101 xWebDoc = SOF.loadDocument("private:factory/swriter/web");
103 } catch (Exception e) {
104 e.printStackTrace(log);
105 throw new StatusException("Couldn't create document ", e);
107 XModel xWebMode1 = UnoRuntime.queryInterface(XModel.class,
108 xWebDoc);
109 XController xWebController = xWebMode1.getCurrentController();
110 XFrame xWebFrame = xWebController.getFrame();
112 // get global document interfaces
113 try {
114 log.println("creating a global document");
115 xGlobalDoc = SOF.loadDocument("private:factory/swriter/GlobalDocument");
117 } catch (Exception e) {
118 e.printStackTrace(log);
119 throw new StatusException("Couldn't create document ", e);
121 XModel xGlobalMode1 = UnoRuntime.queryInterface(XModel.class,
122 xGlobalDoc);
123 XController xGlobalController = xGlobalMode1.getCurrentController();
124 XFrame xGlobalFrame = xGlobalController.getFrame();
126 // get clac interfaces
127 try {
128 log.println("creating a spreadsheetdocument");
129 xSheetDoc = SOF.createCalcDoc(null);
130 } catch (Exception e) {
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't create document ", e);
134 XModel xSheetMode1 = UnoRuntime.queryInterface(XModel.class,
135 xSheetDoc);
137 XController xSheetController = xSheetMode1.getCurrentController();
138 XFrame xSheetFrame = xSheetController.getFrame();
139 // get draw interfaces
140 try {
141 log.println("creating a draw document");
142 xDrawDoc = SOF.createDrawDoc(null);
143 } catch (Exception e) {
144 e.printStackTrace(log);
145 throw new StatusException("Couldn't create document ", e);
147 XModel xDrawMode1 = UnoRuntime.queryInterface(XModel.class,
148 xDrawDoc);
149 XController xDrawController = xDrawMode1.getCurrentController();
150 XFrame xDrawFrame = xDrawController.getFrame();
152 // get impress interfaces
153 try {
154 log.println("creating a impress document");
155 xImpressDoc = SOF.createImpressDoc(null);
156 } catch (Exception e) {
157 e.printStackTrace(log);
158 throw new StatusException("Couldn't create document ", e);
160 XModel xImpressMode1 = UnoRuntime.queryInterface(XModel.class,
161 xImpressDoc);
162 XController xImpressController = xImpressMode1.getCurrentController();
163 XFrame xImpressFrame = xImpressController.getFrame();
165 // get math interfaces
166 try {
167 log.println("creating a math document");
168 xMathDoc = SOF.createMathDoc(null);
169 } catch (Exception e) {
170 e.printStackTrace(log);
171 throw new StatusException("Couldn't create document ", e);
173 XModel xMathMode1 = UnoRuntime.queryInterface(XModel.class,
174 xMathDoc);
175 XController xMathController = xMathMode1.getCurrentController();
176 XFrame xMathFrame = xMathController.getFrame();
178 PropertyValue[] xFrameSeq = new PropertyValue[7];
179 xFrameSeq[0] = new PropertyValue();
180 xFrameSeq[0].Name = "com.sun.star.text.TextDocument";
181 xFrameSeq[0].Value = xTextFrame;
182 xFrameSeq[1] = new PropertyValue();
183 xFrameSeq[1].Name = "com.sun.star.text.WebDocument";
184 xFrameSeq[1].Value = xWebFrame;
185 xFrameSeq[2] = new PropertyValue();
186 xFrameSeq[2].Name = "com.sun.star.text.GlobalDocument";
187 xFrameSeq[2].Value = xGlobalFrame;
188 xFrameSeq[3] = new PropertyValue();
189 xFrameSeq[3].Name = "com.sun.star.sheet.SpreadsheetDocument";
190 xFrameSeq[3].Value = xSheetFrame;
191 xFrameSeq[4] = new PropertyValue();
192 xFrameSeq[4].Name = "com.sun.star.drawing.DrawingDocument";
193 xFrameSeq[4].Value = xDrawFrame;
194 xFrameSeq[5] = new PropertyValue();
195 xFrameSeq[5].Name = "com.sun.star.formula.FormulaProperties";
196 xFrameSeq[5].Value = xMathFrame;
197 xFrameSeq[6] = new PropertyValue();
198 xFrameSeq[6].Name = "com.sun.star.presentation.PresentationDocument";
199 xFrameSeq[6].Value = xImpressFrame;
201 PropertyValue[] xControllerSeq = new PropertyValue[7];
202 xControllerSeq[0] = new PropertyValue();
203 xControllerSeq[0].Name = "com.sun.star.text.TextDocument";
204 xControllerSeq[0].Value = xTextController;
205 xControllerSeq[1] = new PropertyValue();
206 xControllerSeq[1].Name = "com.sun.star.text.WebDocument";
207 xControllerSeq[1].Value = xWebController;
208 xControllerSeq[2] = new PropertyValue();
209 xControllerSeq[2].Name = "com.sun.star.text.GlobalDocument";
210 xControllerSeq[2].Value = xGlobalController;
211 xControllerSeq[3] = new PropertyValue();
212 xControllerSeq[3].Name = "com.sun.star.sheet.SpreadsheetDocument";
213 xControllerSeq[3].Value = xSheetController;
214 xControllerSeq[4] = new PropertyValue();
215 xControllerSeq[4].Name = "com.sun.star.drawing.DrawingDocument";
216 xControllerSeq[4].Value = xDrawController;
217 xControllerSeq[5] = new PropertyValue();
218 xControllerSeq[5].Name = "com.sun.star.formula.FormulaProperties";
219 xControllerSeq[5].Value = xMathController;
220 xControllerSeq[6] = new PropertyValue();
221 xControllerSeq[6].Name = "com.sun.star.presentation.PresentationDocument";
222 xControllerSeq[6].Value = xImpressController;
224 PropertyValue[] xModelSeq = new PropertyValue[7];
225 xModelSeq[0] = new PropertyValue();
226 xModelSeq[0].Name = "com.sun.star.text.TextDocument";
227 xModelSeq[0].Value = xTextMode1;
228 xModelSeq[1] = new PropertyValue();
229 xModelSeq[1].Name = "com.sun.star.text.WebDocument";
230 xModelSeq[1].Value = xWebMode1;
231 xModelSeq[2] = new PropertyValue();
232 xModelSeq[2].Name = "com.sun.star.text.GlobalDocument";
233 xModelSeq[2].Value = xGlobalMode1;
234 xModelSeq[3] = new PropertyValue();
235 xModelSeq[3].Name = "com.sun.star.sheet.SpreadsheetDocument";
236 xModelSeq[3].Value = xSheetMode1;
237 xModelSeq[4] = new PropertyValue();
238 xModelSeq[4].Name = "com.sun.star.drawing.DrawingDocument";
239 xModelSeq[4].Value = xDrawMode1;
240 xModelSeq[5] = new PropertyValue();
241 xModelSeq[5].Name = "com.sun.star.presentation.PresentationDocument";
242 xModelSeq[5].Value = xImpressMode1;
243 xModelSeq[6] = new PropertyValue();
244 xModelSeq[6].Name = "com.sun.star.formula.FormulaProperties";
245 xModelSeq[6].Value = xMathMode1;
247 TestEnvironment tEnv = new TestEnvironment( oObj );
250 tEnv.addObjRelation("XModuleManager.XFrame", xFrameSeq);
251 tEnv.addObjRelation("XModuleManager.XController", xControllerSeq);
252 tEnv.addObjRelation("XModuleManager.XModel", xModelSeq);
253 return tEnv;
254 } // finish method getTestEnvironment
256 /** Disposes text document.
257 * @param tParam test parameters
258 * @param log simple logger
260 @Override
261 protected void cleanup( TestParameters tParam, PrintWriter log ) {
262 log.println( " closing all documents " );
263 DesktopTools.closeDoc(xTextDoc);
264 DesktopTools.closeDoc(xWebDoc);
265 DesktopTools.closeDoc(xGlobalDoc);
266 DesktopTools.closeDoc(xSheetDoc);
267 DesktopTools.closeDoc(xDrawDoc);
268 DesktopTools.closeDoc(xImpressDoc);
269 DesktopTools.closeDoc(xMathDoc);