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