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.XModel; 28 import java.io.PrintWriter; 29 30 import lib.StatusException; 31 import lib.TestCase; 32 import lib.TestEnvironment; 33 import lib.TestParameters; 34 import util.SOfficeFactory; 35 36 import com.sun.star.beans.XPropertySet; 37 import com.sun.star.frame.DispatchStatement; 38 import com.sun.star.frame.XDispatchRecorder; 39 import com.sun.star.frame.XDispatchRecorderSupplier; 40 import com.sun.star.frame.XFrame; 41 import com.sun.star.lang.XComponent; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 import com.sun.star.uno.AnyConverter; 46 import com.sun.star.uno.Type; 47 import com.sun.star.util.URL; 48 import util.utils; 49 50 /** 51 * Test for object that implements the following interfaces : 52 * <ul> 53 * <li><code>com::sun::star::container::XElementAccess</code></li> 54 * <li><code>com::sun::star::container::XIndexAccess</code></li> 55 * <li><code>com::sun::star::container::XIndexReplace</code></li> 56 * <li><code>com::sun::star::frame::XDispatchRecorder</code></li> 57 * </ul><p> 58 * @see com.sun.star.container.XElementAccess 59 * @see com.sun.star.container.XIndexAccess 60 * @see com.sun.star.container.XIndexReplace 61 * @see com.sun.star.frame.XDispatchRecorder 62 * @see ifc.container._XElementAccess 63 * @see ifc.container._XIndexAccess 64 * @see ifc.container._XIndexReplace 65 * @see ifc.frame._XDispatchRecorder 66 */ 67 public class DispatchRecorder extends TestCase { 68 XComponent oDoc = null; 69 70 /** 71 * Creating a Testenvironment for the interfaces to be tested. 72 * Creates service <code>com.sun.star.frame.Desktop</code>. 73 */ createTestEnvironment( TestParameters Param, PrintWriter log )74 public TestEnvironment createTestEnvironment( TestParameters Param, 75 PrintWriter log ) throws StatusException { 76 77 XInterface oObj = null; 78 XFrame xFrame = null; 79 XDispatchRecorder xDR = null; 80 81 try { 82 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)Param.getMSF()); 83 oDoc = SOF.createTextDoc(null); 84 try { 85 Thread.sleep(1000); 86 } 87 catch (InterruptedException ex) { 88 } 89 90 XModel model = (XModel) UnoRuntime.queryInterface(XModel.class, oDoc); 91 xFrame = model.getCurrentController().getFrame(); 92 93 XPropertySet xFramePS = (XPropertySet) UnoRuntime.queryInterface 94 (XPropertySet.class, xFrame); 95 XDispatchRecorderSupplier xDRS = null; 96 xDRS = (XDispatchRecorderSupplier) AnyConverter.toObject( 97 new Type(XDispatchRecorderSupplier.class), 98 xFramePS.getPropertyValue("DispatchRecorderSupplier")); 99 if (xDRS == null) { 100 101 Object oDRS = ((XMultiServiceFactory)Param.getMSF()).createInstance( 102 "com.sun.star.comp.framework.DispatchRecorderSupplier"); 103 xFramePS.setPropertyValue("DispatchRecorderSupplier", oDRS); 104 xDRS = (XDispatchRecorderSupplier) 105 UnoRuntime.queryInterface(XDispatchRecorderSupplier.class,oDRS); 106 } 107 108 xDR = xDRS.getDispatchRecorder(); 109 if (xDR != null) { 110 oObj = xDR; 111 } else { 112 oObj = (XInterface)((XMultiServiceFactory)Param.getMSF()).createInstance( 113 "com.sun.star.comp.framework.DispatchRecorder"); 114 xDR = (XDispatchRecorder) UnoRuntime.queryInterface 115 (XDispatchRecorder.class, oObj); 116 xDRS.setDispatchRecorder(xDR); 117 } 118 } catch (com.sun.star.uno.Exception e) { 119 throw new StatusException("Can't create component", e); 120 } 121 122 123 // fill recorder with content. It's needed for XIndexReplace 124 URL dispURL = utils.parseURL((XMultiServiceFactory) Param.getMSF(), ".uno:InsertDateField"); 125 PropertyValue prop = new PropertyValue(); 126 prop.Name = "Text"; 127 prop.Value = "XDispatchRecorder.recordDispatch()"; 128 PropertyValue[] dispArgs = new PropertyValue[] {prop}; 129 xDR.recordDispatch(dispURL, dispArgs); 130 131 132 TestEnvironment tEnv = new TestEnvironment( oObj ); 133 134 // INSTANCEn : _XIndexReplace 135 log.println("adding INSTANCEn as obj relation to environment"); 136 137 int THRCNT = 1; 138 if (Param.get("THRCNT")!= null) { 139 THRCNT = Integer.parseInt((String) Param.get("THRCNT")); 140 } 141 142 URL instanceURL = null; 143 DispatchStatement instance = new DispatchStatement(); 144 PropertyValue dispProp = new PropertyValue(); 145 146 for (int n = 1; n < (THRCNT + 1); n++) { 147 log.println("adding INSTANCE" + n + 148 " as obj relation to environment"); 149 instanceURL = utils.parseURL((XMultiServiceFactory) Param.getMSF(), ".uno:InsertText"); 150 dispProp.Name = "Text"; 151 dispProp.Value = "Instance " + n; 152 dispArgs = new PropertyValue[] {dispProp}; 153 instance.aCommand = instanceURL.Complete; 154 instance.aArgs = dispArgs; 155 instance.aTarget = "_top"; 156 instance.nFlags = com.sun.star.frame.FrameSearchFlag.ALL; 157 158 tEnv.addObjRelation("INSTANCE" + n, instance); 159 } 160 161 tEnv.addObjRelation("XDispatchRecorder.Frame", xFrame); 162 log.println("Object created: TRUE"); 163 return tEnv; 164 } // finish method getTestEnvironment 165 cleanup( TestParameters Param, PrintWriter log)166 protected void cleanup( TestParameters Param, PrintWriter log) { 167 util.DesktopTools.closeDoc(oDoc); 168 } 169 170 } 171