bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OFormattedControl.java
blobe76ada4407ce308a48044e162ff8afa53dbf3e41
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.XControlModel;
31 import com.sun.star.awt.XDevice;
32 import com.sun.star.awt.XGraphics;
33 import com.sun.star.awt.XTextComponent;
34 import com.sun.star.awt.XToolkit;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.awt.XWindowPeer;
37 import com.sun.star.drawing.XControlShape;
38 import com.sun.star.lang.XMultiServiceFactory;
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.FormattedField</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::awt::XWindow</code></li>
60 * <li> <code>com::sun::star::lang::XComponent</code></li>
61 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
62 * <li> <code>com::sun::star::lang::XEventListener</code></li>
63 * </ul> <p>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
67 * @see com.sun.star.awt.XView
68 * @see com.sun.star.form.XBoundControl
69 * @see com.sun.star.awt.XControl
70 * @see com.sun.star.awt.XTextComponent
71 * @see com.sun.star.awt.XLayoutConstrains
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._XTextListener
83 * @see ifc.awt._XWindow
84 * @see ifc.lang._XComponent
85 * @see ifc.awt._XTextLayoutConstrains
86 * @see ifc.lang._XEventListener
88 public class OFormattedControl extends TestCase {
89 XTextDocument xTextDoc;
91 /**
92 * Creates a new text document.
94 protected void initialize(TestParameters Param, PrintWriter log) {
95 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
97 try {
98 log.println("creating a textdocument");
99 xTextDoc = SOF.createTextDoc(null);
100 } catch (com.sun.star.uno.Exception e) {
101 // Some exception occurs.FAILED
102 e.printStackTrace(log);
103 throw new StatusException("Couldn't create document", e);
108 * Disposes the text document created before
110 protected void cleanup(TestParameters tParam, PrintWriter log) {
111 log.println(" disposing xTextDoc ");
113 try {
114 XCloseable closer = UnoRuntime.queryInterface(
115 XCloseable.class, xTextDoc);
116 closer.close(true);
117 } catch (com.sun.star.util.CloseVetoException e) {
118 log.println("couldn't close document");
119 } catch (com.sun.star.lang.DisposedException e) {
120 log.println("couldn't close document");
125 * Creates two components and inserts them to the form of
126 * text document. One component
127 * (<code>com.sun.star.form.component.FormattedField</code>) is created
128 * for testing, another to be passed as relation. Using a controller
129 * of the text document the controller of the first component is
130 * obtained and returned in environment as a test object. <p>
132 * Object relations created :
133 * <ul>
134 * <li> <code>'GRAPHICS'</code> for
135 * {@link ifc.awt._XView} : a graphics component
136 * created using screen device of the window peer of
137 * the controller tested. </li>
138 * <li> <code>'CONTEXT'</code> for
139 * {@link ifc.awt._XControl} : the text document
140 * where the component is inserted. </li>
141 * <li> <code>'WINPEER'</code> for
142 * {@link ifc.awt._XControl} : Window peer of the
143 * controller tested. </li>
144 * <li> <code>'TOOLKIT'</code> for
145 * {@link ifc.awt._XControl} : toolkit of the component.</li>
146 * <li> <code>'MODEL'</code> for
147 * {@link ifc.awt._XControl} : the model of the controller.</li>
148 * <li> <code>'XWindow.AnotherWindow'</code> for
149 * {@link ifc.awt._XWindow} : the controller of another
150 * component. </li>
151 * </ul>
153 protected TestEnvironment createTestEnvironment(TestParameters Param,
154 PrintWriter log) {
155 XInterface oObj = null;
156 Object anotherCtrl = null;
157 XWindowPeer the_win = null;
158 XToolkit the_kit = null;
159 XDevice aDevice = null;
160 XGraphics aGraphic = null;
162 //Insert a ControlShape and get the ControlModel
163 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
164 4500, 15000, 10000,
165 "FormattedField");
167 WriterTools.getDrawPage(xTextDoc).add(aShape);
169 XControlModel the_Model = aShape.getControl();
171 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
172 4500, 5000, 10000,
173 "TextField");
175 WriterTools.getDrawPage(xTextDoc).add(aShape2);
177 XControlModel the_Model2 = aShape2.getControl();
179 //Try to query XControlAccess
180 XControlAccess the_access = UnoRuntime.queryInterface(
181 XControlAccess.class,
182 xTextDoc.getCurrentController());
184 //now get the OFormattedControl
185 try {
186 oObj = the_access.getControl(the_Model);
187 anotherCtrl = the_access.getControl(the_Model2);
188 the_win = the_access.getControl(the_Model).getPeer();
189 the_kit = the_win.getToolkit();
190 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
191 aGraphic = aDevice.createGraphics();
192 } catch (com.sun.star.container.NoSuchElementException e) {
193 log.println("Couldn't get OFormattedControl");
194 e.printStackTrace(log);
195 throw new StatusException("Couldn't get OFormattedControl", e);
198 log.println("creating a new environment for OFormattedControl object");
200 TestEnvironment tEnv = new TestEnvironment(oObj);
203 //Adding ObjRelation for XView
204 tEnv.addObjRelation("GRAPHICS", aGraphic);
207 //Adding ObjRelation for XControl
208 tEnv.addObjRelation("CONTEXT", xTextDoc);
209 tEnv.addObjRelation("WINPEER", the_win);
210 tEnv.addObjRelation("TOOLKIT", the_kit);
211 tEnv.addObjRelation("MODEL", the_Model);
213 // Adding relation for XWindow
214 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
215 anotherCtrl);
217 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
218 tEnv.addObjRelation("XWindow.ControlShape", aShape);
220 // Adding relation for XTextListener
221 ifc.awt._XTextListener.TestTextListener listener =
222 new ifc.awt._XTextListener.TestTextListener();
223 XTextComponent textComp = UnoRuntime.queryInterface(
224 XTextComponent.class, oObj);
225 textComp.addTextListener(listener);
226 tEnv.addObjRelation("TestTextListener", listener);
228 return tEnv;
229 } // finish method getTestEnvironment
230 } // finish class OFormattedControl