tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OFormattedControl.java
blob11793b31d320e40cf6ea7c33109c0e353db8ed6a
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.TestCase;
23 import lib.TestEnvironment;
24 import lib.TestParameters;
25 import util.FormTools;
26 import util.SOfficeFactory;
27 import util.WriterTools;
29 import com.sun.star.awt.XControlModel;
30 import com.sun.star.awt.XDevice;
31 import com.sun.star.awt.XGraphics;
32 import com.sun.star.awt.XTextComponent;
33 import com.sun.star.awt.XToolkit;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.awt.XWindowPeer;
36 import com.sun.star.drawing.XControlShape;
37 import com.sun.star.text.XTextDocument;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 import com.sun.star.util.XCloseable;
41 import com.sun.star.view.XControlAccess;
44 /**
45 * Test for object which is represented by default controller
46 * of the <code>com.sun.star.form.component.FormattedField</code>
47 * component. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>com::sun::star::awt::XView</code></li>
52 * <li> <code>com::sun::star::form::XBoundControl</code></li>
53 * <li> <code>com::sun::star::awt::XControl</code></li>
54 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
55 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
56 * <li> <code>com::sun::star::awt::XTextListener</code></li>
57 * <li> <code>com::sun::star::awt::XWindow</code></li>
58 * <li> <code>com::sun::star::lang::XComponent</code></li>
59 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
60 * <li> <code>com::sun::star::lang::XEventListener</code></li>
61 * </ul> <p>
62 * This object test <b> is NOT </b> designed to be run in several
63 * threads concurrently.
65 * @see com.sun.star.awt.XView
66 * @see com.sun.star.form.XBoundControl
67 * @see com.sun.star.awt.XControl
68 * @see com.sun.star.awt.XTextComponent
69 * @see com.sun.star.awt.XLayoutConstrains
70 * @see com.sun.star.awt.XTextListener
71 * @see com.sun.star.awt.XWindow
72 * @see com.sun.star.lang.XComponent
73 * @see com.sun.star.awt.XTextLayoutConstrains
74 * @see com.sun.star.lang.XEventListener
75 * @see ifc.awt._XView
76 * @see ifc.form._XBoundControl
77 * @see ifc.awt._XControl
78 * @see ifc.awt._XTextComponent
79 * @see ifc.awt._XLayoutConstrains
80 * @see ifc.awt._XTextListener
81 * @see ifc.awt._XWindow
82 * @see ifc.lang._XComponent
83 * @see ifc.awt._XTextLayoutConstrains
84 * @see ifc.lang._XEventListener
86 public class OFormattedControl extends TestCase {
87 XTextDocument xTextDoc;
89 /**
90 * Creates a new text document.
92 @Override
93 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
94 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());
96 log.println("creating a textdocument");
97 xTextDoc = SOF.createTextDoc(null);
101 * Disposes the text document created before
103 @Override
104 protected void cleanup(TestParameters tParam, PrintWriter log) {
105 log.println(" disposing xTextDoc ");
107 try {
108 XCloseable closer = UnoRuntime.queryInterface(
109 XCloseable.class, xTextDoc);
110 closer.close(true);
111 } catch (com.sun.star.util.CloseVetoException e) {
112 log.println("couldn't close document");
113 } catch (com.sun.star.lang.DisposedException e) {
114 log.println("couldn't close document");
119 * Creates two components and inserts them to the form of
120 * text document. One component
121 * (<code>com.sun.star.form.component.FormattedField</code>) is created
122 * for testing, another to be passed as relation. Using a controller
123 * of the text document the controller of the first component is
124 * obtained and returned in environment as a test object. <p>
126 * Object relations created :
127 * <ul>
128 * <li> <code>'GRAPHICS'</code> for
129 * {@link ifc.awt._XView} : a graphics component
130 * created using screen device of the window peer of
131 * the controller tested. </li>
132 * <li> <code>'CONTEXT'</code> for
133 * {@link ifc.awt._XControl} : the text document
134 * where the component is inserted. </li>
135 * <li> <code>'WINPEER'</code> for
136 * {@link ifc.awt._XControl} : Window peer of the
137 * controller tested. </li>
138 * <li> <code>'TOOLKIT'</code> for
139 * {@link ifc.awt._XControl} : toolkit of the component.</li>
140 * <li> <code>'MODEL'</code> for
141 * {@link ifc.awt._XControl} : the model of the controller.</li>
142 * <li> <code>'XWindow.AnotherWindow'</code> for
143 * {@link ifc.awt._XWindow} : the controller of another
144 * component. </li>
145 * </ul>
147 @Override
148 protected TestEnvironment createTestEnvironment(TestParameters Param,
149 PrintWriter log) throws Exception {
150 XInterface oObj = null;
151 Object anotherCtrl = null;
152 XWindowPeer the_win = null;
153 XToolkit the_kit = null;
154 XDevice aDevice = null;
155 XGraphics aGraphic = null;
157 //Insert a ControlShape and get the ControlModel
158 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
159 4500, 15000, 10000,
160 "FormattedField");
162 WriterTools.getDrawPage(xTextDoc).add(aShape);
164 XControlModel the_Model = aShape.getControl();
166 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
167 4500, 5000, 10000,
168 "TextField");
170 WriterTools.getDrawPage(xTextDoc).add(aShape2);
172 XControlModel the_Model2 = aShape2.getControl();
174 //Try to query XControlAccess
175 XControlAccess the_access = UnoRuntime.queryInterface(
176 XControlAccess.class,
177 xTextDoc.getCurrentController());
179 //now get the OFormattedControl
180 oObj = the_access.getControl(the_Model);
181 anotherCtrl = the_access.getControl(the_Model2);
182 the_win = the_access.getControl(the_Model).getPeer();
183 the_kit = the_win.getToolkit();
184 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
185 aGraphic = aDevice.createGraphics();
187 log.println("creating a new environment for OFormattedControl object");
189 TestEnvironment tEnv = new TestEnvironment(oObj);
192 //Adding ObjRelation for XView
193 tEnv.addObjRelation("GRAPHICS", aGraphic);
196 //Adding ObjRelation for XControl
197 tEnv.addObjRelation("CONTEXT", xTextDoc);
198 tEnv.addObjRelation("WINPEER", the_win);
199 tEnv.addObjRelation("TOOLKIT", the_kit);
200 tEnv.addObjRelation("MODEL", the_Model);
202 // Adding relation for XWindow
203 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
204 anotherCtrl);
206 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
207 tEnv.addObjRelation("XWindow.ControlShape", aShape);
209 // Adding relation for XTextListener
210 ifc.awt._XTextListener.TestTextListener listener =
211 new ifc.awt._XTextListener.TestTextListener();
212 XTextComponent textComp = UnoRuntime.queryInterface(
213 XTextComponent.class, oObj);
214 textComp.addTextListener(listener);
215 tEnv.addObjRelation("TestTextListener", listener);
217 return tEnv;
218 } // finish method getTestEnvironment
219 } // finish class OFormattedControl