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