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
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
40 import com
.sun
.star
.uno
.AnyConverter
;
41 import com
.sun
.star
.uno
.Type
;
42 import com
.sun
.star
.util
.URL
;
46 * Test for object that implements the following interfaces :
48 * <li><code>com::sun::star::container::XElementAccess</code></li>
49 * <li><code>com::sun::star::container::XIndexAccess</code></li>
50 * <li><code>com::sun::star::container::XIndexReplace</code></li>
51 * <li><code>com::sun::star::frame::XDispatchRecorder</code></li>
53 * @see com.sun.star.container.XElementAccess
54 * @see com.sun.star.container.XIndexAccess
55 * @see com.sun.star.container.XIndexReplace
56 * @see com.sun.star.frame.XDispatchRecorder
57 * @see ifc.container._XElementAccess
58 * @see ifc.container._XIndexAccess
59 * @see ifc.container._XIndexReplace
60 * @see ifc.frame._XDispatchRecorder
62 public class DispatchRecorder
extends TestCase
{
63 XComponent oDoc
= null;
66 * Creating a Testenvironment for the interfaces to be tested.
67 * 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((XMultiServiceFactory
)Param
.getMSF());
78 oDoc
= SOF
.createTextDoc(null);
82 catch (InterruptedException ex
) {
85 XModel model
= UnoRuntime
.queryInterface(XModel
.class, oDoc
);
86 xFrame
= model
.getCurrentController().getFrame();
88 XPropertySet xFramePS
= UnoRuntime
.queryInterface
89 (XPropertySet
.class, xFrame
);
90 XDispatchRecorderSupplier xDRS
= null;
91 xDRS
= (XDispatchRecorderSupplier
) AnyConverter
.toObject(
92 new Type(XDispatchRecorderSupplier
.class),
93 xFramePS
.getPropertyValue("DispatchRecorderSupplier"));
96 Object oDRS
= ((XMultiServiceFactory
)Param
.getMSF()).createInstance(
97 "com.sun.star.comp.framework.DispatchRecorderSupplier");
98 xFramePS
.setPropertyValue("DispatchRecorderSupplier", oDRS
);
99 xDRS
= UnoRuntime
.queryInterface(XDispatchRecorderSupplier
.class,oDRS
);
102 xDR
= xDRS
.getDispatchRecorder();
106 oObj
= (XInterface
)((XMultiServiceFactory
)Param
.getMSF()).createInstance(
107 "com.sun.star.comp.framework.DispatchRecorder");
108 xDR
= UnoRuntime
.queryInterface
109 (XDispatchRecorder
.class, oObj
);
110 xDRS
.setDispatchRecorder(xDR
);
112 } catch (com
.sun
.star
.uno
.Exception e
) {
113 throw new StatusException("Can't create component", e
);
117 // fill recorder with content. It's needed for XIndexReplace
118 URL dispURL
= utils
.parseURL((XMultiServiceFactory
) Param
.getMSF(), ".uno:InsertDateField");
119 PropertyValue prop
= new PropertyValue();
121 prop
.Value
= "XDispatchRecorder.recordDispatch()";
122 PropertyValue
[] dispArgs
= new PropertyValue
[] {prop
};
123 xDR
.recordDispatch(dispURL
, dispArgs
);
126 TestEnvironment tEnv
= new TestEnvironment( oObj
);
128 // INSTANCEn : _XIndexReplace
129 log
.println("adding INSTANCEn as obj relation to environment");
132 if (Param
.get("THRCNT")!= null) {
133 THRCNT
= Integer
.parseInt((String
) Param
.get("THRCNT"));
136 URL instanceURL
= null;
137 DispatchStatement instance
= new DispatchStatement();
138 PropertyValue dispProp
= new PropertyValue();
140 for (int n
= 1; n
< (THRCNT
+ 1); n
++) {
141 log
.println("adding INSTANCE" + n
+
142 " as obj relation to environment");
143 instanceURL
= utils
.parseURL((XMultiServiceFactory
) Param
.getMSF(), ".uno:InsertText");
144 dispProp
.Name
= "Text";
145 dispProp
.Value
= "Instance " + n
;
146 dispArgs
= new PropertyValue
[] {dispProp
};
147 instance
.aCommand
= instanceURL
.Complete
;
148 instance
.aArgs
= dispArgs
;
149 instance
.aTarget
= "_top";
150 instance
.nFlags
= com
.sun
.star
.frame
.FrameSearchFlag
.ALL
;
152 tEnv
.addObjRelation("INSTANCE" + n
, instance
);
155 tEnv
.addObjRelation("XDispatchRecorder.Frame", xFrame
);
156 log
.println("Object created: TRUE");
158 } // finish method getTestEnvironment
160 protected void cleanup( TestParameters Param
, PrintWriter log
) {
161 util
.DesktopTools
.closeDoc(oDoc
);