bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OEditControl.java
blob18ab08bcf517a086025306f39ba5a8ccb4a07e80
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 .
18 package mod._forms;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.FormTools;
27 import util.SOfficeFactory;
28 import util.WriterTools;
30 import com.sun.star.awt.XControl;
31 import com.sun.star.awt.XControlModel;
32 import com.sun.star.awt.XDevice;
33 import com.sun.star.awt.XGraphics;
34 import com.sun.star.awt.XTextComponent;
35 import com.sun.star.awt.XToolkit;
36 import com.sun.star.awt.XWindow;
37 import com.sun.star.awt.XWindowPeer;
38 import com.sun.star.drawing.XControlShape;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.util.XCloseable;
43 import com.sun.star.view.XControlAccess;
46 /**
47 * Test for object which is represented by default controller
48 * of the <code>com.sun.star.form.component.TextField</code>
49 * component. <p>
51 * Object implements the following interfaces :
52 * <ul>
53 * <li> <code>com::sun::star::awt::XView</code></li>
54 * <li> <code>com::sun::star::form::XBoundControl</code></li>
55 * <li> <code>com::sun::star::awt::XControl</code></li>
56 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
57 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
58 * <li> <code>com::sun::star::awt::XTextListener</code></li>
59 * <li> <code>com::sun::star::form::XChangeBroadcaster</code></li>
60 * <li> <code>com::sun::star::awt::XWindow</code></li>
61 * <li> <code>com::sun::star::lang::XComponent</code></li>
62 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
63 * <li> <code>com::sun::star::lang::XEventListener</code></li>
64 * </ul> <p>
65 * This object test <b> is NOT </b> designed to be run in several
66 * threads concurently.
68 * @see com.sun.star.awt.XView
69 * @see com.sun.star.form.XBoundControl
70 * @see com.sun.star.awt.XControl
71 * @see com.sun.star.awt.XTextComponent
72 * @see com.sun.star.awt.XLayoutConstrains
73 * @see com.sun.star.awt.XTextListener
74 * @see com.sun.star.form.XChangeBroadcaster
75 * @see com.sun.star.awt.XWindow
76 * @see com.sun.star.lang.XComponent
77 * @see com.sun.star.awt.XTextLayoutConstrains
78 * @see com.sun.star.lang.XEventListener
79 * @see ifc.awt._XView
80 * @see ifc.form._XBoundControl
81 * @see ifc.awt._XControl
82 * @see ifc.awt._XTextComponent
83 * @see ifc.awt._XLayoutConstrains
84 * @see ifc.awt._XTextListener
85 * @see ifc.form._XChangeBroadcaster
86 * @see ifc.awt._XWindow
87 * @see ifc.lang._XComponent
88 * @see ifc.awt._XTextLayoutConstrains
89 * @see ifc.lang._XEventListener
91 public class OEditControl extends TestCase {
92 XTextDocument xTextDoc;
94 /**
95 * Creates a new text document.
97 @Override
98 protected void initialize(TestParameters Param, PrintWriter log) {
99 SOfficeFactory SOF = SOfficeFactory.getFactory((Param.getMSF()));
101 try {
102 log.println("creating a textdocument");
103 xTextDoc = SOF.createTextDoc(null);
104 } catch (com.sun.star.uno.Exception e) {
105 // Some exception occurs.FAILED
106 e.printStackTrace(log);
107 throw new StatusException("Couldn't create document", e);
112 * Disposes the text document created before
114 @Override
115 protected void cleanup(TestParameters tParam, PrintWriter log) {
116 log.println(" disposing xTextDoc ");
118 try {
119 XCloseable closer = UnoRuntime.queryInterface(
120 XCloseable.class, xTextDoc);
121 closer.close(true);
122 } catch (com.sun.star.util.CloseVetoException e) {
123 log.println("couldn't close document");
124 } catch (com.sun.star.lang.DisposedException e) {
125 log.println("couldn't close document");
130 * Creates two components and inserts them to the form of
131 * text document. One component
132 * (<code>com.sun.star.form.component.TextField</code>) is created
133 * for testing, another to be passed as relation. Using a controller
134 * of the text document the controller of the first component is
135 * obtained and returned in environment as a test object. <p>
137 * Object relations created :
138 * <ul>
139 * <li> <code>'GRAPHICS'</code> for
140 * {@link ifc.awt._XView} : a graphics component
141 * created using screen device of the window peer of
142 * the controller tested. </li>
143 * <li> <code>'CONTEXT'</code> for
144 * {@link ifc.awt._XControl} : the text document
145 * where the component is inserted. </li>
146 * <li> <code>'WINPEER'</code> for
147 * {@link ifc.awt._XControl} : Window peer of the
148 * controller tested. </li>
149 * <li> <code>'TOOLKIT'</code> for
150 * {@link ifc.awt._XControl} : toolkit of the component.</li>
151 * <li> <code>'MODEL'</code> for
152 * {@link ifc.awt._XControl} : the model of the controller.</li>
153 * <li> <code>'XWindow.AnotherWindow'</code> for
154 * {@link ifc.awt._XWindow} : the controller of another
155 * component. </li>
156 * <li> <code>'Win1'</code> for
157 * {@link ifc.form._XChangeBroadcaster} : the window (controller)
158 * of the tested component. </li>
159 * <li> <code>'Win2'</code> for
160 * {@link ifc.form._XChangeBroadcaster} : the window (controller)
161 * of another component. </li>
162 * <li> <code>'CONTROL'</code> for
163 * {@link ifc.form._XChangeBroadcaster} : the controller
164 * of another component. </li>
165 * </ul>
167 @Override
168 protected TestEnvironment createTestEnvironment(TestParameters Param,
169 PrintWriter log) {
170 XInterface oObj = null;
171 XControl aControl = null;
172 XWindowPeer the_win = null;
173 XToolkit the_kit = null;
174 XDevice aDevice = null;
175 XGraphics aGraphic = null;
177 //Insert a ControlShape and get the ControlModel
178 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
179 4500, 15000, 10000,
180 "TextField");
182 WriterTools.getDrawPage(xTextDoc).add(aShape);
184 XControlModel the_Model = aShape.getControl();
186 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
187 4500, 5000, 10000,
188 "TextField");
190 WriterTools.getDrawPage(xTextDoc).add(aShape2);
192 XControlModel the_Model2 = aShape2.getControl();
194 //Try to query XControlAccess
195 XControlAccess the_access = UnoRuntime.queryInterface(
196 XControlAccess.class,
197 xTextDoc.getCurrentController());
199 //now get the OEditControl
200 try {
201 oObj = the_access.getControl(the_Model);
202 aControl = the_access.getControl(the_Model2);
203 the_win = the_access.getControl(the_Model).getPeer();
204 the_kit = the_win.getToolkit();
205 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
206 aGraphic = aDevice.createGraphics();
207 } catch (com.sun.star.container.NoSuchElementException e) {
208 log.println("Couldn't get OEditControl");
209 e.printStackTrace(log);
210 throw new StatusException("Couldn't get OEditControl", e);
213 log.println("creating a new environment for OEditControl object");
215 TestEnvironment tEnv = new TestEnvironment(oObj);
218 //Adding ObjRelation for XView
219 tEnv.addObjRelation("GRAPHICS", aGraphic);
222 //Adding ObjRelation for XControl
223 tEnv.addObjRelation("CONTEXT", xTextDoc);
224 tEnv.addObjRelation("WINPEER", the_win);
225 tEnv.addObjRelation("TOOLKIT", the_kit);
226 tEnv.addObjRelation("MODEL", the_Model);
228 // relations for XChangeBroadcaster
229 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
230 aControl);
232 tEnv.addObjRelation("Win1",
233 UnoRuntime.queryInterface(XWindow.class,
234 oObj));
235 tEnv.addObjRelation("Win2", forObjRel);
236 tEnv.addObjRelation("CONTROL", aControl);
239 // relation for XWindow
240 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
241 tEnv.addObjRelation("XWindow.ControlShape", aShape);
243 // Adding relation for XTextListener
244 ifc.awt._XTextListener.TestTextListener listener =
245 new ifc.awt._XTextListener.TestTextListener();
246 XTextComponent textComp = UnoRuntime.queryInterface(
247 XTextComponent.class, oObj);
248 textComp.addTextListener(listener);
249 tEnv.addObjRelation("TestTextListener", listener);
251 return tEnv;
252 } // finish method getTestEnvironment
253 } // finish class OEditControl