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