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 ifc.frame; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 import util.utils; 30 31 import com.sun.star.beans.PropertyValue; 32 import com.sun.star.frame.XDispatch; 33 import com.sun.star.frame.XDispatchProvider; 34 import com.sun.star.frame.XDispatchRecorder; 35 import com.sun.star.frame.XFrame; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.util.URL; 39 40 /** 41 * Testing <code>com.sun.star.frame.XDispatchRecorder</code> 42 * interface methods: 43 * <ul> 44 * <li><code> startRecording() </code></li> 45 * <li><code> recordDispatch() </code></li> 46 * <li><code> recordDispatchAsComment() </code></li> 47 * <li><code> endRecording() </code></li> 48 * <li><code> getRecordedMacro() </code></li> 49 * </ul><p> 50 * Test is <b> NOT </b> multithread compilant. <p> 51 * @see com.sun.star.frame.XDispatchRecorder 52 */ 53 public class _XDispatchRecorder extends MultiMethodTest { 54 public static XDispatchRecorder oObj = null; 55 56 XFrame xFrame = null; 57 URL dispURL = null; 58 PropertyValue[] dispArgs = new PropertyValue[0]; 59 before()60 protected void before() { 61 xFrame = (XFrame) tEnv.getObjRelation("XDispatchRecorder.Frame"); 62 63 if (xFrame == null) { 64 throw new StatusException(Status.failed("Relation not found")); 65 } 66 } 67 _startRecording()68 public void _startRecording() { 69 70 oObj.startRecording(xFrame); 71 oObj.endRecording(); 72 tRes.tested("startRecording()", true); 73 } 74 _getRecordedMacro()75 public void _getRecordedMacro() { 76 77 clearBuffer(); 78 79 oObj.startRecording(xFrame); 80 81 log.println("dispatch calles via API must be recorded"); 82 dispURL = utils.parseURL((XMultiServiceFactory)tParam.getMSF(), ".uno:InsertText"); 83 84 PropertyValue prop = new PropertyValue(); 85 prop.Name = "Text"; 86 prop.Value = "XDispatchRecorder.endRecording()"; 87 dispArgs = new PropertyValue[] {prop}; 88 89 log.println("Dispatching event for frame ..."); 90 XDispatchProvider xDispProv = (XDispatchProvider) 91 UnoRuntime.queryInterface(XDispatchProvider.class, xFrame); 92 XDispatch xDisp = xDispProv.queryDispatch(dispURL, "", 0); 93 xDisp.dispatch(dispURL, dispArgs); 94 95 shortWait(); 96 97 log.println("Getting macro ... :"); 98 String macro = oObj.getRecordedMacro(); 99 log.println(macro); 100 101 log.println("Ending record ..."); 102 oObj.endRecording(); 103 104 boolean res = macro != null 105 && macro.indexOf(dispURL.Complete) > -1; 106 if (!res) log.println("Dispatch URL '" + dispURL.Complete 107 + "' was NOT found in macro - FAILED"); 108 109 tRes.tested("getRecordedMacro()", res); 110 } 111 _endRecording()112 public void _endRecording() { 113 114 oObj.startRecording(xFrame); 115 oObj.endRecording(); 116 String macro = oObj.getRecordedMacro(); 117 boolean res = true; 118 if (macro.length() != 0){ 119 log.println("'endRecording()' was called but macro buffer is not cleared: FALSE"); 120 log.println(macro); 121 res = false; 122 } 123 124 tRes.tested("endRecording()", res); 125 } 126 _recordDispatch()127 public void _recordDispatch() { 128 clearBuffer(); 129 130 oObj.startRecording(xFrame); 131 132 // positve test 133 dispURL = utils.parseURL((XMultiServiceFactory)tParam.getMSF(), ".uno:InsertText"); 134 135 PropertyValue prop = new PropertyValue(); 136 prop.Name = "Text"; 137 prop.Value = "XDispatchRecorder.recordDispatch()"; 138 dispArgs = new PropertyValue[] {prop}; 139 140 log.println("Recording dispatch ..."); 141 oObj.recordDispatch(dispURL, dispArgs); 142 143 log.println("Getting macro ... :"); 144 String macro = oObj.getRecordedMacro(); 145 log.println(macro); 146 147 oObj.endRecording(); 148 149 boolean res = macro != null 150 && macro.indexOf(dispURL.Complete) > -1 151 && macro.indexOf((String)dispArgs[0].Value) > -1; 152 if (!res) log.println("Dispatch URL '" + dispURL.Complete 153 + "' or its argument '" + dispArgs[0].Value 154 + "' was not found in macro returned - FAILED"); 155 156 tRes.tested("recordDispatch()", res); 157 } 158 _recordDispatchAsComment()159 public void _recordDispatchAsComment() { 160 clearBuffer(); 161 162 oObj.startRecording(xFrame); 163 164 dispURL = utils.parseURL((XMultiServiceFactory)tParam.getMSF(), ".uno:InsertText"); 165 166 PropertyValue prop = new PropertyValue(); 167 prop.Name = "Text"; 168 prop.Value = "XDispatchRecorder.recordDispatchAsComment()"; 169 dispArgs = new PropertyValue[] {prop}; 170 171 log.println("Recording dispatch ..."); 172 oObj.recordDispatchAsComment(dispURL, dispArgs); 173 174 log.println("Getting macro ... :"); 175 String macro = oObj.getRecordedMacro(); 176 log.println(macro); 177 178 oObj.endRecording(); 179 180 boolean res = macro != null 181 && macro.indexOf(dispURL.Complete) > -1 182 && macro.indexOf((String)dispArgs[0].Value) > -1; 183 if (!res) log.println("Dispatch URL '" + dispURL.Complete 184 + "' or its argument '" + dispArgs[0].Value 185 + "' was not found in macro returned - FAILED"); 186 187 log.println("Checking if macro is commented ..."); 188 int idx = macro.indexOf((String)dispArgs[0].Value); 189 int lineStartIdx = macro.lastIndexOf("\n", idx); 190 String lineStart = macro.substring(lineStartIdx + 1, idx).toLowerCase(); 191 log.println("Line start is '" + lineStart + "'"); 192 193 if (lineStart.startsWith("'") || lineStart.startsWith("rem")) { 194 log.println("Line is commented : OK"); 195 } else { 196 log.println("Line is not commented : FAILED"); 197 res =false; 198 } 199 200 tRes.tested("recordDispatchAsComment()", res); 201 } 202 203 shortWait()204 private void shortWait() { 205 try { 206 Thread.sleep(500); 207 } catch (InterruptedException ex) {} 208 } 209 clearBuffer()210 private void clearBuffer() { 211 oObj.startRecording(xFrame); 212 oObj.endRecording(); 213 String macro = oObj.getRecordedMacro(); 214 if (macro.length() != 0){ 215 log.println("ERROR: 'endRecording()' was called but macro buffer is not cleared!"); 216 log.println(macro); 217 } 218 } 219 220 } 221