merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / frame / _XDispatchRecorder.java
blob179d8ce1630a58c6422d35ef00428009f09c5687
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDispatchRecorder.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.frame;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
36 import util.utils;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.frame.XDispatch;
40 import com.sun.star.frame.XDispatchProvider;
41 import com.sun.star.frame.XDispatchRecorder;
42 import com.sun.star.frame.XFrame;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.util.URL;
47 /**
48 * Testing <code>com.sun.star.frame.XDispatchRecorder</code>
49 * interface methods:
50 * <ul>
51 * <li><code> startRecording() </code></li>
52 * <li><code> recordDispatch() </code></li>
53 * <li><code> recordDispatchAsComment() </code></li>
54 * <li><code> endRecording() </code></li>
55 * <li><code> getRecordedMacro() </code></li>
56 * </ul><p>
57 * Test is <b> NOT </b> multithread compilant. <p>
58 * @see com.sun.star.frame.XDispatchRecorder
60 public class _XDispatchRecorder extends MultiMethodTest {
61 public static XDispatchRecorder oObj = null;
63 XFrame xFrame = null;
64 URL dispURL = null;
65 PropertyValue[] dispArgs = new PropertyValue[0];
67 protected void before() {
68 xFrame = (XFrame) tEnv.getObjRelation("XDispatchRecorder.Frame");
70 if (xFrame == null) {
71 throw new StatusException(Status.failed("Relation not found"));
75 public void _startRecording() {
77 oObj.startRecording(xFrame);
78 oObj.endRecording();
79 tRes.tested("startRecording()", true);
82 public void _getRecordedMacro() {
84 clearBuffer();
86 oObj.startRecording(xFrame);
88 log.println("dispatch calles via API must be recorded");
89 dispURL = utils.parseURL((XMultiServiceFactory)tParam.getMSF(), ".uno:InsertText");
91 PropertyValue prop = new PropertyValue();
92 prop.Name = "Text";
93 prop.Value = "XDispatchRecorder.endRecording()";
94 dispArgs = new PropertyValue[] {prop};
96 log.println("Dispatching event for frame ...");
97 XDispatchProvider xDispProv = (XDispatchProvider)
98 UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
99 XDispatch xDisp = xDispProv.queryDispatch(dispURL, "", 0);
100 xDisp.dispatch(dispURL, dispArgs);
102 shortWait();
104 log.println("Getting macro ... :");
105 String macro = oObj.getRecordedMacro();
106 log.println(macro);
108 log.println("Ending record ...");
109 oObj.endRecording();
111 boolean res = macro != null
112 && macro.indexOf(dispURL.Complete) > -1;
113 if (!res) log.println("Dispatch URL '" + dispURL.Complete
114 + "' was NOT found in macro - FAILED");
116 tRes.tested("getRecordedMacro()", res);
119 public void _endRecording() {
121 oObj.startRecording(xFrame);
122 oObj.endRecording();
123 String macro = oObj.getRecordedMacro();
124 boolean res = true;
125 if (macro.length() != 0){
126 log.println("'endRecording()' was called but macro buffer is not cleared: FALSE");
127 log.println(macro);
128 res = false;
131 tRes.tested("endRecording()", res);
134 public void _recordDispatch() {
135 clearBuffer();
137 oObj.startRecording(xFrame);
139 // positve test
140 dispURL = utils.parseURL((XMultiServiceFactory)tParam.getMSF(), ".uno:InsertText");
142 PropertyValue prop = new PropertyValue();
143 prop.Name = "Text";
144 prop.Value = "XDispatchRecorder.recordDispatch()";
145 dispArgs = new PropertyValue[] {prop};
147 log.println("Recording dispatch ...");
148 oObj.recordDispatch(dispURL, dispArgs);
150 log.println("Getting macro ... :");
151 String macro = oObj.getRecordedMacro();
152 log.println(macro);
154 oObj.endRecording();
156 boolean res = macro != null
157 && macro.indexOf(dispURL.Complete) > -1
158 && macro.indexOf((String)dispArgs[0].Value) > -1;
159 if (!res) log.println("Dispatch URL '" + dispURL.Complete
160 + "' or its argument '" + dispArgs[0].Value
161 + "' was not found in macro returned - FAILED");
163 tRes.tested("recordDispatch()", res);
166 public void _recordDispatchAsComment() {
167 clearBuffer();
169 oObj.startRecording(xFrame);
171 dispURL = utils.parseURL((XMultiServiceFactory)tParam.getMSF(), ".uno:InsertText");
173 PropertyValue prop = new PropertyValue();
174 prop.Name = "Text";
175 prop.Value = "XDispatchRecorder.recordDispatchAsComment()";
176 dispArgs = new PropertyValue[] {prop};
178 log.println("Recording dispatch ...");
179 oObj.recordDispatchAsComment(dispURL, dispArgs);
181 log.println("Getting macro ... :");
182 String macro = oObj.getRecordedMacro();
183 log.println(macro);
185 oObj.endRecording();
187 boolean res = macro != null
188 && macro.indexOf(dispURL.Complete) > -1
189 && macro.indexOf((String)dispArgs[0].Value) > -1;
190 if (!res) log.println("Dispatch URL '" + dispURL.Complete
191 + "' or its argument '" + dispArgs[0].Value
192 + "' was not found in macro returned - FAILED");
194 log.println("Checking if macro is commented ...");
195 int idx = macro.indexOf((String)dispArgs[0].Value);
196 int lineStartIdx = macro.lastIndexOf("\n", idx);
197 String lineStart = macro.substring(lineStartIdx + 1, idx).toLowerCase();
198 log.println("Line start is '" + lineStart + "'");
200 if (lineStart.startsWith("'") || lineStart.startsWith("rem")) {
201 log.println("Line is commented : OK");
202 } else {
203 log.println("Line is not commented : FAILED");
204 res =false;
207 tRes.tested("recordDispatchAsComment()", res);
211 private void shortWait() {
212 try {
213 Thread.sleep(500);
214 } catch (InterruptedException ex) {}
217 private void clearBuffer() {
218 oObj.startRecording(xFrame);
219 oObj.endRecording();
220 String macro = oObj.getRecordedMacro();
221 if (macro.length() != 0){
222 log.println("ERROR: 'endRecording()' was called but macro buffer is not cleared!");
223 log.println(macro);