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