1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._fwk;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
27cdf0e10cSrcweir import com.sun.star.frame.XController;
28cdf0e10cSrcweir import com.sun.star.frame.XFrame;
29cdf0e10cSrcweir import com.sun.star.frame.XModel;
30cdf0e10cSrcweir import com.sun.star.lang.XComponent;
31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
32cdf0e10cSrcweir import lib.*;
33cdf0e10cSrcweir import util.DesktopTools;
34cdf0e10cSrcweir import util.SOfficeFactory;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir import com.sun.star.uno.Exception;
38cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
39cdf0e10cSrcweir import com.sun.star.uno.XInterface;
40cdf0e10cSrcweir import java.io.PrintWriter;
41cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument;
42cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /** Test for object that implements the following interfaces :
45cdf0e10cSrcweir  * <ul>
46cdf0e10cSrcweir  *  <li><code>com::sun::star::frame::XModuleManager</code></li>
47cdf0e10cSrcweir  *  <li><code>com::sun::star::container::XNameAccess</code></li>
48cdf0e10cSrcweir  *  <li><code>com::sun::star::container::XElementAccess</code></li>
49cdf0e10cSrcweir  * </ul><p>
50cdf0e10cSrcweir  * @see com.sun.star.frame.XModuleManager
51cdf0e10cSrcweir  * @see com.sun.star.container.XNameAccess
52cdf0e10cSrcweir  * @see com.sun.star.container.XElementAccess
53cdf0e10cSrcweir  * @see ifc.frame._XModuleManager
54cdf0e10cSrcweir  * @see ifc.container._XNameAccess
55cdf0e10cSrcweir  * @see ifc.container._XElementAccess
56cdf0e10cSrcweir  */
57cdf0e10cSrcweir public class ModuleManager extends TestCase {
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     XTextDocument xTextDoc = null;
60cdf0e10cSrcweir     XComponent xWebDoc = null;
61cdf0e10cSrcweir     XComponent xGlobalDoc = null;
62cdf0e10cSrcweir     XSpreadsheetDocument xSheetDoc = null;
63cdf0e10cSrcweir     XComponent xDrawDoc = null;
64cdf0e10cSrcweir     XComponent xImpressDoc = null;
65cdf0e10cSrcweir     XComponent xMathDoc = null;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     /** Creating a Testenvironment for the interfaces to be tested.
68cdf0e10cSrcweir      * @param Param test parameters
69cdf0e10cSrcweir      * @param log simple logger
70cdf0e10cSrcweir      * @throws StatusException was thrwon on error
71cdf0e10cSrcweir      * @return the test environement
72cdf0e10cSrcweir      */
73cdf0e10cSrcweir     public TestEnvironment createTestEnvironment( TestParameters Param,
74cdf0e10cSrcweir         PrintWriter log ) throws StatusException {
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         XInterface oObj = null;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         try {
79cdf0e10cSrcweir             oObj = (XInterface)((XMultiServiceFactory)Param.getMSF()).createInstance(
80cdf0e10cSrcweir                 "com.sun.star.comp.framework.ModuleManager");
81cdf0e10cSrcweir         } catch(Exception e) {
82cdf0e10cSrcweir             e.printStackTrace(log);
83cdf0e10cSrcweir             throw new StatusException(
84cdf0e10cSrcweir                 Status.failed("Couldn't create instance"));
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir         // get a soffice factory object
87cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(
88cdf0e10cSrcweir                                      (XMultiServiceFactory) Param.getMSF());
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         // get text document interfaces
91cdf0e10cSrcweir         try {
92cdf0e10cSrcweir             log.println("creating a text document");
93cdf0e10cSrcweir             xTextDoc = SOF.createTextDoc(null);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         } catch (Exception e) {
96cdf0e10cSrcweir             e.printStackTrace(log);
97cdf0e10cSrcweir             throw new StatusException("Couldn't create document ", e);
98cdf0e10cSrcweir         }
99cdf0e10cSrcweir         XModel xTextMode1 = (XModel) UnoRuntime.queryInterface(XModel.class,
100cdf0e10cSrcweir                                                        xTextDoc);
101cdf0e10cSrcweir         XController xTextController = xTextMode1.getCurrentController();
102cdf0e10cSrcweir         XFrame xTextFrame = xTextController.getFrame();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         // get webdoc interfaces
106cdf0e10cSrcweir         try {
107cdf0e10cSrcweir             log.println("creating a web document");
108cdf0e10cSrcweir             xWebDoc = SOF.loadDocument("private:factory/swriter/web");
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         } catch (Exception e) {
111cdf0e10cSrcweir             e.printStackTrace(log);
112cdf0e10cSrcweir             throw new StatusException("Couldn't create document ", e);
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir         XModel xWebMode1 = (XModel) UnoRuntime.queryInterface(XModel.class,
115cdf0e10cSrcweir                                                        xWebDoc);
116cdf0e10cSrcweir         XController xWebController = xWebMode1.getCurrentController();
117cdf0e10cSrcweir         XFrame xWebFrame = xWebController.getFrame();
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         // get global document interfaces
120cdf0e10cSrcweir         try {
121cdf0e10cSrcweir             log.println("creating a global document");
122cdf0e10cSrcweir             xGlobalDoc = SOF.loadDocument("private:factory/swriter/GlobalDocument");
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         } catch (Exception e) {
125cdf0e10cSrcweir             e.printStackTrace(log);
126cdf0e10cSrcweir             throw new StatusException("Couldn't create document ", e);
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir         XModel xGlobalMode1 = (XModel) UnoRuntime.queryInterface(XModel.class,
129cdf0e10cSrcweir                                                        xGlobalDoc);
130cdf0e10cSrcweir         XController xGlobalController = xGlobalMode1.getCurrentController();
131cdf0e10cSrcweir         XFrame xGlobalFrame = xGlobalController.getFrame();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         // get clac interfaces
134cdf0e10cSrcweir         try {
135cdf0e10cSrcweir             log.println("creating a spreadsheetdocument");
136cdf0e10cSrcweir             xSheetDoc = SOF.createCalcDoc(null);
137cdf0e10cSrcweir         } catch (Exception e) {
138cdf0e10cSrcweir             e.printStackTrace(log);
139cdf0e10cSrcweir             throw new StatusException("Couldn't create document ", e);
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir         XModel xSheetMode1 = (XModel) UnoRuntime.queryInterface(XModel.class,
142cdf0e10cSrcweir                                                        xSheetDoc);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         XController xSheetController = xSheetMode1.getCurrentController();
145cdf0e10cSrcweir         XFrame xSheetFrame = xSheetController.getFrame();
146cdf0e10cSrcweir         // get draw interfaces
147cdf0e10cSrcweir         try {
148cdf0e10cSrcweir             log.println("creating a draw document");
149cdf0e10cSrcweir             xDrawDoc = SOF.createDrawDoc(null);
150cdf0e10cSrcweir         } catch (Exception e) {
151cdf0e10cSrcweir             e.printStackTrace(log);
152cdf0e10cSrcweir             throw new StatusException("Couldn't create document ", e);
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir         XModel xDrawMode1 = (XModel) UnoRuntime.queryInterface(XModel.class,
155cdf0e10cSrcweir                                                        xDrawDoc);
156cdf0e10cSrcweir         XController xDrawController = xDrawMode1.getCurrentController();
157cdf0e10cSrcweir         XFrame xDrawFrame = xDrawController.getFrame();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         // get impress interfaces
160cdf0e10cSrcweir         try {
161cdf0e10cSrcweir             log.println("creating a impress document");
162cdf0e10cSrcweir             xImpressDoc = SOF.createImpressDoc(null);
163cdf0e10cSrcweir         } catch (Exception e) {
164cdf0e10cSrcweir             e.printStackTrace(log);
165cdf0e10cSrcweir             throw new StatusException("Couldn't create document ", e);
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir         XModel xImpressMode1 = (XModel) UnoRuntime.queryInterface(XModel.class,
168cdf0e10cSrcweir                                                        xImpressDoc);
169cdf0e10cSrcweir         XController xImpressController = xImpressMode1.getCurrentController();
170cdf0e10cSrcweir         XFrame xImpressFrame = xImpressController.getFrame();
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         // get math interfaces
173cdf0e10cSrcweir         try {
174cdf0e10cSrcweir             log.println("creating a math document");
175cdf0e10cSrcweir             xMathDoc = SOF.createMathDoc(null);
176cdf0e10cSrcweir         } catch (Exception e) {
177cdf0e10cSrcweir             e.printStackTrace(log);
178cdf0e10cSrcweir             throw new StatusException("Couldn't create document ", e);
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir         XModel xMathMode1 = (XModel) UnoRuntime.queryInterface(XModel.class,
181cdf0e10cSrcweir                                                        xMathDoc);
182cdf0e10cSrcweir         XController xMathController = xMathMode1.getCurrentController();
183cdf0e10cSrcweir         XFrame xMathFrame = xMathController.getFrame();
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         PropertyValue[] xFrameSeq = new PropertyValue[7];
186cdf0e10cSrcweir         xFrameSeq[0] = new PropertyValue();
187cdf0e10cSrcweir         xFrameSeq[0].Name = "com.sun.star.text.TextDocument";
188cdf0e10cSrcweir         xFrameSeq[0].Value = xTextFrame;
189cdf0e10cSrcweir         xFrameSeq[1] = new PropertyValue();
190cdf0e10cSrcweir         xFrameSeq[1].Name = "com.sun.star.text.WebDocument";
191cdf0e10cSrcweir         xFrameSeq[1].Value = xWebFrame;
192cdf0e10cSrcweir         xFrameSeq[2] = new PropertyValue();
193cdf0e10cSrcweir         xFrameSeq[2].Name = "com.sun.star.text.GlobalDocument";
194cdf0e10cSrcweir         xFrameSeq[2].Value = xGlobalFrame;
195cdf0e10cSrcweir         xFrameSeq[3] = new PropertyValue();
196cdf0e10cSrcweir         xFrameSeq[3].Name = "com.sun.star.sheet.SpreadsheetDocument";
197cdf0e10cSrcweir         xFrameSeq[3].Value = xSheetFrame;
198cdf0e10cSrcweir         xFrameSeq[4] = new PropertyValue();
199cdf0e10cSrcweir         xFrameSeq[4].Name = "com.sun.star.drawing.DrawingDocument";
200cdf0e10cSrcweir         xFrameSeq[4].Value = xDrawFrame;
201cdf0e10cSrcweir         xFrameSeq[5] = new PropertyValue();
202cdf0e10cSrcweir         xFrameSeq[5].Name = "com.sun.star.formula.FormulaProperties";
203cdf0e10cSrcweir         xFrameSeq[5].Value = xMathFrame;
204cdf0e10cSrcweir         xFrameSeq[6] = new PropertyValue();
205cdf0e10cSrcweir         xFrameSeq[6].Name = "com.sun.star.presentation.PresentationDocument";
206cdf0e10cSrcweir         xFrameSeq[6].Value = xImpressFrame;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         PropertyValue[] xControllerSeq = new PropertyValue[7];
209cdf0e10cSrcweir         xControllerSeq[0] = new PropertyValue();
210cdf0e10cSrcweir         xControllerSeq[0].Name = "com.sun.star.text.TextDocument";
211cdf0e10cSrcweir         xControllerSeq[0].Value = xTextController;
212cdf0e10cSrcweir         xControllerSeq[1] = new PropertyValue();
213cdf0e10cSrcweir         xControllerSeq[1].Name = "com.sun.star.text.WebDocument";
214cdf0e10cSrcweir         xControllerSeq[1].Value = xWebController;
215cdf0e10cSrcweir         xControllerSeq[2] = new PropertyValue();
216cdf0e10cSrcweir         xControllerSeq[2].Name = "com.sun.star.text.GlobalDocument";
217cdf0e10cSrcweir         xControllerSeq[2].Value = xGlobalController;
218cdf0e10cSrcweir         xControllerSeq[3] = new PropertyValue();
219cdf0e10cSrcweir         xControllerSeq[3].Name = "com.sun.star.sheet.SpreadsheetDocument";
220cdf0e10cSrcweir         xControllerSeq[3].Value = xSheetController;
221cdf0e10cSrcweir         xControllerSeq[4] = new PropertyValue();
222cdf0e10cSrcweir         xControllerSeq[4].Name = "com.sun.star.drawing.DrawingDocument";
223cdf0e10cSrcweir         xControllerSeq[4].Value = xDrawController;
224cdf0e10cSrcweir         xControllerSeq[5] = new PropertyValue();
225cdf0e10cSrcweir         xControllerSeq[5].Name = "com.sun.star.formula.FormulaProperties";
226cdf0e10cSrcweir         xControllerSeq[5].Value = xMathController;
227cdf0e10cSrcweir         xControllerSeq[6] = new PropertyValue();
228cdf0e10cSrcweir         xControllerSeq[6].Name = "com.sun.star.presentation.PresentationDocument";
229cdf0e10cSrcweir         xControllerSeq[6].Value = xImpressController;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         PropertyValue[] xModelSeq = new PropertyValue[7];
232cdf0e10cSrcweir         xModelSeq[0] = new PropertyValue();
233cdf0e10cSrcweir         xModelSeq[0].Name = "com.sun.star.text.TextDocument";
234cdf0e10cSrcweir         xModelSeq[0].Value = xTextMode1;
235cdf0e10cSrcweir         xModelSeq[1] = new PropertyValue();
236cdf0e10cSrcweir         xModelSeq[1].Name = "com.sun.star.text.WebDocument";
237cdf0e10cSrcweir         xModelSeq[1].Value = xWebMode1;
238cdf0e10cSrcweir         xModelSeq[2] = new PropertyValue();
239cdf0e10cSrcweir         xModelSeq[2].Name = "com.sun.star.text.GlobalDocument";
240cdf0e10cSrcweir         xModelSeq[2].Value = xGlobalMode1;
241cdf0e10cSrcweir         xModelSeq[3] = new PropertyValue();
242cdf0e10cSrcweir         xModelSeq[3].Name = "com.sun.star.sheet.SpreadsheetDocument";
243cdf0e10cSrcweir         xModelSeq[3].Value = xSheetMode1;
244cdf0e10cSrcweir         xModelSeq[4] = new PropertyValue();
245cdf0e10cSrcweir         xModelSeq[4].Name = "com.sun.star.drawing.DrawingDocument";
246cdf0e10cSrcweir         xModelSeq[4].Value = xDrawMode1;
247cdf0e10cSrcweir         xModelSeq[5] = new PropertyValue();
248cdf0e10cSrcweir         xModelSeq[5].Name = "com.sun.star.presentation.PresentationDocument";
249cdf0e10cSrcweir         xModelSeq[5].Value = xImpressMode1;
250cdf0e10cSrcweir         xModelSeq[6] = new PropertyValue();
251cdf0e10cSrcweir         xModelSeq[6].Name = "com.sun.star.formula.FormulaProperties";
252cdf0e10cSrcweir         xModelSeq[6].Value = xMathMode1;
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         tEnv.addObjRelation("XModuleManager.XFrame", xFrameSeq);
258cdf0e10cSrcweir         tEnv.addObjRelation("XModuleManager.XController", xControllerSeq);
259cdf0e10cSrcweir         tEnv.addObjRelation("XModuleManager.XModel", xModelSeq);
260cdf0e10cSrcweir         return tEnv;
261cdf0e10cSrcweir     } // finish method getTestEnvironment
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     /** Disposes text document.
264cdf0e10cSrcweir      * @param tParam test parameters
265cdf0e10cSrcweir      * @param log simple logger
266cdf0e10cSrcweir      */
267cdf0e10cSrcweir     protected void cleanup( TestParameters tParam, PrintWriter log ) {
268cdf0e10cSrcweir         log.println( "    closing all documents " );
269cdf0e10cSrcweir         DesktopTools.closeDoc(xTextDoc);
270cdf0e10cSrcweir         DesktopTools.closeDoc(xWebDoc);
271cdf0e10cSrcweir         DesktopTools.closeDoc(xGlobalDoc);
272cdf0e10cSrcweir         DesktopTools.closeDoc(xSheetDoc);
273cdf0e10cSrcweir         DesktopTools.closeDoc(xDrawDoc);
274cdf0e10cSrcweir         DesktopTools.closeDoc(xImpressDoc);
275cdf0e10cSrcweir         DesktopTools.closeDoc(xMathDoc);
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir }
278