1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDispatchRecorder.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
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
;
48 * Testing <code>com.sun.star.frame.XDispatchRecorder</code>
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>
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;
65 PropertyValue
[] dispArgs
= new PropertyValue
[0];
67 protected void before() {
68 xFrame
= (XFrame
) tEnv
.getObjRelation("XDispatchRecorder.Frame");
71 throw new StatusException(Status
.failed("Relation not found"));
75 public void _startRecording() {
77 oObj
.startRecording(xFrame
);
79 tRes
.tested("startRecording()", true);
82 public void _getRecordedMacro() {
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();
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
);
104 log
.println("Getting macro ... :");
105 String macro
= oObj
.getRecordedMacro();
108 log
.println("Ending record ...");
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
);
123 String macro
= oObj
.getRecordedMacro();
125 if (macro
.length() != 0){
126 log
.println("'endRecording()' was called but macro buffer is not cleared: FALSE");
131 tRes
.tested("endRecording()", res
);
134 public void _recordDispatch() {
137 oObj
.startRecording(xFrame
);
140 dispURL
= utils
.parseURL((XMultiServiceFactory
)tParam
.getMSF(), ".uno:InsertText");
142 PropertyValue prop
= new PropertyValue();
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();
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() {
169 oObj
.startRecording(xFrame
);
171 dispURL
= utils
.parseURL((XMultiServiceFactory
)tParam
.getMSF(), ".uno:InsertText");
173 PropertyValue prop
= new PropertyValue();
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();
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");
203 log
.println("Line is not commented : FAILED");
207 tRes
.tested("recordDispatchAsComment()", res
);
211 private void shortWait() {
214 } catch (InterruptedException ex
) {}
217 private void clearBuffer() {
218 oObj
.startRecording(xFrame
);
220 String macro
= oObj
.getRecordedMacro();
221 if (macro
.length() != 0){
222 log
.println("ERROR: 'endRecording()' was called but macro buffer is not cleared!");