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 .
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 com
.sun
.star
.lang
.XMultiServiceFactory
;
28 import util
.DesktopTools
;
29 import util
.SOfficeFactory
;
32 import com
.sun
.star
.uno
.Exception
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
35 import java
.io
.PrintWriter
;
36 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
37 import com
.sun
.star
.text
.XTextDocument
;
39 /** Test for object that implements the following interfaces :
41 * <li><code>com::sun::star::frame::XModuleManager</code></li>
42 * <li><code>com::sun::star::container::XNameAccess</code></li>
43 * <li><code>com::sun::star::container::XElementAccess</code></li>
45 * @see com.sun.star.frame.XModuleManager
46 * @see com.sun.star.container.XNameAccess
47 * @see com.sun.star.container.XElementAccess
48 * @see ifc.frame._XModuleManager
49 * @see ifc.container._XNameAccess
50 * @see ifc.container._XElementAccess
52 public class ModuleManager
extends TestCase
{
54 XTextDocument xTextDoc
= null;
55 XComponent xWebDoc
= null;
56 XComponent xGlobalDoc
= null;
57 XSpreadsheetDocument xSheetDoc
= null;
58 XComponent xDrawDoc
= null;
59 XComponent xImpressDoc
= null;
60 XComponent xMathDoc
= null;
62 /** Creating a Testenvironment for the interfaces to be tested.
63 * @param Param test parameters
64 * @param log simple logger
65 * @throws StatusException was thrwon on error
66 * @return the test environement
68 public TestEnvironment
createTestEnvironment( TestParameters Param
,
69 PrintWriter log
) throws StatusException
{
71 XInterface oObj
= null;
74 oObj
= (XInterface
)((XMultiServiceFactory
)Param
.getMSF()).createInstance(
75 "com.sun.star.comp.framework.ModuleManager");
76 } catch(Exception e
) {
77 e
.printStackTrace(log
);
78 throw new StatusException(
79 Status
.failed("Couldn't create instance"));
81 // get a soffice factory object
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
83 (XMultiServiceFactory
) Param
.getMSF());
85 // get text document interfaces
87 log
.println("creating a text document");
88 xTextDoc
= SOF
.createTextDoc(null);
90 } catch (Exception e
) {
91 e
.printStackTrace(log
);
92 throw new StatusException("Couldn't create document ", e
);
94 XModel xTextMode1
= UnoRuntime
.queryInterface(XModel
.class,
96 XController xTextController
= xTextMode1
.getCurrentController();
97 XFrame xTextFrame
= xTextController
.getFrame();
100 // get webdoc interfaces
102 log
.println("creating a web document");
103 xWebDoc
= SOF
.loadDocument("private:factory/swriter/web");
105 } catch (Exception e
) {
106 e
.printStackTrace(log
);
107 throw new StatusException("Couldn't create document ", e
);
109 XModel xWebMode1
= UnoRuntime
.queryInterface(XModel
.class,
111 XController xWebController
= xWebMode1
.getCurrentController();
112 XFrame xWebFrame
= xWebController
.getFrame();
114 // get global document interfaces
116 log
.println("creating a global document");
117 xGlobalDoc
= SOF
.loadDocument("private:factory/swriter/GlobalDocument");
119 } catch (Exception e
) {
120 e
.printStackTrace(log
);
121 throw new StatusException("Couldn't create document ", e
);
123 XModel xGlobalMode1
= UnoRuntime
.queryInterface(XModel
.class,
125 XController xGlobalController
= xGlobalMode1
.getCurrentController();
126 XFrame xGlobalFrame
= xGlobalController
.getFrame();
128 // get clac interfaces
130 log
.println("creating a spreadsheetdocument");
131 xSheetDoc
= SOF
.createCalcDoc(null);
132 } catch (Exception e
) {
133 e
.printStackTrace(log
);
134 throw new StatusException("Couldn't create document ", e
);
136 XModel xSheetMode1
= UnoRuntime
.queryInterface(XModel
.class,
139 XController xSheetController
= xSheetMode1
.getCurrentController();
140 XFrame xSheetFrame
= xSheetController
.getFrame();
141 // get draw interfaces
143 log
.println("creating a draw document");
144 xDrawDoc
= SOF
.createDrawDoc(null);
145 } catch (Exception e
) {
146 e
.printStackTrace(log
);
147 throw new StatusException("Couldn't create document ", e
);
149 XModel xDrawMode1
= UnoRuntime
.queryInterface(XModel
.class,
151 XController xDrawController
= xDrawMode1
.getCurrentController();
152 XFrame xDrawFrame
= xDrawController
.getFrame();
154 // get impress interfaces
156 log
.println("creating a impress document");
157 xImpressDoc
= SOF
.createImpressDoc(null);
158 } catch (Exception e
) {
159 e
.printStackTrace(log
);
160 throw new StatusException("Couldn't create document ", e
);
162 XModel xImpressMode1
= UnoRuntime
.queryInterface(XModel
.class,
164 XController xImpressController
= xImpressMode1
.getCurrentController();
165 XFrame xImpressFrame
= xImpressController
.getFrame();
167 // get math interfaces
169 log
.println("creating a math document");
170 xMathDoc
= SOF
.createMathDoc(null);
171 } catch (Exception e
) {
172 e
.printStackTrace(log
);
173 throw new StatusException("Couldn't create document ", e
);
175 XModel xMathMode1
= UnoRuntime
.queryInterface(XModel
.class,
177 XController xMathController
= xMathMode1
.getCurrentController();
178 XFrame xMathFrame
= xMathController
.getFrame();
180 PropertyValue
[] xFrameSeq
= new PropertyValue
[7];
181 xFrameSeq
[0] = new PropertyValue();
182 xFrameSeq
[0].Name
= "com.sun.star.text.TextDocument";
183 xFrameSeq
[0].Value
= xTextFrame
;
184 xFrameSeq
[1] = new PropertyValue();
185 xFrameSeq
[1].Name
= "com.sun.star.text.WebDocument";
186 xFrameSeq
[1].Value
= xWebFrame
;
187 xFrameSeq
[2] = new PropertyValue();
188 xFrameSeq
[2].Name
= "com.sun.star.text.GlobalDocument";
189 xFrameSeq
[2].Value
= xGlobalFrame
;
190 xFrameSeq
[3] = new PropertyValue();
191 xFrameSeq
[3].Name
= "com.sun.star.sheet.SpreadsheetDocument";
192 xFrameSeq
[3].Value
= xSheetFrame
;
193 xFrameSeq
[4] = new PropertyValue();
194 xFrameSeq
[4].Name
= "com.sun.star.drawing.DrawingDocument";
195 xFrameSeq
[4].Value
= xDrawFrame
;
196 xFrameSeq
[5] = new PropertyValue();
197 xFrameSeq
[5].Name
= "com.sun.star.formula.FormulaProperties";
198 xFrameSeq
[5].Value
= xMathFrame
;
199 xFrameSeq
[6] = new PropertyValue();
200 xFrameSeq
[6].Name
= "com.sun.star.presentation.PresentationDocument";
201 xFrameSeq
[6].Value
= xImpressFrame
;
203 PropertyValue
[] xControllerSeq
= new PropertyValue
[7];
204 xControllerSeq
[0] = new PropertyValue();
205 xControllerSeq
[0].Name
= "com.sun.star.text.TextDocument";
206 xControllerSeq
[0].Value
= xTextController
;
207 xControllerSeq
[1] = new PropertyValue();
208 xControllerSeq
[1].Name
= "com.sun.star.text.WebDocument";
209 xControllerSeq
[1].Value
= xWebController
;
210 xControllerSeq
[2] = new PropertyValue();
211 xControllerSeq
[2].Name
= "com.sun.star.text.GlobalDocument";
212 xControllerSeq
[2].Value
= xGlobalController
;
213 xControllerSeq
[3] = new PropertyValue();
214 xControllerSeq
[3].Name
= "com.sun.star.sheet.SpreadsheetDocument";
215 xControllerSeq
[3].Value
= xSheetController
;
216 xControllerSeq
[4] = new PropertyValue();
217 xControllerSeq
[4].Name
= "com.sun.star.drawing.DrawingDocument";
218 xControllerSeq
[4].Value
= xDrawController
;
219 xControllerSeq
[5] = new PropertyValue();
220 xControllerSeq
[5].Name
= "com.sun.star.formula.FormulaProperties";
221 xControllerSeq
[5].Value
= xMathController
;
222 xControllerSeq
[6] = new PropertyValue();
223 xControllerSeq
[6].Name
= "com.sun.star.presentation.PresentationDocument";
224 xControllerSeq
[6].Value
= xImpressController
;
226 PropertyValue
[] xModelSeq
= new PropertyValue
[7];
227 xModelSeq
[0] = new PropertyValue();
228 xModelSeq
[0].Name
= "com.sun.star.text.TextDocument";
229 xModelSeq
[0].Value
= xTextMode1
;
230 xModelSeq
[1] = new PropertyValue();
231 xModelSeq
[1].Name
= "com.sun.star.text.WebDocument";
232 xModelSeq
[1].Value
= xWebMode1
;
233 xModelSeq
[2] = new PropertyValue();
234 xModelSeq
[2].Name
= "com.sun.star.text.GlobalDocument";
235 xModelSeq
[2].Value
= xGlobalMode1
;
236 xModelSeq
[3] = new PropertyValue();
237 xModelSeq
[3].Name
= "com.sun.star.sheet.SpreadsheetDocument";
238 xModelSeq
[3].Value
= xSheetMode1
;
239 xModelSeq
[4] = new PropertyValue();
240 xModelSeq
[4].Name
= "com.sun.star.drawing.DrawingDocument";
241 xModelSeq
[4].Value
= xDrawMode1
;
242 xModelSeq
[5] = new PropertyValue();
243 xModelSeq
[5].Name
= "com.sun.star.presentation.PresentationDocument";
244 xModelSeq
[5].Value
= xImpressMode1
;
245 xModelSeq
[6] = new PropertyValue();
246 xModelSeq
[6].Name
= "com.sun.star.formula.FormulaProperties";
247 xModelSeq
[6].Value
= xMathMode1
;
249 TestEnvironment tEnv
= new TestEnvironment( oObj
);
252 tEnv
.addObjRelation("XModuleManager.XFrame", xFrameSeq
);
253 tEnv
.addObjRelation("XModuleManager.XController", xControllerSeq
);
254 tEnv
.addObjRelation("XModuleManager.XModel", xModelSeq
);
256 } // finish method getTestEnvironment
258 /** Disposes text document.
259 * @param tParam test parameters
260 * @param log simple logger
262 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
263 log
.println( " closing all documents " );
264 DesktopTools
.closeDoc(xTextDoc
);
265 DesktopTools
.closeDoc(xWebDoc
);
266 DesktopTools
.closeDoc(xGlobalDoc
);
267 DesktopTools
.closeDoc(xSheetDoc
);
268 DesktopTools
.closeDoc(xDrawDoc
);
269 DesktopTools
.closeDoc(xImpressDoc
);
270 DesktopTools
.closeDoc(xMathDoc
);