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
;
25 import lib
.StatusException
;
27 import lib
.TestEnvironment
;
28 import lib
.TestParameters
;
29 import util
.SOfficeFactory
;
31 import com
.sun
.star
.beans
.XPropertySet
;
32 import com
.sun
.star
.frame
.DispatchStatement
;
33 import com
.sun
.star
.frame
.XDispatchRecorder
;
34 import com
.sun
.star
.frame
.XDispatchRecorderSupplier
;
35 import com
.sun
.star
.frame
.XFrame
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.util
.URL
;
45 * Test for object that implements the following interfaces :
47 * <li><code>com::sun::star::container::XElementAccess</code></li>
48 * <li><code>com::sun::star::container::XIndexAccess</code></li>
49 * <li><code>com::sun::star::container::XIndexReplace</code></li>
50 * <li><code>com::sun::star::frame::XDispatchRecorder</code></li>
52 * @see com.sun.star.container.XElementAccess
53 * @see com.sun.star.container.XIndexAccess
54 * @see com.sun.star.container.XIndexReplace
55 * @see com.sun.star.frame.XDispatchRecorder
56 * @see ifc.container._XElementAccess
57 * @see ifc.container._XIndexAccess
58 * @see ifc.container._XIndexReplace
59 * @see ifc.frame._XDispatchRecorder
61 public class DispatchRecorder
extends TestCase
{
62 XComponent oDoc
= null;
65 * Creating a Testenvironment for the interfaces to be tested.
66 * Creates service <code>com.sun.star.frame.Desktop</code>.
69 public TestEnvironment
createTestEnvironment( TestParameters Param
,
70 PrintWriter log
) throws StatusException
{
72 XInterface oObj
= null;
74 XDispatchRecorder xDR
= null;
77 SOfficeFactory SOF
= SOfficeFactory
.getFactory(Param
.getMSF());
78 oDoc
= SOF
.createTextDoc(null);
79 util
.utils
.pause(1000);
81 XModel model
= UnoRuntime
.queryInterface(XModel
.class, oDoc
);
82 xFrame
= model
.getCurrentController().getFrame();
84 XPropertySet xFramePS
= UnoRuntime
.queryInterface
85 (XPropertySet
.class, xFrame
);
86 XDispatchRecorderSupplier xDRS
= null;
87 xDRS
= (XDispatchRecorderSupplier
) AnyConverter
.toObject(
88 new Type(XDispatchRecorderSupplier
.class),
89 xFramePS
.getPropertyValue("DispatchRecorderSupplier"));
92 Object oDRS
= Param
.getMSF().createInstance(
93 "com.sun.star.comp.framework.DispatchRecorderSupplier");
94 xFramePS
.setPropertyValue("DispatchRecorderSupplier", oDRS
);
95 xDRS
= UnoRuntime
.queryInterface(XDispatchRecorderSupplier
.class,oDRS
);
98 xDR
= xDRS
.getDispatchRecorder();
102 oObj
= (XInterface
)Param
.getMSF().createInstance(
103 "com.sun.star.comp.framework.DispatchRecorder");
104 xDR
= UnoRuntime
.queryInterface
105 (XDispatchRecorder
.class, oObj
);
106 xDRS
.setDispatchRecorder(xDR
);
108 } catch (com
.sun
.star
.uno
.Exception e
) {
109 throw new StatusException("Can't create component", e
);
113 // fill recorder with content. It's needed for XIndexReplace
114 URL dispURL
= utils
.parseURL(Param
.getMSF(), ".uno:InsertDateField");
115 PropertyValue prop
= new PropertyValue();
117 prop
.Value
= "XDispatchRecorder.recordDispatch()";
118 PropertyValue
[] dispArgs
= new PropertyValue
[] {prop
};
119 xDR
.recordDispatch(dispURL
, dispArgs
);
122 TestEnvironment tEnv
= new TestEnvironment( oObj
);
124 // INSTANCEn : _XIndexReplace
125 log
.println("adding INSTANCEn as obj relation to environment");
128 if (Param
.get("THRCNT")!= null) {
129 THRCNT
= Integer
.parseInt((String
) Param
.get("THRCNT"));
132 URL instanceURL
= null;
133 DispatchStatement instance
= new DispatchStatement();
134 PropertyValue dispProp
= new PropertyValue();
136 for (int n
= 1; n
< (THRCNT
+ 1); n
++) {
137 log
.println("adding INSTANCE" + n
+
138 " as obj relation to environment");
139 instanceURL
= utils
.parseURL(Param
.getMSF(), ".uno:InsertText");
140 dispProp
.Name
= "Text";
141 dispProp
.Value
= "Instance " + n
;
142 dispArgs
= new PropertyValue
[] {dispProp
};
143 instance
.aCommand
= instanceURL
.Complete
;
144 instance
.aArgs
= dispArgs
;
145 instance
.aTarget
= "_top";
146 instance
.nFlags
= com
.sun
.star
.frame
.FrameSearchFlag
.ALL
;
148 tEnv
.addObjRelation("INSTANCE" + n
, instance
);
151 tEnv
.addObjRelation("XDispatchRecorder.Frame", xFrame
);
152 log
.println("Object created: TRUE");
154 } // finish method getTestEnvironment
157 protected void cleanup( TestParameters Param
, PrintWriter log
) {
158 util
.DesktopTools
.closeDoc(oDoc
);