2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
26 import com
.sun
.star
.beans
.PropertyValue
;
27 import com
.sun
.star
.frame
.XDispatch
;
28 import com
.sun
.star
.frame
.XDispatchProvider
;
29 import com
.sun
.star
.frame
.XDispatchRecorder
;
30 import com
.sun
.star
.frame
.XFrame
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.util
.URL
;
35 * Testing <code>com.sun.star.frame.XDispatchRecorder</code>
38 * <li><code> startRecording() </code></li>
39 * <li><code> recordDispatch() </code></li>
40 * <li><code> recordDispatchAsComment() </code></li>
41 * <li><code> endRecording() </code></li>
42 * <li><code> getRecordedMacro() </code></li>
44 * Test is <b> NOT </b> multithread compliant. <p>
45 * @see com.sun.star.frame.XDispatchRecorder
47 public class _XDispatchRecorder
extends MultiMethodTest
{
48 public static XDispatchRecorder oObj
= null;
52 PropertyValue
[] dispArgs
= new PropertyValue
[0];
55 protected void before() {
56 xFrame
= (XFrame
) tEnv
.getObjRelation("XDispatchRecorder.Frame");
59 throw new StatusException(Status
.failed("Relation not found"));
63 public void _startRecording() {
65 oObj
.startRecording(xFrame
);
67 tRes
.tested("startRecording()", true);
70 public void _getRecordedMacro() throws Exception
{
74 oObj
.startRecording(xFrame
);
76 log
.println("dispatch calls via API must be recorded");
77 dispURL
= utils
.parseURL(tParam
.getMSF(), ".uno:InsertText");
79 PropertyValue prop
= new PropertyValue();
81 prop
.Value
= "XDispatchRecorder.endRecording()";
82 dispArgs
= new PropertyValue
[] {prop
};
84 log
.println("Dispatching event for frame ...");
85 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xFrame
);
86 XDispatch xDisp
= xDispProv
.queryDispatch(dispURL
, "", 0);
87 xDisp
.dispatch(dispURL
, dispArgs
);
91 log
.println("Getting macro ... :");
92 String macro
= oObj
.getRecordedMacro();
95 log
.println("Ending record ...");
98 boolean res
= macro
!= null
99 && macro
.indexOf(dispURL
.Complete
) > -1;
100 if (!res
) log
.println("Dispatch URL '" + dispURL
.Complete
101 + "' was NOT found in macro - FAILED");
103 tRes
.tested("getRecordedMacro()", res
);
106 public void _endRecording() {
108 oObj
.startRecording(xFrame
);
110 String macro
= oObj
.getRecordedMacro();
112 if (macro
.length() != 0){
113 log
.println("'endRecording()' was called but macro buffer is not cleared: FALSE");
118 tRes
.tested("endRecording()", res
);
121 public void _recordDispatch() {
124 oObj
.startRecording(xFrame
);
127 dispURL
= utils
.parseURL(tParam
.getMSF(), ".uno:InsertText");
129 PropertyValue prop
= new PropertyValue();
131 prop
.Value
= "XDispatchRecorder.recordDispatch()";
132 dispArgs
= new PropertyValue
[] {prop
};
134 log
.println("Recording dispatch ...");
135 oObj
.recordDispatch(dispURL
, dispArgs
);
137 log
.println("Getting macro ... :");
138 String macro
= oObj
.getRecordedMacro();
143 boolean res
= macro
!= null
144 && macro
.indexOf(dispURL
.Complete
) > -1
145 && macro
.indexOf((String
)dispArgs
[0].Value
) > -1;
146 if (!res
) log
.println("Dispatch URL '" + dispURL
.Complete
147 + "' or its argument '" + dispArgs
[0].Value
148 + "' was not found in macro returned - FAILED");
150 tRes
.tested("recordDispatch()", res
);
153 public void _recordDispatchAsComment() {
156 oObj
.startRecording(xFrame
);
158 dispURL
= utils
.parseURL(tParam
.getMSF(), ".uno:InsertText");
160 PropertyValue prop
= new PropertyValue();
162 prop
.Value
= "XDispatchRecorder.recordDispatchAsComment()";
163 dispArgs
= new PropertyValue
[] {prop
};
165 log
.println("Recording dispatch ...");
166 oObj
.recordDispatchAsComment(dispURL
, dispArgs
);
168 log
.println("Getting macro ... :");
169 String macro
= oObj
.getRecordedMacro();
174 boolean res
= macro
!= null
175 && macro
.indexOf(dispURL
.Complete
) > -1
176 && macro
.indexOf((String
)dispArgs
[0].Value
) > -1;
177 if (!res
) log
.println("Dispatch URL '" + dispURL
.Complete
178 + "' or its argument '" + dispArgs
[0].Value
179 + "' was not found in macro returned - FAILED");
181 log
.println("Checking if macro is commented ...");
182 int idx
= macro
.indexOf((String
)dispArgs
[0].Value
);
183 int lineStartIdx
= macro
.lastIndexOf("\n", idx
);
184 String lineStart
= macro
.substring(lineStartIdx
+ 1, idx
).toLowerCase();
185 log
.println("Line start is '" + lineStart
+ "'");
187 if (lineStart
.startsWith("'") || lineStart
.startsWith("rem")) {
188 log
.println("Line is commented : OK");
190 log
.println("Line is not commented : FAILED");
194 tRes
.tested("recordDispatchAsComment()", res
);
198 private void clearBuffer() {
199 oObj
.startRecording(xFrame
);
201 String macro
= oObj
.getRecordedMacro();
202 if (macro
.length() != 0){
203 log
.println("ERROR: 'endRecording()' was called but macro buffer is not cleared!");