Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / DispatchRecorder.java
blobd155c4c665252b2b3ca75c77263582349f64e80e
1 /*
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 .
19 package mod._fwk;
21 import com.sun.star.beans.PropertyValue;
22 import com.sun.star.frame.XModel;
23 import java.io.PrintWriter;
25 import lib.StatusException;
26 import lib.TestCase;
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;
42 import util.utils;
44 /**
45 * Test for object that implements the following interfaces :
46 * <ul>
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>
51 * </ul><p>
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;
64 /**
65 * Creating a Testenvironment for the interfaces to be tested.
66 * Creates service <code>com.sun.star.frame.Desktop</code>.
68 @Override
69 public TestEnvironment createTestEnvironment( TestParameters Param,
70 PrintWriter log ) throws StatusException {
72 XInterface oObj = null;
73 XFrame xFrame = null;
74 XDispatchRecorder xDR = null;
76 try {
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"));
90 if (xDRS == null) {
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();
99 if (xDR != null) {
100 oObj = xDR;
101 } else {
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();
116 prop.Name = "Text";
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");
127 int THRCNT = 1;
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");
153 return tEnv;
154 } // finish method getTestEnvironment
156 @Override
157 protected void cleanup( TestParameters Param, PrintWriter log) {
158 util.DesktopTools.closeDoc(oDoc);