tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ONumericControl.java
blob843e5c8a9f3f590dfa46014e5fbce085af66be8d
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.NumericField</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::XNumericField</code></li>
57 * <li> <code>com::sun::star::awt::XTextListener</code></li>
58 * <li> <code>com::sun::star::awt::XWindow</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
61 * <li> <code>com::sun::star::lang::XEventListener</code></li>
62 * </ul> <p>
63 * This object test <b> is NOT </b> designed to be run in several
64 * threads concurrently.
66 * @see com.sun.star.awt.XView
67 * @see com.sun.star.form.XBoundControl
68 * @see com.sun.star.awt.XControl
69 * @see com.sun.star.awt.XTextComponent
70 * @see com.sun.star.awt.XLayoutConstrains
71 * @see com.sun.star.awt.XNumericField
72 * @see com.sun.star.awt.XTextListener
73 * @see com.sun.star.awt.XWindow
74 * @see com.sun.star.lang.XComponent
75 * @see com.sun.star.awt.XTextLayoutConstrains
76 * @see com.sun.star.lang.XEventListener
77 * @see ifc.awt._XView
78 * @see ifc.form._XBoundControl
79 * @see ifc.awt._XControl
80 * @see ifc.awt._XTextComponent
81 * @see ifc.awt._XLayoutConstrains
82 * @see ifc.awt._XNumericField
83 * @see ifc.awt._XTextListener
84 * @see ifc.awt._XWindow
85 * @see ifc.lang._XComponent
86 * @see ifc.awt._XTextLayoutConstrains
87 * @see ifc.lang._XEventListener
89 public class ONumericControl extends TestCase {
90 XTextDocument xTextDoc;
92 /**
93 * Creates a new text document.
95 @Override
96 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
97 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());
99 log.println("creating a textdocument");
100 xTextDoc = SOF.createTextDoc(null);
104 * Disposes the text document created before
106 @Override
107 protected void cleanup(TestParameters tParam, PrintWriter log) {
108 log.println(" disposing xTextDoc ");
110 try {
111 XCloseable closer = UnoRuntime.queryInterface(
112 XCloseable.class, xTextDoc);
113 closer.close(true);
114 } catch (com.sun.star.util.CloseVetoException e) {
115 log.println("couldn't close document");
116 } catch (com.sun.star.lang.DisposedException e) {
117 log.println("couldn't close document");
122 * Creates two components and inserts them to the form of
123 * text document. One component
124 * (<code>com.sun.star.form.component.NumericField</code>) is created
125 * for testing, another to be passed as relation. Using a controller
126 * of the text document the controller of the first component is
127 * obtained and returned in environment as a test object. <p>
129 * Object relations created :
130 * <ul>
131 * <li> <code>'GRAPHICS'</code> for
132 * {@link ifc.awt._XView} : a graphics component
133 * created using screen device of the window peer of
134 * the controller tested. </li>
135 * <li> <code>'CONTEXT'</code> for
136 * {@link ifc.awt._XControl} : the text document
137 * where the component is inserted. </li>
138 * <li> <code>'WINPEER'</code> for
139 * {@link ifc.awt._XControl} : Window peer of the
140 * controller tested. </li>
141 * <li> <code>'TOOLKIT'</code> for
142 * {@link ifc.awt._XControl} : toolkit of the component.</li>
143 * <li> <code>'MODEL'</code> for
144 * {@link ifc.awt._XControl} : the model of the controller.</li>
145 * <li> <code>'XWindow.AnotherWindow'</code> for
146 * {@link ifc.awt._XWindow} : the controller of another
147 * component. </li>
148 * </ul>
150 @Override
151 protected TestEnvironment createTestEnvironment(TestParameters Param,
152 PrintWriter log) throws Exception {
153 XInterface oObj = null;
154 Object anotherCtrl = null;
155 XWindowPeer the_win = null;
156 XToolkit the_kit = null;
157 XDevice aDevice = null;
158 XGraphics aGraphic = null;
160 //Insert a ControlShape and get the ControlModel
161 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
162 4500, 15000, 10000,
163 "NumericField");
165 WriterTools.getDrawPage(xTextDoc).add(aShape);
167 XControlModel the_Model = aShape.getControl();
169 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
170 4500, 5000, 10000,
171 "TextField");
173 WriterTools.getDrawPage(xTextDoc).add(aShape2);
175 XControlModel the_Model2 = aShape2.getControl();
177 //Try to query XControlAccess
178 XControlAccess the_access = UnoRuntime.queryInterface(
179 XControlAccess.class,
180 xTextDoc.getCurrentController());
182 //now get the ONumericControl
183 oObj = the_access.getControl(the_Model);
184 anotherCtrl = the_access.getControl(the_Model2);
185 the_win = the_access.getControl(the_Model).getPeer();
186 the_kit = the_win.getToolkit();
187 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
188 aGraphic = aDevice.createGraphics();
190 log.println("creating a new environment for ONumericControl object");
192 TestEnvironment tEnv = new TestEnvironment(oObj);
195 //Adding ObjRelation for XView
196 tEnv.addObjRelation("GRAPHICS", aGraphic);
199 //Adding ObjRelation for XControl
200 tEnv.addObjRelation("CONTEXT", xTextDoc);
201 tEnv.addObjRelation("WINPEER", the_win);
202 tEnv.addObjRelation("TOOLKIT", the_kit);
203 tEnv.addObjRelation("MODEL", the_Model);
205 // Adding relation for XWindow
206 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
207 anotherCtrl);
209 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
210 tEnv.addObjRelation("XWindow.ControlShape", aShape);
212 // Adding relation for XTextListener
213 ifc.awt._XTextListener.TestTextListener listener =
214 new ifc.awt._XTextListener.TestTextListener();
215 XTextComponent textComp = UnoRuntime.queryInterface(
216 XTextComponent.class, oObj);
217 textComp.addTextListener(listener);
218 tEnv.addObjRelation("TestTextListener", listener);
220 tEnv.addObjRelation("XTextComponent.onlyNumbers", Boolean.TRUE);
222 return tEnv;
223 } // finish method getTestEnvironment
224 } // finish class ONumericControl