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 com
.sun
.star
.beans
.PropertyValue
;
22 import com
.sun
.star
.frame
.XModel
;
23 import java
.io
.PrintWriter
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.SOfficeFactory
;
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.frame
.DispatchStatement
;
32 import com
.sun
.star
.frame
.XDispatchRecorder
;
33 import com
.sun
.star
.frame
.XDispatchRecorderSupplier
;
34 import com
.sun
.star
.frame
.XFrame
;
35 import com
.sun
.star
.lang
.XComponent
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.util
.URL
;
44 * Test for object that implements the following interfaces :
46 * <li><code>com::sun::star::container::XElementAccess</code></li>
47 * <li><code>com::sun::star::container::XIndexAccess</code></li>
48 * <li><code>com::sun::star::container::XIndexReplace</code></li>
49 * <li><code>com::sun::star::frame::XDispatchRecorder</code></li>
51 * @see com.sun.star.container.XElementAccess
52 * @see com.sun.star.container.XIndexAccess
53 * @see com.sun.star.container.XIndexReplace
54 * @see com.sun.star.frame.XDispatchRecorder
55 * @see ifc.container._XElementAccess
56 * @see ifc.container._XIndexAccess
57 * @see ifc.container._XIndexReplace
58 * @see ifc.frame._XDispatchRecorder
60 public class DispatchRecorder
extends TestCase
{
61 XComponent oDoc
= null;
64 * Creating a TestEnvironment for the interfaces to be tested.
65 * Creates service <code>com.sun.star.frame.Desktop</code>.
68 public TestEnvironment
createTestEnvironment( TestParameters Param
,
69 PrintWriter log
) throws Exception
{
71 XInterface oObj
= null;
73 XDispatchRecorder xDR
= null;
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory(Param
.getMSF());
76 oDoc
= SOF
.createTextDoc(null);
77 util
.utils
.waitForEventIdle(Param
.getMSF());
79 XModel model
= UnoRuntime
.queryInterface(XModel
.class, oDoc
);
80 xFrame
= model
.getCurrentController().getFrame();
82 XPropertySet xFramePS
= UnoRuntime
.queryInterface
83 (XPropertySet
.class, xFrame
);
84 XDispatchRecorderSupplier xDRS
= null;
85 xDRS
= (XDispatchRecorderSupplier
) AnyConverter
.toObject(
86 new Type(XDispatchRecorderSupplier
.class),
87 xFramePS
.getPropertyValue("DispatchRecorderSupplier"));
90 Object oDRS
= Param
.getMSF().createInstance(
91 "com.sun.star.comp.framework.DispatchRecorderSupplier");
92 xFramePS
.setPropertyValue("DispatchRecorderSupplier", oDRS
);
93 xDRS
= UnoRuntime
.queryInterface(XDispatchRecorderSupplier
.class,oDRS
);
96 xDR
= xDRS
.getDispatchRecorder();
100 oObj
= (XInterface
)Param
.getMSF().createInstance(
101 "com.sun.star.comp.framework.DispatchRecorder");
102 xDR
= UnoRuntime
.queryInterface
103 (XDispatchRecorder
.class, oObj
);
104 xDRS
.setDispatchRecorder(xDR
);
108 // fill recorder with content. It's needed for XIndexReplace
109 URL dispURL
= utils
.parseURL(Param
.getMSF(), ".uno:InsertDateField");
110 PropertyValue prop
= new PropertyValue();
112 prop
.Value
= "XDispatchRecorder.recordDispatch()";
113 PropertyValue
[] dispArgs
= new PropertyValue
[] {prop
};
114 xDR
.recordDispatch(dispURL
, dispArgs
);
117 TestEnvironment tEnv
= new TestEnvironment( oObj
);
119 // INSTANCEn : _XIndexReplace
120 log
.println("adding INSTANCEn as obj relation to environment");
123 if (Param
.get("THRCNT")!= null) {
124 THRCNT
= Integer
.parseInt((String
) Param
.get("THRCNT"));
127 URL instanceURL
= null;
128 DispatchStatement instance
= new DispatchStatement();
129 PropertyValue dispProp
= new PropertyValue();
131 for (int n
= 1; n
< (THRCNT
+ 1); n
++) {
132 log
.println("adding INSTANCE" + n
+
133 " as obj relation to environment");
134 instanceURL
= utils
.parseURL(Param
.getMSF(), ".uno:InsertText");
135 dispProp
.Name
= "Text";
136 dispProp
.Value
= "Instance " + n
;
137 dispArgs
= new PropertyValue
[] {dispProp
};
138 instance
.aCommand
= instanceURL
.Complete
;
139 instance
.aArgs
= dispArgs
;
140 instance
.aTarget
= "_top";
141 instance
.nFlags
= com
.sun
.star
.frame
.FrameSearchFlag
.ALL
;
143 tEnv
.addObjRelation("INSTANCE" + n
, instance
);
146 tEnv
.addObjRelation("XDispatchRecorder.Frame", xFrame
);
147 log
.println("Object created: TRUE");
149 } // finish method getTestEnvironment
152 protected void cleanup( TestParameters Param
, PrintWriter log
) {
153 util
.DesktopTools
.closeDoc(oDoc
);